[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] | e7ca289 | 2012-09-01 00:52:15 | [diff] [blame] | 15 | #include "base/debug/trace_event.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 16 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 17 | #include "base/lazy_instance.h" |
[email protected] | cffd752 | 2012-10-23 19:10:58 | [diff] [blame] | 18 | #include "base/memory/scoped_ptr.h" |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 19 | #include "base/message_loop_proxy.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 20 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 21 | #include "base/path_service.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 22 | #include "base/process_util.h" |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 23 | #include "base/string_number_conversions.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | #include "base/string_util.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 25 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 26 | #include "base/strings/string_split.h" |
[email protected] | 40d11e0 | 2013-03-28 17:43:14 | [diff] [blame] | 27 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 28 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 29 | #include "base/utf_string_conversions.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 30 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 31 | #include "content/common/child_thread.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 32 | #include "content/common/clipboard_messages.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 33 | #include "content/common/database_messages.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 34 | #include "content/common/drag_messages.h" |
[email protected] | 16dd6e2 | 2012-03-01 19:08:20 | [diff] [blame] | 35 | #include "content/common/fileapi/file_system_dispatcher.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 36 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 37 | #include "content/common/input_messages.h" |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 38 | #include "content/common/java_bridge_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 39 | #include "content/common/pepper_messages.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 40 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 41 | #include "content/common/quota_dispatcher.h" |
[email protected] | 940895b | 2011-08-20 00:50:05 | [diff] [blame] | 42 | #include "content/common/request_extra_data.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 43 | #include "content/common/socket_stream_handle_data.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 44 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 45 | #include "content/common/view_messages.h" |
[email protected] | 4e1eb339 | 2012-05-18 00:08:05 | [diff] [blame] | 46 | #include "content/common/webmessageportchannel_impl.h" |
[email protected] | 61d271f3 | 2013-05-28 04:59:23 | [diff] [blame] | 47 | #include "content/common_child/fileapi/webfilesystem_callback_adapters.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 48 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 49 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 50 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 51 | #include "content/public/common/content_switches.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 52 | #include "content/public/common/context_menu_params.h" |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 53 | #include "content/public/common/favicon_url.h" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 54 | #include "content/public/common/file_chooser_params.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 55 | #include "content/public/common/ssl_status.h" |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 56 | #include "content/public/common/three_d_api_types.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 57 | #include "content/public/common/url_constants.h" |
[email protected] | 3b366ae | 2013-05-17 21:16:58 | [diff] [blame] | 58 | #include "content/public/common/url_utils.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 59 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 97f5813 | 2012-11-15 20:41:32 | [diff] [blame] | 60 | #include "content/public/renderer/context_menu_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 61 | #include "content/public/renderer/document_state.h" |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 62 | #include "content/public/renderer/history_item_serialization.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 63 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 64 | #include "content/public/renderer/password_form_conversion_utils.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 65 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 66 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 4e4646a5 | 2013-02-08 07:23:41 | [diff] [blame] | 67 | #include "content/renderer/accessibility/renderer_accessibility.h" |
| 68 | #include "content/renderer/accessibility/renderer_accessibility_complete.h" |
| 69 | #include "content/renderer/accessibility/renderer_accessibility_focus_only.h" |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 70 | #include "content/renderer/browser_plugin/browser_plugin.h" |
| 71 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 72 | #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
[email protected] | 3175fea | 2013-05-16 10:57:48 | [diff] [blame] | 73 | #include "content/renderer/context_menu_params_builder.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 74 | #include "content/renderer/device_orientation_dispatcher.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 75 | #include "content/renderer/devtools/devtools_agent.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 76 | #include "content/renderer/disambiguation_popup_helper.h" |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 77 | #include "content/renderer/dom_automation_controller.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 78 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 79 | #include "content/renderer/external_popup_menu.h" |
[email protected] | f8c700ba | 2013-05-14 08:25:49 | [diff] [blame] | 80 | #include "content/renderer/fetchers/alt_error_page_resource_fetcher.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 81 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 82 | #include "content/renderer/gpu/input_handler_manager.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 83 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 84 | #include "content/renderer/idle_user_detector.h" |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 85 | #include "content/renderer/image_loading_helper.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 86 | #include "content/renderer/ime_event_guard.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 87 | #include "content/renderer/input_tag_speech_dispatcher.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 88 | #include "content/renderer/internal_document_state_data.h" |
[email protected] | 0716190 | 2011-11-11 09:57:42 | [diff] [blame] | 89 | #include "content/renderer/java/java_bridge_dispatcher.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 90 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 91 | #include "content/renderer/media/audio_device_factory.h" |
| 92 | #include "content/renderer/media/audio_renderer_mixer_manager.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 93 | #include "content/renderer/media/media_stream_dependency_factory.h" |
| 94 | #include "content/renderer/media/media_stream_dispatcher.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 95 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 96 | #include "content/renderer/media/render_media_log.h" |
[email protected] | 6048d51 | 2012-01-28 03:14:48 | [diff] [blame] | 97 | #include "content/renderer/media/renderer_gpu_video_decoder_factories.h" |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 98 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 99 | #include "content/renderer/media/video_capture_impl_manager.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 100 | #include "content/renderer/mhtml_generator.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 101 | #include "content/renderer/notification_provider.h" |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 102 | #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 103 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame^] | 104 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 105 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 106 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 107 | #include "content/renderer/render_view_impl_params.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 108 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 109 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 110 | #include "content/renderer/renderer_date_time_picker.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 111 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 112 | #include "content/renderer/renderer_webcolorchooser_impl.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 113 | #include "content/renderer/savable_resources.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 114 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 115 | #include "content/renderer/stats_collection_controller.h" |
| 116 | #include "content/renderer/stats_collection_observer.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 117 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 118 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 119 | #include "content/renderer/web_ui_extension.h" |
| 120 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 121 | #include "content/renderer/webplugin_delegate_proxy.h" |
| 122 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 123 | #include "media/audio/audio_output_device.h" |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 124 | #include "media/base/audio_renderer_mixer_input.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 125 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 126 | #include "media/base/media_switches.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 127 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 128 | #include "media/filters/gpu_video_decoder.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 129 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 130 | #include "net/base/escape.h" |
| 131 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 132 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 133 | #include "net/http/http_util.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 134 | #include "third_party/WebKit/public/platform/WebCString.h" |
| 135 | #include "third_party/WebKit/public/platform/WebDragData.h" |
| 136 | #include "third_party/WebKit/public/platform/WebFileSystemType.h" |
| 137 | #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 138 | #include "third_party/WebKit/public/platform/WebImage.h" |
| 139 | #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 140 | #include "third_party/WebKit/public/platform/WebPoint.h" |
| 141 | #include "third_party/WebKit/public/platform/WebRect.h" |
| 142 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 143 | #include "third_party/WebKit/public/platform/WebSocketStreamHandle.h" |
| 144 | #include "third_party/WebKit/public/platform/WebString.h" |
| 145 | #include "third_party/WebKit/public/platform/WebURL.h" |
| 146 | #include "third_party/WebKit/public/platform/WebURLError.h" |
| 147 | #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 148 | #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 149 | #include "third_party/WebKit/public/platform/WebVector.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 150 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | 97516a0 | 2012-10-23 18:19:25 | [diff] [blame] | 151 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h" |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 152 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h" |
| 153 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 154 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 155 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserCompletion.h" |
| 156 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserParams.h" |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 157 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 158 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 159 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 160 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 161 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 162 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" |
| 163 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" |
| 164 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 165 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 166 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 167 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 168 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 169 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
[email protected] | 69f110d6 | 2011-03-17 19:01:14 | [diff] [blame] | 170 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h" |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 171 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 172 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 173 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 174 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 175 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 176 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 177 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h" |
| 178 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 179 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 180 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 181 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h" |
| 182 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 183 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
[email protected] | 54177cd | 2013-01-18 17:10:56 | [diff] [blame] | 184 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptValue.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 185 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 186 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h" |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 187 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserGestureIndicator.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 188 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 189 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 190 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 191 | #include "third_party/WebKit/Source/WebKit/chromium/public/default/WebRenderTheme.h" |
[email protected] | f8c700ba | 2013-05-14 08:25:49 | [diff] [blame] | 192 | #include "third_party/skia/include/core/SkBitmap.h" |
| 193 | #include "third_party/skia/include/core/SkPicture.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 194 | #include "ui/base/ui_base_switches_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 195 | #include "ui/gfx/native_widget_types.h" |
| 196 | #include "ui/gfx/point.h" |
| 197 | #include "ui/gfx/rect.h" |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 198 | #include "ui/gfx/rect_conversions.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 199 | #include "ui/gfx/size_conversions.h" |
[email protected] | 4344a3c | 2013-01-17 23:49:20 | [diff] [blame] | 200 | #include "ui/shell_dialogs/selected_file_info.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 201 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 202 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 203 | #include "webkit/base/file_path_string_conversions.h" |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 204 | #include "webkit/common/webdropdata.h" |
[email protected] | b928936b | 2012-04-13 01:16:16 | [diff] [blame] | 205 | #include "webkit/dom_storage/dom_storage_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 206 | #include "webkit/glue/webkit_glue.h" |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 207 | #include "webkit/glue/weburlresponse_extradata_impl.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 208 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 209 | #include "webkit/plugins/npapi/plugin_utils.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 210 | #include "webkit/plugins/npapi/webplugin_delegate.h" |
| 211 | #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
| 212 | #include "webkit/plugins/npapi/webplugin_impl.h" |
[email protected] | 85a37afd | 2013-05-30 22:51:15 | [diff] [blame] | 213 | #include "webkit/renderer/media/webmediaplayer_impl.h" |
| 214 | #include "webkit/renderer/media/webmediaplayer_ms.h" |
| 215 | #include "webkit/renderer/media/webmediaplayer_params.h" |
[email protected] | fab55e7 | 2013-05-31 07:06:18 | [diff] [blame] | 216 | #include "webkit/renderer/webpreferences_renderer.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 217 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 218 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 219 | #include <cpu-features.h> |
| 220 | |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 221 | #include "content/common/android/device_telephony_info.h" |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 222 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 223 | #include "content/renderer/android/address_detector.h" |
| 224 | #include "content/renderer/android/content_detector.h" |
| 225 | #include "content/renderer/android/email_detector.h" |
| 226 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | dbd3d21 | 2012-07-13 02:17:22 | [diff] [blame] | 227 | #include "content/renderer/media/stream_texture_factory_impl_android.h" |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 228 | #include "content/renderer/media/webmediaplayer_proxy_impl_android.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 229 | #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 230 | #include "third_party/WebKit/public/platform/WebFloatRect.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 231 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 232 | #include "ui/gfx/rect_f.h" |
[email protected] | 85a37afd | 2013-05-30 22:51:15 | [diff] [blame] | 233 | #include "webkit/renderer/media/android/webmediaplayer_android.h" |
| 234 | #include "webkit/renderer/media/android/webmediaplayer_manager_android.h" |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 235 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 236 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 237 | // * theming |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 238 | #include "ui/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 239 | #elif defined(USE_X11) |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 240 | #include "ui/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 241 | #elif defined(OS_MACOSX) |
| 242 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 243 | #endif |
| 244 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 245 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 246 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 247 | using WebKit::WebApplicationCacheHost; |
| 248 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 249 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 250 | using WebKit::WebColor; |
| 251 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 252 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 253 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 254 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 255 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 256 | using WebKit::WebDataSource; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 257 | using WebKit::WebDocument; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 258 | using WebKit::WebDOMEvent; |
| 259 | using WebKit::WebDOMMessageEvent; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 260 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 261 | using WebKit::WebDragOperation; |
| 262 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 263 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 264 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 265 | using WebKit::WebExternalPopupMenu; |
| 266 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 267 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 268 | using WebKit::WebFileSystem; |
| 269 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 270 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 271 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 272 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 273 | using WebKit::WebFrame; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 274 | using WebKit::WebGestureEvent; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 275 | using WebKit::WebHistoryItem; |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 276 | using WebKit::WebHTTPBody; |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 277 | using WebKit::WebIconURL; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 278 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 279 | using WebKit::WebInputElement; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 280 | using WebKit::WebInputEvent; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 281 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 282 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 283 | using WebKit::WebMediaPlayerClient; |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 284 | using WebKit::WebMouseEvent; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 285 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 286 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 287 | using WebKit::WebNode; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 288 | using WebKit::WebPageSerializer; |
| 289 | using WebKit::WebPageSerializerClient; |
[email protected] | 50da23d0 | 2012-04-13 17:47:48 | [diff] [blame] | 290 | using WebKit::WebPeerConnection00Handler; |
| 291 | using WebKit::WebPeerConnection00HandlerClient; |
| 292 | using WebKit::WebPeerConnectionHandler; |
| 293 | using WebKit::WebPeerConnectionHandlerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 294 | using WebKit::WebPlugin; |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 295 | using WebKit::WebPluginAction; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 296 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 297 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 298 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 299 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 300 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 301 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 302 | using WebKit::WebRect; |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 303 | using WebKit::WebReferrerPolicy; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 304 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 305 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 306 | using WebKit::WebSecurityOrigin; |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 307 | using WebKit::WebSecurityPolicy; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 308 | using WebKit::WebSerializedScriptValue; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 309 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 310 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 311 | using WebKit::WebSize; |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 312 | using WebKit::WebSocketStreamHandle; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 313 | using WebKit::WebStorageNamespace; |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 314 | using WebKit::WebStorageQuotaCallbacks; |
| 315 | using WebKit::WebStorageQuotaError; |
| 316 | using WebKit::WebStorageQuotaType; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 317 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 318 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 319 | using WebKit::WebTextDirection; |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 320 | using WebKit::WebTouchEvent; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 321 | using WebKit::WebURL; |
| 322 | using WebKit::WebURLError; |
| 323 | using WebKit::WebURLRequest; |
| 324 | using WebKit::WebURLResponse; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 325 | using WebKit::WebUserGestureIndicator; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 326 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 327 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 328 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 329 | using WebKit::WebWindowFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 330 | using appcache::WebApplicationCacheHostImpl; |
| 331 | using base::Time; |
| 332 | using base::TimeDelta; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 333 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 334 | using webkit_glue::WebURLResponseExtraDataImpl; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 335 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 336 | #if defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 337 | using WebKit::WebContentDetectionResult; |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 338 | using WebKit::WebFloatPoint; |
| 339 | using WebKit::WebFloatRect; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 340 | using WebKit::WebHitTestResult; |
| 341 | #endif |
| 342 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 343 | namespace content { |
| 344 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 345 | //----------------------------------------------------------------------------- |
| 346 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 347 | typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 348 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 349 | typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap; |
| 350 | static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map = |
| 351 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 352 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 353 | // Time, in seconds, we delay before sending content state changes (such as form |
| 354 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 355 | // spamming the browser. |
| 356 | // To avoid having tab/session restore require sending a message to get the |
| 357 | // current content state during tab closing we use a shorter timeout for the |
| 358 | // foreground renderer. This means there is a small window of time from which |
| 359 | // content state is modified and not sent to session restore, but this is |
| 360 | // better than having to wake up all renderers during shutdown. |
| 361 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 362 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 363 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 364 | static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 365 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 366 | // The maximum number of popups that can be spawned from one page. |
| 367 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 368 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 369 | static const float kScalingIncrement = 0.1f; |
| 370 | |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 371 | static const float kScalingIncrementForGesture = 0.01f; |
| 372 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 373 | #if defined(OS_ANDROID) |
| 374 | // Delay between tapping in content and launching the associated android intent. |
| 375 | // Used to allow users see what has been recognized as content. |
| 376 | static const size_t kContentIntentDelayMilliseconds = 700; |
| 377 | #endif |
| 378 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 379 | static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
| 380 | NULL; |
| 381 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 382 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 383 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 384 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 385 | WebVector<WebURL> urls; |
| 386 | ds->redirectChain(urls); |
| 387 | result->reserve(urls.size()); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 388 | for (size_t i = 0; i < urls.size(); ++i) { |
| 389 | if (urls[i] != GURL(kSwappedOutURL)) |
| 390 | result->push_back(urls[i]); |
| 391 | else |
| 392 | result->push_back(blank_url); |
| 393 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 396 | // If |data_source| is non-null and has an InternalDocumentStateData associated |
| 397 | // with it, the AltErrorPageResourceFetcher is reset. |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 398 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 399 | if (data_source) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 400 | InternalDocumentStateData* internal_data = |
| 401 | InternalDocumentStateData::FromDataSource(data_source); |
| 402 | if (internal_data) |
| 403 | internal_data->set_alt_error_page_fetcher(NULL); |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 407 | static bool IsReload(const ViewMsg_Navigate_Params& params) { |
| 408 | return |
| 409 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 410 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
| 411 | params.navigation_type == |
| 412 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 413 | } |
| 414 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 415 | static WebReferrerPolicy GetReferrerPolicyFromRequest( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 416 | WebFrame* frame, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 417 | const WebURLRequest& request) { |
| 418 | return request.extraData() ? |
| 419 | static_cast<RequestExtraData*>(request.extraData())->referrer_policy() : |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 420 | frame->document().referrerPolicy(); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 423 | static WebURLResponseExtraDataImpl* GetExtraDataFromResponse( |
| 424 | const WebURLResponse& response) { |
| 425 | return static_cast<WebURLResponseExtraDataImpl*>( |
| 426 | response.extraData()); |
| 427 | } |
| 428 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 429 | NOINLINE static void CrashIntentionally() { |
| 430 | // NOTE(shess): Crash directly rather than using NOTREACHED() so |
| 431 | // that the signature is easier to triage in crash reports. |
| 432 | volatile int* zero = NULL; |
| 433 | *zero = 0; |
| 434 | } |
| 435 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 436 | static void MaybeHandleDebugURL(const GURL& url) { |
| 437 | if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 438 | return; |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 439 | if (url == GURL(kChromeUICrashURL)) { |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 440 | CrashIntentionally(); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 441 | } else if (url == GURL(kChromeUIKillURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 442 | base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 443 | } else if (url == GURL(kChromeUIHangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 444 | for (;;) { |
| 445 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 446 | } |
[email protected] | 50f86bc | 2012-11-01 19:59:13 | [diff] [blame] | 447 | } else if (url == GURL(kChromeUIShorthangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 448 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 449 | } |
| 450 | } |
| 451 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 452 | // Returns false unless this is a top-level navigation. |
| 453 | static bool IsTopLevelNavigation(WebFrame* frame) { |
| 454 | return frame->parent() == NULL; |
| 455 | } |
| 456 | |
| 457 | // Returns false unless this is a top-level navigation that crosses origins. |
| 458 | static bool IsNonLocalTopLevelNavigation(const GURL& url, |
| 459 | WebFrame* frame, |
| 460 | WebNavigationType type) { |
| 461 | if (!IsTopLevelNavigation(frame)) |
| 462 | return false; |
| 463 | |
| 464 | // Navigations initiated within Webkit are not sent out to the external host |
| 465 | // in the following cases. |
| 466 | // 1. The url scheme is not http/https |
| 467 | // 2. The origin of the url and the opener is the same in which case the |
| 468 | // opener relationship is maintained. |
| 469 | // 3. Reloads/form submits/back forward navigations |
| 470 | if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) |
| 471 | return false; |
| 472 | |
| 473 | // Not interested in reloads/form submits/resubmits/back forward navigations. |
| 474 | if (type != WebKit::WebNavigationTypeReload && |
| 475 | type != WebKit::WebNavigationTypeFormSubmitted && |
| 476 | type != WebKit::WebNavigationTypeFormResubmitted && |
| 477 | type != WebKit::WebNavigationTypeBackForward) { |
| 478 | // The opener relationship between the new window and the parent allows the |
| 479 | // new window to script the parent and vice versa. This is not allowed if |
| 480 | // the origins of the two domains are different. This can be treated as a |
| 481 | // top level navigation and routed back to the host. |
| 482 | WebKit::WebFrame* opener = frame->opener(); |
| 483 | if (!opener) { |
| 484 | return true; |
| 485 | } |
| 486 | |
| 487 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 488 | return true; |
| 489 | } |
| 490 | return false; |
| 491 | } |
| 492 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 493 | static void NotifyTimezoneChange(WebKit::WebFrame* frame) { |
| 494 | v8::HandleScope handle_scope; |
| 495 | v8::Context::Scope context_scope(frame->mainWorldScriptContext()); |
| 496 | v8::Date::DateTimeConfigurationChangeNotification(); |
| 497 | WebKit::WebFrame* child = frame->firstChild(); |
| 498 | for (; child; child = child->nextSibling()) |
| 499 | NotifyTimezoneChange(child); |
| 500 | } |
| 501 | |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 502 | static WindowOpenDisposition NavigationPolicyToDisposition( |
| 503 | WebNavigationPolicy policy) { |
| 504 | switch (policy) { |
| 505 | case WebKit::WebNavigationPolicyIgnore: |
| 506 | return IGNORE_ACTION; |
| 507 | case WebKit::WebNavigationPolicyDownload: |
| 508 | return SAVE_TO_DISK; |
| 509 | case WebKit::WebNavigationPolicyCurrentTab: |
| 510 | return CURRENT_TAB; |
| 511 | case WebKit::WebNavigationPolicyNewBackgroundTab: |
| 512 | return NEW_BACKGROUND_TAB; |
| 513 | case WebKit::WebNavigationPolicyNewForegroundTab: |
| 514 | return NEW_FOREGROUND_TAB; |
| 515 | case WebKit::WebNavigationPolicyNewWindow: |
| 516 | return NEW_WINDOW; |
| 517 | case WebKit::WebNavigationPolicyNewPopup: |
| 518 | return NEW_POPUP; |
| 519 | default: |
| 520 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
| 521 | return IGNORE_ACTION; |
| 522 | } |
| 523 | } |
| 524 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 525 | // Returns true if the device scale is high enough that losing subpixel |
| 526 | // antialiasing won't have a noticeable effect on text quality. |
| 527 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 528 | #if defined(OS_ANDROID) |
| 529 | // On Android, we never have subpixel antialiasing. |
| 530 | return true; |
| 531 | #else |
| 532 | return device_scale_factor > 1.5f; |
| 533 | #endif |
| 534 | |
| 535 | } |
| 536 | |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 537 | static bool ShouldUseFixedPositionCompositing(float device_scale_factor) { |
| 538 | // Compositing for fixed-position elements is dependent on |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 539 | // device_scale_factor if no flag is set. http://crbug.com/172738 |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 540 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 541 | |
| 542 | if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition)) |
| 543 | return false; |
| 544 | |
| 545 | if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition)) |
| 546 | return true; |
| 547 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 548 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 549 | } |
| 550 | |
| 551 | static bool ShouldUseTransitionCompositing(float device_scale_factor) { |
| 552 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 553 | |
| 554 | if (command_line.HasSwitch(switches::kDisableCompositingForTransition)) |
| 555 | return false; |
| 556 | |
| 557 | if (command_line.HasSwitch(switches::kEnableCompositingForTransition)) |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 558 | return true; |
| 559 | |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 560 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 561 | } |
| 562 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 563 | static FaviconURL::IconType ToFaviconType(WebKit::WebIconURL::Type type) { |
| 564 | switch (type) { |
| 565 | case WebKit::WebIconURL::TypeFavicon: |
| 566 | return FaviconURL::FAVICON; |
| 567 | case WebKit::WebIconURL::TypeTouch: |
| 568 | return FaviconURL::TOUCH_ICON; |
| 569 | case WebKit::WebIconURL::TypeTouchPrecomposed: |
| 570 | return FaviconURL::TOUCH_PRECOMPOSED_ICON; |
| 571 | case WebKit::WebIconURL::TypeInvalid: |
| 572 | return FaviconURL::INVALID_ICON; |
| 573 | } |
| 574 | return FaviconURL::INVALID_ICON; |
| 575 | } |
| 576 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 577 | /////////////////////////////////////////////////////////////////////////////// |
| 578 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 579 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 580 | PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 581 | : params(p), |
| 582 | completion(c) { |
| 583 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 584 | FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 585 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 586 | }; |
| 587 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 588 | namespace { |
| 589 | |
| 590 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 591 | public: |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 592 | explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 593 | : webwidget_(webwidget) {} |
| 594 | |
| 595 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 596 | if (succeeded) |
| 597 | webwidget_->didAcquirePointerLock(); |
| 598 | else |
| 599 | webwidget_->didNotAcquirePointerLock(); |
| 600 | } |
| 601 | |
| 602 | virtual void OnMouseLockLost() OVERRIDE { |
| 603 | webwidget_->didLosePointerLock(); |
| 604 | } |
| 605 | |
| 606 | virtual bool HandleMouseLockedInputEvent( |
| 607 | const WebKit::WebMouseEvent &event) OVERRIDE { |
| 608 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 609 | return false; |
| 610 | } |
| 611 | |
| 612 | private: |
| 613 | WebKit::WebWidget* webwidget_; |
| 614 | }; |
| 615 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 616 | int64 ExtractPostId(const WebHistoryItem& item) { |
| 617 | if (item.isNull()) |
| 618 | return -1; |
| 619 | |
| 620 | if (item.httpBody().isNull()) |
| 621 | return -1; |
| 622 | |
| 623 | return item.httpBody().identifier(); |
| 624 | } |
| 625 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 626 | bool TouchEnabled() { |
| 627 | // Based on the definition of chrome::kEnableTouchIcon. |
| 628 | #if defined(OS_ANDROID) |
| 629 | return true; |
| 630 | #else |
| 631 | return false; |
| 632 | #endif |
| 633 | } |
| 634 | |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 635 | WebDragData WebDropDataToDragData(const WebDropData& drop_data) { |
| 636 | std::vector<WebDragData::Item> item_list; |
| 637 | |
| 638 | // These fields are currently unused when dragging into WebKit. |
| 639 | DCHECK(drop_data.download_metadata.empty()); |
| 640 | DCHECK(drop_data.file_contents.empty()); |
| 641 | DCHECK(drop_data.file_description_filename.empty()); |
| 642 | |
| 643 | if (!drop_data.text.is_null()) { |
| 644 | WebDragData::Item item; |
| 645 | item.storageType = WebDragData::Item::StorageTypeString; |
| 646 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 647 | item.stringData = drop_data.text.string(); |
| 648 | item_list.push_back(item); |
| 649 | } |
| 650 | |
| 651 | // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it |
| 652 | // meaningful to write an empty URL to the clipboard? |
| 653 | if (!drop_data.url.is_empty()) { |
| 654 | WebDragData::Item item; |
| 655 | item.storageType = WebDragData::Item::StorageTypeString; |
| 656 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 657 | item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 658 | item.title = drop_data.url_title; |
| 659 | item_list.push_back(item); |
| 660 | } |
| 661 | |
| 662 | if (!drop_data.html.is_null()) { |
| 663 | WebDragData::Item item; |
| 664 | item.storageType = WebDragData::Item::StorageTypeString; |
| 665 | item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 666 | item.stringData = drop_data.html.string(); |
| 667 | item.baseURL = drop_data.html_base_url; |
| 668 | item_list.push_back(item); |
| 669 | } |
| 670 | |
| 671 | for (std::vector<WebDropData::FileInfo>::const_iterator it = |
| 672 | drop_data.filenames.begin(); |
| 673 | it != drop_data.filenames.end(); |
| 674 | ++it) { |
| 675 | WebDragData::Item item; |
| 676 | item.storageType = WebDragData::Item::StorageTypeFilename; |
| 677 | item.filenameData = it->path; |
| 678 | item.displayNameData = it->display_name; |
| 679 | item_list.push_back(item); |
| 680 | } |
| 681 | |
| 682 | for (std::map<base::string16, base::string16>::const_iterator it = |
| 683 | drop_data.custom_data.begin(); |
| 684 | it != drop_data.custom_data.end(); |
| 685 | ++it) { |
| 686 | WebDragData::Item item; |
| 687 | item.storageType = WebDragData::Item::StorageTypeString; |
| 688 | item.stringType = it->first; |
| 689 | item.stringData = it->second; |
| 690 | item_list.push_back(item); |
| 691 | } |
| 692 | |
| 693 | WebDragData result; |
| 694 | result.initialize(); |
| 695 | result.setItems(item_list); |
| 696 | result.setFilesystemId(drop_data.filesystem_id); |
| 697 | return result; |
| 698 | } |
| 699 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 700 | } // namespace |
| 701 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 702 | RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) |
| 703 | : RenderWidget(WebKit::WebPopupTypeNone, |
| 704 | params->screen_info, |
| 705 | params->swapped_out), |
| 706 | webkit_preferences_(params->webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 707 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 708 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 709 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 710 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 711 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 712 | opened_by_user_gesture_(true), |
| 713 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 714 | page_id_(-1), |
| 715 | last_page_id_sent_to_browser_(-1), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 716 | next_page_id_(params->next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 717 | history_list_offset_(-1), |
| 718 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 719 | target_url_status_(TARGET_NONE), |
[email protected] | bbef1d3 | 2011-10-25 14:36:55 | [diff] [blame] | 720 | selection_text_offset_(0), |
[email protected] | e017c9c | 2013-02-20 13:44:52 | [diff] [blame] | 721 | selection_range_(ui::Range::InvalidRange()), |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 722 | cached_is_main_frame_pinned_to_left_(false), |
| 723 | cached_is_main_frame_pinned_to_right_(false), |
| 724 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 725 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 726 | cookie_jar_(this), |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 727 | notification_provider_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 728 | geolocation_dispatcher_(NULL), |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 729 | input_tag_speech_dispatcher_(NULL), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 730 | speech_recognition_dispatcher_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 731 | device_orientation_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 732 | media_stream_dispatcher_(NULL), |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 733 | browser_plugin_manager_(NULL), |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 734 | media_stream_impl_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 735 | devtools_agent_(NULL), |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 736 | accessibility_mode_(AccessibilityModeOff), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 737 | renderer_accessibility_(NULL), |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 738 | java_bridge_dispatcher_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 739 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 740 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 741 | body_background_color_(SK_ColorWHITE), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 742 | expected_content_intent_id_(0), |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 743 | media_player_proxy_(NULL), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 744 | #endif |
| 745 | #if defined(OS_WIN) |
| 746 | focused_plugin_id_(-1), |
| 747 | #endif |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 748 | enumeration_completion_id_(0), |
[email protected] | a756427 | 2013-04-19 14:24:46 | [diff] [blame] | 749 | #if defined(OS_ANDROID) |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 750 | load_progress_tracker_(new LoadProgressTracker(this)), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 751 | #endif |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 752 | session_storage_namespace_id_(params->session_storage_namespace_id), |
[email protected] | 8a67aa35 | 2013-02-20 02:58:29 | [diff] [blame] | 753 | decrement_shared_popup_at_destruction_(false), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 754 | handling_select_range_(false), |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 755 | next_snapshot_id_(0), |
[email protected] | bf4a231 | 2013-04-23 00:32:11 | [diff] [blame] | 756 | allow_partial_swap_(params->allow_partial_swap) { |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | void RenderViewImpl::Initialize(RenderViewImplParams* params) { |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame^] | 760 | main_render_frame_.reset(new RenderFrameImpl( |
| 761 | this, params->main_frame_routing_id)); |
| 762 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 763 | #if defined(ENABLE_PLUGINS) |
| 764 | pepper_helper_.reset(new PepperPluginDelegateImpl(this)); |
| 765 | #else |
| 766 | pepper_helper_.reset(new RenderViewPepperHelper()); |
| 767 | #endif |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 768 | set_throttle_input_events(params->renderer_prefs.throttle_input_events); |
| 769 | routing_id_ = params->routing_id; |
| 770 | surface_id_ = params->surface_id; |
| 771 | if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created) |
| 772 | opener_id_ = params->opener_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 773 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 774 | // Ensure we start with a valid next_page_id_ from the browser. |
| 775 | DCHECK_GE(next_page_id_, 0); |
| 776 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 777 | #if defined(ENABLE_NOTIFICATIONS) |
| 778 | notification_provider_ = new NotificationProvider(this); |
| 779 | #else |
| 780 | notification_provider_ = NULL; |
| 781 | #endif |
| 782 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 783 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 784 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 785 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 786 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 787 | |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 788 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 789 | stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
| 790 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 791 | #if defined(OS_ANDROID) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 792 | content::DeviceTelephonyInfo device_info; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 793 | |
| 794 | const std::string region_code = |
| 795 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 796 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 797 | : device_info.GetNetworkCountryIso(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 798 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 799 | new AddressDetector())); |
| 800 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 801 | new PhoneNumberDetector(region_code))); |
| 802 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 803 | new EmailDetector())); |
| 804 | #endif |
| 805 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 806 | if (params->counter) { |
| 807 | shared_popup_counter_ = params->counter; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 808 | // Only count this if it isn't swapped out upon creation. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 809 | if (!params->swapped_out) |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 810 | shared_popup_counter_->data++; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 811 | decrement_shared_popup_at_destruction_ = true; |
| 812 | } else { |
| 813 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 814 | decrement_shared_popup_at_destruction_ = false; |
| 815 | } |
| 816 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 817 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 818 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 819 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 820 | AddRef(); |
| 821 | |
| 822 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 823 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 824 | if (opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 825 | did_show_ = true; |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 826 | CompleteInit(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 827 | } |
| 828 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 829 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 830 | g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 831 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 832 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 833 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 834 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 835 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 836 | |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 837 | webkit_glue::ApplyWebPreferences(webkit_preferences_, webview()); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 838 | webview()->initializeMainFrame(this); |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 839 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 840 | if (switches::IsTouchDragDropEnabled()) |
[email protected] | edbea62 | 2012-11-28 20:39:38 | [diff] [blame] | 841 | webview()->settings()->setTouchDragDropEnabled(true); |
| 842 | |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 843 | if (switches::IsTouchEditingEnabled()) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 844 | webview()->settings()->setTouchEditingEnabled(true); |
| 845 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 846 | if (!params->frame_name.empty()) |
| 847 | webview()->mainFrame()->setName(params->frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 848 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 849 | OnSetRendererPrefs(params->renderer_prefs); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 850 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 851 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 852 | if (!media_stream_dispatcher_) |
| 853 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 854 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 855 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 856 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 857 | #if defined(OS_MACOSX) |
| 858 | new TextInputClientObserver(this); |
| 859 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 860 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 861 | #if defined(OS_ANDROID) |
| 862 | media_player_manager_.reset( |
| 863 | new webkit_media::WebMediaPlayerManagerAndroid()); |
| 864 | #endif |
| 865 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 866 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 867 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 868 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 869 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 870 | |
| 871 | new ImageLoadingHelper(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 872 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 873 | // Create renderer_accessibility_ if needed. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 874 | OnSetAccessibilityMode(params->accessibility_mode); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 875 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 876 | new IdleUserDetector(this); |
| 877 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 878 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 879 | enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 880 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 881 | enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION; |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 882 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 883 | ProcessViewLayoutFlags(command_line); |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 884 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 885 | GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 886 | |
| 887 | // If we have an opener_id but we weren't created by a renderer, then |
| 888 | // it's the browser asking us to set our opener to another RenderView. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 889 | if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) { |
| 890 | RenderViewImpl* opener_view = FromRoutingID(params->opener_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 891 | if (opener_view) |
| 892 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 896 | // This ensures we are in a unique origin that others cannot script. |
| 897 | if (is_swapped_out_) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 898 | NavigateToSwappedOutURL(webview()->mainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 899 | } |
| 900 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 901 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 902 | history_page_ids_.clear(); |
| 903 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 904 | if (decrement_shared_popup_at_destruction_) |
| 905 | shared_popup_counter_->data--; |
| 906 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 907 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 908 | while (!file_chooser_completions_.empty()) { |
| 909 | if (file_chooser_completions_.front()->completion) { |
| 910 | file_chooser_completions_.front()->completion->didChooseFile( |
| 911 | WebVector<WebString>()); |
| 912 | } |
| 913 | file_chooser_completions_.pop_front(); |
| 914 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 915 | |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 916 | #if defined(OS_ANDROID) |
| 917 | // The date/time picker client is both a scoped_ptr member of this class and |
| 918 | // a RenderViewObserver. Reset it to prevent double deletion. |
| 919 | date_time_picker_client_.reset(); |
| 920 | #endif |
| 921 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 922 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 923 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 924 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 925 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 926 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 927 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 928 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 929 | it != routing_id_views->end(); ++it) |
| 930 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 931 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 932 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 933 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 934 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 938 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 939 | ViewMap* views = g_view_map.Pointer(); |
| 940 | ViewMap::iterator it = views->find(webview); |
| 941 | return it == views->end() ? NULL : it->second; |
| 942 | } |
| 943 | |
| 944 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 945 | RenderView* RenderView::FromWebView(WebKit::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 946 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /*static*/ |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 950 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) { |
| 951 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
| 952 | RoutingIDViewMap::iterator it = views->find(routing_id); |
| 953 | return it == views->end() ? NULL : it->second; |
| 954 | } |
| 955 | |
| 956 | /*static*/ |
| 957 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 958 | return RenderViewImpl::FromRoutingID(routing_id); |
| 959 | } |
| 960 | |
| 961 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 962 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 963 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 964 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 965 | if (!visitor->Visit(it->second)) |
| 966 | return; |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 971 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 972 | int32 opener_id, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 973 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 974 | const WebPreferences& webkit_prefs, |
| 975 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 976 | int32 routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame^] | 977 | int32 main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 978 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 979 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 980 | const string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 981 | bool is_renderer_created, |
| 982 | bool swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 983 | int32 next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 984 | const WebKit::WebScreenInfo& screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 985 | AccessibilityMode accessibility_mode, |
| 986 | bool allow_partial_swap) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 987 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 988 | RenderViewImplParams params( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 989 | opener_id, |
| 990 | renderer_prefs, |
| 991 | webkit_prefs, |
| 992 | counter, |
| 993 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame^] | 994 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 995 | surface_id, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 996 | session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 997 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 998 | is_renderer_created, |
| 999 | swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1000 | next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1001 | screen_info, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 1002 | accessibility_mode, |
| 1003 | allow_partial_swap); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1004 | RenderViewImpl* render_view = NULL; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1005 | if (g_create_render_view_impl) |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1006 | render_view = g_create_render_view_impl(¶ms); |
| 1007 | else |
| 1008 | render_view = new RenderViewImpl(¶ms); |
| 1009 | render_view->Initialize(¶ms); |
| 1010 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | // static |
| 1014 | void RenderViewImpl::InstallCreateHook( |
| 1015 | RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) { |
| 1016 | CHECK(!g_create_render_view_impl); |
| 1017 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1020 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1021 | observers_.AddObserver(observer); |
| 1022 | } |
| 1023 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1024 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1025 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1026 | observers_.RemoveObserver(observer); |
| 1027 | } |
| 1028 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1029 | WebKit::WebView* RenderViewImpl::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 1030 | return static_cast<WebKit::WebView*>(webwidget()); |
| 1031 | } |
| 1032 | |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 1033 | void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path, |
[email protected] | cf4d6e74 | 2013-01-10 14:06:42 | [diff] [blame] | 1034 | base::ProcessId plugin_pid) { |
| 1035 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1036 | } |
| 1037 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1038 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1039 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1040 | // If the renderer is visible, set initial visibility and focus state. |
| 1041 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1042 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1043 | delegate->SetContainerVisibility(true); |
| 1044 | if (webview() && webview()->isActive()) |
| 1045 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1046 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 1047 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 1048 | // Plugins start assuming the content has focus (so that they work in |
| 1049 | // environments where RenderView isn't hosting them), so we always have to |
| 1050 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 1051 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1052 | } |
| 1053 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1054 | void RenderViewImpl::UnregisterPluginDelegate( |
| 1055 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1056 | plugin_delegates_.erase(delegate); |
| 1057 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 1058 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1059 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 1060 | const GURL& page_url, |
| 1061 | const std::string& mime_type, |
| 1062 | webkit::WebPluginInfo* plugin_info, |
| 1063 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 1064 | bool found = false; |
| 1065 | Send(new ViewHostMsg_GetPluginInfo( |
| 1066 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 1067 | actual_mime_type)); |
| 1068 | return found; |
| 1069 | } |
| 1070 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 1071 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
| 1072 | const WebKit::WebActiveWheelFlingParameters& params) { |
| 1073 | if (webview()) |
| 1074 | webview()->transferActiveWheelFlingAnimation(params); |
| 1075 | } |
| 1076 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 1077 | bool RenderViewImpl::HasIMETextFocus() { |
| 1078 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 1079 | } |
| 1080 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1081 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1082 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1083 | if (main_frame) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1084 | GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1085 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1086 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 1087 | RenderViewObserver* observer; |
| 1088 | while ((observer = it.GetNext()) != NULL) |
| 1089 | if (observer->OnMessageReceived(message)) |
| 1090 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1091 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1092 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1093 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1094 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1095 | IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy) |
| 1096 | IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut) |
| 1097 | IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete) |
| 1098 | IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 1099 | IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) |
| 1100 | IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste) |
| 1101 | IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
| 1102 | IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo) |
| 1103 | IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace) |
| 1104 | IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling) |
| 1105 | IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, |
| 1106 | OnScrollFocusedEditableNodeIntoRect) |
| 1107 | IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll) |
| 1108 | IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange) |
| 1109 | IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent, |
| 1110 | OnSetEditCommandsForNextKeyEvent) |
| 1111 | IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo) |
| 1112 | IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1113 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 1114 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1115 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1116 | IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1117 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets, |
| 1118 | OnSetEditableSelectionOffsets) |
| 1119 | IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText, |
| 1120 | OnSetCompositionFromExistingText) |
| 1121 | IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete, |
| 1122 | OnExtendSelectionAndDelete) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1123 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
| 1124 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 1125 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 1126 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1127 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 1128 | IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1129 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 1130 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1131 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 1132 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 1133 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1134 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 1135 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 1136 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1137 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 1138 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 1139 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 1140 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 1141 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 1142 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1143 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1144 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1145 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1146 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1147 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 1148 | IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1149 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1150 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1151 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1152 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 1153 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1154 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1155 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 1156 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1157 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 1158 | OnDisassociateFromPopupCount) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1159 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 1160 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1161 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1162 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1163 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1164 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1165 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1166 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1167 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1168 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 1169 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 1170 | IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent, |
| 1171 | OnOrientationChangeEvent) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1172 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 1173 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 1174 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 1175 | OnCustomContextMenuAction) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 1176 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 1177 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, |
| 1178 | OnPpapiBrokerChannelCreated) |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 1179 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, |
| 1180 | OnPpapiBrokerPermissionResult) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 1181 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 1182 | OnGetAllSavableResourceLinksForCurrentPage) |
| 1183 | IPC_MESSAGE_HANDLER( |
| 1184 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 1185 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 1186 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 1187 | IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 1188 | // TODO(viettrungluu): Move to a separate message filter. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1189 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 1190 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 1191 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 1192 | #if defined(ENABLE_JAVA_BRIDGE) |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 1193 | IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 1194 | #endif |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1195 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 1196 | IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1197 | #if defined(OS_ANDROID) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1198 | IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult, |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1199 | OnActivateNearestFindResult) |
| 1200 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
| 1201 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1202 | IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView, |
| 1203 | OnUndoScrollFocusedEditableNodeIntoRect) |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 1204 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState, |
| 1205 | OnUpdateTopControlsState) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1206 | #elif defined(OS_MACOSX) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1207 | IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1208 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1209 | OnPluginImeCompositionCompleted) |
| 1210 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1211 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1212 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1213 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1214 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 1215 | IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, |
| 1216 | OnReleaseDisambiguationPopupDIB) |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 1217 | IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| 1218 | OnWindowSnapshotCompleted) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1219 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1220 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1221 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1222 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1223 | |
| 1224 | if (!msg_is_ok) { |
| 1225 | // The message had a handler, but its deserialization failed. |
| 1226 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1227 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1228 | } |
| 1229 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1230 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1231 | } |
| 1232 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1233 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1234 | MaybeHandleDebugURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1235 | if (!webview()) |
| 1236 | return; |
| 1237 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 1238 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 1239 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1240 | bool is_reload = IsReload(params); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1241 | |
| 1242 | // If this is a stale back/forward (due to a recent navigation the browser |
| 1243 | // didn't know about), ignore it. |
| 1244 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 1245 | return; |
| 1246 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1247 | // Swap this renderer back in if necessary. |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1248 | if (is_swapped_out_) { |
| 1249 | // We marked the view as hidden when swapping the view out, so be sure to |
| 1250 | // reset the visibility state before navigating to the new URL. |
| 1251 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 1252 | |
| 1253 | // If this is an attempt to reload while we are swapped out, we should not |
| 1254 | // reload swappedout://, but the previous page, which is stored in |
| 1255 | // params.state. Setting is_reload to false will treat this like a back |
| 1256 | // navigation to accomplish that. |
| 1257 | is_reload = false; |
| 1258 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1259 | SetSwappedOut(false); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1260 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1261 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1262 | if (params.should_clear_history_list) { |
| 1263 | CHECK_EQ(params.pending_history_list_offset, -1); |
| 1264 | CHECK_EQ(params.current_history_list_offset, -1); |
| 1265 | CHECK_EQ(params.current_history_list_length, 0); |
| 1266 | } |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1267 | history_list_offset_ = params.current_history_list_offset; |
| 1268 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1269 | if (history_list_length_ >= 0) |
| 1270 | history_page_ids_.resize(history_list_length_, -1); |
| 1271 | if (params.pending_history_list_offset >= 0 && |
| 1272 | params.pending_history_list_offset < history_list_length_) |
| 1273 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1274 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1275 | GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1276 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1277 | WebFrame* frame = webview()->mainFrame(); |
| 1278 | if (!params.frame_to_navigate.empty()) { |
| 1279 | frame = webview()->findFrameByName( |
| 1280 | WebString::fromUTF8(params.frame_to_navigate)); |
| 1281 | CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; |
| 1282 | } |
| 1283 | |
| 1284 | if (is_reload && frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1285 | // We cannot reload if we do not have any history state. This happens, for |
| 1286 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1287 | // a hack since it means that reload after a crashed tab does not cause an |
| 1288 | // end-to-end cache validation. |
| 1289 | is_reload = false; |
| 1290 | } |
| 1291 | |
[email protected] | 3d2fd59 | 2012-11-30 02:05:50 | [diff] [blame] | 1292 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params)); |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 1293 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1294 | // If we are reloading, then WebKit will use the history state of the current |
| 1295 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1296 | // have history state, then we need to navigate to it, which corresponds to a |
| 1297 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1298 | if (is_reload) { |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1299 | bool reload_original_url = |
| 1300 | (params.navigation_type == |
| 1301 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1302 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 1303 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1304 | |
| 1305 | if (reload_original_url) |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1306 | frame->reloadWithOverrideURL(params.url, true); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1307 | else |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1308 | frame->reload(ignore_cache); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1309 | } else if (params.page_state.IsValid()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1310 | // 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] | 1311 | DCHECK_NE(params.page_id, -1); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1312 | WebHistoryItem item = PageStateToHistoryItem(params.page_state); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1313 | if (!item.isNull()) { |
| 1314 | // Ensure we didn't save the swapped out URL in UpdateState, since the |
| 1315 | // browser should never be telling us to navigate to swappedout://. |
| 1316 | CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL)); |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1317 | frame->loadHistoryItem(item); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1318 | } |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1319 | } else if (!params.base_url_for_data_url.is_empty()) { |
| 1320 | // A loadData request with a specified base URL. |
| 1321 | std::string mime_type, charset, data; |
| 1322 | if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1323 | frame->loadData( |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1324 | WebData(data.c_str(), data.length()), |
| 1325 | WebString::fromUTF8(mime_type), |
| 1326 | WebString::fromUTF8(charset), |
| 1327 | params.base_url_for_data_url, |
| 1328 | params.history_url_for_data_url, |
| 1329 | false); |
| 1330 | } else { |
| 1331 | CHECK(false) << |
| 1332 | "Invalid URL passed: " << params.url.possibly_invalid_spec(); |
| 1333 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1334 | } else { |
| 1335 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1336 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1337 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1338 | // A session history navigation should have been accompanied by state. |
[email protected] | cbc0cb7 | 2011-12-06 18:58:23 | [diff] [blame] | 1339 | CHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1340 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1341 | if (frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1342 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1343 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1344 | if (params.referrer.url.is_valid()) { |
| 1345 | WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 1346 | params.referrer.policy, |
| 1347 | params.url, |
| 1348 | WebString::fromUTF8(params.referrer.url.spec())); |
| 1349 | if (!referrer.isEmpty()) |
| 1350 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1351 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1352 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 1353 | if (!params.extra_headers.empty()) { |
| 1354 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 1355 | params.extra_headers.end(), "\n"); |
| 1356 | i.GetNext(); ) { |
| 1357 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 1358 | WebString::fromUTF8(i.values())); |
| 1359 | } |
| 1360 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1361 | |
| 1362 | if (params.is_post) { |
| 1363 | request.setHTTPMethod(WebString::fromUTF8("POST")); |
| 1364 | |
| 1365 | // Set post data. |
| 1366 | WebHTTPBody http_body; |
| 1367 | http_body.initialize(); |
| 1368 | http_body.appendData(WebData( |
| 1369 | reinterpret_cast<const char*>( |
| 1370 | ¶ms.browser_initiated_post_data.front()), |
| 1371 | params.browser_initiated_post_data.size())); |
| 1372 | request.setHTTPBody(http_body); |
| 1373 | } |
| 1374 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 1375 | frame->loadRequest(request); |
[email protected] | 198a95d6 | 2013-04-11 00:44:21 | [diff] [blame] | 1376 | |
| 1377 | // If this is a cross-process navigation, the browser process will send |
| 1378 | // along the proper navigation start value. |
| 1379 | if (!params.browser_navigation_start.is_null() && |
| 1380 | frame->provisionalDataSource()) { |
| 1381 | // browser_navigation_start is likely before this process existed, so we |
| 1382 | // can't use InterProcessTimeTicksConverter. Instead, the best we can do |
| 1383 | // is just ensure we don't report a bogus value in the future. |
| 1384 | base::TimeTicks navigation_start = std::min( |
| 1385 | base::TimeTicks::Now(), params.browser_navigation_start); |
| 1386 | double navigation_start_seconds = |
| 1387 | (navigation_start - base::TimeTicks()).InSecondsF(); |
| 1388 | frame->provisionalDataSource()->setNavigationStartTime( |
| 1389 | navigation_start_seconds); |
| 1390 | } |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1391 | } |
| 1392 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1393 | // In case LoadRequest failed before DidCreateDataSource was called. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1394 | pending_navigation_params_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1395 | } |
| 1396 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1397 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1398 | const ViewMsg_Navigate_Params& params, |
| 1399 | bool is_reload) { |
| 1400 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 1401 | // or replaced from our history, before the browser knew about it. If so, |
| 1402 | // 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] | 1403 | bool is_back_forward = !is_reload && params.page_state.IsValid(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1404 | |
| 1405 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 1406 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 1407 | if (!is_back_forward || history_list_length_ <= 0) |
| 1408 | return false; |
| 1409 | |
| 1410 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 1411 | |
| 1412 | // Check for whether the forward history has been cropped due to a recent |
| 1413 | // navigation the browser didn't know about. |
| 1414 | if (params.pending_history_list_offset >= history_list_length_) |
| 1415 | return true; |
| 1416 | |
| 1417 | // Check for whether this entry has been replaced with a new one. |
| 1418 | int expected_page_id = |
| 1419 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 1420 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 1421 | if (params.page_id < expected_page_id) |
| 1422 | return true; |
| 1423 | |
| 1424 | // Otherwise we've removed an earlier entry and should have shifted all |
| 1425 | // entries left. For now, it's ok to lazily update the list. |
| 1426 | // TODO(creis): Notify all live renderers when we remove entries from |
| 1427 | // the front of the list, so that we don't hit this case. |
| 1428 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 1429 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1430 | |
| 1431 | return false; |
| 1432 | } |
| 1433 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1434 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1435 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 1436 | if (webview()) { |
| 1437 | WebFrame* main_frame = webview()->mainFrame(); |
| 1438 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 1439 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 1440 | // it may no longer be active. |
| 1441 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 1442 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 1443 | main_frame->stopLoading(); |
| 1444 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1445 | } |
| 1446 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1447 | // Reload current focused frame. |
| 1448 | // 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] | 1449 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1450 | if (webview() && webview()->focusedFrame()) { |
| 1451 | // We always obey the cache (ignore_cache=false) here. |
| 1452 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1453 | // a cache-ignoring reload of the frame. |
| 1454 | webview()->focusedFrame()->reload(false); |
| 1455 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1456 | } |
| 1457 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1458 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1459 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1460 | } |
| 1461 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1462 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1463 | // Check if there is a targeturl waiting to be sent. |
| 1464 | if (target_url_status_ == TARGET_PENDING) { |
| 1465 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1466 | pending_target_url_)); |
| 1467 | } |
| 1468 | |
| 1469 | target_url_status_ = TARGET_NONE; |
| 1470 | } |
| 1471 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1472 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1473 | if (!webview()) |
| 1474 | return; |
| 1475 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1476 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1477 | WebNode current_node = context_menu_node_.isNull() ? |
| 1478 | GetFocusedNode() : context_menu_node_; |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 1479 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1480 | current_node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1481 | } |
| 1482 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1483 | void RenderViewImpl::OnCut() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1484 | if (!webview()) |
| 1485 | return; |
| 1486 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1487 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1488 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"), |
| 1489 | GetFocusedNode()); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1490 | } |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1491 | |
| 1492 | void RenderViewImpl::OnDelete() { |
| 1493 | if (!webview()) |
| 1494 | return; |
| 1495 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1496 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"), |
| 1497 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
| 1501 | const std::string& value) { |
| 1502 | if (!webview() || !webview()->focusedFrame()) |
| 1503 | return; |
| 1504 | |
| 1505 | webview()->focusedFrame()->executeCommand( |
| 1506 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
| 1507 | } |
| 1508 | |
| 1509 | void RenderViewImpl::OnMoveCaret(const gfx::Point& point) { |
| 1510 | if (!webview()) |
| 1511 | return; |
| 1512 | |
| 1513 | Send(new ViewHostMsg_MoveCaret_ACK(routing_id_)); |
| 1514 | |
| 1515 | webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point); |
| 1516 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1517 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1518 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1519 | if (!webview()) |
| 1520 | return; |
| 1521 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1522 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1523 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"), |
| 1524 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1525 | } |
| 1526 | |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1527 | void RenderViewImpl::OnPasteAndMatchStyle() { |
| 1528 | if (!webview()) |
| 1529 | return; |
| 1530 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1531 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1532 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1533 | WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode()); |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1534 | } |
| 1535 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1536 | void RenderViewImpl::OnRedo() { |
| 1537 | if (!webview()) |
| 1538 | return; |
| 1539 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1540 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"), |
| 1541 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1542 | } |
| 1543 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1544 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1545 | if (!webview()) |
| 1546 | return; |
| 1547 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1548 | WebFrame* frame = webview()->focusedFrame(); |
| 1549 | if (!frame->hasSelection()) |
| 1550 | frame->selectWordAroundCaret(); |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1551 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1552 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1553 | } |
| 1554 | |
[email protected] | 2365c64 | 2013-02-12 19:16:47 | [diff] [blame] | 1555 | void RenderViewImpl::OnReplaceMisspelling(const string16& text) { |
| 1556 | if (!webview()) |
| 1557 | return; |
| 1558 | |
| 1559 | WebFrame* frame = webview()->focusedFrame(); |
| 1560 | if (!frame->hasSelection()) |
| 1561 | return; |
| 1562 | |
| 1563 | frame->replaceMisspelledRange(text); |
| 1564 | } |
| 1565 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1566 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1567 | const gfx::Rect& rect) { |
| 1568 | WebKit::WebNode node = GetFocusedNode(); |
| 1569 | if (!node.isNull()) { |
| 1570 | if (IsEditableNode(node)) { |
| 1571 | webview()->saveScrollAndScaleState(); |
| 1572 | webview()->scrollFocusedNodeIntoRect(rect); |
| 1573 | } |
| 1574 | } |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 1575 | } |
| 1576 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1577 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1578 | if (!webview()) |
| 1579 | return; |
| 1580 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1581 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1582 | webview()->focusedFrame()->executeCommand( |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1583 | WebString::fromUTF8("SelectAll"), GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1584 | } |
| 1585 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1586 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 1587 | const gfx::Point& end) { |
| 1588 | if (!webview()) |
| 1589 | return; |
| 1590 | |
| 1591 | Send(new ViewHostMsg_SelectRange_ACK(routing_id_)); |
| 1592 | |
| 1593 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1594 | webview()->focusedFrame()->selectRange(start, end); |
| 1595 | } |
| 1596 | |
| 1597 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
| 1598 | const EditCommands& edit_commands) { |
| 1599 | edit_commands_ = edit_commands; |
| 1600 | } |
| 1601 | |
| 1602 | void RenderViewImpl::OnUndo() { |
| 1603 | if (!webview()) |
| 1604 | return; |
| 1605 | |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1606 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"), |
| 1607 | GetFocusedNode()); |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1608 | } |
| 1609 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1610 | void RenderViewImpl::OnUnselect() { |
| 1611 | if (!webview()) |
| 1612 | return; |
| 1613 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1614 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 1615 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 1616 | GetFocusedNode()); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1617 | } |
| 1618 | |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 1619 | #if defined(OS_MACOSX) |
| 1620 | void RenderViewImpl::OnCopyToFindPboard() { |
| 1621 | if (!webview()) |
| 1622 | return; |
| 1623 | |
| 1624 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1625 | // than the |OnCopy()| case. |
| 1626 | WebFrame* frame = webview()->focusedFrame(); |
| 1627 | if (frame->hasSelection()) { |
| 1628 | string16 selection = frame->selectionAsText(); |
| 1629 | RenderThread::Get()->Send( |
| 1630 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
| 1631 | } |
| 1632 | } |
| 1633 | #endif |
| 1634 | |
| 1635 | void RenderViewImpl::OnSetName(const std::string& name) { |
| 1636 | if (!webview()) |
| 1637 | return; |
| 1638 | |
| 1639 | webview()->mainFrame()->setName(WebString::fromUTF8(name)); |
| 1640 | } |
| 1641 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1642 | void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) { |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 1643 | base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1644 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1645 | webview()->setEditableSelectionOffsets(start, end); |
| 1646 | } |
| 1647 | |
| 1648 | void RenderViewImpl::OnSetCompositionFromExistingText( |
| 1649 | int start, int end, |
| 1650 | const std::vector<WebKit::WebCompositionUnderline>& underlines) { |
| 1651 | if (!webview()) |
| 1652 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1653 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1654 | webview()->setCompositionFromExistingText(start, end, underlines); |
| 1655 | } |
| 1656 | |
| 1657 | void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) { |
| 1658 | if (!webview()) |
| 1659 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1660 | ImeEventGuard guard(this); |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1661 | webview()->extendSelectionAndDelete(before, after); |
| 1662 | } |
| 1663 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1664 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1665 | int32 minimum_page_id) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1666 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1667 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1668 | DCHECK_GE(minimum_page_id, -1); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1669 | |
| 1670 | // Generate the new list. |
| 1671 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1672 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1673 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1674 | continue; |
| 1675 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1676 | } |
| 1677 | new_history_page_ids.swap(history_page_ids_); |
| 1678 | |
| 1679 | // Update indexes. |
| 1680 | history_list_length_ = history_page_ids_.size(); |
| 1681 | history_list_offset_ = history_list_length_ - 1; |
| 1682 | } |
| 1683 | |
| 1684 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1685 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1686 | if (!webview()) |
| 1687 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1688 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1689 | } |
| 1690 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1691 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1692 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1693 | if (!webview()) |
| 1694 | return; |
| 1695 | if (in_live_resize) |
| 1696 | webview()->willStartLiveResize(); |
| 1697 | else |
| 1698 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1699 | } |
| 1700 | #endif |
| 1701 | |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1702 | #if defined(OS_ANDROID) |
| 1703 | void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() { |
| 1704 | const WebNode node = GetFocusedNode(); |
| 1705 | if (!node.isNull() && IsEditableNode(node)) |
| 1706 | webview()->restoreScrollAndScaleState(); |
| 1707 | } |
| 1708 | #endif |
| 1709 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1710 | /////////////////////////////////////////////////////////////////////////////// |
| 1711 | |
| 1712 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1713 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1714 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1715 | DCHECK(ds); |
| 1716 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1717 | const WebURLRequest& request = ds->request(); |
| 1718 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1719 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1720 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1721 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 1722 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1723 | InternalDocumentStateData* internal_data = |
| 1724 | InternalDocumentStateData::FromDocumentState(document_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1725 | |
| 1726 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1727 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1728 | params.is_post = false; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1729 | params.post_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1730 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1731 | params.frame_id = frame->identifier(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1732 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1733 | params.socket_address.set_port(response.remotePort()); |
[email protected] | e07ddafe | 2013-03-05 21:03:36 | [diff] [blame] | 1734 | WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response); |
| 1735 | if (extra_data) { |
| 1736 | params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy(); |
| 1737 | } |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1738 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1739 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1740 | |
| 1741 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 1742 | params.url = GetLoadingUrl(frame); |
[email protected] | 809be03 | 2013-03-19 01:56:56 | [diff] [blame] | 1743 | DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1744 | |
[email protected] | 5f9b871 | 2011-11-23 08:55:57 | [diff] [blame] | 1745 | if (frame->document().baseURL() != params.url) |
| 1746 | params.base_url = frame->document().baseURL(); |
| 1747 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1748 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1749 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 1750 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1751 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1752 | params.searchable_form_url = internal_data->searchable_form_url(); |
| 1753 | params.searchable_form_encoding = internal_data->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1754 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1755 | const PasswordForm* password_form_data = document_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1756 | if (password_form_data) |
| 1757 | params.password_form = *password_form_data; |
| 1758 | |
| 1759 | params.gesture = navigation_gesture_; |
| 1760 | navigation_gesture_ = NavigationGestureUnknown; |
| 1761 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1762 | // Make navigation state a part of the FrameNavigate message so that commited |
| 1763 | // entry had it at all times. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1764 | WebHistoryItem item = frame->currentHistoryItem(); |
| 1765 | if (item.isNull()) { |
| 1766 | item.initialize(); |
| 1767 | item.setURLString(request.url().spec().utf16()); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1768 | } |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1769 | params.page_state = HistoryItemToPageState(item); |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1770 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1771 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1772 | // Top-level navigation. |
| 1773 | |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1774 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1775 | // will also call us back which will cause us to send a message to |
| 1776 | // update WebContentsImpl. |
| 1777 | webview()->zoomLimitsChanged( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1778 | WebView::zoomFactorToZoomLevel(kMinimumZoomFactor), |
| 1779 | WebView::zoomFactorToZoomLevel(kMaximumZoomFactor)); |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1780 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1781 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1782 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1783 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1784 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1785 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1786 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1787 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1788 | } else { |
| 1789 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1790 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1791 | } |
| 1792 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1793 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1794 | // This zoom level was merely recorded transiently for this load. We can |
| 1795 | // erase it now. If at some point we reload this page, the browser will |
| 1796 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1797 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1798 | } |
| 1799 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1800 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1801 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1802 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1803 | params.transition = navigation_state->transition_type(); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1804 | if (!PageTransitionIsMainFrame(params.transition)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1805 | // If the main frame does a load, it should not be reported as a subframe |
| 1806 | // navigation. This can occur in the following case: |
| 1807 | // 1. You're on a site with frames. |
| 1808 | // 2. You do a subframe navigation. This is stored with transition type |
| 1809 | // MANUAL_SUBFRAME. |
| 1810 | // 3. You navigate to some non-frame site, say, google.com. |
| 1811 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1812 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1813 | // We don't want that, because any navigation that changes the toplevel |
| 1814 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1815 | // update the URL bar, etc). |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1816 | params.transition = PAGE_TRANSITION_LINK; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1817 | } |
| 1818 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1819 | // If we have a valid consumed client redirect source, |
| 1820 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1821 | // so we set the referrer and transition to match. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1822 | if (completed_client_redirect_src_.url.is_valid()) { |
| 1823 | DCHECK(completed_client_redirect_src_.url == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1824 | params.referrer = completed_client_redirect_src_; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1825 | params.transition = static_cast<PageTransition>( |
| 1826 | params.transition | PAGE_TRANSITION_CLIENT_REDIRECT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1827 | } else { |
| 1828 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1829 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1830 | params.referrer = Referrer(GURL( |
| 1831 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 1832 | GetReferrerPolicyFromRequest(frame, original_request)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1833 | } |
| 1834 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1835 | string16 method = request.httpMethod(); |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1836 | if (EqualsASCII(method, "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1837 | params.is_post = true; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1838 | params.post_id = ExtractPostId(item); |
| 1839 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1840 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1841 | // Send the user agent override back. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 1842 | params.is_overriding_user_agent = internal_data->is_overriding_user_agent(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1843 | |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1844 | // Track the URL of the original request. |
| 1845 | params.original_request_url = original_request.url(); |
| 1846 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1847 | params.history_list_was_cleared = |
| 1848 | navigation_state->history_list_was_cleared(); |
| 1849 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1850 | // Save some histogram data so we can compute the average memory used per |
| 1851 | // page load of the glyphs. |
| 1852 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1853 | webkit_glue::GetGlyphPageCount()); |
| 1854 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1855 | // This message needs to be sent before any of allowScripts(), |
| 1856 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1857 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1858 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1859 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1860 | } else { |
| 1861 | // Subframe navigation: the type depends on whether this navigation |
| 1862 | // generated a new session history entry. When they do generate a session |
| 1863 | // history entry, it means the user initiated the navigation and we should |
| 1864 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1865 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1866 | if (page_id_ > last_page_id_sent_to_browser_) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1867 | params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1868 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1869 | params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1870 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1871 | DCHECK(!navigation_state->history_list_was_cleared()); |
| 1872 | params.history_list_was_cleared = false; |
| 1873 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1874 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1875 | } |
| 1876 | |
| 1877 | last_page_id_sent_to_browser_ = |
| 1878 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1879 | |
| 1880 | // 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] | 1881 | // we don't want the transition type to persist. Just clear it. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1882 | navigation_state->set_transition_type(PAGE_TRANSITION_LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1886 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 1887 | const string16& title, |
| 1888 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1889 | // Ignore all but top level navigations. |
| 1890 | if (frame->parent()) |
| 1891 | return; |
| 1892 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1893 | string16 shortened_title = title.substr(0, kMaxTitleChars); |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1894 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 1895 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1896 | } |
| 1897 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1898 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 1899 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1900 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1901 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1902 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1903 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1904 | last_encoding_name_ = encoding_name; |
| 1905 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1906 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 1910 | // Sends the last committed session history state to the browser so it will be |
| 1911 | // saved before we navigate to a new page. This must be called *before* the |
| 1912 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1913 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1914 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1915 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1916 | // there is no past session history to record. |
| 1917 | if (page_id_ == -1) |
| 1918 | return; |
| 1919 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1920 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1921 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1922 | SendUpdateState(item); |
| 1923 | } |
| 1924 | |
| 1925 | void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1926 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1927 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1928 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1929 | // Don't send state updates for kSwappedOutURL. |
| 1930 | if (item.urlString() == WebString::fromUTF8(kSwappedOutURL)) |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1931 | return; |
| 1932 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1933 | Send(new ViewHostMsg_UpdateState( |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 1934 | routing_id_, page_id_, HistoryItemToPageState(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1935 | } |
| 1936 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1937 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 1938 | const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1939 | const Referrer& referrer, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1940 | WebNavigationPolicy policy) { |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 1941 | ViewHostMsg_OpenURL_Params params; |
| 1942 | params.url = url; |
| 1943 | params.referrer = referrer; |
| 1944 | params.disposition = NavigationPolicyToDisposition(policy); |
| 1945 | params.frame_id = frame->identifier(); |
[email protected] | b4c0969 | 2012-12-13 19:15:46 | [diff] [blame] | 1946 | WebDataSource* ds = frame->provisionalDataSource(); |
| 1947 | if (ds) { |
| 1948 | params.is_cross_site_redirect = ds->isClientRedirect(); |
| 1949 | } else { |
| 1950 | params.is_cross_site_redirect = false; |
| 1951 | } |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 1952 | |
| 1953 | Send(new ViewHostMsg_OpenURL(routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1954 | } |
| 1955 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1956 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1957 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1958 | void RenderViewImpl::LoadNavigationErrorPage( |
| 1959 | WebFrame* frame, |
| 1960 | const WebURLRequest& failed_request, |
| 1961 | const WebURLError& error, |
| 1962 | const std::string& html, |
| 1963 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1964 | std::string alt_html; |
| 1965 | const std::string* error_html; |
| 1966 | |
| 1967 | if (!html.empty()) { |
| 1968 | error_html = &html; |
| 1969 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1970 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 1971 | frame, failed_request, error, &alt_html, NULL); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1972 | error_html = &alt_html; |
| 1973 | } |
| 1974 | |
| 1975 | frame->loadHTMLString(*error_html, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1976 | GURL(kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 1977 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1978 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1979 | } |
| 1980 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1981 | bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1982 | const string16& message, |
| 1983 | const string16& default_value, |
| 1984 | const GURL& frame_url, |
| 1985 | string16* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1986 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1987 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1988 | if (!result) |
| 1989 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1990 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1991 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1992 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1993 | return success; |
| 1994 | } |
| 1995 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1996 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1997 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1998 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1999 | // it is particularly important that we do not call willEnterModalLoop as |
| 2000 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2001 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2002 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2003 | |
| 2004 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 2005 | return Send(message); |
| 2006 | } |
| 2007 | |
[email protected] | c9bc8f1 | 2012-12-15 22:20:09 | [diff] [blame] | 2008 | void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { |
| 2009 | int id = next_snapshot_id_++; |
| 2010 | pending_snapshots_.insert(std::make_pair(id, callback)); |
| 2011 | Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id)); |
| 2012 | } |
| 2013 | |
| 2014 | void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| 2015 | const gfx::Size& size, const std::vector<unsigned char>& png) { |
| 2016 | PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id); |
| 2017 | DCHECK(it != pending_snapshots_.end()); |
| 2018 | it->second.Run(size, png); |
| 2019 | pending_snapshots_.erase(it); |
| 2020 | } |
| 2021 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2022 | // WebKit::WebViewClient ------------------------------------------------------ |
| 2023 | |
[email protected] | 916dfb6 | 2012-03-05 03:39:37 | [diff] [blame] | 2024 | WebView* RenderViewImpl::createView( |
| 2025 | WebFrame* creator, |
| 2026 | const WebURLRequest& request, |
| 2027 | const WebWindowFeatures& features, |
| 2028 | const WebString& frame_name, |
| 2029 | WebNavigationPolicy policy) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2030 | // Check to make sure we aren't overloading on popups. |
| 2031 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 2032 | return NULL; |
| 2033 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2034 | ViewHostMsg_CreateWindow_Params params; |
| 2035 | params.opener_id = routing_id_; |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2036 | params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2037 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 2038 | params.session_storage_namespace_id = session_storage_namespace_id_; |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2039 | if (frame_name != "_blank") |
| 2040 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2041 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2042 | params.opener_url = creator->document().url(); |
[email protected] | 7f48b71 | 2013-01-25 01:48:30 | [diff] [blame] | 2043 | GURL security_url(creator->document().securityOrigin().toString().utf8()); |
| 2044 | if (!security_url.is_valid()) |
| 2045 | security_url = GURL(); |
| 2046 | params.opener_security_origin = security_url; |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2047 | params.opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
| 2048 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 2049 | if (!request.isNull()) |
| 2050 | params.target_url = request.url(); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2051 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2052 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame^] | 2053 | int32 main_frame_routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2054 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 2055 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2056 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 2057 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2058 | new ViewHostMsg_CreateWindow(params, |
| 2059 | &routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame^] | 2060 | &main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2061 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2062 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2063 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2064 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2065 | |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2066 | WebUserGestureIndicator::consumeUserGesture(); |
[email protected] | c5926242 | 2012-11-30 21:20:52 | [diff] [blame] | 2067 | |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 2068 | WebPreferences transferred_preferences = webkit_preferences_; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2069 | |
| 2070 | // Unless accelerated compositing has been explicitly disabled from the |
| 2071 | // command line (e.g. via the blacklist or about:flags) re-enable it for |
| 2072 | // new views that get spawned by this view. This gets around the issue that |
| 2073 | // background extension pages disable accelerated compositing via web prefs |
| 2074 | // but can themselves spawn a visible render view which should be allowed |
| 2075 | // use gpu acceleration. |
| 2076 | if (!webkit_preferences_.accelerated_compositing_enabled) { |
| 2077 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2078 | if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing)) |
| 2079 | transferred_preferences.accelerated_compositing_enabled = true; |
| 2080 | } |
| 2081 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2082 | RenderViewImpl* view = RenderViewImpl::Create( |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2083 | routing_id_, |
| 2084 | renderer_preferences_, |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 2085 | transferred_preferences, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2086 | shared_popup_counter_, |
| 2087 | routing_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame^] | 2088 | main_frame_routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 2089 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2090 | cloned_session_storage_namespace_id, |
[email protected] | 5cef23d | 2013-02-27 13:11:21 | [diff] [blame] | 2091 | string16(), // WebCore will take care of setting the correct name. |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2092 | true, |
| 2093 | false, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 2094 | 1, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2095 | screen_info_, |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 2096 | accessibility_mode_, |
| 2097 | allow_partial_swap_); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2098 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2099 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2100 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2101 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2102 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2103 | // Copy over the alternate error page URL so we can have alt error pages in |
| 2104 | // the new render view (we don't need the browser to send the URL back down). |
| 2105 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 2106 | |
| 2107 | return view->webview(); |
| 2108 | } |
| 2109 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2110 | WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 2111 | RenderWidget* widget = |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2112 | RenderWidget::Create(routing_id_, popup_type, screen_info_); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2113 | return widget->webwidget(); |
| 2114 | } |
| 2115 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2116 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2117 | const WebPopupMenuInfo& popup_menu_info, |
| 2118 | WebExternalPopupMenuClient* popup_menu_client) { |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2119 | // An IPC message is sent to the browser to build and display the actual |
| 2120 | // popup. The user could have time to click a different select by the time |
| 2121 | // the popup is shown. In that case external_popup_menu_ is non NULL. |
| 2122 | // By returning NULL in that case, we instruct WebKit to cancel that new |
| 2123 | // popup. So from the user perspective, only the first one will show, and |
| 2124 | // will have to close the first one before another one can be shown. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 2125 | if (external_popup_menu_) |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 2126 | return NULL; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2127 | external_popup_menu_.reset( |
| 2128 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 2129 | return external_popup_menu_.get(); |
| 2130 | } |
| 2131 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2132 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 2133 | webkit::ppapi::PluginInstance* plugin) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2134 | #if defined(ENABLE_PLUGINS) |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 2135 | GURL active_url; |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 2136 | if (webview() && webview()->mainFrame()) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2137 | active_url = GURL(webview()->mainFrame()->document().url()); |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 2138 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
[email protected] | bee6eb7 | 2012-07-26 03:47:32 | [diff] [blame] | 2139 | routing_id_, plugin, active_url, screen_info_); |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 2140 | widget->show(WebKit::WebNavigationPolicyIgnore); |
[email protected] | 92abcb83 | 2011-01-06 20:39:56 | [diff] [blame] | 2141 | return widget; |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2142 | #else // defined(ENABLE_PLUGINS) |
| 2143 | NOTREACHED() << "CreatePepperFullscreenContainer: plugins disabled"; |
| 2144 | return NULL; |
| 2145 | #endif |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 2146 | } |
| 2147 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2148 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace( |
| 2149 | unsigned quota) { |
[email protected] | b928936b | 2012-04-13 01:16:16 | [diff] [blame] | 2150 | CHECK(session_storage_namespace_id_ != |
| 2151 | dom_storage::kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 2152 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 2153 | } |
| 2154 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2155 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2156 | const WebConsoleMessage& message, const WebString& source_name, |
| 2157 | unsigned source_line) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2158 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 2159 | switch (message.level) { |
[email protected] | 80ac894 | 2013-01-30 22:53:22 | [diff] [blame] | 2160 | case WebConsoleMessage::LevelDebug: |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2161 | log_severity = logging::LOG_VERBOSE; |
| 2162 | break; |
| 2163 | case WebConsoleMessage::LevelLog: |
| 2164 | log_severity = logging::LOG_INFO; |
| 2165 | break; |
| 2166 | case WebConsoleMessage::LevelWarning: |
| 2167 | log_severity = logging::LOG_WARNING; |
| 2168 | break; |
| 2169 | case WebConsoleMessage::LevelError: |
| 2170 | log_severity = logging::LOG_ERROR; |
| 2171 | break; |
| 2172 | default: |
| 2173 | NOTREACHED(); |
| 2174 | } |
| 2175 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2176 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 2177 | static_cast<int32>(log_severity), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 2178 | message.text, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2179 | static_cast<int32>(source_line), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 2180 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2181 | } |
| 2182 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2183 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 2184 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2185 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2186 | } |
| 2187 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2188 | WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2189 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 2190 | } |
| 2191 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2192 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2193 | const WebString& path, |
| 2194 | WebFileChooserCompletion* chooser_completion) { |
| 2195 | int id = enumeration_completion_id_++; |
| 2196 | enumeration_completions_[id] = chooser_completion; |
| 2197 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 2198 | routing_id_, |
| 2199 | id, |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 2200 | webkit_base::WebStringToFilePath(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 2201 | } |
| 2202 | |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 2203 | void RenderViewImpl::initializeHelperPluginWebFrame( |
| 2204 | WebKit::WebHelperPlugin* plugin) { |
| 2205 | plugin->initializeFrame(this); |
| 2206 | } |
| 2207 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2208 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2209 | if (is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2210 | DVLOG(1) << "didStartLoading called while loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2211 | return; |
| 2212 | } |
| 2213 | |
| 2214 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2215 | |
| 2216 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2217 | |
| 2218 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2219 | } |
| 2220 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2221 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2222 | if (!is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 2223 | DVLOG(1) << "DidStopLoading called while not loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2224 | return; |
| 2225 | } |
| 2226 | |
| 2227 | is_loading_ = false; |
| 2228 | |
| 2229 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 2230 | // when done loading. This currently isn't an issue as the favicon is only |
| 2231 | // displayed when done loading. Ideally we would send notification when |
| 2232 | // finished parsing the head, but webkit doesn't support that yet. |
| 2233 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2234 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 2235 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2236 | if (load_progress_tracker_ != NULL) |
| 2237 | load_progress_tracker_->DidStopLoading(); |
| 2238 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 2239 | DidStopLoadingIcons(); |
| 2240 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2241 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2242 | } |
| 2243 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2244 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 2245 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2246 | if (load_progress_tracker_ != NULL) |
| 2247 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 2248 | } |
| 2249 | |
[email protected] | 550b0c9 | 2013-02-04 05:09:15 | [diff] [blame] | 2250 | void RenderViewImpl::didCancelCompositionOnSelectionChange() { |
| 2251 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 2252 | } |
| 2253 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2254 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 2255 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 2256 | return; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 2257 | |
[email protected] | fca5202 | 2012-04-03 17:00:50 | [diff] [blame] | 2258 | if (is_empty_selection) |
| 2259 | selection_text_.clear(); |
| 2260 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 2261 | SyncSelectionIfRequired(); |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 2262 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2263 | } |
| 2264 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2265 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 2266 | const std::string& name = UTF16ToUTF8(command_name); |
| 2267 | if (StartsWithASCII(name, "Move", true) || |
| 2268 | StartsWithASCII(name, "Insert", true) || |
| 2269 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2270 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2271 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2272 | } |
| 2273 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2274 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2275 | if (edit_commands_.empty()) |
| 2276 | return false; |
| 2277 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2278 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2279 | if (!frame) |
| 2280 | return false; |
| 2281 | |
| 2282 | EditCommands::iterator it = edit_commands_.begin(); |
| 2283 | EditCommands::iterator end = edit_commands_.end(); |
| 2284 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2285 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2286 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2287 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2288 | // key (but it's the exception). Once one edit command is not executed, it |
| 2289 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2290 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 2291 | WebString::fromUTF8(it->value))) |
| 2292 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2293 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2294 | } |
| 2295 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2296 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2297 | } |
| 2298 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2299 | WebKit::WebColorChooser* RenderViewImpl::createColorChooser( |
| 2300 | WebKit::WebColorChooserClient* client, |
| 2301 | const WebKit::WebColor& initial_color) { |
| 2302 | RendererWebColorChooserImpl* color_chooser = |
| 2303 | new RendererWebColorChooserImpl(this, client); |
| 2304 | color_chooser->Open(static_cast<SkColor>(initial_color)); |
| 2305 | return color_chooser; |
| 2306 | } |
| 2307 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2308 | bool RenderViewImpl::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2309 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2310 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 2311 | // Do not open the file dialog in a hidden RenderView. |
| 2312 | if (is_hidden()) |
| 2313 | return false; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2314 | FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2315 | if (params.directory) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2316 | ipc_params.mode = FileChooserParams::OpenFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2317 | else if (params.multiSelect) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2318 | ipc_params.mode = FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 2319 | else if (params.saveAs) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2320 | ipc_params.mode = FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2321 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2322 | ipc_params.mode = FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2323 | ipc_params.title = params.title; |
| 2324 | ipc_params.default_file_name = |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 2325 | webkit_base::WebStringToFilePath(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 2326 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 2327 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 2328 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2329 | #if defined(OS_ANDROID) |
| 2330 | ipc_params.capture = params.capture; |
| 2331 | #endif |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2332 | |
| 2333 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2334 | } |
| 2335 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2336 | void RenderViewImpl::runModalAlertDialog(WebFrame* frame, |
| 2337 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2338 | RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2339 | message, |
| 2340 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2341 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2342 | NULL); |
| 2343 | } |
| 2344 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2345 | bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame, |
| 2346 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2347 | return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2348 | message, |
| 2349 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2350 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2351 | NULL); |
| 2352 | } |
| 2353 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2354 | bool RenderViewImpl::runModalPromptDialog(WebFrame* frame, |
| 2355 | const WebString& message, |
| 2356 | const WebString& default_value, |
| 2357 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2358 | string16 result; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2359 | bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2360 | message, |
| 2361 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2362 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2363 | &result); |
| 2364 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2365 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2366 | return ok; |
| 2367 | } |
| 2368 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2369 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2370 | WebFrame* frame, const WebString& message) { |
[email protected] | ab533826b | 2013-05-10 23:54:56 | [diff] [blame] | 2371 | bool is_reload = false; |
| 2372 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2373 | if (ds) |
| 2374 | is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload); |
| 2375 | return runModalBeforeUnloadDialog(frame, is_reload, message); |
| 2376 | } |
| 2377 | |
| 2378 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
| 2379 | WebFrame* frame, bool is_reload, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2380 | // If we are swapping out, we have already run the beforeunload handler. |
| 2381 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 2382 | // at all, to avoid running it twice. |
| 2383 | if (is_swapped_out_) |
| 2384 | return true; |
| 2385 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2386 | bool success = false; |
| 2387 | // This is an ignored return value, but is included so we can accept the same |
| 2388 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2389 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2390 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2391 | routing_id_, frame->document().url(), message, is_reload, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2392 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2393 | return success; |
| 2394 | } |
| 2395 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2396 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2397 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | 3175fea | 2013-05-16 10:57:48 | [diff] [blame] | 2398 | ContextMenuParams params = ContextMenuParamsBuilder::Build(data); |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2399 | |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2400 | // Plugins, e.g. PDF, don't currently update the render view when their |
| 2401 | // selected text changes, but the context menu params do contain the updated |
| 2402 | // selection. If that's the case, update the render view's state just prior |
| 2403 | // to showing the context menu. |
| 2404 | // TODO(asvitkine): http://crbug.com/152432 |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 2405 | if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_, |
| 2406 | selection_text_offset_, |
| 2407 | selection_range_, |
| 2408 | params)) { |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2409 | selection_text_ = params.selection_text; |
| 2410 | // TODO(asvitkine): Text offset and range is not available in this case. |
| 2411 | selection_text_offset_ = 0; |
| 2412 | selection_range_ = ui::Range(0, selection_text_.length()); |
| 2413 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 2414 | selection_text_, |
| 2415 | selection_text_offset_, |
| 2416 | selection_range_)); |
| 2417 | } |
| 2418 | |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2419 | // frame is NULL if invoked by BlockedPlugin. |
| 2420 | if (frame) |
| 2421 | params.frame_id = frame->identifier(); |
| 2422 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2423 | // Serializing a GURL longer than kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2424 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2425 | // in the context menu. |
| 2426 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2427 | // data encoded images. We should have a way to save them. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2428 | if (params.src_url.spec().size() > kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2429 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 2430 | context_menu_node_ = data.node; |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2431 | |
| 2432 | #if defined(OS_ANDROID) |
| 2433 | gfx::Rect start_rect; |
| 2434 | gfx::Rect end_rect; |
| 2435 | GetSelectionBounds(&start_rect, &end_rect); |
[email protected] | 326a234 | 2013-02-15 15:47:51 | [diff] [blame] | 2436 | params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom()); |
| 2437 | params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom()); |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2438 | #endif |
| 2439 | |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2440 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2441 | |
| 2442 | FOR_EACH_OBSERVER( |
| 2443 | RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2444 | } |
| 2445 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2446 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2447 | } |
| 2448 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2449 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 2450 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2451 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2452 | if (latest_url == target_url_) |
| 2453 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2454 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2455 | // Tell the browser to display a destination link. |
| 2456 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2457 | target_url_status_ == TARGET_PENDING) { |
| 2458 | // If we have a request in-flight, save the URL to be sent when we |
| 2459 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2460 | // any existing pending sends. |
| 2461 | pending_target_url_ = latest_url; |
| 2462 | target_url_status_ = TARGET_PENDING; |
| 2463 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2464 | // URLs larger than |kMaxURLChars| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2465 | // see |ParamTraits<GURL>|. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2466 | if (latest_url.possibly_invalid_spec().size() > kMaxURLChars) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2467 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2468 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2469 | target_url_ = latest_url; |
| 2470 | target_url_status_ = TARGET_INFLIGHT; |
| 2471 | } |
| 2472 | } |
| 2473 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 2474 | gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect( |
| 2475 | const gfx::RectF& rect) const { |
| 2476 | gfx::RectF window_rect = rect; |
| 2477 | window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor()); |
| 2478 | return window_rect; |
| 2479 | } |
| 2480 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2481 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | a183fb8 | 2012-12-14 04:46:22 | [diff] [blame] | 2482 | // No need to update state if no page has committed yet. |
| 2483 | if (page_id_ == -1) |
| 2484 | return; |
| 2485 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2486 | int delay; |
| 2487 | if (send_content_state_immediately_) |
| 2488 | delay = 0; |
| 2489 | else if (is_hidden()) |
| 2490 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2491 | else |
| 2492 | delay = kDelaySecondsForContentStateSync; |
| 2493 | |
| 2494 | if (nav_state_sync_timer_.IsRunning()) { |
| 2495 | // The timer is already running. If the delay of the timer maches the amount |
| 2496 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2497 | // gets started with the right delay. |
| 2498 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2499 | return; |
| 2500 | nav_state_sync_timer_.Stop(); |
| 2501 | } |
| 2502 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 2503 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2504 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2505 | } |
| 2506 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2507 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2508 | mouse_over_url_ = GURL(url); |
| 2509 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2510 | } |
| 2511 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2512 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2513 | focus_url_ = GURL(url); |
| 2514 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2515 | } |
| 2516 | |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 2517 | void RenderViewImpl::startDragging(WebFrame* frame, |
| 2518 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2519 | WebDragOperationsMask mask, |
| 2520 | const WebImage& image, |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2521 | const WebPoint& webImageOffset) { |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2522 | WebDropData drop_data(data); |
| 2523 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2524 | gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2525 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2526 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2527 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 2528 | image.getSkBitmap(), |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 2529 | imageOffset, |
| 2530 | possible_drag_event_info_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2531 | } |
| 2532 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2533 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2534 | return renderer_preferences_.can_accept_load_drops; |
| 2535 | } |
| 2536 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2537 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2538 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2539 | } |
| 2540 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2541 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2542 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2543 | } |
| 2544 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2545 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 2546 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2547 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 2548 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2549 | } |
| 2550 | |
[email protected] | 572a6ca | 2012-10-11 19:38:01 | [diff] [blame] | 2551 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
| 2552 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
| 2553 | } |
| 2554 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2555 | void RenderViewImpl::didUpdateLayout() { |
| 2556 | // We don't always want to set up a timer, only if we've been put in that |
| 2557 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2558 | // message. |
| 2559 | if (!send_preferred_size_changes_ || !webview()) |
| 2560 | return; |
| 2561 | |
| 2562 | if (check_preferred_size_timer_.IsRunning()) |
| 2563 | return; |
| 2564 | check_preferred_size_timer_.Start(FROM_HERE, |
| 2565 | TimeDelta::FromMilliseconds(0), this, |
| 2566 | &RenderViewImpl::CheckPreferredSize); |
| 2567 | } |
| 2568 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2569 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2570 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2571 | } |
| 2572 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2573 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2574 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2575 | } |
| 2576 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2577 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2578 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2579 | } |
| 2580 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2581 | void RenderViewImpl::postAccessibilityNotification( |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2582 | const WebAccessibilityObject& obj, |
| 2583 | WebAccessibilityNotification notification) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2584 | if (renderer_accessibility_) { |
| 2585 | renderer_accessibility_->HandleWebAccessibilityNotification( |
| 2586 | obj, notification); |
| 2587 | } |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2588 | } |
| 2589 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2590 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2591 | const WebString& value) { |
| 2592 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2593 | key.utf8(), |
| 2594 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2595 | } |
| 2596 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2597 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2598 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2599 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2600 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2601 | // we won't have to test for user gesture anymore and we can |
| 2602 | // move that code back to render_widget.cc |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2603 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2604 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2605 | Send(new ViewHostMsg_Focus(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2609 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2610 | // TODO(jcivelli): see TODO above in didFocus(). |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 2611 | if (WebUserGestureIndicator::isProcessingUserGesture() && |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 2612 | !RenderThreadImpl::current()->layout_test_mode()) { |
[email protected] | e117615 | 2013-03-06 09:16:44 | [diff] [blame] | 2613 | Send(new ViewHostMsg_Blur(routing_id_)); |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2614 | } |
| 2615 | } |
| 2616 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2617 | // 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] | 2618 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2619 | // point to dispatch the ShowView message. |
| 2620 | // |
| 2621 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 2622 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2623 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2624 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2625 | if (did_show_) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2626 | // When supports_multiple_windows is disabled, popups are reusing |
| 2627 | // the same view. In some scenarios, this makes WebKit to call show() twice. |
[email protected] | c9edabd | 2013-05-23 13:56:24 | [diff] [blame] | 2628 | if (webkit_preferences_.supports_multiple_windows) |
| 2629 | NOTREACHED() << "received extraneous Show call"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2630 | return; |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2631 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2632 | did_show_ = true; |
| 2633 | |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2634 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2635 | |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 2636 | if (GetContentClient()->renderer()->AllowPopup()) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2637 | opened_by_user_gesture_ = true; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2638 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2639 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2640 | if (!opened_by_user_gesture_) { |
| 2641 | // We exempt background tabs for compat with older versions of Chrome. |
| 2642 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2643 | // we probably don't need this check. |
| 2644 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2645 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2646 | } |
| 2647 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2648 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2649 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2650 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2651 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2652 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2653 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2654 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2655 | } |
| 2656 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2657 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2658 | DCHECK(did_show_) << "should already have shown the view"; |
| 2659 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2660 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2661 | // showModalDialog to function properly. |
| 2662 | // |
| 2663 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2664 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2665 | // handed manner. |
| 2666 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2667 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2668 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2669 | |
[email protected] | 08a1c810 | 2012-05-11 23:14:26 | [diff] [blame] | 2670 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 2671 | routing_id_, opener_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2672 | } |
| 2673 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2674 | bool RenderViewImpl::enterFullScreen() { |
| 2675 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 2676 | return true; |
| 2677 | } |
| 2678 | |
| 2679 | void RenderViewImpl::exitFullScreen() { |
| 2680 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 2681 | } |
| 2682 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2683 | bool RenderViewImpl::requestPointerLock() { |
| 2684 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2685 | } |
| 2686 | |
| 2687 | void RenderViewImpl::requestPointerUnlock() { |
| 2688 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2689 | } |
| 2690 | |
| 2691 | bool RenderViewImpl::isPointerLocked() { |
| 2692 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2693 | webwidget_mouse_lock_target_.get()); |
| 2694 | } |
| 2695 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2696 | void RenderViewImpl::didActivateCompositor(int input_handler_identifier) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 2697 | #if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003 |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 2698 | InputHandlerManager* input_handler_manager = |
| 2699 | RenderThreadImpl::current()->input_handler_manager(); |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 2700 | if (input_handler_manager) { |
| 2701 | input_handler_manager->AddInputHandler( |
| 2702 | routing_id_, |
| 2703 | compositor_->GetInputHandler(), |
| 2704 | AsWeakPtr()); |
| 2705 | } |
[email protected] | 70cff2750 | 2013-01-17 09:16:49 | [diff] [blame] | 2706 | #endif |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2707 | |
| 2708 | RenderWidget::didActivateCompositor(input_handler_identifier); |
| 2709 | } |
| 2710 | |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2711 | void RenderViewImpl::didHandleGestureEvent( |
| 2712 | const WebGestureEvent& event, |
| 2713 | bool event_cancelled) { |
| 2714 | RenderWidget::didHandleGestureEvent(event, event_cancelled); |
| 2715 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2716 | DidHandleGestureEvent(event)); |
| 2717 | } |
| 2718 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2719 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2720 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2721 | WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 2722 | const WebPluginParams& params) { |
[email protected] | eaacd1f | 2011-09-23 02:32:55 | [diff] [blame] | 2723 | WebPlugin* plugin = NULL; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2724 | if (GetContentClient()->renderer()->OverrideCreatePlugin( |
[email protected] | eaacd1f | 2011-09-23 02:32:55 | [diff] [blame] | 2725 | this, frame, params, &plugin)) { |
| 2726 | return plugin; |
| 2727 | } |
| 2728 | |
[email protected] | 463ba65fd | 2013-01-03 23:16:43 | [diff] [blame] | 2729 | #if defined(ENABLE_PLUGINS) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2730 | if (UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType) { |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 2731 | return GetBrowserPluginManager()->CreateBrowserPlugin(this, frame, params); |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 2732 | } |
| 2733 | |
[email protected] | a813c8e | 2011-10-08 01:34:11 | [diff] [blame] | 2734 | webkit::WebPluginInfo info; |
| 2735 | std::string mime_type; |
| 2736 | bool found = GetPluginInfo(params.url, frame->top()->document().url(), |
| 2737 | params.mimeType.utf8(), &info, &mime_type); |
| 2738 | if (!found) |
| 2739 | return NULL; |
| 2740 | |
| 2741 | WebPluginParams params_to_use = params; |
| 2742 | params_to_use.mimeType = WebString::fromUTF8(mime_type); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2743 | return CreatePlugin(frame, info, params_to_use); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2744 | #else |
| 2745 | return NULL; |
| 2746 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2747 | } |
| 2748 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2749 | WebSharedWorker* RenderViewImpl::createSharedWorker( |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2750 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2751 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2752 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2753 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2754 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2755 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2756 | ViewHostMsg_CreateWorker_Params params; |
| 2757 | params.url = url; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2758 | params.name = name; |
| 2759 | params.document_id = document_id; |
| 2760 | params.render_view_route_id = routing_id_; |
| 2761 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2762 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2763 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2764 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2765 | if (url_mismatch) { |
| 2766 | return NULL; |
| 2767 | } else { |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2768 | return new WebSharedWorkerProxy(RenderThreadImpl::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2769 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2770 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2771 | route_id, |
| 2772 | routing_id_); |
| 2773 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2774 | } |
| 2775 | |
[email protected] | 97b150db | 2012-08-16 18:26:02 | [diff] [blame] | 2776 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
| 2777 | WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2778 | FOR_EACH_OBSERVER( |
| 2779 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 2780 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2781 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 2782 | #if defined(ENABLE_WEBRTC) |
[email protected] | b3d080fc | 2013-03-01 04:17:32 | [diff] [blame] | 2783 | if (MediaStreamImpl::CheckMediaStream(url)) { |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 2784 | #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 2785 | bool found_neon = |
| 2786 | (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; |
| 2787 | UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon); |
| 2788 | #endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
[email protected] | d05e216 | 2012-11-16 22:21:46 | [diff] [blame] | 2789 | EnsureMediaStreamImpl(); |
| 2790 | return new webkit_media::WebMediaPlayerMS( |
| 2791 | frame, client, AsWeakPtr(), media_stream_impl_, new RenderMediaLog()); |
| 2792 | } |
| 2793 | #endif |
| 2794 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2795 | #if defined(OS_ANDROID) |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2796 | GpuChannelHost* gpu_channel_host = |
| 2797 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2798 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2799 | if (!gpu_channel_host) { |
| 2800 | LOG(ERROR) << "Failed to establish GPU channel for media player"; |
| 2801 | return NULL; |
| 2802 | } |
| 2803 | |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 2804 | scoped_refptr<cc::ContextProvider> context_provider = |
| 2805 | RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); |
[email protected] | e06e112 | 2013-03-15 17:12:38 | [diff] [blame] | 2806 | if (!context_provider) { |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 2807 | LOG(ERROR) << "Failed to get context3d for media player"; |
| 2808 | return NULL; |
| 2809 | } |
| 2810 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2811 | if (!media_player_proxy_) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2812 | media_player_proxy_ = new WebMediaPlayerProxyImplAndroid( |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2813 | this, media_player_manager_.get()); |
| 2814 | } |
[email protected] | 1051443 | 2013-04-26 23:32:19 | [diff] [blame] | 2815 | return new webkit_media::WebMediaPlayerAndroid( |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2816 | frame, |
| 2817 | client, |
| 2818 | media_player_manager_.get(), |
| 2819 | media_player_proxy_, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2820 | new StreamTextureFactoryImpl( |
[email protected] | 1e04260f2 | 2013-04-27 20:45:42 | [diff] [blame] | 2821 | context_provider->Context3d(), gpu_channel_host, routing_id_), |
| 2822 | new RenderMediaLog()); |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2823 | #endif |
| 2824 | |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 2825 | scoped_refptr<media::AudioRendererSink> sink; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2826 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
[email protected] | 17c4ce62f | 2013-05-03 19:54:02 | [diff] [blame] | 2827 | sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()-> |
| 2828 | CreateInput(routing_id_); |
| 2829 | DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2830 | } |
| 2831 | |
[email protected] | e82b2bd | 2013-01-02 17:47:57 | [diff] [blame] | 2832 | scoped_refptr<media::GpuVideoDecoder::Factories> gpu_factories; |
[email protected] | 15d206e | 2012-08-17 22:35:13 | [diff] [blame] | 2833 | WebGraphicsContext3DCommandBufferImpl* context3d = NULL; |
[email protected] | 5f04c353 | 2012-09-25 01:28:39 | [diff] [blame] | 2834 | if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode)) |
[email protected] | 15d206e | 2012-08-17 22:35:13 | [diff] [blame] | 2835 | context3d = RenderThreadImpl::current()->GetGpuVDAContext3D(); |
[email protected] | 851334d | 2012-06-15 22:39:31 | [diff] [blame] | 2836 | if (context3d) { |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 2837 | scoped_refptr<base::MessageLoopProxy> factories_loop = |
| 2838 | RenderThreadImpl::current()->compositor_message_loop_proxy(); |
| 2839 | if (!factories_loop) |
[email protected] | 7f1f63f | 2013-03-07 06:07:29 | [diff] [blame] | 2840 | factories_loop = base::MessageLoopProxy::current(); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2841 | GpuChannelHost* gpu_channel_host = |
| 2842 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2843 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
[email protected] | e82b2bd | 2013-01-02 17:47:57 | [diff] [blame] | 2844 | gpu_factories = new RendererGpuVideoDecoderFactories( |
| 2845 | gpu_channel_host, factories_loop, context3d); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2846 | } |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2847 | |
[email protected] | e82b2bd | 2013-01-02 17:47:57 | [diff] [blame] | 2848 | webkit_media::WebMediaPlayerParams params( |
[email protected] | b3d080fc | 2013-03-01 04:17:32 | [diff] [blame] | 2849 | sink, gpu_factories, new RenderMediaLog()); |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 2850 | WebMediaPlayer* media_player = |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2851 | GetContentClient()->renderer()->OverrideCreateWebMediaPlayer( |
[email protected] | e82b2bd | 2013-01-02 17:47:57 | [diff] [blame] | 2852 | this, frame, client, AsWeakPtr(), params); |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2853 | if (!media_player) { |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2854 | media_player = new webkit_media::WebMediaPlayerImpl( |
[email protected] | e82b2bd | 2013-01-02 17:47:57 | [diff] [blame] | 2855 | frame, client, AsWeakPtr(), params); |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2856 | } |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2857 | return media_player; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2858 | } |
| 2859 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2860 | WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost( |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2861 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
[email protected] | cdeeeb2 | 2012-01-11 07:44:23 | [diff] [blame] | 2862 | if (!frame || !frame->view()) |
| 2863 | return NULL; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2864 | return new RendererWebApplicationCacheHostImpl( |
| 2865 | FromWebView(frame->view()), client, |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2866 | RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy()); |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2867 | } |
| 2868 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2869 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 2870 | return &cookie_jar_; |
| 2871 | } |
| 2872 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2873 | void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) { |
[email protected] | 5090445 | 2013-05-09 02:05:12 | [diff] [blame] | 2874 | Send(new ViewHostMsg_FrameAttached(routing_id_, parent->identifier(), |
| 2875 | child->identifier(), UTF16ToUTF8(child->assignedName()))); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2876 | } |
| 2877 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 2878 | void RenderViewImpl::didDisownOpener(WebKit::WebFrame* frame) { |
[email protected] | 29ece2e | 2013-04-03 04:53:52 | [diff] [blame] | 2879 | // We only need to notify the browser if the active, top-level frame clears |
| 2880 | // its opener. We can ignore cases where a swapped out frame clears its |
| 2881 | // opener after hearing about it from the browser, and the browser does not |
| 2882 | // (yet) care about subframe openers. |
| 2883 | if (is_swapped_out_ || frame->parent()) |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 2884 | return; |
| 2885 | |
| 2886 | // Notify WebContents and all its swapped out RenderViews. |
| 2887 | Send(new ViewHostMsg_DidDisownOpener(routing_id_)); |
| 2888 | } |
| 2889 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2890 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 5090445 | 2013-05-09 02:05:12 | [diff] [blame] | 2891 | int64 parent_frame_id = -1; |
| 2892 | if (frame->parent()) |
| 2893 | parent_frame_id = frame->parent()->identifier(); |
| 2894 | |
| 2895 | Send(new ViewHostMsg_FrameDetached(routing_id_, parent_frame_id, |
| 2896 | frame->identifier())); |
[email protected] | 8607c83 | 2013-01-18 14:11:57 | [diff] [blame] | 2897 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2898 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2899 | } |
| 2900 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2901 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2902 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2903 | } |
| 2904 | |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 2905 | void RenderViewImpl::didChangeName(WebFrame* frame, |
| 2906 | const WebString& name) { |
[email protected] | 34cdde09 | 2013-01-10 02:29:03 | [diff] [blame] | 2907 | if (!renderer_preferences_.report_frame_name_changes) |
| 2908 | return; |
| 2909 | |
[email protected] | 25bcc8f | 2013-01-09 02:49:25 | [diff] [blame] | 2910 | Send(new ViewHostMsg_UpdateFrameName(routing_id_, |
| 2911 | frame->identifier(), |
| 2912 | !frame->parent(), |
| 2913 | UTF16ToUTF8(name))); |
| 2914 | } |
| 2915 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2916 | void RenderViewImpl::loadURLExternally( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2917 | WebFrame* frame, const WebURLRequest& request, |
| 2918 | WebNavigationPolicy policy) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2919 | loadURLExternally(frame, request, policy, WebString()); |
| 2920 | } |
| 2921 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2922 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 2923 | OnRepaint(size); |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2924 | } |
| 2925 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2926 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 2927 | const std::string& value) { |
| 2928 | EditCommands edit_commands; |
| 2929 | edit_commands.push_back(EditCommand(name, value)); |
| 2930 | OnSetEditCommandsForNextKeyEvent(edit_commands); |
| 2931 | } |
| 2932 | |
| 2933 | void RenderViewImpl::ClearEditCommands() { |
| 2934 | edit_commands_.clear(); |
| 2935 | } |
| 2936 | |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 2937 | SSLStatus RenderViewImpl::GetSSLStatusOfFrame(WebKit::WebFrame* frame) const { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 2938 | return SSLStatus(); |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 2939 | } |
| 2940 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2941 | void RenderViewImpl::loadURLExternally( |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2942 | WebFrame* frame, const WebURLRequest& request, |
| 2943 | WebNavigationPolicy policy, |
| 2944 | const WebString& suggested_name) { |
[email protected] | 5650554 | 2012-05-12 00:25:37 | [diff] [blame] | 2945 | Referrer referrer( |
| 2946 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 2947 | GetReferrerPolicyFromRequest(frame, request)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2948 | if (policy == WebKit::WebNavigationPolicyDownload) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2949 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer, |
| 2950 | suggested_name)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2951 | } else { |
[email protected] | 5650554 | 2012-05-12 00:25:37 | [diff] [blame] | 2952 | OpenURL(frame, request.url(), referrer, policy); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2953 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2954 | } |
| 2955 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2956 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 2957 | WebFrame* frame, WebDataSource::ExtraData* extraData, |
| 2958 | const WebURLRequest& request, WebNavigationType type, |
| 2959 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 099df81cf | 2012-11-14 17:44:04 | [diff] [blame] | 2960 | if (request.url() != GURL(kSwappedOutURL) && |
| 2961 | GetContentClient()->renderer()->HandleNavigation(frame, request, type, |
| 2962 | default_policy, |
| 2963 | is_redirect)) { |
| 2964 | return WebKit::WebNavigationPolicyIgnore; |
| 2965 | } |
| 2966 | |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2967 | Referrer referrer( |
| 2968 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 2969 | GetReferrerPolicyFromRequest(frame, request)); |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2970 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2971 | if (is_swapped_out_) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2972 | if (request.url() != GURL(kSwappedOutURL)) { |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2973 | // Targeted links may try to navigate a swapped out frame. Allow the |
| 2974 | // browser process to navigate the tab instead. Note that it is also |
| 2975 | // possible for non-targeted navigations (from this view) to arrive |
| 2976 | // here just after we are swapped out. It's ok to send them to the |
| 2977 | // browser, as long as they're for the top level frame. |
| 2978 | // TODO(creis): Ensure this supports targeted form submissions when |
| 2979 | // fixing http://crbug.com/101395. |
| 2980 | if (frame->parent() == NULL) { |
| 2981 | OpenURL(frame, request.url(), referrer, default_policy); |
| 2982 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2983 | } |
| 2984 | |
| 2985 | // We should otherwise ignore in-process iframe navigations, if they |
| 2986 | // arrive just after we are swapped out. |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2987 | return WebKit::WebNavigationPolicyIgnore; |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2988 | } |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2989 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2990 | // Allow kSwappedOutURL to complete. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2991 | return default_policy; |
| 2992 | } |
| 2993 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2994 | // Webkit is asking whether to navigate to a new URL. |
| 2995 | // This is fine normally, except if we're showing UI from one security |
| 2996 | // context and they're trying to navigate to a different context. |
| 2997 | const GURL& url = request.url(); |
| 2998 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2999 | // A content initiated navigation may have originated from a link-click, |
| 3000 | // script, drag-n-drop operation, etc. |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3001 | bool is_content_initiated = static_cast<DocumentState*>(extraData)-> |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3002 | navigation_state()->is_content_initiated(); |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 3003 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3004 | // Experimental: |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3005 | // If --enable-strict-site-isolation or --site-per-process is enabled, send |
| 3006 | // all top-level navigations to the browser to let it swap processes when |
| 3007 | // crossing site boundaries. This is currently expected to break some script |
| 3008 | // calls and navigations, such as form submissions. |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3009 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 3010 | bool force_swap_due_to_flag = |
| 3011 | command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
| 3012 | command_line.HasSwitch(switches::kSitePerProcess); |
| 3013 | if (force_swap_due_to_flag && |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3014 | !frame->parent() && (is_content_initiated || is_redirect)) { |
| 3015 | WebString origin_str = frame->document().securityOrigin().toString(); |
| 3016 | GURL frame_url(origin_str.utf8().data()); |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 3017 | // TODO(cevans): revisit whether this site check is still necessary once |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3018 | // crbug.com/101395 is fixed. |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 3019 | bool same_domain_or_host = |
| 3020 | net::registry_controlled_domains::SameDomainOrHost( |
| 3021 | frame_url, |
| 3022 | url, |
| 3023 | net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 3024 | if (!same_domain_or_host || frame_url.scheme() != url.scheme()) { |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 3025 | OpenURL(frame, url, referrer, default_policy); |
| 3026 | return WebKit::WebNavigationPolicyIgnore; |
| 3027 | } |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 3028 | } |
| 3029 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3030 | // 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] | 3031 | if (is_content_initiated) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3032 | bool browser_handles_request = |
| 3033 | renderer_preferences_.browser_handles_non_local_top_level_requests && |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3034 | IsNonLocalTopLevelNavigation(url, frame, type); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 3035 | if (!browser_handles_request) { |
| 3036 | browser_handles_request = |
| 3037 | renderer_preferences_.browser_handles_all_top_level_requests && |
| 3038 | IsTopLevelNavigation(frame); |
| 3039 | } |
| 3040 | |
| 3041 | if (browser_handles_request) { |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 3042 | // Reset these counters as the RenderView could be reused for the next |
| 3043 | // navigation. |
| 3044 | page_id_ = -1; |
| 3045 | last_page_id_sent_to_browser_ = -1; |
| 3046 | OpenURL(frame, url, referrer, default_policy); |
| 3047 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3048 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3049 | } |
| 3050 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3051 | // Use the frame's original request's URL rather than the document's URL for |
| 3052 | // subsequent checks. For a popup, the document's URL may become the opener |
| 3053 | // window's URL if the opener has called document.write(). |
| 3054 | // See http://crbug.com/93517. |
| 3055 | GURL old_url(frame->dataSource()->request().url()); |
| 3056 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3057 | // 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] | 3058 | // 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] | 3059 | // top-level navigations (not iframes). But we sometimes navigate to |
| 3060 | // about:blank to clear a tab, and we want to still allow that. |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3061 | // |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3062 | // Note: this is known to break POST submissions when crossing process |
| 3063 | // boundaries until http://crbug.com/101395 is fixed. This is better for |
| 3064 | // security than loading a WebUI, extension or app page in the wrong process. |
| 3065 | // POST requests don't work because this mechanism does not preserve form |
| 3066 | // POST data. We will need to send the request's httpBody data up to the |
| 3067 | // browser process, and issue a special POST navigation in WebKit (via |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 3068 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 3069 | // for examples of how to send the httpBody data. |
[email protected] | 2762a1b | 2011-12-09 15:25:22 | [diff] [blame] | 3070 | if (!frame->parent() && is_content_initiated && |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3071 | !url.SchemeIs(chrome::kAboutScheme)) { |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3072 | bool send_referrer = false; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3073 | |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3074 | // All navigations to or from WebUI URLs or within WebUI-enabled |
| 3075 | // RenderProcesses must be handled by the browser process so that the |
| 3076 | // correct bindings and data sources can be registered. |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 3077 | // Similarly, navigations to view-source URLs or within ViewSource mode |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3078 | // must be handled by the browser process (except for reloads - those are |
| 3079 | // safe to leave within the renderer). |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3080 | // Lastly, access to file:// URLs from non-file:// URL pages must be |
| 3081 | // handled by the browser so that ordinary renderer processes don't get |
| 3082 | // blessed with file permissions. |
| 3083 | int cumulative_bindings = RenderProcess::current()->GetEnabledBindings(); |
| 3084 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | 0a57375a | 2013-03-07 22:18:59 | [diff] [blame] | 3085 | bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) || |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3086 | (cumulative_bindings & BINDINGS_POLICY_WEB_UI) || |
[email protected] | dbdda540 | 2013-05-30 22:13:48 | [diff] [blame] | 3087 | url.SchemeIs(kViewSourceScheme) || |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 3088 | (frame->isViewSourceModeEnabled() && |
| 3089 | type != WebKit::WebNavigationTypeReload); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3090 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 3091 | if (!should_fork && url.SchemeIs(chrome::kFileScheme)) { |
| 3092 | // Fork non-file to file opens. Check the opener URL if this is the |
| 3093 | // initial navigation in a newly opened window. |
| 3094 | GURL source_url(old_url); |
| 3095 | if (is_initial_navigation && source_url.is_empty() && frame->opener()) |
| 3096 | source_url = frame->opener()->top()->document().url(); |
| 3097 | DCHECK(!source_url.is_empty()); |
| 3098 | should_fork = !source_url.SchemeIs(chrome::kFileScheme); |
| 3099 | } |
| 3100 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3101 | if (!should_fork) { |
| 3102 | // Give the embedder a chance. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 3103 | should_fork = GetContentClient()->renderer()->ShouldFork( |
| 3104 | frame, url, request.httpMethod().utf8(), is_initial_navigation, |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 3105 | is_redirect, &send_referrer); |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | if (should_fork) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3109 | OpenURL( |
| 3110 | frame, url, send_referrer ? referrer : Referrer(), default_policy); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3111 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 3112 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 3116 | // its own process. This is done by sites like Gmail that try to open links |
| 3117 | // in new windows without script connections back to the original page. We |
| 3118 | // treat such cases as browser navigations (in which we will create a new |
| 3119 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 3120 | // |
| 3121 | // We use the following heuristic to decide whether to fork a new page in its |
| 3122 | // own process: |
| 3123 | // The parent page must open a new tab to about:blank, set the new tab's |
| 3124 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 3125 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3126 | // |
| 3127 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 3128 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3129 | bool is_fork = |
| 3130 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3131 | old_url == GURL(kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3132 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3133 | historyBackListCount() < 1 && |
| 3134 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3135 | // The parent page must have set the child's window.opener to null before |
| 3136 | // redirecting to the desired URL. |
| 3137 | frame->opener() == NULL && |
| 3138 | // Must be a top-level frame. |
| 3139 | frame->parent() == NULL && |
| 3140 | // Must not have issued the request from this page. |
| 3141 | is_content_initiated && |
| 3142 | // Must be targeted at the current tab. |
| 3143 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 3144 | // Must be a JavaScript navigation, which appears as "other". |
| 3145 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 3146 | |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 3147 | if (is_fork) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3148 | // Open the URL via the browser, not via WebKit. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3149 | OpenURL(frame, url, Referrer(), default_policy); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3150 | return WebKit::WebNavigationPolicyIgnore; |
| 3151 | } |
| 3152 | |
| 3153 | return default_policy; |
| 3154 | } |
| 3155 | |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3156 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
| 3157 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3158 | WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 0d8f04b | 2013-04-29 20:05:31 | [diff] [blame] | 3159 | return decidePolicyForNavigation(frame, |
| 3160 | frame->provisionalDataSource()->extraData(), |
[email protected] | 89bc54c6 | 2013-04-24 01:51:33 | [diff] [blame] | 3161 | request, type, default_policy, is_redirect); |
[email protected] | f4f40a05 | 2013-04-19 15:28:11 | [diff] [blame] | 3162 | } |
| 3163 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3164 | bool RenderViewImpl::canHandleRequest( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3165 | WebFrame* frame, const WebURLRequest& request) { |
| 3166 | // We allow WebKit to think that everything can be handled even though |
| 3167 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 3168 | return true; |
| 3169 | } |
| 3170 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3171 | WebURLError RenderViewImpl::cannotHandleRequestError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3172 | WebFrame* frame, const WebURLRequest& request) { |
| 3173 | NOTREACHED(); // Since we said we can handle all requests. |
| 3174 | return WebURLError(); |
| 3175 | } |
| 3176 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3177 | WebURLError RenderViewImpl::cancelledError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3178 | WebFrame* frame, const WebURLRequest& request) { |
| 3179 | WebURLError error; |
| 3180 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 3181 | error.reason = net::ERR_ABORTED; |
| 3182 | error.unreachableURL = request.url(); |
| 3183 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 3184 | } |
| 3185 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3186 | void RenderViewImpl::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3187 | WebFrame*, const WebURLError&) { |
| 3188 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 3189 | } |
| 3190 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3191 | void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame, |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3192 | const WebKit::WebFormElement& form) { |
| 3193 | // Some login forms have onSubmit handlers that put a hash of the password |
| 3194 | // into a hidden field and then clear the password. (Issue 28910.) |
| 3195 | // This method gets called before any of those handlers run, so save away |
| 3196 | // a copy of the password in case it gets lost. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3197 | DocumentState* document_state = |
| 3198 | DocumentState::FromDataSource(frame->dataSource()); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3199 | document_state->set_password_form_data(CreatePasswordForm(form)); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3200 | } |
| 3201 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3202 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 3203 | const WebFormElement& form) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3204 | DocumentState* document_state = |
| 3205 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
| 3206 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3207 | InternalDocumentStateData* internal_data = |
| 3208 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3209 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3210 | if (navigation_state->transition_type() == PAGE_TRANSITION_LINK) |
| 3211 | navigation_state->set_transition_type(PAGE_TRANSITION_FORM_SUBMIT); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3212 | |
| 3213 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 3214 | WebSearchableFormData web_searchable_form_data(form); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3215 | internal_data->set_searchable_form_url(web_searchable_form_data.url()); |
| 3216 | internal_data->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 3217 | web_searchable_form_data.encoding().utf8()); |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 3218 | scoped_ptr<PasswordForm> password_form_data = |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3219 | CreatePasswordForm(form); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3220 | |
[email protected] | 098c95cb | 2011-04-28 16:49:01 | [diff] [blame] | 3221 | // In order to save the password that the user actually typed and not one |
| 3222 | // that may have gotten transformed by the site prior to submit, recover it |
| 3223 | // from the form contents already stored by |willSendSubmitEvent| into the |
| 3224 | // dataSource's NavigationState (as opposed to the provisionalDataSource's, |
| 3225 | // which is what we're storing into now.) |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 3226 | if (password_form_data) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3227 | DocumentState* old_document_state = |
| 3228 | DocumentState::FromDataSource(frame->dataSource()); |
| 3229 | if (old_document_state) { |
| 3230 | PasswordForm* old_form_data = old_document_state->password_form_data(); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 3231 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 3232 | password_form_data->password_value = old_form_data->password_value; |
| 3233 | } |
| 3234 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3235 | |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 3236 | document_state->set_password_form_data(password_form_data.Pass()); |
| 3237 | |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 3238 | FOR_EACH_OBSERVER( |
| 3239 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3240 | } |
| 3241 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3242 | void RenderViewImpl::willPerformClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3243 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 3244 | double fire_time) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3245 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3246 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 3247 | |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 3248 | FOR_EACH_OBSERVER( |
| 3249 | RenderViewObserver, observers_, |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3250 | WillPerformClientRedirect(frame, |
| 3251 | from == GURL(kSwappedOutURL) ? blank_url : from, |
| 3252 | to, interval, fire_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3253 | } |
| 3254 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3255 | void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 3256 | FOR_EACH_OBSERVER( |
| 3257 | RenderViewObserver, observers_, DidCancelClientRedirect(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3258 | } |
| 3259 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3260 | void RenderViewImpl::didCompleteClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3261 | WebFrame* frame, const WebURL& from) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3262 | // Replace any occurrences of swappedout:// with about:blank. |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3263 | const WebURL& blank_url = GURL(kAboutBlankURL); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3264 | if (!frame->parent()) { |
| 3265 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3266 | // If there's no provisional data source, it's a reference fragment |
| 3267 | // navigation. |
| 3268 | completed_client_redirect_src_ = Referrer( |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3269 | from == GURL(kSwappedOutURL) ? blank_url : from, |
| 3270 | ds ? GetReferrerPolicyFromRequest(frame, ds->request()) : |
[email protected] | f36f409 | 2012-05-09 18:31:04 | [diff] [blame] | 3271 | frame->document().referrerPolicy()); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3272 | } |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 3273 | FOR_EACH_OBSERVER( |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 3274 | RenderViewObserver, observers_, DidCompleteClientRedirect( |
| 3275 | frame, from == GURL(kSwappedOutURL) ? blank_url : from)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3276 | } |
| 3277 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3278 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3279 | bool content_initiated = !pending_navigation_params_.get(); |
| 3280 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3281 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3282 | if (!document_state) { |
| 3283 | document_state = new DocumentState; |
| 3284 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3285 | if (!content_initiated) |
| 3286 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3287 | } |
| 3288 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3289 | // Carry over the user agent override flag, if it exists. |
| 3290 | if (content_initiated && webview() && webview()->mainFrame() && |
| 3291 | webview()->mainFrame()->dataSource()) { |
| 3292 | DocumentState* old_document_state = |
| 3293 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 3294 | if (old_document_state) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3295 | InternalDocumentStateData* internal_data = |
| 3296 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3297 | InternalDocumentStateData* old_internal_data = |
| 3298 | InternalDocumentStateData::FromDocumentState(old_document_state); |
| 3299 | internal_data->set_is_overriding_user_agent( |
| 3300 | old_internal_data->is_overriding_user_agent()); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3301 | } |
| 3302 | } |
| 3303 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3304 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 3305 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3306 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3307 | document_state->set_navigation_state( |
| 3308 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3309 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3310 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 3311 | pending_navigation_params_.reset(); |
| 3312 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3313 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3314 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3315 | // navigating from a page that used prefetching using a link on that |
| 3316 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3317 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3318 | // this value appropriately. |
| 3319 | // TODO(gavinp): catch the important case of navigation in a new |
| 3320 | // renderer process. |
| 3321 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3322 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3323 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3324 | const GURL referrer( |
| 3325 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 3326 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3327 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3328 | old_frame->dataSource())->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 3329 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3330 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 3331 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3332 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3333 | break; |
| 3334 | } |
| 3335 | } |
| 3336 | } |
| 3337 | } |
| 3338 | } |
| 3339 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3340 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3341 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3342 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3343 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3344 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3345 | break; |
| 3346 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3347 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3348 | break; |
| 3349 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3350 | document_state->set_load_type( |
| 3351 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3352 | break; |
| 3353 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3354 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3355 | break; |
| 3356 | } |
| 3357 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3358 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 3359 | FOR_EACH_OBSERVER( |
| 3360 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3361 | } |
| 3362 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3363 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3364 | DocumentState* document_state) { |
| 3365 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3366 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3367 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3368 | InternalDocumentStateData* internal_data = |
| 3369 | InternalDocumentStateData::FromDocumentState(document_state); |
| 3370 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3371 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme) && |
| 3372 | params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
| 3373 | // We're doing a load of a page that was restored from the last session. By |
| 3374 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 3375 | // can result in stale data for pages that are set to expire. We explicitly |
| 3376 | // override that by setting the policy here so that as necessary we load |
| 3377 | // from the network. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3378 | internal_data->set_cache_policy_override( |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3379 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | if (IsReload(params)) |
| 3383 | document_state->set_load_type(DocumentState::RELOAD); |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3384 | else if (params.page_state.IsValid()) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3385 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 3386 | else |
| 3387 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3388 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3389 | internal_data->set_referrer_policy(params.referrer.policy); |
| 3390 | internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent); |
| 3391 | internal_data->set_must_reset_scroll_and_scale_state( |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3392 | params.navigation_type == |
| 3393 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 3394 | document_state->set_can_load_local_resources(params.can_load_local_resources); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3395 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3396 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3397 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
| 3398 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
| 3399 | NavigationState* navigation_state = NULL; |
| 3400 | |
| 3401 | // A navigation resulting from loading a javascript URL should not be treated |
| 3402 | // as a browser initiated event. Instead, we want it to look as if the page |
| 3403 | // initiated any load resulting from JS execution. |
| 3404 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 3405 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 3406 | params.page_id, |
| 3407 | params.pending_history_list_offset, |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3408 | params.should_clear_history_list, |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3409 | params.transition); |
| 3410 | navigation_state->set_transferred_request_child_id( |
| 3411 | params.transferred_request_child_id); |
| 3412 | navigation_state->set_transferred_request_request_id( |
| 3413 | params.transferred_request_request_id); |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3414 | navigation_state->set_allow_download(params.allow_download); |
[email protected] | f050fde | 2013-03-21 00:40:45 | [diff] [blame] | 3415 | navigation_state->set_extra_headers(params.extra_headers); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3416 | } else { |
| 3417 | navigation_state = NavigationState::CreateContentInitiated(); |
| 3418 | } |
| 3419 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3420 | } |
| 3421 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3422 | void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) { |
| 3423 | bool enable_viewport = |
[email protected] | 06ea34a | 2012-05-07 18:52:10 | [diff] [blame] | 3424 | command_line.HasSwitch(switches::kEnableViewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3425 | bool enable_fixed_layout = |
| 3426 | command_line.HasSwitch(switches::kEnableFixedLayout); |
| 3427 | |
| 3428 | webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3429 | |
[email protected] | 47e932da | 2013-03-07 00:11:24 | [diff] [blame] | 3430 | // If viewport tag is enabled, then the WebKit side will take care |
| 3431 | // of setting the fixed layout size and page scale limits. |
| 3432 | if (enable_viewport) |
| 3433 | return; |
| 3434 | |
| 3435 | if (enable_fixed_layout) { |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3436 | std::string str = |
| 3437 | command_line.GetSwitchValueASCII(switches::kEnableFixedLayout); |
| 3438 | std::vector<std::string> tokens; |
| 3439 | base::SplitString(str, ',', &tokens); |
| 3440 | if (tokens.size() == 2) { |
| 3441 | int width, height; |
| 3442 | if (base::StringToInt(tokens[0], &width) && |
| 3443 | base::StringToInt(tokens[1], &height)) |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3444 | webview()->setFixedLayoutSize(WebSize(width, height)); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3445 | } |
| 3446 | } |
[email protected] | e4cd82e | 2013-04-10 15:20:38 | [diff] [blame] | 3447 | float maxPageScaleFactor = |
| 3448 | command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ; |
| 3449 | webview()->setPageScaleFactorLimits(1, maxPageScaleFactor); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3450 | } |
| 3451 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3452 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3453 | WebDataSource* ds = frame->provisionalDataSource(); |
[email protected] | 09c48ef5 | 2013-01-09 12:25:07 | [diff] [blame] | 3454 | |
| 3455 | // In fast/loader/stop-provisional-loads.html, we abort the load before this |
| 3456 | // callback is invoked. |
| 3457 | if (!ds) |
| 3458 | return; |
| 3459 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3460 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3461 | |
[email protected] | 890b06ca | 2012-12-13 21:07:36 | [diff] [blame] | 3462 | // We should only navigate to swappedout:// when is_swapped_out_ is true. |
| 3463 | CHECK((ds->request().url() != GURL(kSwappedOutURL)) || |
| 3464 | is_swapped_out_) << "Heard swappedout:// when not swapped out."; |
| 3465 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3466 | // Update the request time if WebKit has better knowledge of it. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3467 | if (document_state->request_time().is_null()) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3468 | double event_time = ds->triggeringEventTime(); |
| 3469 | if (event_time != 0.0) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3470 | document_state->set_request_time(Time::FromDoubleT(event_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3471 | } |
| 3472 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3473 | // Start time is only set after request time. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3474 | document_state->set_start_load_time(Time::Now()); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3475 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3476 | bool is_top_most = !frame->parent(); |
| 3477 | if (is_top_most) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 3478 | navigation_gesture_ = WebUserGestureIndicator::isProcessingUserGesture() ? |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3479 | NavigationGestureUser : NavigationGestureAuto; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3480 | |
[email protected] | d06bcac | 2013-03-27 21:17:57 | [diff] [blame] | 3481 | // If the navigation is not triggered by a user gesture, e.g. by some ajax |
| 3482 | // callback, then inherit the submitted password form from the previous |
| 3483 | // state. This fixes the no password save issue for ajax login, tracked in |
| 3484 | // [http://crbug/43219]. Note that there are still some sites that this |
| 3485 | // fails for because they use some element other than a submit button to |
| 3486 | // trigger submission. |
| 3487 | if (navigation_gesture_ == NavigationGestureAuto) { |
| 3488 | DocumentState* old_document_state = DocumentState::FromDataSource( |
| 3489 | frame->dataSource()); |
| 3490 | const content::PasswordForm* old_password_form = |
| 3491 | old_document_state->password_form_data(); |
| 3492 | if (old_password_form) { |
| 3493 | document_state->set_password_form_data( |
| 3494 | make_scoped_ptr(new content::PasswordForm(*old_password_form))); |
| 3495 | } |
| 3496 | } |
| 3497 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3498 | // Make sure redirect tracking state is clear for the new load. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3499 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3500 | } else if (frame->parent()->isLoading()) { |
| 3501 | // Take note of AUTO_SUBFRAME loads here, so that we can know how to |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 3502 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3503 | document_state->navigation_state()->set_transition_type( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3504 | PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3505 | } |
| 3506 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3507 | FOR_EACH_OBSERVER( |
| 3508 | RenderViewObserver, observers_, DidStartProvisionalLoad(frame)); |
| 3509 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3510 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | d37c33e | 2012-10-12 13:35:13 | [diff] [blame] | 3511 | routing_id_, frame->identifier(), |
| 3512 | frame->parent() ? frame->parent()->identifier() : -1, |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 3513 | is_top_most, ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3514 | } |
| 3515 | |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3516 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 3517 | WebFrame* frame) { |
| 3518 | if (frame->parent()) |
| 3519 | return; |
| 3520 | // Received a redirect on the main frame. |
| 3521 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3522 | if (!data_source) { |
| 3523 | // Should only be invoked when we have a data source. |
| 3524 | NOTREACHED(); |
| 3525 | return; |
| 3526 | } |
| 3527 | std::vector<GURL> redirects; |
| 3528 | GetRedirectChain(data_source, &redirects); |
| 3529 | if (redirects.size() >= 2) { |
| 3530 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
[email protected] | 434bc9b | 2012-11-27 21:22:14 | [diff] [blame] | 3531 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3532 | } |
| 3533 | } |
| 3534 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3535 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 3536 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3537 | // Notify the browser that we failed a provisional load with an error. |
| 3538 | // |
| 3539 | // Note: It is important this notification occur before DidStopLoading so the |
| 3540 | // SSL manager can react to the provisional load failure before being |
| 3541 | // notified the load stopped. |
| 3542 | // |
| 3543 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3544 | DCHECK(ds); |
| 3545 | |
| 3546 | const WebURLRequest& failed_request = ds->request(); |
| 3547 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3548 | FOR_EACH_OBSERVER( |
| 3549 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 3550 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3551 | bool show_repost_interstitial = |
| 3552 | (error.reason == net::ERR_CACHE_MISS && |
| 3553 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3554 | |
| 3555 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 3556 | params.frame_id = frame->identifier(); |
| 3557 | params.is_main_frame = !frame->parent(); |
| 3558 | params.error_code = error.reason; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3559 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3560 | frame, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3561 | failed_request, |
| 3562 | error, |
| 3563 | NULL, |
| 3564 | ¶ms.error_description); |
| 3565 | params.url = error.unreachableURL; |
| 3566 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3567 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3568 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3569 | |
| 3570 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3571 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3572 | if (error.reason == net::ERR_ABORTED) |
| 3573 | return; |
| 3574 | |
[email protected] | 70dee7e | 2013-05-29 18:28:30 | [diff] [blame] | 3575 | if (RenderThreadImpl::current()->layout_test_mode()) |
[email protected] | ac7f5a0 | 2013-03-16 16:14:41 | [diff] [blame] | 3576 | return; |
| 3577 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3578 | // Make sure we never show errors in view source mode. |
| 3579 | frame->enableViewSourceMode(false); |
| 3580 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3581 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3582 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3583 | |
| 3584 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3585 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3586 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3587 | // as session history is concerned. |
| 3588 | // |
| 3589 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3590 | // the page id. |
| 3591 | // |
| 3592 | bool replace = |
| 3593 | navigation_state->pending_page_id() != -1 || |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3594 | navigation_state->transition_type() == |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3595 | PAGE_TRANSITION_AUTO_SUBFRAME; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3596 | |
| 3597 | // If we failed on a browser initiated request, then make sure that our error |
| 3598 | // page load is regarded as the same browser initiated request. |
| 3599 | if (!navigation_state->is_content_initiated()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3600 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 3601 | pending_navigation_params_->page_id = |
| 3602 | navigation_state->pending_page_id(); |
| 3603 | pending_navigation_params_->pending_history_list_offset = |
| 3604 | navigation_state->pending_history_list_offset(); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 3605 | pending_navigation_params_->should_clear_history_list = |
| 3606 | navigation_state->history_list_was_cleared(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3607 | pending_navigation_params_->transition = |
| 3608 | navigation_state->transition_type(); |
| 3609 | pending_navigation_params_->request_time = |
| 3610 | document_state->request_time(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | // Provide the user with a more helpful error page? |
| 3614 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3615 | return; |
| 3616 | |
| 3617 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3618 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3619 | } |
| 3620 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3621 | void RenderViewImpl::didReceiveDocumentData( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3622 | WebFrame* frame, const char* data, size_t data_len, |
| 3623 | bool& prevent_default) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3624 | InternalDocumentStateData* internal_data = |
| 3625 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 3626 | internal_data->set_use_error_page(false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3627 | } |
| 3628 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3629 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 3630 | bool is_new_navigation) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3631 | DocumentState* document_state = |
| 3632 | DocumentState::FromDataSource(frame->dataSource()); |
| 3633 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3634 | InternalDocumentStateData* internal_data = |
| 3635 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3636 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3637 | if (document_state->commit_load_time().is_null()) |
| 3638 | document_state->set_commit_load_time(Time::Now()); |
| 3639 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3640 | if (internal_data->must_reset_scroll_and_scale_state()) { |
[email protected] | 06c7ba02 | 2012-12-17 19:24:12 | [diff] [blame] | 3641 | webview()->resetScrollAndScaleState(); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3642 | internal_data->set_must_reset_scroll_and_scale_state(false); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3643 | } |
| 3644 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3645 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 3646 | // When we perform a new navigation, we need to update the last committed |
| 3647 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3648 | UpdateSessionHistory(frame); |
| 3649 | |
| 3650 | // We bump our Page ID to correspond with the new session history entry. |
| 3651 | page_id_ = next_page_id_++; |
| 3652 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3653 | // Don't update history_page_ids_ (etc) for kSwappedOutURL, since |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 3654 | // 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] | 3655 | // never come back to kSwappedOutURL. Note that we have to call |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3656 | // UpdateSessionHistory and update page_id_ even in this case, so that |
| 3657 | // the current entry gets a state update and so that we don't send a |
| 3658 | // state update to the wrong entry when we swap back in. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3659 | if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3660 | // Advance our offset in session history, applying the length limit. |
| 3661 | // There is now no forward history. |
| 3662 | history_list_offset_++; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3663 | if (history_list_offset_ >= kMaxSessionHistoryEntries) |
| 3664 | history_list_offset_ = kMaxSessionHistoryEntries - 1; |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3665 | history_list_length_ = history_list_offset_ + 1; |
| 3666 | history_page_ids_.resize(history_list_length_, -1); |
| 3667 | history_page_ids_[history_list_offset_] = page_id_; |
| 3668 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3669 | } else { |
| 3670 | // Inspect the navigation_state on this frame to see if the navigation |
| 3671 | // corresponds to a session history navigation... Note: |frame| may or |
| 3672 | // may not be the toplevel frame, but for the case of capturing session |
| 3673 | // history, the first committed frame suffices. We keep track of whether |
| 3674 | // we've seen this commit before so that only capture session history once |
| 3675 | // per navigation. |
| 3676 | // |
| 3677 | // Note that we need to check if the page ID changed. In the case of a |
| 3678 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3679 | // previous URL and the current page ID, which would be wrong. |
| 3680 | if (navigation_state->pending_page_id() != -1 && |
| 3681 | navigation_state->pending_page_id() != page_id_ && |
| 3682 | !navigation_state->request_committed()) { |
| 3683 | // This is a successful session history navigation! |
| 3684 | UpdateSessionHistory(frame); |
| 3685 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3686 | |
| 3687 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 3688 | |
| 3689 | // If the history list is valid, our list of page IDs should be correct. |
| 3690 | DCHECK(history_list_length_ <= 0 || |
| 3691 | history_list_offset_ < 0 || |
| 3692 | history_list_offset_ >= history_list_length_ || |
| 3693 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3697 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3698 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 3699 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3700 | // Remember that we've already processed this request, so we don't update |
| 3701 | // the session history again. We do this regardless of whether this is |
| 3702 | // a session history navigation, because if we attempted a session history |
| 3703 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3704 | // new navigation. |
| 3705 | navigation_state->set_request_committed(true); |
| 3706 | |
| 3707 | UpdateURL(frame); |
| 3708 | |
| 3709 | // If this committed load was initiated by a client redirect, we're |
| 3710 | // at the last stop now, so clear it. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3711 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3712 | |
| 3713 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3714 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 3715 | |
| 3716 | if (!frame->parent()) { // Only for top frames. |
| 3717 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 3718 | if (render_thread_impl) { // Can be NULL in tests. |
| 3719 | render_thread_impl->histogram_customizer()-> |
| 3720 | RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(), |
| 3721 | g_view_map.Get().size()); |
| 3722 | } |
| 3723 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3724 | } |
| 3725 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3726 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 3727 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3728 | DidClearWindowObject(frame)); |
| 3729 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3730 | if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 3731 | if (!dom_automation_controller_) |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3732 | dom_automation_controller_.reset(new DomAutomationController()); |
| 3733 | dom_automation_controller_->set_message_sender( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3734 | static_cast<RenderView*>(this)); |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3735 | dom_automation_controller_->set_routing_id(routing_id()); |
| 3736 | dom_automation_controller_->BindToJavascript(frame, |
| 3737 | "domAutomationController"); |
| 3738 | } |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 3739 | |
| 3740 | if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) { |
| 3741 | if (!stats_collection_controller_.get()) |
| 3742 | stats_collection_controller_.reset(new StatsCollectionController()); |
| 3743 | stats_collection_controller_->set_message_sender( |
| 3744 | static_cast<RenderView*>(this)); |
| 3745 | stats_collection_controller_->BindToJavascript(frame, |
| 3746 | "statsCollectionController"); |
| 3747 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3748 | } |
| 3749 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3750 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3751 | // Notify the browser about non-blank documents loading in the top frame. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3752 | GURL url = frame->document().url(); |
[email protected] | 081dc52 | 2013-05-15 04:59:20 | [diff] [blame] | 3753 | if (url.is_valid() && url.spec() != kAboutBlankURL) { |
[email protected] | 87717d0e | 2012-04-26 02:58:43 | [diff] [blame] | 3754 | if (frame == webview()->mainFrame()) |
| 3755 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3756 | } |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3757 | |
| 3758 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3759 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3760 | } |
| 3761 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3762 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 3763 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 3764 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3765 | |
| 3766 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3767 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3768 | } |
| 3769 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 3770 | void RenderViewImpl::didChangeIcon(WebFrame* frame, |
| 3771 | WebIconURL::Type icon_type) { |
| 3772 | if (frame->parent()) |
| 3773 | return; |
| 3774 | |
| 3775 | if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon) |
| 3776 | return; |
| 3777 | |
| 3778 | WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 3779 | std::vector<FaviconURL> urls; |
| 3780 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 3781 | urls.push_back(FaviconURL(icon_urls[i].iconURL(), |
| 3782 | ToFaviconType(icon_urls[i].iconType()))); |
| 3783 | } |
| 3784 | SendUpdateFaviconURL(urls); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3785 | } |
| 3786 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3787 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3788 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3789 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3790 | document_state->set_finish_document_load_time(Time::Now()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3791 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 3792 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3793 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3794 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3795 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3796 | |
| 3797 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3798 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3799 | } |
| 3800 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3801 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3802 | if (webview()->mainFrame() == frame) { |
| 3803 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3804 | page_id_)); |
| 3805 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3806 | } |
| 3807 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3808 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3809 | WebDataSource* ds = frame->dataSource(); |
| 3810 | DCHECK(ds); |
| 3811 | |
| 3812 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3813 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3814 | |
| 3815 | const WebURLRequest& failed_request = ds->request(); |
| 3816 | string16 error_description; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3817 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 8da4d26 | 2013-04-23 05:15:53 | [diff] [blame] | 3818 | frame, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3819 | failed_request, |
| 3820 | error, |
| 3821 | NULL, |
| 3822 | &error_description); |
| 3823 | Send(new ViewHostMsg_DidFailLoadWithError(routing_id_, |
| 3824 | frame->identifier(), |
| 3825 | failed_request.url(), |
| 3826 | !frame->parent(), |
| 3827 | error.reason, |
| 3828 | error_description)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3829 | } |
| 3830 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3831 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3832 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3833 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3834 | if (document_state->finish_load_time().is_null()) |
| 3835 | document_state->set_finish_load_time(Time::Now()); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3836 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3837 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 3838 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3839 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, |
| 3840 | frame->identifier(), |
| 3841 | ds->request().url(), |
| 3842 | !frame->parent())); |
[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::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3846 | WebFrame* frame, bool is_new_navigation) { |
| 3847 | // If this was a reference fragment navigation that we initiated, then we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3848 | // 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] | 3849 | // update the ExtraData on the datasource so that others who read the |
| 3850 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3851 | // initiate this navigation, then we need to take care to reset any pre- |
| 3852 | // existing navigation state to a content-initiated navigation state. |
| 3853 | // DidCreateDataSource conveniently takes care of this for us. |
| 3854 | didCreateDataSource(frame, frame->dataSource()); |
| 3855 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3856 | DocumentState* document_state = |
| 3857 | DocumentState::FromDataSource(frame->dataSource()); |
| 3858 | NavigationState* new_state = document_state->navigation_state(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3859 | new_state->set_was_within_same_page(true); |
| 3860 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3861 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3862 | |
[email protected] | 750fcf87 | 2011-08-03 23:10:47 | [diff] [blame] | 3863 | WebDataSource* datasource = frame->view()->mainFrame()->dataSource(); |
| 3864 | UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3865 | } |
| 3866 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3867 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3868 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3869 | } |
| 3870 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3871 | void RenderViewImpl::assignIdentifierToRequest( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3872 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3873 | // Ignore |
| 3874 | } |
| 3875 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3876 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 3877 | unsigned identifier, |
| 3878 | WebURLRequest& request, |
| 3879 | const WebURLResponse& redirect_response) { |
[email protected] | b4576a1 | 2013-01-22 10:41:43 | [diff] [blame] | 3880 | // The request my be empty during tests. |
| 3881 | if (request.url().isEmpty()) |
| 3882 | return; |
| 3883 | |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3884 | WebFrame* top_frame = frame->top(); |
| 3885 | if (!top_frame) |
| 3886 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3887 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 3888 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 3889 | WebDataSource* data_source = |
| 3890 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 3891 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3892 | PageTransition transition_type = PAGE_TRANSITION_LINK; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3893 | DocumentState* document_state = DocumentState::FromDataSource(data_source); |
[email protected] | def55e02 | 2012-07-26 01:15:29 | [diff] [blame] | 3894 | DCHECK(document_state); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3895 | InternalDocumentStateData* internal_data = |
| 3896 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3897 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3898 | transition_type = navigation_state->transition_type(); |
| 3899 | |
| 3900 | GURL request_url(request.url()); |
| 3901 | GURL new_url; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3902 | if (GetContentClient()->renderer()->WillSendRequest( |
[email protected] | 53d96fb | 2012-11-27 15:36:27 | [diff] [blame] | 3903 | frame, |
| 3904 | transition_type, |
| 3905 | request_url, |
| 3906 | request.firstPartyForCookies(), |
| 3907 | &new_url)) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3908 | request.setURL(WebURL(new_url)); |
| 3909 | } |
| 3910 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3911 | if (internal_data->is_cache_policy_override_set()) |
| 3912 | request.setCachePolicy(internal_data->cache_policy_override()); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3913 | |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3914 | WebKit::WebReferrerPolicy referrer_policy; |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 3915 | if (internal_data->is_referrer_policy_set()) { |
| 3916 | referrer_policy = internal_data->referrer_policy(); |
| 3917 | internal_data->clear_referrer_policy(); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3918 | } else { |
| 3919 | referrer_policy = frame->document().referrerPolicy(); |
| 3920 | } |
| 3921 | |
[email protected] | e372f3d | 2012-07-17 19:16:44 | [diff] [blame] | 3922 | // The request's extra data may indicate that we should set a custom user |
| 3923 | // agent. This needs to be done here, after WebKit is through with setting the |
| 3924 | // user agent on its own. |
| 3925 | WebString custom_user_agent; |
| 3926 | if (request.extraData()) { |
| 3927 | webkit_glue::WebURLRequestExtraDataImpl* old_extra_data = |
| 3928 | static_cast<webkit_glue::WebURLRequestExtraDataImpl*>( |
| 3929 | request.extraData()); |
| 3930 | custom_user_agent = old_extra_data->custom_user_agent(); |
| 3931 | |
| 3932 | if (!custom_user_agent.isNull()) { |
| 3933 | if (custom_user_agent.isEmpty()) |
| 3934 | request.clearHTTPHeaderField("User-Agent"); |
| 3935 | else |
| 3936 | request.setHTTPHeaderField("User-Agent", custom_user_agent); |
| 3937 | } |
| 3938 | } |
| 3939 | |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 3940 | request.setExtraData( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3941 | new RequestExtraData(referrer_policy, |
[email protected] | e372f3d | 2012-07-17 19:16:44 | [diff] [blame] | 3942 | custom_user_agent, |
[email protected] | 537fbe0 | 2011-11-24 00:58:06 | [diff] [blame] | 3943 | (frame == top_frame), |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 3944 | frame->identifier(), |
| 3945 | frame->parent() == top_frame, |
| 3946 | frame->parent() ? frame->parent()->identifier() : -1, |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3947 | navigation_state->allow_download(), |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 3948 | transition_type, |
| 3949 | navigation_state->transferred_request_child_id(), |
| 3950 | navigation_state->transferred_request_request_id())); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 3951 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3952 | DocumentState* top_document_state = |
| 3953 | DocumentState::FromDataSource(top_data_source); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 3954 | // TODO(gavinp): separate out prefetching and prerender field trials |
| 3955 | // if the rel=prerender rel type is sticking around. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3956 | if (top_document_state && |
[email protected] | 925dec1c | 2012-05-18 05:09:00 | [diff] [blame] | 3957 | request.targetType() == WebURLRequest::TargetIsPrefetch) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3958 | top_document_state->set_was_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3959 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3960 | request.setRequestorID(routing_id_); |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 3961 | request.setHasUserGesture(WebUserGestureIndicator::isProcessingUserGesture()); |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3962 | |
[email protected] | f050fde | 2013-03-21 00:40:45 | [diff] [blame] | 3963 | if (!navigation_state->extra_headers().empty()) { |
| 3964 | for (net::HttpUtil::HeadersIterator i( |
| 3965 | navigation_state->extra_headers().begin(), |
| 3966 | navigation_state->extra_headers().end(), "\n"); |
| 3967 | i.GetNext(); ) { |
| 3968 | request.setHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 3969 | WebString::fromUTF8(i.values())); |
| 3970 | } |
| 3971 | } |
| 3972 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 3973 | if (!renderer_preferences_.enable_referrers) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 3974 | request.clearHTTPHeaderField("Referer"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3975 | } |
| 3976 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3977 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3978 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3979 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3980 | // Only do this for responses that correspond to a provisional data source |
| 3981 | // of the top-most frame. If we have a provisional data source, then we |
| 3982 | // can't have any sub-resources yet, so we know that this response must |
| 3983 | // correspond to a frame load. |
| 3984 | if (!frame->provisionalDataSource() || frame->parent()) |
| 3985 | return; |
| 3986 | |
| 3987 | // If we are in view source mode, then just let the user see the source of |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3988 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3989 | if (frame->isViewSourceModeEnabled()) |
| 3990 | return; |
| 3991 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3992 | DocumentState* document_state = |
| 3993 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3994 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3995 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3996 | // Record page load flags. |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 3997 | WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response); |
| 3998 | if (extra_data) { |
[email protected] | e07ddafe | 2013-03-05 21:03:36 | [diff] [blame] | 3999 | document_state->set_was_fetched_via_spdy( |
| 4000 | extra_data->was_fetched_via_spdy()); |
| 4001 | document_state->set_was_npn_negotiated( |
| 4002 | extra_data->was_npn_negotiated()); |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 4003 | document_state->set_npn_negotiated_protocol( |
| 4004 | extra_data->npn_negotiated_protocol()); |
[email protected] | e07ddafe | 2013-03-05 21:03:36 | [diff] [blame] | 4005 | document_state->set_was_alternate_protocol_available( |
| 4006 | extra_data->was_alternate_protocol_available()); |
| 4007 | document_state->set_was_fetched_via_proxy( |
| 4008 | extra_data->was_fetched_via_proxy()); |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 4009 | } |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4010 | InternalDocumentStateData* internal_data = |
| 4011 | InternalDocumentStateData::FromDocumentState(document_state); |
| 4012 | internal_data->set_http_status_code(http_status_code); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4013 | // Whether or not the http status code actually corresponds to an error is |
| 4014 | // only checked when the page is done loading, if |use_error_page| is |
| 4015 | // still true. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4016 | internal_data->set_use_error_page(true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4017 | } |
| 4018 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4019 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4020 | WebFrame* frame, unsigned identifier) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4021 | InternalDocumentStateData* internal_data = |
| 4022 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 4023 | if (!internal_data->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4024 | return; |
| 4025 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 4026 | // Do not show error page when DevTools is attached. |
| 4027 | if (devtools_agent_->IsAttached()) |
| 4028 | return; |
| 4029 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4030 | // Display error page, if appropriate. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4031 | int http_status_code = internal_data->http_status_code(); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 4032 | if (http_status_code == 404) { |
| 4033 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4034 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4035 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4036 | const GURL& error_page_url = |
| 4037 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4038 | if (error_page_url.is_valid()) { |
| 4039 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 4040 | original_error.domain = "http"; |
| 4041 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4042 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4043 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4044 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4045 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 4046 | error_page_url, frame, frame->dataSource()->request(), |
| 4047 | original_error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 4048 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 4049 | base::Unretained(this)))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4050 | return; |
| 4051 | } |
| 4052 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4053 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 4054 | std::string error_domain; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4055 | if (GetContentClient()->renderer()->HasErrorPage( |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 4056 | http_status_code, &error_domain)) { |
| 4057 | WebURLError error; |
| 4058 | error.unreachableURL = frame->document().url(); |
| 4059 | error.domain = WebString::fromUTF8(error_domain); |
| 4060 | error.reason = http_status_code; |
| 4061 | |
| 4062 | LoadNavigationErrorPage( |
| 4063 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 4064 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4065 | } |
| 4066 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4067 | void RenderViewImpl::didFailResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4068 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 4069 | // Ignore |
| 4070 | } |
| 4071 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4072 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4073 | WebFrame* frame, const WebURLRequest& request, |
| 4074 | const WebURLResponse& response) { |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 4075 | // The recipients of this message have no use for data: URLs: they don't |
| 4076 | // affect the page's insecure content list and are not in the disk cache. To |
| 4077 | // prevent large (1M+) data: URLs from crashing in the IPC system, we simply |
| 4078 | // filter them out here. |
| 4079 | GURL url(request.url()); |
| 4080 | if (url.SchemeIs("data")) |
| 4081 | return; |
| 4082 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4083 | // Let the browser know we loaded a resource from the memory cache. This |
| 4084 | // message is needed to display the correct SSL indicators. |
| 4085 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 4086 | routing_id_, |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 4087 | url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 4088 | response.securityInfo(), |
| 4089 | request.httpMethod().utf8(), |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 4090 | response.mimeType().utf8(), |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 4091 | ResourceType::FromTargetType(request.targetType()))); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4092 | } |
| 4093 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4094 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 4095 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 4096 | } |
| 4097 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4098 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 4099 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 4100 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 4101 | routing_id_, |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 4102 | origin.toString().utf8(), |
| 4103 | target)); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 4104 | } |
| 4105 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4106 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4107 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 4108 | } |
| 4109 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4110 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 4111 | v8::Handle<v8::Context> context, |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 4112 | int extension_group, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4113 | int world_id) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4114 | GetContentClient()->renderer()->DidCreateScriptContext( |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 4115 | frame, context, extension_group, world_id); |
| 4116 | } |
| 4117 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4118 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 4119 | v8::Handle<v8::Context> context, |
| 4120 | int world_id) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4121 | GetContentClient()->renderer()->WillReleaseScriptContext( |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 4122 | frame, context, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 4123 | } |
| 4124 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4125 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 4126 | // We don't always want to send the change messages over IPC, only if we've |
| 4127 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 4128 | // message. |
| 4129 | if (!send_preferred_size_changes_ || !webview()) |
| 4130 | return; |
| 4131 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4132 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 4133 | webview()->mainFrame()->documentElementScrollHeight()); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 4134 | |
| 4135 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 4136 | // so we need to adjust. |
| 4137 | double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel()); |
| 4138 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 4139 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 4140 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4141 | if (size == preferred_size_) |
| 4142 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 4143 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 4144 | preferred_size_ = size; |
| 4145 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 4146 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4147 | } |
| 4148 | |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 4149 | BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() { |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 4150 | if (!browser_plugin_manager_) |
| 4151 | browser_plugin_manager_ = BrowserPluginManager::Create(this); |
| 4152 | return browser_plugin_manager_; |
| 4153 | } |
| 4154 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4155 | void RenderViewImpl::EnsureMediaStreamImpl() { |
[email protected] | 7082fb94 | 2012-05-16 23:44:59 | [diff] [blame] | 4156 | if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
[email protected] | 0838156 | 2012-05-15 20:55:40 | [diff] [blame] | 4157 | return; |
| 4158 | |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4159 | #if defined(OS_ANDROID) |
[email protected] | ce585bf | 2013-03-14 16:25:16 | [diff] [blame] | 4160 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC)) |
[email protected] | d9da958 | 2013-01-31 04:59:05 | [diff] [blame] | 4161 | return; |
| 4162 | #endif |
| 4163 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 4164 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4165 | if (!media_stream_dispatcher_) |
| 4166 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 4167 | |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 4168 | if (!media_stream_impl_) { |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4169 | media_stream_impl_ = new MediaStreamImpl( |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 4170 | this, |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4171 | media_stream_dispatcher_, |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 4172 | RenderThreadImpl::current()->GetMediaStreamDependencyFactory()); |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4173 | } |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 4174 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4175 | } |
| 4176 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4177 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 4178 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4179 | if (webview()->mainFrame() != frame) |
| 4180 | return; |
| 4181 | WebView* frameView = frame->view(); |
| 4182 | if (!frameView) |
| 4183 | return; |
| 4184 | |
| 4185 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 4186 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 4187 | |
| 4188 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 4189 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 4190 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 4191 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 4192 | |
| 4193 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 4194 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 4195 | } |
| 4196 | } |
| 4197 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4198 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4199 | WebSize offset = frame->scrollOffset(); |
| 4200 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 4201 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 4202 | |
| 4203 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 4204 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 4205 | |
| 4206 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 4207 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 4208 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 4209 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 4210 | |
| 4211 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 4212 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 4213 | } |
[email protected] | 4e72174 | 2013-02-04 21:39:30 | [diff] [blame] | 4214 | |
| 4215 | Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4216 | } |
| 4217 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4218 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 4219 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4220 | |
| 4221 | if (webview()->mainFrame() == frame) |
| 4222 | UpdateScrollState(frame); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 4223 | |
| 4224 | FOR_EACH_OBSERVER( |
| 4225 | RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4226 | } |
| 4227 | |
[email protected] | a9344092d | 2013-02-27 00:56:45 | [diff] [blame] | 4228 | void RenderViewImpl::willInsertBody(WebKit::WebFrame* frame) { |
| 4229 | if (!frame->parent()) { |
| 4230 | Send(new ViewHostMsg_WillInsertBody(routing_id())); |
| 4231 | } |
| 4232 | } |
| 4233 | |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4234 | void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) { |
| 4235 | if (frame != webview()->mainFrame()) |
| 4236 | return; |
| 4237 | |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4238 | InternalDocumentStateData* data = |
| 4239 | InternalDocumentStateData::FromDataSource(frame->dataSource()); |
| 4240 | data->set_did_first_visually_non_empty_layout(true); |
| 4241 | |
| 4242 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4243 | // Update body background color if necessary. |
| 4244 | SkColor bg_color = webwidget_->backgroundColor(); |
| 4245 | |
| 4246 | // If not initialized, default to white. Note that 0 is different from black |
| 4247 | // as black still has alpha 0xFF. |
| 4248 | if (!bg_color) |
| 4249 | bg_color = SK_ColorWHITE; |
| 4250 | |
| 4251 | if (bg_color != body_background_color_) { |
| 4252 | body_background_color_ = bg_color; |
| 4253 | Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id_, bg_color)); |
| 4254 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4255 | #endif |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 4256 | } |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 4257 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4258 | void RenderViewImpl::SendFindReply(int request_id, |
| 4259 | int match_count, |
| 4260 | int ordinal, |
| 4261 | const WebRect& selection_rect, |
| 4262 | bool final_status_update) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4263 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4264 | request_id, |
| 4265 | match_count, |
| 4266 | selection_rect, |
| 4267 | ordinal, |
| 4268 | final_status_update)); |
| 4269 | } |
| 4270 | |
[email protected] | 432c9a7 | 2013-02-27 01:51:03 | [diff] [blame] | 4271 | // static |
| 4272 | bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams( |
| 4273 | const string16& selection_text, |
| 4274 | size_t selection_text_offset, |
| 4275 | const ui::Range& selection_range, |
| 4276 | const ContextMenuParams& params) { |
| 4277 | string16 trimmed_selection_text; |
| 4278 | if (!selection_text.empty() && !selection_range.is_empty()) { |
| 4279 | const int start = selection_range.GetMin() - selection_text_offset; |
| 4280 | const size_t length = selection_range.length(); |
| 4281 | if (start >= 0 && start + length <= selection_text.length()) { |
| 4282 | TrimWhitespace(selection_text.substr(start, length), TRIM_ALL, |
| 4283 | &trimmed_selection_text); |
| 4284 | } |
| 4285 | } |
| 4286 | string16 trimmed_params_text; |
| 4287 | TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text); |
| 4288 | return trimmed_params_text != trimmed_selection_text; |
| 4289 | } |
| 4290 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4291 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, |
| 4292 | int count, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4293 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4294 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 4295 | if (!count) |
| 4296 | active_match_ordinal = 0; |
| 4297 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4298 | // Send the search result over to the browser process. |
| 4299 | SendFindReply(request_id, |
| 4300 | count, |
| 4301 | active_match_ordinal, |
| 4302 | gfx::Rect(), |
| 4303 | final_update); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4304 | } |
| 4305 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4306 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 4307 | int active_match_ordinal, |
| 4308 | const WebRect& selection_rect) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4309 | SendFindReply(request_id, |
| 4310 | -1, |
| 4311 | active_match_ordinal, |
| 4312 | selection_rect, |
| 4313 | false); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4314 | } |
| 4315 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4316 | void RenderViewImpl::openFileSystem( |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4317 | WebFrame* frame, |
[email protected] | 18cdb0e | 2013-03-19 16:37:53 | [diff] [blame] | 4318 | WebKit::WebFileSystemType type, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4319 | long long size, |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 4320 | bool create, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4321 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 4322 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4323 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4324 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4325 | if (origin.isUnique()) { |
| 4326 | // Unique origins cannot store persistent state. |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 4327 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 4328 | return; |
| 4329 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4330 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 4331 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 4332 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
[email protected] | d269196 | 2013-05-16 14:19:27 | [diff] [blame] | 4333 | size, create, |
| 4334 | base::Bind(&OpenFileSystemCallbackAdapter, callbacks), |
| 4335 | base::Bind(&FileStatusCallbackAdapter, callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4336 | } |
| 4337 | |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 4338 | void RenderViewImpl::deleteFileSystem( |
| 4339 | WebFrame* frame, |
[email protected] | 18cdb0e | 2013-03-19 16:37:53 | [diff] [blame] | 4340 | WebKit::WebFileSystemType type , |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 4341 | WebFileSystemCallbacks* callbacks) { |
| 4342 | DCHECK(callbacks); |
| 4343 | |
| 4344 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 4345 | if (origin.isUnique()) { |
| 4346 | // Unique origins cannot store persistent state. |
| 4347 | callbacks->didSucceed(); |
| 4348 | return; |
| 4349 | } |
| 4350 | |
| 4351 | ChildThread::current()->file_system_dispatcher()->DeleteFileSystem( |
| 4352 | GURL(origin.toString()), |
| 4353 | static_cast<fileapi::FileSystemType>(type), |
[email protected] | d269196 | 2013-05-16 14:19:27 | [diff] [blame] | 4354 | base::Bind(&FileStatusCallbackAdapter, callbacks)); |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 4355 | } |
| 4356 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4357 | void RenderViewImpl::queryStorageUsageAndQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4358 | WebFrame* frame, |
| 4359 | WebStorageQuotaType type, |
| 4360 | WebStorageQuotaCallbacks* callbacks) { |
| 4361 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4362 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4363 | if (origin.isUnique()) { |
| 4364 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4365 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 4366 | return; |
| 4367 | } |
| 4368 | ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 4369 | GURL(origin.toString()), |
| 4370 | static_cast<quota::StorageType>(type), |
| 4371 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4372 | } |
| 4373 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4374 | void RenderViewImpl::requestStorageQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4375 | WebFrame* frame, |
| 4376 | WebStorageQuotaType type, |
| 4377 | unsigned long long requested_size, |
| 4378 | WebStorageQuotaCallbacks* callbacks) { |
| 4379 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4380 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4381 | if (origin.isUnique()) { |
| 4382 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4383 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 4384 | return; |
| 4385 | } |
| 4386 | ChildThread::current()->quota_dispatcher()->RequestStorageQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 4387 | routing_id(), GURL(origin.toString()), |
| 4388 | static_cast<quota::StorageType>(type), requested_size, |
| 4389 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4390 | } |
| 4391 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4392 | bool RenderViewImpl::willCheckAndDispatchMessageEvent( |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4393 | WebKit::WebFrame* sourceFrame, |
| 4394 | WebKit::WebFrame* targetFrame, |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4395 | WebKit::WebSecurityOrigin target_origin, |
| 4396 | WebKit::WebDOMMessageEvent event) { |
| 4397 | if (!is_swapped_out_) |
| 4398 | return false; |
| 4399 | |
| 4400 | ViewMsg_PostMessage_Params params; |
| 4401 | params.data = event.data().toString(); |
| 4402 | params.source_origin = event.origin(); |
| 4403 | if (!target_origin.isNull()) |
| 4404 | params.target_origin = target_origin.toString(); |
| 4405 | |
| 4406 | // Include the routing ID for the source frame, which the browser process |
| 4407 | // will translate into the routing ID for the equivalent frame in the target |
| 4408 | // process. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4409 | params.source_routing_id = MSG_ROUTING_NONE; |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4410 | RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4411 | if (source_view) |
| 4412 | params.source_routing_id = source_view->routing_id(); |
| 4413 | |
| 4414 | Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 4415 | return true; |
| 4416 | } |
| 4417 | |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 4418 | void RenderViewImpl::willOpenSocketStream( |
| 4419 | WebSocketStreamHandle* handle) { |
| 4420 | SocketStreamHandleData::AddToHandle(handle, routing_id_); |
| 4421 | } |
| 4422 | |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 4423 | void RenderViewImpl::willStartUsingPeerConnectionHandler( |
| 4424 | WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) { |
| 4425 | #if defined(ENABLE_WEBRTC) |
| 4426 | static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame); |
| 4427 | #endif |
| 4428 | } |
| 4429 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4430 | WebKit::WebString RenderViewImpl::userAgentOverride( |
| 4431 | WebKit::WebFrame* frame, |
| 4432 | const WebKit::WebURL& url) { |
| 4433 | if (!webview() || !webview()->mainFrame() || |
| 4434 | renderer_preferences_.user_agent_override.empty()) { |
| 4435 | return WebKit::WebString(); |
| 4436 | } |
| 4437 | |
| 4438 | // If we're in the middle of committing a load, the data source we need |
| 4439 | // will still be provisional. |
| 4440 | WebFrame* main_frame = webview()->mainFrame(); |
| 4441 | WebDataSource* data_source = NULL; |
| 4442 | if (main_frame->provisionalDataSource()) |
| 4443 | data_source = main_frame->provisionalDataSource(); |
| 4444 | else |
| 4445 | data_source = main_frame->dataSource(); |
| 4446 | |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4447 | InternalDocumentStateData* internal_data = data_source ? |
| 4448 | InternalDocumentStateData::FromDataSource(data_source) : NULL; |
| 4449 | if (internal_data && internal_data->is_overriding_user_agent()) |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4450 | return WebString::fromUTF8(renderer_preferences_.user_agent_override); |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 4451 | return WebKit::WebString(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4452 | } |
| 4453 | |
[email protected] | a3e217f | 2013-04-12 22:38:34 | [diff] [blame] | 4454 | WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) { |
| 4455 | if (renderer_preferences_.enable_do_not_track) |
| 4456 | return WebString::fromUTF8("1"); |
| 4457 | return WebString(); |
| 4458 | } |
| 4459 | |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 4460 | bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) { |
| 4461 | if (!default_value) |
| 4462 | return false; |
| 4463 | |
| 4464 | bool blocked = true; |
| 4465 | Send(new ViewHostMsg_Are3DAPIsBlocked( |
| 4466 | routing_id_, |
| 4467 | GURL(frame->top()->document().securityOrigin().toString()), |
| 4468 | THREE_D_API_TYPE_WEBGL, |
| 4469 | &blocked)); |
| 4470 | return !blocked; |
| 4471 | } |
| 4472 | |
| 4473 | void RenderViewImpl::didLoseWebGLContext( |
| 4474 | WebKit::WebFrame* frame, |
| 4475 | int arb_robustness_status_code) { |
| 4476 | Send(new ViewHostMsg_DidLose3DContext( |
| 4477 | GURL(frame->top()->document().securityOrigin().toString()), |
| 4478 | THREE_D_API_TYPE_WEBGL, |
| 4479 | arb_robustness_status_code)); |
| 4480 | } |
| 4481 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4482 | // WebKit::WebPageSerializerClient implementation ------------------------------ |
| 4483 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4484 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4485 | const WebURL& frame_url, |
| 4486 | const WebCString& data, |
| 4487 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4488 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4489 | routing_id(), |
| 4490 | frame_url, |
| 4491 | data.data(), |
| 4492 | static_cast<int32>(status))); |
| 4493 | } |
| 4494 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4495 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4496 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4497 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4498 | return RenderWidget::Send(message); |
| 4499 | } |
| 4500 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4501 | int RenderViewImpl::GetRoutingID() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4502 | return routing_id_; |
| 4503 | } |
| 4504 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4505 | int RenderViewImpl::GetPageId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4506 | return page_id_; |
| 4507 | } |
| 4508 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4509 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4510 | return size(); |
| 4511 | } |
| 4512 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4513 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4514 | return webkit_preferences_; |
| 4515 | } |
| 4516 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 4517 | void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { |
| 4518 | OnUpdateWebPreferences(preferences); |
| 4519 | } |
| 4520 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4521 | WebKit::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4522 | return webview(); |
| 4523 | } |
| 4524 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4525 | WebKit::WebNode RenderViewImpl::GetFocusedNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4526 | if (!webview()) |
| 4527 | return WebNode(); |
| 4528 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 4529 | if (focused_frame) { |
| 4530 | WebDocument doc = focused_frame->document(); |
| 4531 | if (!doc.isNull()) |
| 4532 | return doc.focusedNode(); |
| 4533 | } |
| 4534 | |
| 4535 | return WebNode(); |
| 4536 | } |
| 4537 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4538 | WebKit::WebNode RenderViewImpl::GetContextMenuNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4539 | return context_menu_node_; |
| 4540 | } |
| 4541 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4542 | bool RenderViewImpl::IsEditableNode(const WebNode& node) const { |
| 4543 | if (node.isNull()) |
| 4544 | return false; |
| 4545 | |
| 4546 | if (node.isContentEditable()) |
| 4547 | return true; |
| 4548 | |
| 4549 | if (node.isElementNode()) { |
| 4550 | const WebElement& element = node.toConst<WebElement>(); |
| 4551 | if (element.isTextFormControlElement()) |
| 4552 | return true; |
| 4553 | |
| 4554 | // Also return true if it has an ARIA role of 'textbox'. |
| 4555 | for (unsigned i = 0; i < element.attributeCount(); ++i) { |
| 4556 | if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { |
| 4557 | if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) |
| 4558 | return true; |
| 4559 | break; |
| 4560 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4561 | } |
| 4562 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4563 | |
| 4564 | return false; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4565 | } |
| 4566 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4567 | WebKit::WebPlugin* RenderViewImpl::CreatePlugin( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4568 | WebKit::WebFrame* frame, |
| 4569 | const webkit::WebPluginInfo& info, |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4570 | const WebKit::WebPluginParams& params) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 4571 | WebKit::WebPlugin* pepper_webplugin = |
| 4572 | pepper_helper_->CreatePepperWebPlugin(info, params); |
| 4573 | |
| 4574 | if (pepper_webplugin) |
| 4575 | return pepper_webplugin; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4576 | |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 4577 | if (!webkit::npapi::NPAPIPluginsSupported()) |
| 4578 | return NULL; |
| 4579 | |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4580 | return new webkit::npapi::WebPluginImpl( |
| 4581 | frame, params, info.path, AsWeakPtr()); |
| 4582 | } |
| 4583 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4584 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 4585 | const string16& jscript, |
| 4586 | int id, |
| 4587 | bool notify_result) { |
[email protected] | 3b2a3a8 | 2013-02-20 15:29:31 | [diff] [blame] | 4588 | v8::HandleScope handle_scope; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4589 | v8::Handle<v8::Value> result; |
| 4590 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4591 | if (web_frame) |
| 4592 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 4593 | if (notify_result) { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4594 | base::ListValue list; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4595 | if (!result.IsEmpty() && web_frame) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4596 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 4597 | v8::Context::Scope context_scope(context); |
| 4598 | V8ValueConverterImpl converter; |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 4599 | converter.SetDateAllowed(true); |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 4600 | converter.SetRegExpAllowed(true); |
| 4601 | base::Value* result_value = converter.FromV8Value(result, context); |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4602 | list.Set(0, result_value ? result_value : base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4603 | } else { |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 4604 | list.Set(0, base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4605 | } |
| 4606 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 4607 | } |
| 4608 | } |
| 4609 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4610 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4611 | return (!send_preferred_size_changes_ || |
| 4612 | (disable_scrollbars_size_limit_.width() <= width || |
| 4613 | disable_scrollbars_size_limit_.height() <= height)); |
| 4614 | } |
| 4615 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4616 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4617 | return enabled_bindings_; |
| 4618 | } |
| 4619 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4620 | bool RenderViewImpl::GetContentStateImmediately() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4621 | return send_content_state_immediately_; |
| 4622 | } |
| 4623 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4624 | float RenderViewImpl::GetFilteredTimePerFrame() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4625 | return filtered_time_per_frame(); |
| 4626 | } |
| 4627 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4628 | int RenderViewImpl::ShowContextMenu(ContextMenuClient* client, |
| 4629 | const ContextMenuParams& params) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4630 | DCHECK(client); // A null client means "internal" when we issue callbacks. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4631 | ContextMenuParams our_params(params); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4632 | our_params.custom_context.request_id = pending_context_menus_.Add(client); |
| 4633 | Send(new ViewHostMsg_ContextMenu(routing_id_, our_params)); |
| 4634 | return our_params.custom_context.request_id; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4635 | } |
| 4636 | |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 4637 | void RenderViewImpl::CancelContextMenu(int request_id) { |
| 4638 | DCHECK(pending_context_menus_.Lookup(request_id)); |
| 4639 | pending_context_menus_.Remove(request_id); |
| 4640 | } |
| 4641 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4642 | WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4643 | return visibilityState(); |
| 4644 | } |
| 4645 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4646 | void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame, |
| 4647 | const WebKit::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4648 | return runModalAlertDialog(frame, message); |
| 4649 | } |
| 4650 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4651 | void RenderViewImpl::LoadURLExternally( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4652 | WebKit::WebFrame* frame, |
| 4653 | const WebKit::WebURLRequest& request, |
| 4654 | WebKit::WebNavigationPolicy policy) { |
| 4655 | loadURLExternally(frame, request, policy); |
| 4656 | } |
| 4657 | |
| 4658 | // webkit_glue::WebPluginPageDelegate ------------------------------------------ |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 4659 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4660 | webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate( |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 4661 | const base::FilePath& file_path, |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 4662 | const std::string& mime_type) { |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 4663 | if (!PluginChannelHost::IsListening()) { |
| 4664 | LOG(ERROR) << "PluginChannelHost isn't listening"; |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4665 | return NULL; |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 4666 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4667 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4668 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 4669 | if (in_process_plugin) { |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 4670 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 3b21be9 | 2012-11-02 06:00:02 | [diff] [blame] | 4671 | return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 4672 | #else |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 4673 | // In-proc plugins aren't supported on non-Windows. |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 4674 | NOTIMPLEMENTED(); |
| 4675 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 4676 | #endif |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4677 | } |
| 4678 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 4679 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4680 | } |
| 4681 | |
[email protected] | 6ac77cb | 2012-05-01 14:49:01 | [diff] [blame] | 4682 | WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement( |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 4683 | const base::FilePath& file_path) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4684 | return GetContentClient()->renderer()->CreatePluginReplacement( |
[email protected] | 6ac77cb | 2012-05-01 14:49:01 | [diff] [blame] | 4685 | this, file_path); |
| 4686 | } |
| 4687 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4688 | void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 4689 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 4690 | Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4691 | #endif |
| 4692 | } |
| 4693 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4694 | void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 4695 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 4696 | Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4697 | #endif |
| 4698 | CleanupWindowInPluginMoves(window); |
| 4699 | } |
| 4700 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4701 | void RenderViewImpl::DidMovePlugin( |
| 4702 | const webkit::npapi::WebPluginGeometry& move) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4703 | SchedulePluginMove(move); |
| 4704 | } |
| 4705 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4706 | void RenderViewImpl::DidStartLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4707 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 4708 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4709 | } |
| 4710 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4711 | void RenderViewImpl::DidStopLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4712 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 4713 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4714 | } |
| 4715 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4716 | WebCookieJar* RenderViewImpl::GetCookieJar() { |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 4717 | return &cookie_jar_; |
| 4718 | } |
| 4719 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4720 | void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4721 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4722 | reinterpret_cast<int64>(player), |
| 4723 | player->hasVideo(), |
| 4724 | player->hasAudio(), |
| 4725 | true)); |
| 4726 | } |
| 4727 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4728 | void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4729 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4730 | reinterpret_cast<int64>(player), |
| 4731 | player->hasVideo(), |
| 4732 | player->hasAudio(), |
| 4733 | false)); |
| 4734 | } |
| 4735 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4736 | void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4737 | DidPause(player); |
| 4738 | } |
| 4739 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4740 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4741 | if (!webview()) |
| 4742 | return; |
| 4743 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4744 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 4745 | SendUpdateState(item); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4746 | } |
| 4747 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4748 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4749 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4750 | if (!frame) |
| 4751 | return; |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4752 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4753 | string16 text; |
| 4754 | size_t offset; |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4755 | ui::Range range; |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 4756 | if (pepper_helper_->IsPluginFocused()) { |
| 4757 | pepper_helper_->GetSurroundingText(&text, &range); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4758 | offset = 0; // Pepper API does not support offset reporting. |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4759 | // TODO(kinaba): cut as needed. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4760 | } else { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4761 | size_t location, length; |
| 4762 | if (!webview()->caretOrSelectionRange(&location, &length)) |
| 4763 | return; |
| 4764 | |
| 4765 | range = ui::Range(location, location + length); |
| 4766 | |
| 4767 | if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { |
| 4768 | // If current focused element is editable, we will send 100 more chars |
| 4769 | // before and after selection. It is for input method surrounding text |
| 4770 | // feature. |
| 4771 | if (location > kExtraCharsBeforeAndAfterSelection) |
| 4772 | offset = location - kExtraCharsBeforeAndAfterSelection; |
| 4773 | else |
| 4774 | offset = 0; |
| 4775 | length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 4776 | WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 4777 | if (!webrange.isNull()) |
| 4778 | text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 4779 | } else { |
| 4780 | offset = location; |
| 4781 | text = frame->selectionAsText(); |
| 4782 | // http://crbug.com/101435 |
| 4783 | // In some case, frame->selectionAsText() returned text's length is not |
| 4784 | // equal to the length returned from webview()->caretOrSelectionRange(). |
| 4785 | // So we have to set the range according to text.length(). |
| 4786 | range.set_end(range.start() + text.length()); |
| 4787 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4788 | } |
| 4789 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4790 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 4791 | // the selection hasn't actually changed. We don't want to report these |
| 4792 | // because it will cause us to continually claim the X clipboard. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4793 | if (selection_text_offset_ != offset || |
| 4794 | selection_range_ != range || |
| 4795 | selection_text_ != text) { |
| 4796 | selection_text_ = text; |
| 4797 | selection_text_offset_ = offset; |
| 4798 | selection_range_ = range; |
| 4799 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 4800 | } |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 4801 | UpdateSelectionBounds(); |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4802 | } |
| 4803 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4804 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 4805 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4806 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4807 | // If the URL that failed was secure, then the embedding web page was not |
| 4808 | // expecting a network attacker to be able to manipulate its contents. As |
| 4809 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 4810 | // attacker to manipulate the contents of the response if we tried to use |
| 4811 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4812 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | // Grab the base URL from the browser process. |
| 4816 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4817 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4818 | |
| 4819 | // Strip query params from the failed URL. |
| 4820 | GURL::Replacements remove_params; |
| 4821 | remove_params.ClearUsername(); |
| 4822 | remove_params.ClearPassword(); |
| 4823 | remove_params.ClearQuery(); |
| 4824 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4825 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 4826 | std::string spec_to_send = url_to_send.spec(); |
| 4827 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 4828 | if (failed_url.has_query()) |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4829 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4830 | |
| 4831 | // Construct the query params to send to link doctor. |
| 4832 | std::string params(alternate_error_page_url_.query()); |
| 4833 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 4834 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4835 | params.append("&sourceid=chrome"); |
| 4836 | params.append("&error="); |
| 4837 | switch (error_type) { |
| 4838 | case DNS_ERROR: |
| 4839 | params.append("dnserror"); |
| 4840 | break; |
| 4841 | |
| 4842 | case HTTP_404: |
| 4843 | params.append("http404"); |
| 4844 | break; |
| 4845 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4846 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 4847 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4848 | break; |
| 4849 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4850 | default: |
| 4851 | NOTREACHED() << "unknown ErrorPageType"; |
| 4852 | } |
| 4853 | |
| 4854 | // OK, build the final url to return. |
| 4855 | GURL::Replacements link_doctor_params; |
| 4856 | link_doctor_params.SetQueryStr(params); |
| 4857 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 4858 | return url; |
| 4859 | } |
| 4860 | |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 4861 | GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { |
| 4862 | WebDataSource* ds = frame->dataSource(); |
| 4863 | if (ds->hasUnreachableURL()) |
| 4864 | return ds->unreachableURL(); |
| 4865 | |
| 4866 | const WebURLRequest& request = ds->request(); |
| 4867 | return request.url(); |
| 4868 | } |
| 4869 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4870 | WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4871 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4872 | } |
| 4873 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4874 | void RenderViewImpl::OnFind(int request_id, |
| 4875 | const string16& search_text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4876 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4877 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4878 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4879 | // Check if the plugin still exists in the document. |
| 4880 | if (main_frame->document().isPluginDocument() && |
| 4881 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4882 | if (options.findNext) { |
| 4883 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4884 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4885 | } else { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4886 | if (!GetWebPluginFromPluginDocument()->startFind( |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 4887 | search_text, options.matchCase, request_id)) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4888 | // Send "no results". |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4889 | SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4890 | } |
| 4891 | } |
| 4892 | return; |
| 4893 | } |
| 4894 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4895 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4896 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4897 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4898 | |
| 4899 | bool multi_frame = (frame_after_main != main_frame); |
| 4900 | |
| 4901 | // If we have multiple frames, we don't want to wrap the search within the |
| 4902 | // frame, so we check here if we only have main_frame in the chain. |
| 4903 | bool wrap_within_frame = !multi_frame; |
| 4904 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 4905 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4906 | bool result = false; |
| 4907 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4908 | // If something is selected when we start searching it means we cannot just |
| 4909 | // increment the current match ordinal; we need to re-generate it. |
| 4910 | WebRange current_selection = focused_frame->selectionRange(); |
| 4911 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4912 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4913 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4914 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4915 | |
| 4916 | if (!result) { |
| 4917 | // don't leave text selected as you move to the next frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4918 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4919 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4920 | |
| 4921 | // Find the next frame, but skip the invisible ones. |
| 4922 | do { |
| 4923 | // What is the next frame to search? (we might be going backwards). Note |
| 4924 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4925 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4926 | search_frame->traverseNext(true) : |
| 4927 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4928 | } while (!search_frame->hasVisibleContent() && |
| 4929 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4930 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 4931 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 4932 | search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
| 4933 | GetFocusedNode()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4934 | |
| 4935 | // If we have multiple frames and we have wrapped back around to the |
| 4936 | // focused frame, we need to search it once more allowing wrap within |
| 4937 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 4938 | // reported matches, but no frames after the focused_frame contain a |
| 4939 | // match for the search word(s). |
| 4940 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4941 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4942 | request_id, search_text, options, true, // Force wrapping. |
| 4943 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4944 | } |
| 4945 | } |
| 4946 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4947 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4948 | } while (!result && search_frame != focused_frame); |
| 4949 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4950 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4951 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4952 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4953 | } else { |
| 4954 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4955 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4956 | // yet what is active. |
| 4957 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4958 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4959 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4960 | // If we find no matches then this will be our last status update. |
| 4961 | // Otherwise the scoping effort will send more results. |
| 4962 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4963 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4964 | SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 4965 | final_status_update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4966 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4967 | // Scoping effort begins, starting with the mainframe. |
| 4968 | search_frame = main_frame; |
| 4969 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4970 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4971 | |
| 4972 | do { |
| 4973 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4974 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4975 | |
| 4976 | // We don't start another scoping effort unless at least one match has |
| 4977 | // been found. |
| 4978 | if (result) { |
| 4979 | // Start new scoping request. If the scoping function determines that it |
| 4980 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4981 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4982 | search_text, |
| 4983 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4984 | true); // reset the tickmarks |
| 4985 | } |
| 4986 | |
| 4987 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4988 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4989 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4990 | } while (search_frame != main_frame); |
| 4991 | } |
| 4992 | } |
| 4993 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4994 | void RenderViewImpl::OnStopFinding(StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4995 | WebView* view = webview(); |
| 4996 | if (!view) |
| 4997 | return; |
| 4998 | |
| 4999 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 5000 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 5001 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 5002 | return; |
| 5003 | } |
| 5004 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5005 | bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 6dd17a8a | 2013-05-01 05:50:10 | [diff] [blame] | 5006 | if (clear_selection) { |
| 5007 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), |
| 5008 | GetFocusedNode()); |
| 5009 | } |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 5010 | |
| 5011 | WebFrame* frame = view->mainFrame(); |
| 5012 | while (frame) { |
| 5013 | frame->stopFinding(clear_selection); |
| 5014 | frame = frame->traverseNext(false); |
| 5015 | } |
| 5016 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5017 | if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 5018 | WebFrame* focused_frame = view->focusedFrame(); |
| 5019 | if (focused_frame) { |
| 5020 | WebDocument doc = focused_frame->document(); |
| 5021 | if (!doc.isNull()) { |
| 5022 | WebNode node = doc.focusedNode(); |
| 5023 | if (!node.isNull()) |
| 5024 | node.simulateClick(); |
| 5025 | } |
| 5026 | } |
| 5027 | } |
| 5028 | } |
| 5029 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 5030 | #if defined(OS_ANDROID) |
| 5031 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 5032 | float x, float y) { |
| 5033 | if (!webview()) |
| 5034 | return; |
| 5035 | |
| 5036 | WebFrame* main_frame = webview()->mainFrame(); |
| 5037 | WebRect selection_rect; |
| 5038 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 5039 | &selection_rect); |
| 5040 | if (ordinal == -1) { |
| 5041 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 5042 | // report the current match count) in case the host is waiting for a |
| 5043 | // response due to rate-limiting). |
| 5044 | main_frame->increaseMatchCount(0, request_id); |
| 5045 | return; |
| 5046 | } |
| 5047 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 5048 | SendFindReply(request_id, |
| 5049 | -1 /* number_of_matches */, |
| 5050 | ordinal, |
| 5051 | selection_rect, |
| 5052 | true /* final_update */); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 5056 | if (!webview()) |
| 5057 | return; |
| 5058 | |
| 5059 | WebFrame* main_frame = webview()->mainFrame(); |
| 5060 | std::vector<gfx::RectF> match_rects; |
| 5061 | |
| 5062 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 5063 | if (current_version != rects_version) { |
| 5064 | WebVector<WebFloatRect> web_match_rects; |
| 5065 | main_frame->findMatchRects(web_match_rects); |
| 5066 | match_rects.reserve(web_match_rects.size()); |
| 5067 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 5068 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 5069 | } |
| 5070 | |
| 5071 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 5072 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 5073 | rects_version, |
| 5074 | match_rects, |
| 5075 | active_rect)); |
| 5076 | } |
| 5077 | #endif |
| 5078 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5079 | void RenderViewImpl::OnZoom(PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 5080 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 5081 | return; |
| 5082 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 5083 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 5084 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5085 | double old_zoom_level = webview()->zoomLevel(); |
| 5086 | double zoom_level; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5087 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5088 | zoom_level = 0; |
| 5089 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 5090 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 5091 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5092 | } else { |
| 5093 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 5094 | // not a whole number, or a plugin changed it to a custom value. We want |
| 5095 | // to go to the next whole number so that the user can always get back to |
| 5096 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 5097 | if ((old_zoom_level > 1 && zoom > 0) || |
| 5098 | (old_zoom_level < 1 && zoom < 0)) { |
| 5099 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5100 | } else { |
| 5101 | // We're going towards 100%, so first go to the next whole number. |
| 5102 | zoom_level = static_cast<int>(old_zoom_level); |
| 5103 | } |
| 5104 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5105 | webview()->setZoomLevel(false, zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 5106 | zoomLevelChanged(); |
| 5107 | } |
| 5108 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5109 | void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x, |
| 5110 | int zoom_center_y) { |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 5111 | ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y, |
| 5112 | kScalingIncrementForGesture); |
| 5113 | } |
| 5114 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5115 | void RenderViewImpl::ZoomFactorHelper(PageZoom zoom, |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 5116 | int zoom_center_x, |
| 5117 | int zoom_center_y, |
| 5118 | float scaling_increment) { |
| 5119 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 5120 | return; |
| 5121 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 5122 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 5123 | double page_scale_factor; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5124 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 5125 | page_scale_factor = 1.0; |
| 5126 | } else { |
| 5127 | page_scale_factor = old_page_scale_factor + |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 5128 | (zoom > 0 ? scaling_increment : -scaling_increment); |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 5129 | } |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 5130 | if (page_scale_factor > 0) { |
[email protected] | 8519136 | 2011-11-08 18:53:09 | [diff] [blame] | 5131 | webview()->setPageScaleFactor(page_scale_factor, |
| 5132 | WebPoint(zoom_center_x, zoom_center_y)); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 5133 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 5134 | } |
| 5135 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5136 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 5137 | webview()->hidePopups(); |
| 5138 | webview()->setZoomLevel(false, zoom_level); |
| 5139 | zoomLevelChanged(); |
| 5140 | } |
| 5141 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5142 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 5143 | double zoom_level) { |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 5144 | #if !defined(OS_ANDROID) |
| 5145 | // On Android, page zoom isn't used, and in case of WebView, text zoom is used |
| 5146 | // for legacy WebView text scaling emulation. Thus, the code that resets |
| 5147 | // the zoom level from this map will be effectively resetting text zoom level. |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 5148 | host_zoom_levels_[url] = zoom_level; |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 5149 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5150 | } |
| 5151 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5152 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5153 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5154 | } |
| 5155 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5156 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5157 | WebString no_encoding; |
| 5158 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 5159 | } |
| 5160 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5161 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5162 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5163 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5164 | |
| 5165 | // xpath string can represent a frame deep down the tree (across multiple |
| 5166 | // frame DOMs). |
| 5167 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 5168 | // should break into 2 xpaths |
| 5169 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 5170 | std::vector<string16> xpaths; |
| 5171 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5172 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5173 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 5174 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 5175 | frame && i != xpaths.end(); ++i) { |
| 5176 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5177 | } |
| 5178 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5179 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5180 | } |
| 5181 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5182 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 5183 | const string16& jscript, |
| 5184 | int id, |
| 5185 | bool notify_result) { |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 5186 | TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest", |
| 5187 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 5188 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5189 | } |
| 5190 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5191 | void RenderViewImpl::OnPostMessageEvent( |
| 5192 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | bf4a231 | 2013-04-23 00:32:11 | [diff] [blame] | 5193 | // TODO(nasko): Support sending to subframes. |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 5194 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5195 | |
| 5196 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5197 | WebFrame* source_frame = NULL; |
| 5198 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 5199 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 5200 | if (source_view) |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 5201 | source_frame = source_view->webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | // Create an event with the message. The final parameter to initMessageEvent |
| 5205 | // is the last event ID, which is not used with postMessage. |
| 5206 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 5207 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 5208 | msg_event.initMessageEvent("message", |
| 5209 | // |canBubble| and |cancellable| are always false |
| 5210 | false, false, |
| 5211 | WebSerializedScriptValue::fromString(params.data), |
| 5212 | params.source_origin, source_frame, ""); |
| 5213 | |
| 5214 | // We must pass in the target_origin to do the security check on this side, |
| 5215 | // since it may have changed since the original postMessage call was made. |
| 5216 | WebSecurityOrigin target_origin; |
| 5217 | if (!params.target_origin.empty()) { |
| 5218 | target_origin = |
| 5219 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 5220 | } |
| 5221 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 5222 | } |
| 5223 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5224 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 5225 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 5226 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 5227 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 5228 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 5229 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 5230 | frame->document().insertUserStyleSheet( |
| 5231 | WebString::fromUTF8(css), |
| 5232 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 5233 | } |
| 5234 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5235 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 5236 | if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && |
| 5237 | !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { |
[email protected] | dcc72db | 2013-01-02 00:44:18 | [diff] [blame] | 5238 | RenderThread::Get()->RegisterExtension(WebUIExtension::Get()); |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 5239 | new WebUIExtensionData(this); |
| 5240 | } |
| 5241 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 5242 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 5243 | |
| 5244 | // Keep track of the total bindings accumulated in this process. |
| 5245 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5246 | } |
| 5247 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5248 | void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data, |
| 5249 | const gfx::Point& client_point, |
| 5250 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5251 | WebDragOperationsMask ops, |
| 5252 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5253 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | c1068031 | 2013-05-31 15:22:05 | [diff] [blame] | 5254 | WebDropDataToDragData(drop_data), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5255 | client_point, |
| 5256 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5257 | ops, |
| 5258 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5259 | |
| 5260 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 5261 | } |
| 5262 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5263 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 5264 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5265 | WebDragOperationsMask ops, |
| 5266 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5267 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 5268 | client_point, |
| 5269 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5270 | ops, |
| 5271 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5272 | |
| 5273 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 5274 | } |
| 5275 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5276 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5277 | webview()->dragTargetDragLeave(); |
| 5278 | } |
| 5279 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5280 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5281 | const gfx::Point& screen_point, |
| 5282 | int key_modifiers) { |
| 5283 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 5284 | |
| 5285 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5286 | } |
| 5287 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5288 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 5289 | const gfx::Point& screen_point, |
| 5290 | bool ended, |
| 5291 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5292 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5293 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 5294 | } else { |
| 5295 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5296 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5297 | } |
| 5298 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5299 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5300 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5301 | } |
| 5302 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5303 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 5304 | webkit_preferences_ = prefs; |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 5305 | webkit_glue::ApplyWebPreferences(webkit_preferences_, webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5306 | } |
| 5307 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 5308 | void RenderViewImpl::OnUpdateTimezone() { |
| 5309 | if (webview()) |
| 5310 | NotifyTimezoneChange(webview()->mainFrame()); |
| 5311 | } |
| 5312 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5313 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5314 | alternate_error_page_url_ = url; |
| 5315 | } |
| 5316 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5317 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5318 | const CustomContextMenuContext& custom_context, |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5319 | unsigned action) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5320 | if (custom_context.request_id) { |
| 5321 | // External context menu request, look in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5322 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5323 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 5324 | if (client) |
| 5325 | client->OnMenuAction(custom_context.request_id, action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5326 | } else { |
| 5327 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5328 | webview()->performCustomContextMenuAction(action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5329 | } |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 5330 | } |
| 5331 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5332 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5333 | int id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5334 | const std::vector<base::FilePath>& paths) { |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5335 | if (!enumeration_completions_[id]) |
| 5336 | return; |
| 5337 | |
| 5338 | WebVector<WebString> ws_file_names(paths.size()); |
| 5339 | for (size_t i = 0; i < paths.size(); ++i) |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5340 | ws_file_names[i] = webkit_base::FilePathToWebString(paths[i]); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5341 | |
| 5342 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 5343 | enumeration_completions_.erase(id); |
| 5344 | } |
| 5345 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 5346 | void RenderViewImpl::OnFileChooserResponse( |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 5347 | const std::vector<ui::SelectedFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5348 | // This could happen if we navigated to a different page before the user |
| 5349 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5350 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5351 | return; |
| 5352 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5353 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 5354 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 5355 | files.size()); |
| 5356 | for (size_t i = 0; i < files.size(); ++i) { |
| 5357 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5358 | selected_file.path = webkit_base::FilePathToWebString(files[i].local_path); |
| 5359 | selected_file.displayName = webkit_base::FilePathStringToWebString( |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5360 | files[i].display_name); |
| 5361 | selected_files[i] = selected_file; |
| 5362 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 5363 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5364 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5365 | file_chooser_completions_.front()->completion->didChooseFile( |
| 5366 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5367 | file_chooser_completions_.pop_front(); |
| 5368 | |
| 5369 | // If there are more pending file chooser requests, schedule one now. |
| 5370 | if (!file_chooser_completions_.empty()) { |
| 5371 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 5372 | file_chooser_completions_.front()->params)); |
| 5373 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5374 | } |
| 5375 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5376 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 5377 | const gfx::Size& max_size) { |
| 5378 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5379 | if (!webview()) |
| 5380 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5381 | auto_resize_mode_ = true; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5382 | webview()->enableAutoResizeMode(min_size, max_size); |
| 5383 | } |
| 5384 | |
| 5385 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 5386 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5387 | if (!webview()) |
| 5388 | return; |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 5389 | auto_resize_mode_ = false; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5390 | webview()->disableAutoResizeMode(); |
| 5391 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 5392 | if (!new_size.IsEmpty()) { |
| 5393 | Resize(new_size, |
| 5394 | physical_backing_size_, |
| 5395 | overdraw_bottom_height_, |
| 5396 | resizer_rect_, |
| 5397 | is_fullscreen_, |
| 5398 | NO_RESIZE_ACK); |
| 5399 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5400 | } |
| 5401 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 5402 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5403 | if (send_preferred_size_changes_) |
| 5404 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5405 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 5406 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5407 | // Start off with an initial preferred size notification (in case |
| 5408 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 5409 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 5410 | } |
| 5411 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5412 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5413 | const gfx::Size& disable_scrollbar_size_limit) { |
| 5414 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 5415 | } |
| 5416 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5417 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5418 | const RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5419 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5420 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 5421 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5422 | |
| 5423 | #if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5424 | if (renderer_prefs.use_custom_colors) { |
| 5425 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 5426 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
| 5427 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5428 | #if defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5429 | ui::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5430 | renderer_prefs.thumb_inactive_color, |
| 5431 | renderer_prefs.thumb_active_color, |
| 5432 | renderer_prefs.track_color); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5433 | #endif // defined(TOOLKIT_GTK) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 5434 | |
| 5435 | if (webview()) { |
| 5436 | #if defined(TOOLKIT_GTK) |
| 5437 | webview()->setScrollbarColors( |
| 5438 | renderer_prefs.thumb_inactive_color, |
| 5439 | renderer_prefs.thumb_active_color, |
| 5440 | renderer_prefs.track_color); |
| 5441 | #endif // defined(TOOLKIT_GTK) |
| 5442 | webview()->setSelectionColors( |
| 5443 | renderer_prefs.active_selection_bg_color, |
| 5444 | renderer_prefs.active_selection_fg_color, |
| 5445 | renderer_prefs.inactive_selection_bg_color, |
| 5446 | renderer_prefs.inactive_selection_fg_color); |
| 5447 | webview()->themeChanged(); |
| 5448 | } |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5449 | } |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 5450 | #endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK) |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5451 | |
[email protected] | 107c053 | 2013-02-06 02:34:09 | [diff] [blame] | 5452 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 5453 | RenderThreadImpl::current()->SetFlingCurveParameters( |
| 5454 | renderer_prefs.touchpad_fling_profile, |
| 5455 | renderer_prefs.touchscreen_fling_profile); |
| 5456 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5457 | // If the zoom level for this page matches the old zoom default, and this |
| 5458 | // is not a plugin, update the zoom level to match the new default. |
| 5459 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
[email protected] | cbe55d2 | 2013-02-14 17:04:33 | [diff] [blame] | 5460 | !ZoomValuesEqual(old_zoom_level, |
| 5461 | renderer_preferences_.default_zoom_level) && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5462 | ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5463 | webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level); |
| 5464 | zoomLevelChanged(); |
| 5465 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5466 | } |
| 5467 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5468 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 5469 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 5470 | if (webview()) |
| 5471 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 5472 | } |
| 5473 | |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5474 | void RenderViewImpl::OnOrientationChangeEvent(int orientation) { |
| 5475 | webview()->mainFrame()->sendOrientationChangeEvent(orientation); |
| 5476 | } |
| 5477 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 5478 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 5479 | const WebPluginAction& action) { |
| 5480 | if (webview()) |
| 5481 | webview()->performPluginAction(action, location); |
| 5482 | } |
| 5483 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5484 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5485 | const GURL& page_url) { |
| 5486 | // Prepare list to storage all savable resource links. |
| 5487 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5488 | std::vector<GURL> referrer_urls_list; |
| 5489 | std::vector<WebKit::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5490 | std::vector<GURL> frames_list; |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5491 | SavableResourcesResult result(&resources_list, |
| 5492 | &referrer_urls_list, |
| 5493 | &referrer_policies_list, |
| 5494 | &frames_list); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5495 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5496 | // webkit/ doesn't know about Referrer. |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 5497 | if (!GetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5498 | webview(), |
| 5499 | page_url, |
| 5500 | &result, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5501 | const_cast<const char**>(GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5502 | // If something is wrong when collecting all savable resource links, |
| 5503 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5504 | referrer_urls_list.clear(); |
| 5505 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5506 | resources_list.clear(); |
| 5507 | frames_list.clear(); |
| 5508 | } |
| 5509 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5510 | std::vector<Referrer> referrers_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5511 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 5512 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 5513 | referrers_list.push_back( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5514 | Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5515 | } |
| 5516 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5517 | // Send result of all savable resource links to embedder. |
| 5518 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 5519 | resources_list, |
| 5520 | referrers_list, |
| 5521 | frames_list)); |
| 5522 | } |
| 5523 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5524 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5525 | const std::vector<GURL>& links, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 5526 | const std::vector<base::FilePath>& local_paths, |
| 5527 | const base::FilePath& local_directory_name) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5528 | |
| 5529 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 5530 | WebVector<WebURL> weburl_links(links); |
| 5531 | |
| 5532 | // Convert std::vector of std::strings to WebVector<WebString> |
| 5533 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 5534 | for (size_t i = 0; i < local_paths.size(); i++) |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5535 | webstring_paths[i] = webkit_base::FilePathToWebString(local_paths[i]); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5536 | |
| 5537 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 5538 | webstring_paths, |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5539 | webkit_base::FilePathToWebString( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5540 | local_directory_name)); |
| 5541 | } |
| 5542 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5543 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5544 | base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5545 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5546 | base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
| 5547 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
| 5548 | before_unload_start_time, |
| 5549 | before_unload_end_time)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5550 | } |
| 5551 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5552 | void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5553 | // Only run unload if we're not swapped out yet, but send the ack either way. |
| 5554 | if (!is_swapped_out_) { |
| 5555 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 5556 | // different process. This involves running the unload handler and clearing |
| 5557 | // the page. Once WasSwappedOut is called, we also allow this process to |
| 5558 | // exit if there are no other active RenderViews in it. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5559 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5560 | // Send an UpdateState message before we get swapped out. |
| 5561 | SyncNavigationState(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5562 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5563 | // Synchronously run the unload handler before sending the ACK. |
| 5564 | webview()->dispatchUnloadEvent(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5565 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5566 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 5567 | SetSwappedOut(true); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5568 | |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 5569 | // Now that we're swapped out and filtering IPC messages, stop loading to |
| 5570 | // ensure that no other in-progress navigation continues. We do this here |
| 5571 | // to avoid sending a DidStopLoading message to the browser process. |
| 5572 | OnStop(); |
| 5573 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5574 | // 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] | 5575 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 5576 | // 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] | 5577 | // beforeunload handler. For now, we just run it a second time silently. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5578 | NavigateToSwappedOutURL(webview()->mainFrame()); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 5579 | |
| 5580 | // Let WebKit know that this view is hidden so it can drop resources and |
| 5581 | // stop compositing. |
| 5582 | webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5583 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5584 | |
| 5585 | // Just echo back the params in the ACK. |
| 5586 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 5587 | } |
| 5588 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5589 | void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5590 | // We use loadRequest instead of loadHTMLString because the former commits |
| 5591 | // synchronously. Otherwise a new navigation can interrupt the navigation |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5592 | // to kSwappedOutURL. If that happens to be to the page we had been |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5593 | // 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] | 5594 | CHECK(is_swapped_out_); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5595 | GURL swappedOutURL(kSwappedOutURL); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5596 | WebURLRequest request(swappedOutURL); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5597 | frame->loadRequest(request); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5598 | } |
| 5599 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5600 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 5601 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5602 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 5603 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 5604 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 5605 | // calling the FrameLoader's CloseURL method directly. This should be |
| 5606 | // revisited to avoid having two ways to close a page. Having a single way |
| 5607 | // to close that can run onunload is also useful for fixing |
| 5608 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5609 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5610 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5611 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5612 | } |
| 5613 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5614 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 5615 | #if defined(USE_AURA) |
| 5616 | // Aura doesn't care if we switch themes. |
| 5617 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5618 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5619 | if (webview()) |
| 5620 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 5621 | #else // defined(OS_WIN) |
| 5622 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 5623 | NOTIMPLEMENTED(); |
| 5624 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5625 | } |
| 5626 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5627 | void RenderViewImpl::OnDisassociateFromPopupCount() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 5628 | if (decrement_shared_popup_at_destruction_) |
| 5629 | shared_popup_counter_->data--; |
| 5630 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 5631 | decrement_shared_popup_at_destruction_ = false; |
| 5632 | } |
| 5633 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5634 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 5635 | const WebURLError& error, |
| 5636 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5637 | // We only show alternate error pages in the main frame. They are |
| 5638 | // intended to assist the user when navigating, so there is not much |
| 5639 | // value in showing them for failed subframes. Ideally, we would be |
| 5640 | // able to use the TYPED transition type for this, but that flag is |
| 5641 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5642 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5643 | return false; |
| 5644 | |
| 5645 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 5646 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5647 | int ec = error.reason; |
| 5648 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 5649 | ec != net::ERR_CONNECTION_FAILED && |
| 5650 | ec != net::ERR_CONNECTION_REFUSED && |
| 5651 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5652 | ec != net::ERR_CONNECTION_TIMED_OUT) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5653 | return false; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5654 | } |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5655 | |
| 5656 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5657 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5658 | if (!error_page_url.is_valid()) |
| 5659 | return false; |
| 5660 | |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5661 | WebDataSource* ds = frame->provisionalDataSource(); |
| 5662 | const WebURLRequest& failed_request = ds->request(); |
| 5663 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5664 | // Load an empty page first so there is an immediate response to the error, |
| 5665 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5666 | frame->loadHTMLString(std::string(), |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5667 | GURL(kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5668 | error.unreachableURL, |
| 5669 | replace); |
| 5670 | |
| 5671 | // Now, create a fetcher for the error page and associate it with the data |
| 5672 | // source we just created via the LoadHTMLString call. That way if another |
| 5673 | // navigation occurs, the fetcher will get destroyed. |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5674 | InternalDocumentStateData* internal_data = |
| 5675 | InternalDocumentStateData::FromDataSource(frame->provisionalDataSource()); |
| 5676 | internal_data->set_alt_error_page_fetcher( |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5677 | new AltErrorPageResourceFetcher( |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5678 | error_page_url, frame, failed_request, error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 5679 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 5680 | base::Unretained(this)))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5681 | return true; |
| 5682 | } |
| 5683 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5684 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5685 | const WebURLRequest& original_request, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5686 | const WebURLError& original_error, |
| 5687 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5688 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5689 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5690 | // will simply display a default error page. |
[email protected] | 11a6577 | 2013-04-27 00:36:42 | [diff] [blame] | 5691 | LoadNavigationErrorPage(frame, original_request, original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5692 | } |
| 5693 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5694 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5695 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5696 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5697 | } |
| 5698 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5699 | void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5700 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5701 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5702 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 5703 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5704 | ShouldDisplayScrollbars(params.new_size.width(), |
| 5705 | params.new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5706 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 5707 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5708 | } |
| 5709 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 5710 | RenderWidget::OnResize(params); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5711 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 5712 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5713 | void RenderViewImpl::WillInitiatePaint() { |
| 5714 | // Notify the pepper plugins that we're about to paint. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5715 | pepper_helper_->ViewWillInitiatePaint(); |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5716 | } |
| 5717 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5718 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5719 | // Notify the pepper plugins that we've painted, and are waiting to flush. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5720 | pepper_helper_->ViewInitiatedPaint(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5721 | } |
| 5722 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5723 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5724 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 5725 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 5726 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 5727 | // won't change out from under us. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5728 | pepper_helper_->ViewFlushedPaint(); |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5729 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 5730 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 5731 | // See crbug.com/112921. |
| 5732 | if (!webview()) |
| 5733 | return; |
| 5734 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5735 | WebFrame* main_frame = webview()->mainFrame(); |
| 5736 | |
| 5737 | // If we have a provisional frame we are between the start and commit stages |
| 5738 | // of loading and we don't want to save stats. |
| 5739 | if (!main_frame->provisionalDataSource()) { |
| 5740 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5741 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5742 | InternalDocumentStateData* data = |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 5743 | InternalDocumentStateData::FromDocumentState(document_state); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 5744 | if (data->did_first_visually_non_empty_layout() && |
| 5745 | !data->did_first_visually_non_empty_paint()) { |
| 5746 | data->set_did_first_visually_non_empty_paint(true); |
| 5747 | Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_, |
| 5748 | page_id_)); |
| 5749 | } |
| 5750 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5751 | // TODO(jar): The following code should all be inside a method, probably in |
| 5752 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5753 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5754 | if (document_state->first_paint_time().is_null()) { |
| 5755 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5756 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5757 | if (document_state->first_paint_after_load_time().is_null() && |
| 5758 | !document_state->finish_load_time().is_null()) { |
| 5759 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5760 | } |
| 5761 | } |
| 5762 | } |
| 5763 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5764 | webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5765 | const gfx::Rect& paint_bounds, |
| 5766 | TransportDIB** dib, |
| 5767 | gfx::Rect* location, |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5768 | gfx::Rect* clip, |
| 5769 | float* scale_factor) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5770 | return pepper_helper_->GetBitmapForOptimizedPluginPaint( |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5771 | paint_bounds, dib, location, clip, scale_factor); |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5772 | } |
| 5773 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5774 | gfx::Vector2d RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5775 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5776 | return gfx::Vector2d(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 5777 | } |
| 5778 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5779 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5780 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5781 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5782 | } |
| 5783 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5784 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5785 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5786 | webview()->setIsTransparent(!background.empty()); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 5787 | if (compositor_) |
| 5788 | compositor_->setHasTransparentBackground(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5789 | |
| 5790 | SetBackground(background); |
| 5791 | } |
| 5792 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5793 | void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) { |
| 5794 | if (accessibility_mode_ == new_mode) |
| 5795 | return; |
| 5796 | accessibility_mode_ = new_mode; |
| 5797 | if (renderer_accessibility_) { |
| 5798 | delete renderer_accessibility_; |
| 5799 | renderer_accessibility_ = NULL; |
| 5800 | } |
| 5801 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 5802 | renderer_accessibility_ = new RendererAccessibilityComplete(this); |
| 5803 | else if (accessibility_mode_ == AccessibilityModeEditableTextOnly) |
| 5804 | renderer_accessibility_ = new RendererAccessibilityFocusOnly(this); |
| 5805 | } |
| 5806 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5807 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5808 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5809 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5810 | |
| 5811 | #if defined(OS_MACOSX) |
| 5812 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5813 | for (plugin_it = plugin_delegates_.begin(); |
| 5814 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5815 | (*plugin_it)->SetWindowFocus(active); |
| 5816 | } |
| 5817 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5818 | } |
| 5819 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5820 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5821 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5822 | // Inform plugins that their container has changed visibility. |
| 5823 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5824 | for (plugin_it = plugin_delegates_.begin(); |
| 5825 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5826 | (*plugin_it)->SetContainerVisibility(visible); |
| 5827 | } |
| 5828 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5829 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5830 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 5831 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5832 | // Inform plugins that their window's frame has changed. |
| 5833 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5834 | for (plugin_it = plugin_delegates_.begin(); |
| 5835 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5836 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 5837 | } |
| 5838 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5839 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5840 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 5841 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5842 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5843 | // applies to it or not, so inform all the delegates. |
| 5844 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5845 | for (plugin_it = plugin_delegates_.begin(); |
| 5846 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5847 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5848 | } |
| 5849 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5850 | #endif // OS_MACOSX |
| 5851 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5852 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5853 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5854 | WebView* doomed = webview(); |
| 5855 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 5856 | g_view_map.Get().erase(doomed); |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 5857 | g_routing_id_view_map.Get().erase(routing_id_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5858 | } |
| 5859 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5860 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 5861 | ClearEditCommands(); |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5862 | } |
| 5863 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5864 | bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5865 | possible_drag_event_info_.event_source = |
| 5866 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 5867 | possible_drag_event_info_.event_location = |
| 5868 | gfx::Point(event.globalX, event.globalY); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5869 | pepper_helper_->WillHandleMouseEvent(); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 5870 | |
| 5871 | // If the mouse is locked, only the current owner of the mouse lock can |
| 5872 | // process mouse events. |
| 5873 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 5874 | } |
| 5875 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5876 | bool RenderViewImpl::WillHandleGestureEvent( |
| 5877 | const WebKit::WebGestureEvent& event) { |
| 5878 | possible_drag_event_info_.event_source = |
| 5879 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 5880 | possible_drag_event_info_.event_location = |
| 5881 | gfx::Point(event.globalX, event.globalY); |
| 5882 | return false; |
| 5883 | } |
| 5884 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 5885 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5886 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5887 | } |
| 5888 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5889 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 5890 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 5891 | } |
| 5892 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 5893 | bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 5894 | if (!webview()) |
| 5895 | return false; |
| 5896 | return webview()->hasTouchEventHandlersAt(point); |
| 5897 | } |
| 5898 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5899 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5900 | RenderWidget::OnWasHidden(); |
| 5901 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5902 | #if defined(OS_ANDROID) |
| 5903 | // Inform WebMediaPlayerManagerAndroid to release all media player resources. |
[email protected] | 5c469b4 | 2012-11-26 22:25:30 | [diff] [blame] | 5904 | // unless some audio is playing. |
[email protected] | 263135d | 2012-11-15 13:01:56 | [diff] [blame] | 5905 | // If something is in progress the resource will not be freed, it will |
| 5906 | // only be freed once the tab is destroyed or if the user navigates away |
| 5907 | // via WebMediaPlayerAndroid::Destroy |
[email protected] | 5c469b4 | 2012-11-26 22:25:30 | [diff] [blame] | 5908 | media_player_manager_->ReleaseMediaResources(); |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5909 | |
| 5910 | #if defined(ENABLE_WEBRTC) |
| 5911 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5912 | SuspendDevices(true); |
| 5913 | #endif |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5914 | #endif |
| 5915 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5916 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5917 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5918 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5919 | // Inform PPAPI plugins that their page is no longer visible. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5920 | pepper_helper_->PageVisibilityChanged(false); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5921 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5922 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5923 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5924 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5925 | for (plugin_it = plugin_delegates_.begin(); |
| 5926 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5927 | (*plugin_it)->SetContainerVisibility(false); |
| 5928 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5929 | #endif // OS_MACOSX |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5930 | } |
| 5931 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 5932 | void RenderViewImpl::OnWasShown(bool needs_repainting) { |
| 5933 | RenderWidget::OnWasShown(needs_repainting); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5934 | |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 5935 | #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 5936 | RenderThreadImpl::current()->video_capture_impl_manager()-> |
| 5937 | SuspendDevices(false); |
| 5938 | #endif |
| 5939 | |
[email protected] | 8869d39 | 2013-05-07 15:34:26 | [diff] [blame] | 5940 | if (webview()) |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5941 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5942 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5943 | // Inform PPAPI plugins that their page is visible. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5944 | pepper_helper_->PageVisibilityChanged(true); |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5945 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5946 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5947 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5948 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5949 | for (plugin_it = plugin_delegates_.begin(); |
| 5950 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5951 | (*plugin_it)->SetContainerVisibility(true); |
| 5952 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5953 | #endif // OS_MACOSX |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5954 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5955 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 5956 | GURL RenderViewImpl::GetURLForGraphicsContext3D() { |
| 5957 | DCHECK(webview()); |
| 5958 | if (webview()->mainFrame()) |
| 5959 | return GURL(webview()->mainFrame()->document().url()); |
| 5960 | else |
| 5961 | return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5962 | } |
| 5963 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 5964 | bool RenderViewImpl::ForceCompositingModeEnabled() { |
| 5965 | return webkit_preferences_.force_compositing_mode; |
| 5966 | } |
| 5967 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5968 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5969 | RenderWidget::OnSetFocus(enable); |
| 5970 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5971 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5972 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5973 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5974 | for (plugin_it = plugin_delegates_.begin(); |
| 5975 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5976 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5977 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5978 | // activation state to change just like a call to setIsActive. |
| 5979 | if (enable) |
| 5980 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5981 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5982 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5983 | } |
| 5984 | } |
[email protected] | a01da568 | 2012-06-30 00:37:31 | [diff] [blame] | 5985 | // Notify all Pepper plugins. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 5986 | pepper_helper_->OnSetFocus(enable); |
[email protected] | 32103299 | 2012-11-08 01:01:27 | [diff] [blame] | 5987 | // Notify all BrowserPlugins of the RenderView's focus state. |
[email protected] | fb325d12 | 2012-11-20 23:58:05 | [diff] [blame] | 5988 | if (browser_plugin_manager_) |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 5989 | browser_plugin_manager_->UpdateFocusState(); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5990 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5991 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5992 | void RenderViewImpl::PpapiPluginFocusChanged() { |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 5993 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5994 | UpdateSelectionBounds(); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5995 | } |
| 5996 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5997 | void RenderViewImpl::PpapiPluginTextInputTypeChanged() { |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 5998 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 5999 | if (renderer_accessibility_) |
| 6000 | renderer_accessibility_->FocusedNodeChanged(WebNode()); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6001 | } |
| 6002 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6003 | void RenderViewImpl::PpapiPluginCaretPositionChanged() { |
| 6004 | UpdateSelectionBounds(); |
| 6005 | } |
| 6006 | |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 6007 | bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6008 | if (!pepper_helper_->IsPluginFocused()) |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 6009 | return false; |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6010 | *rect = pepper_helper_->GetCaretBounds(); |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 6011 | return true; |
| 6012 | } |
| 6013 | |
[email protected] | 397c2396 | 2012-05-21 07:09:32 | [diff] [blame] | 6014 | void RenderViewImpl::SimulateImeSetComposition( |
| 6015 | const string16& text, |
| 6016 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 6017 | int selection_start, |
| 6018 | int selection_end) { |
| 6019 | OnImeSetComposition(text, underlines, selection_start, selection_end); |
| 6020 | } |
| 6021 | |
| 6022 | void RenderViewImpl::SimulateImeConfirmComposition( |
| 6023 | const string16& text, |
| 6024 | const ui::Range& replacement_range) { |
| 6025 | OnImeConfirmComposition(text, replacement_range); |
| 6026 | } |
| 6027 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6028 | void RenderViewImpl::PpapiPluginCancelComposition() { |
| 6029 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 6030 | const ui::Range range(ui::Range::InvalidRange()); |
| 6031 | const std::vector<gfx::Rect> empty_bounds; |
| 6032 | UpdateCompositionInfo(range, empty_bounds); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6033 | } |
| 6034 | |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 6035 | void RenderViewImpl::PpapiPluginSelectionChanged() { |
| 6036 | SyncSelectionIfRequired(); |
| 6037 | } |
| 6038 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6039 | void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) { |
[email protected] | 236bf85 | 2012-07-27 22:49:36 | [diff] [blame] | 6040 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 6041 | DidCreatePepperPlugin(host)); |
| 6042 | } |
| 6043 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6044 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6045 | const string16& text, |
| 6046 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 6047 | int selection_start, |
| 6048 | int selection_end) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6049 | if (pepper_helper_->IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6050 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6051 | pepper_helper_->OnImeSetComposition(text, |
| 6052 | underlines, |
| 6053 | selection_start, |
| 6054 | selection_end); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6055 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 6056 | #if defined(OS_WIN) |
| 6057 | // When a plug-in has focus, we create platform-specific IME data used by |
| 6058 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 6059 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 6060 | // instance ID is the same one as the specified ID.) |
| 6061 | if (focused_plugin_id_ >= 0) { |
| 6062 | std::vector<int> clauses; |
| 6063 | std::vector<int> target; |
| 6064 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 6065 | clauses.push_back(underlines[i].startOffset); |
| 6066 | clauses.push_back(underlines[i].endOffset); |
| 6067 | if (underlines[i].thick) { |
| 6068 | target.clear(); |
| 6069 | target.push_back(underlines[i].startOffset); |
| 6070 | target.push_back(underlines[i].endOffset); |
| 6071 | } |
| 6072 | } |
| 6073 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 6074 | for (it = plugin_delegates_.begin(); |
| 6075 | it != plugin_delegates_.end(); ++it) { |
| 6076 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 6077 | focused_plugin_id_); |
| 6078 | } |
| 6079 | return; |
| 6080 | } |
| 6081 | #endif |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6082 | RenderWidget::OnImeSetComposition(text, |
| 6083 | underlines, |
| 6084 | selection_start, |
| 6085 | selection_end); |
| 6086 | } |
| 6087 | } |
| 6088 | |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 6089 | void RenderViewImpl::OnImeConfirmComposition( |
| 6090 | const string16& text, const ui::Range& replacement_range) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6091 | if (pepper_helper_->IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6092 | // When a PPAPI plugin has focus, we bypass WebKit. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6093 | pepper_helper_->OnImeConfirmComposition(text); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6094 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 6095 | #if defined(OS_WIN) |
| 6096 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 6097 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 6098 | // it to WebKit to prevent WebKit from controlling IMEs. |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 6099 | // TODO(thakis): Honor |replacement_range| for plugins? |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 6100 | if (focused_plugin_id_ >= 0) { |
| 6101 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 6102 | for (it = plugin_delegates_.begin(); |
| 6103 | it != plugin_delegates_.end(); ++it) { |
| 6104 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 6105 | } |
| 6106 | return; |
| 6107 | } |
| 6108 | #endif |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 6109 | if (replacement_range.IsValid() && webview()) { |
| 6110 | // Select the text in |replacement_range|, it will then be replaced by |
| 6111 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 6112 | if (WebFrame* frame = webview()->focusedFrame()) { |
[email protected] | 4bacb82 | 2011-11-02 15:10:16 | [diff] [blame] | 6113 | WebRange webrange = WebRange::fromDocumentRange( |
| 6114 | frame, replacement_range.start(), replacement_range.length()); |
| 6115 | if (!webrange.isNull()) |
[email protected] | 884f900 | 2012-08-21 19:33:58 | [diff] [blame] | 6116 | frame->selectRange(webrange); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 6117 | } |
| 6118 | } |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 6119 | RenderWidget::OnImeConfirmComposition(text, replacement_range); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6120 | } |
| 6121 | } |
| 6122 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 6123 | void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 6124 | RenderWidget::SetDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 6125 | if (webview()) { |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 6126 | webview()->setDeviceScaleFactor(device_scale_factor); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 6127 | webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled( |
| 6128 | ShouldUseFixedPositionCompositing(device_scale_factor_)); |
[email protected] | d8221b2 | 2013-05-23 05:35:43 | [diff] [blame] | 6129 | webview()->settings()->setAcceleratedCompositingForTransitionEnabled( |
| 6130 | ShouldUseTransitionCompositing(device_scale_factor_)); |
[email protected] | fb85419 | 2013-02-06 01:30:04 | [diff] [blame] | 6131 | } |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6132 | if (auto_resize_mode_) |
| 6133 | AutoResizeCompositor(); |
[email protected] | caaf248 | 2013-05-01 20:33:32 | [diff] [blame] | 6134 | |
| 6135 | if (browser_plugin_manager_) |
| 6136 | browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_); |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 6137 | } |
| 6138 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6139 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6140 | return pepper_helper_->IsPluginFocused() ? |
| 6141 | pepper_helper_->GetTextInputType() : RenderWidget::GetTextInputType(); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 6142 | } |
| 6143 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6144 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6145 | if (pepper_helper_->IsPluginFocused()) { |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6146 | // TODO(kinaba) http://crbug.com/101101 |
| 6147 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 6148 | // use the caret position as an empty range for now. It will be updated |
| 6149 | // after Pepper API equips features related to surrounding text retrieval. |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6150 | gfx::Rect caret = pepper_helper_->GetCaretBounds(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 6151 | *start = caret; |
| 6152 | *end = caret; |
| 6153 | return; |
| 6154 | } |
| 6155 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 6156 | } |
| 6157 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 6158 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 6159 | std::vector<gfx::Rect>* bounds) { |
| 6160 | DCHECK(bounds); |
| 6161 | bounds->clear(); |
| 6162 | |
| 6163 | if (!webview()) |
| 6164 | return; |
| 6165 | size_t start_offset = 0; |
| 6166 | size_t character_count = 0; |
| 6167 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 6168 | return; |
| 6169 | if (character_count == 0) |
| 6170 | return; |
| 6171 | |
| 6172 | WebKit::WebFrame* frame = webview()->focusedFrame(); |
| 6173 | if (!frame) |
| 6174 | return; |
| 6175 | |
| 6176 | bounds->reserve(character_count); |
| 6177 | WebKit::WebRect webrect; |
| 6178 | for (size_t i = 0; i < character_count; ++i) { |
| 6179 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 6180 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 6181 | bounds->clear(); |
| 6182 | return; |
| 6183 | } |
| 6184 | bounds->push_back(webrect); |
| 6185 | } |
| 6186 | } |
| 6187 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6188 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6189 | return pepper_helper_->IsPluginFocused() ? |
| 6190 | pepper_helper_->CanComposeInline() : true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 6191 | } |
| 6192 | |
[email protected] | 35134e1 | 2013-02-22 20:07:40 | [diff] [blame] | 6193 | void RenderViewImpl::InstrumentWillBeginFrame() { |
| 6194 | if (!webview()) |
| 6195 | return; |
| 6196 | if (!webview()->devToolsAgent()) |
| 6197 | return; |
| 6198 | webview()->devToolsAgent()->didBeginFrame(); |
| 6199 | } |
| 6200 | |
| 6201 | void RenderViewImpl::InstrumentDidBeginFrame() { |
| 6202 | if (!webview()) |
| 6203 | return; |
| 6204 | if (!webview()->devToolsAgent()) |
| 6205 | return; |
| 6206 | // TODO(jamesr/caseq): Decide if this needs to be renamed. |
| 6207 | webview()->devToolsAgent()->didComposite(); |
| 6208 | } |
| 6209 | |
| 6210 | void RenderViewImpl::InstrumentDidCancelFrame() { |
| 6211 | if (!webview()) |
| 6212 | return; |
| 6213 | if (!webview()->devToolsAgent()) |
| 6214 | return; |
| 6215 | webview()->devToolsAgent()->didCancelFrame(); |
| 6216 | } |
| 6217 | |
| 6218 | void RenderViewImpl::InstrumentWillComposite() { |
| 6219 | if (!webview()) |
| 6220 | return; |
| 6221 | if (!webview()->devToolsAgent()) |
| 6222 | return; |
| 6223 | webview()->devToolsAgent()->willComposite(); |
| 6224 | } |
| 6225 | |
[email protected] | 34bb3ac | 2013-03-08 02:41:28 | [diff] [blame] | 6226 | bool RenderViewImpl::AllowPartialSwap() const { |
| 6227 | return allow_partial_swap_; |
| 6228 | } |
| 6229 | |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 6230 | #if defined(OS_WIN) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6231 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 6232 | if (focused) |
| 6233 | focused_plugin_id_ = plugin_id; |
| 6234 | else |
| 6235 | focused_plugin_id_ = -1; |
| 6236 | } |
| 6237 | #endif |
| 6238 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 6239 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6240 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 6241 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 6242 | } |
| 6243 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6244 | void RenderViewImpl::StartPluginIme() { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 6245 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 6246 | // This message can be sent during event-handling, and needs to be delivered |
| 6247 | // within that context. |
| 6248 | msg->set_unblock(true); |
| 6249 | Send(msg); |
| 6250 | } |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 6251 | #endif // defined(OS_MACOSX) |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 6252 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6253 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6254 | const FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 6255 | WebFileChooserCompletion* completion) { |
| 6256 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 6257 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 6258 | // This sanity check prevents too many file choose requests from getting |
| 6259 | // queued which could DoS the user. Getting these is most likely a |
| 6260 | // programming error (there are many ways to DoS the user so it's not |
| 6261 | // considered a "real" security check), either in JS requesting many file |
| 6262 | // choosers to pop up, or in a plugin. |
| 6263 | // |
| 6264 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 6265 | // a file picker, which will address this issue in a better way. |
| 6266 | return false; |
| 6267 | } |
| 6268 | |
| 6269 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 6270 | new PendingFileChooser(params, completion))); |
| 6271 | if (file_chooser_completions_.size() == 1) { |
| 6272 | // Actually show the browse dialog when this is the first request. |
| 6273 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 6274 | } |
| 6275 | return true; |
| 6276 | } |
| 6277 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6278 | WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6279 | if (!geolocation_dispatcher_) |
| 6280 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 6281 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 6282 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6283 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6284 | WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6285 | WebKit::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6286 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6287 | if (!input_tag_speech_dispatcher_) |
| 6288 | input_tag_speech_dispatcher_ = |
| 6289 | new InputTagSpeechDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6290 | #endif |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6291 | return input_tag_speech_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6292 | } |
| 6293 | |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6294 | WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6295 | if (!speech_recognition_dispatcher_) |
| 6296 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6297 | return speech_recognition_dispatcher_; |
| 6298 | } |
| 6299 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6300 | WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6301 | if (!device_orientation_dispatcher_) |
| 6302 | device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this); |
| 6303 | return device_orientation_dispatcher_; |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 6304 | } |
| 6305 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6306 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 6307 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6308 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 6309 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 6310 | // different). |
| 6311 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 6312 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6313 | int minimum_percent = static_cast<int>( |
| 6314 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 6315 | int maximum_percent = static_cast<int>( |
| 6316 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6317 | |
| 6318 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 6319 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 6320 | } |
| 6321 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6322 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6323 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6324 | float zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 6325 | |
| 6326 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged()); |
| 6327 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6328 | // Tell the browser which url got zoomed so it can update the menu and the |
| 6329 | // saved values if necessary |
| 6330 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6331 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 6332 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6333 | } |
| 6334 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6335 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 6336 | const WebString& base_url, |
| 6337 | const WebString& url, |
| 6338 | const WebString& title) { |
[email protected] | af15bf2 | 2013-03-08 01:18:17 | [diff] [blame] | 6339 | bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture(); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6340 | GURL base(base_url); |
| 6341 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 6342 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 6343 | return; |
| 6344 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 6345 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 6346 | UTF16ToUTF8(scheme), |
| 6347 | absolute_url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6348 | title, |
| 6349 | user_gesture)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6350 | } |
| 6351 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6352 | WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6353 | WebKit::WebPageVisibilityState current_state = is_hidden() ? |
| 6354 | WebKit::WebPageVisibilityStateHidden : |
| 6355 | WebKit::WebPageVisibilityStateVisible; |
| 6356 | WebKit::WebPageVisibilityState override_state = current_state; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6357 | if (GetContentClient()->renderer()-> |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6358 | ShouldOverridePageVisibilityState(this, |
| 6359 | &override_state)) |
| 6360 | return override_state; |
| 6361 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 6362 | } |
| 6363 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6364 | WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6365 | EnsureMediaStreamImpl(); |
| 6366 | return media_stream_impl_; |
| 6367 | } |
| 6368 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 6369 | void RenderViewImpl::draggableRegionsChanged() { |
| 6370 | FOR_EACH_OBSERVER( |
| 6371 | RenderViewObserver, |
| 6372 | observers_, |
| 6373 | DraggableRegionsChanged(webview()->mainFrame())); |
| 6374 | } |
| 6375 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6376 | #if defined(OS_ANDROID) |
| 6377 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 6378 | const WebHitTestResult& touch_hit) { |
| 6379 | DCHECK(!touch_hit.isNull()); |
| 6380 | DCHECK(!touch_hit.node().isNull()); |
| 6381 | DCHECK(touch_hit.node().isTextNode()); |
| 6382 | |
| 6383 | // Process the position with all the registered content detectors until |
| 6384 | // a match is found. Priority is provided by their relative order. |
| 6385 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 6386 | it != content_detectors_.end(); ++it) { |
| 6387 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 6388 | if (content.valid) { |
| 6389 | return WebContentDetectionResult(content.content_boundaries, |
| 6390 | UTF8ToUTF16(content.text), content.intent_url); |
| 6391 | } |
| 6392 | } |
| 6393 | return WebContentDetectionResult(); |
| 6394 | } |
| 6395 | |
| 6396 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 6397 | // Introduce a short delay so that the user can notice the content. |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6398 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6399 | FROM_HERE, |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 6400 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, |
| 6401 | AsWeakPtr(), |
| 6402 | intent, |
| 6403 | expected_content_intent_id_), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6404 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 6405 | } |
| 6406 | |
| 6407 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 6408 | ++expected_content_intent_id_; |
| 6409 | } |
| 6410 | |
| 6411 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 6412 | size_t request_id) { |
| 6413 | if (request_id != expected_content_intent_id_) |
| 6414 | return; |
| 6415 | |
| 6416 | // Remove the content highlighting if any. |
| 6417 | scheduleComposite(); |
| 6418 | |
| 6419 | if (!intent.is_empty()) |
| 6420 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 6421 | } |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 6422 | |
| 6423 | bool RenderViewImpl::openDateTimeChooser( |
| 6424 | const WebKit::WebDateTimeChooserParams& params, |
| 6425 | WebKit::WebDateTimeChooserCompletion* completion) { |
| 6426 | date_time_picker_client_.reset( |
| 6427 | new RendererDateTimePicker(this, params, completion)); |
| 6428 | return date_time_picker_client_->Open(); |
| 6429 | } |
| 6430 | |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6431 | #endif // defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6432 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6433 | void RenderViewImpl::OnAsyncFileOpened( |
| 6434 | base::PlatformFileError error_code, |
| 6435 | IPC::PlatformFileForTransit file_for_transit, |
| 6436 | int message_id) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6437 | pepper_helper_->OnAsyncFileOpened( |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 6438 | error_code, |
| 6439 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 6440 | message_id); |
| 6441 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6442 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6443 | void RenderViewImpl::OnPpapiBrokerChannelCreated( |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6444 | int request_id, |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 6445 | base::ProcessId broker_pid, |
[email protected] | d5430507 | 2011-06-22 20:58:43 | [diff] [blame] | 6446 | const IPC::ChannelHandle& handle) { |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 6447 | pepper_helper_->OnPpapiBrokerChannelCreated(request_id, broker_pid, handle); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 6448 | } |
| 6449 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 6450 | void RenderViewImpl::OnPpapiBrokerPermissionResult( |
| 6451 | int request_id, |
| 6452 | bool result) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 6453 | pepper_helper_->OnPpapiBrokerPermissionResult(request_id, result); |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 6454 | } |
| 6455 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6456 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6457 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 6458 | if (external_popup_menu_ == NULL) { |
| 6459 | // Crash reports from the field indicate that we can be notified with a |
| 6460 | // NULL external popup menu (we probably get notified twice). |
| 6461 | // If you hit this please file a bug against jcivelli and include the page |
| 6462 | // and steps to repro. |
| 6463 | NOTREACHED(); |
| 6464 | return; |
| 6465 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6466 | external_popup_menu_->DidSelectItem(selected_index); |
| 6467 | external_popup_menu_.reset(); |
| 6468 | } |
| 6469 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 6470 | |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6471 | #if defined(OS_ANDROID) |
| 6472 | void RenderViewImpl::OnSelectPopupMenuItems( |
| 6473 | bool canceled, |
| 6474 | const std::vector<int>& selected_indices) { |
| 6475 | // It is possible to receive more than one of these calls if the user presses |
| 6476 | // a select faster than it takes for the show-select-popup IPC message to make |
| 6477 | // it to the browser UI thread. Ignore the extra-messages. |
| 6478 | // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 6479 | if (!external_popup_menu_) |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6480 | return; |
| 6481 | |
| 6482 | external_popup_menu_->DidSelectItems(canceled, selected_indices); |
| 6483 | external_popup_menu_.reset(); |
| 6484 | } |
| 6485 | #endif |
| 6486 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6487 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6488 | const CustomContextMenuContext& custom_context) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6489 | if (custom_context.request_id) { |
| 6490 | // External request, should be in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6491 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6492 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 6493 | if (client) { |
| 6494 | client->OnMenuClosed(custom_context.request_id); |
| 6495 | pending_context_menus_.Remove(custom_context.request_id); |
| 6496 | } |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6497 | } else { |
| 6498 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 6499 | context_menu_node_.reset(); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6500 | } |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 6501 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6502 | |
[email protected] | 4782226 | 2013-04-23 17:22:36 | [diff] [blame] | 6503 | void RenderViewImpl::OnShowContextMenu() { |
| 6504 | if (webview()) |
| 6505 | webview()->showContextMenu(); |
| 6506 | } |
| 6507 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6508 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6509 | if (!webview()) |
| 6510 | return; |
| 6511 | WebFrame* main_frame = webview()->mainFrame(); |
| 6512 | if (!main_frame) |
| 6513 | return; |
| 6514 | main_frame->enableViewSourceMode(true); |
| 6515 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 6516 | |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 6517 | #if defined(ENABLE_JAVA_BRIDGE) |
[email protected] | 64d0e19 | 2011-12-09 14:44:20 | [diff] [blame] | 6518 | void RenderViewImpl::OnJavaBridgeInit() { |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6519 | DCHECK(!java_bridge_dispatcher_); |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6520 | java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 6521 | } |
[email protected] | da81627 | 2013-05-15 21:31:17 | [diff] [blame] | 6522 | #endif |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 6523 | |
[email protected] | 7cc7890 | 2012-12-06 02:32:26 | [diff] [blame] | 6524 | void RenderViewImpl::OnDisownOpener() { |
| 6525 | if (!webview()) |
| 6526 | return; |
| 6527 | |
| 6528 | WebFrame* main_frame = webview()->mainFrame(); |
| 6529 | if (main_frame && main_frame->opener()) |
| 6530 | main_frame->setOpener(NULL); |
| 6531 | } |
| 6532 | |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6533 | #if defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6534 | bool RenderViewImpl::didTapMultipleTargets( |
| 6535 | const WebKit::WebGestureEvent& event, |
| 6536 | const WebVector<WebRect>& target_rects) { |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6537 | gfx::Rect finger_rect( |
| 6538 | event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2, |
| 6539 | event.data.tap.width, event.data.tap.height); |
| 6540 | gfx::Rect zoom_rect; |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6541 | float new_total_scale = |
| 6542 | DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
| 6543 | finger_rect, target_rects, GetSize(), |
| 6544 | gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(), |
| 6545 | device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect); |
| 6546 | if (!new_total_scale) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6547 | return false; |
| 6548 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6549 | gfx::Size canvas_size = gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), |
| 6550 | new_total_scale)); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6551 | TransportDIB* transport_dib = NULL; |
| 6552 | { |
| 6553 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 6554 | RenderProcess::current()->GetDrawingCanvas(&transport_dib, |
| 6555 | gfx::Rect(canvas_size))); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 6556 | if (!canvas) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6557 | return false; |
| 6558 | |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6559 | // TODO(trchen): Cleanup the device scale factor mess. |
| 6560 | // device scale will be applied in WebKit |
| 6561 | // --> zoom_rect doesn't include device scale, |
| 6562 | // but WebKit will still draw on zoom_rect * device_scale_factor_ |
| 6563 | canvas->scale(new_total_scale / device_scale_factor_, |
| 6564 | new_total_scale / device_scale_factor_); |
| 6565 | canvas->translate(-zoom_rect.x() * device_scale_factor_, |
| 6566 | -zoom_rect.y() * device_scale_factor_); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6567 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6568 | webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect, |
| 6569 | WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent); |
| 6570 | } |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6571 | |
| 6572 | gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect( |
| 6573 | ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect))); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6574 | Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_, |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 6575 | physical_window_zoom_rect, |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6576 | canvas_size, |
| 6577 | transport_dib->id())); |
| 6578 | |
| 6579 | return true; |
| 6580 | } |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 6581 | |
| 6582 | skia::RefPtr<SkPicture> RenderViewImpl::CapturePicture() { |
[email protected] | 635353c | 2013-03-06 09:11:20 | [diff] [blame] | 6583 | return compositor_ ? compositor_->CapturePicture() : |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 6584 | skia::RefPtr<SkPicture>(); |
| 6585 | } |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6586 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6587 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 6588 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 6589 | return history_list_length_; |
| 6590 | } |
| 6591 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 6592 | void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) { |
| 6593 | if (enable) { |
| 6594 | if (has_focus()) |
| 6595 | return; |
| 6596 | OnSetActive(true); |
| 6597 | OnSetFocus(true); |
| 6598 | } else { |
| 6599 | if (!has_focus()) |
| 6600 | return; |
| 6601 | OnSetFocus(false); |
| 6602 | OnSetActive(false); |
| 6603 | } |
| 6604 | } |
| 6605 | |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 6606 | void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) { |
| 6607 | SetDeviceScaleFactor(factor); |
| 6608 | if (!auto_resize_mode_) |
| 6609 | AutoResizeCompositor(); |
| 6610 | } |
| 6611 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 6612 | void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size, |
| 6613 | const gfx::Size& max_size) { |
| 6614 | OnEnableAutoResize(min_size, max_size); |
| 6615 | } |
| 6616 | |
| 6617 | void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) { |
| 6618 | OnDisableAutoResize(new_size); |
| 6619 | } |
| 6620 | |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6621 | void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
| 6622 | TransportDIB::Handle dib_handle) { |
| 6623 | TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| 6624 | RenderProcess::current()->ReleaseTransportDIB(dib); |
| 6625 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6626 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 6627 | void RenderViewImpl::DidCommitCompositorFrame() { |
| 6628 | RenderWidget::DidCommitCompositorFrame(); |
| 6629 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); |
| 6630 | } |
| 6631 | |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 6632 | void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) { |
| 6633 | if (!urls.empty()) |
| 6634 | Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls)); |
| 6635 | } |
| 6636 | |
| 6637 | void RenderViewImpl::DidStopLoadingIcons() { |
| 6638 | int icon_types = WebIconURL::TypeFavicon; |
| 6639 | if (TouchEnabled()) |
| 6640 | icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 6641 | |
| 6642 | WebVector<WebIconURL> icon_urls = |
| 6643 | webview()->mainFrame()->iconURLs(icon_types); |
| 6644 | |
| 6645 | std::vector<FaviconURL> urls; |
| 6646 | for (size_t i = 0; i < icon_urls.size(); i++) { |
| 6647 | WebURL url = icon_urls[i].iconURL(); |
| 6648 | if (!url.isEmpty()) |
| 6649 | urls.push_back(FaviconURL(url, |
| 6650 | ToFaviconType(icon_urls[i].iconType()))); |
| 6651 | } |
| 6652 | SendUpdateFaviconURL(urls); |
| 6653 | } |
| 6654 | |
| 6655 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6656 | } // namespace content |