[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] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 10 | #include "base/bind.h" |
| 11 | #include "base/bind_helpers.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | e7ca289 | 2012-09-01 00:52:15 | [diff] [blame] | 14 | #include "base/debug/trace_event.h" |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 15 | #include "base/json/json_reader.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" |
[email protected] | 0a35efc | 2012-03-13 17:28:13 | [diff] [blame] | 24 | #include "base/string_piece.h" |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 25 | #include "base/string_split.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | #include "base/string_util.h" |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 27 | #include "base/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] | 65bfd997 | 2012-10-19 03:39:37 | [diff] [blame] | 30 | #include "cc/switches.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 31 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 32 | #include "content/common/child_thread.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 33 | #include "content/common/clipboard_messages.h" |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 34 | #include "content/common/content_constants_internal.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 35 | #include "content/common/database_messages.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 36 | #include "content/common/drag_messages.h" |
[email protected] | 16dd6e2 | 2012-03-01 19:08:20 | [diff] [blame] | 37 | #include "content/common/fileapi/file_system_dispatcher.h" |
| 38 | #include "content/common/fileapi/webfilesystem_callback_dispatcher.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 39 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 40 | #include "content/common/intents_messages.h" |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 41 | #include "content/common/java_bridge_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 42 | #include "content/common/pepper_messages.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 43 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 44 | #include "content/common/quota_dispatcher.h" |
[email protected] | 940895b | 2011-08-20 00:50:05 | [diff] [blame] | 45 | #include "content/common/request_extra_data.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 46 | #include "content/common/socket_stream_handle_data.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 47 | #include "content/common/view_messages.h" |
[email protected] | 4e1eb339 | 2012-05-18 00:08:05 | [diff] [blame] | 48 | #include "content/common/webmessageportchannel_impl.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 49 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 50 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 51 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 52 | #include "content/public/common/content_switches.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 53 | #include "content/public/common/context_menu_params.h" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 54 | #include "content/public/common/file_chooser_params.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 55 | #include "content/public/common/url_constants.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 56 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 57 | #include "content/public/renderer/document_state.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 58 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 59 | #include "content/public/renderer/password_form_conversion_utils.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 60 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 61 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 62 | #include "content/renderer/browser_plugin/browser_plugin.h" |
| 63 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 64 | #include "content/renderer/device_orientation_dispatcher.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 65 | #include "content/renderer/devtools_agent.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 66 | #include "content/renderer/disambiguation_popup_helper.h" |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 67 | #include "content/renderer/dom_automation_controller.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 68 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 69 | #include "content/renderer/do_not_track_bindings.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 70 | #include "content/renderer/external_popup_menu.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 71 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 72 | #include "content/renderer/gpu/compositor_thread.h" |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 73 | #include "content/renderer/gpu/compositor_output_surface.h" |
[email protected] | 7d4481d1 | 2012-09-24 21:26:47 | [diff] [blame] | 74 | #include "content/renderer/gpu/compositor_software_output_device_gl_adapter.h" |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 75 | #include "content/renderer/idle_user_detector.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 76 | #include "content/renderer/input_tag_speech_dispatcher.h" |
[email protected] | 0716190 | 2011-11-11 09:57:42 | [diff] [blame] | 77 | #include "content/renderer/java/java_bridge_dispatcher.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 78 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 79 | #include "content/renderer/media/media_stream_dependency_factory.h" |
| 80 | #include "content/renderer/media/media_stream_dispatcher.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 81 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 6048d51 | 2012-01-28 03:14:48 | [diff] [blame] | 82 | #include "content/renderer/media/render_audiosourceprovider.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 83 | #include "content/renderer/media/render_media_log.h" |
[email protected] | 6048d51 | 2012-01-28 03:14:48 | [diff] [blame] | 84 | #include "content/renderer/media/renderer_gpu_video_decoder_factories.h" |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 85 | #include "content/renderer/media/rtc_peer_connection_handler.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 86 | #include "content/renderer/mhtml_generator.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 87 | #include "content/renderer/notification_provider.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 88 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 89 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 90 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 91 | #include "content/renderer/render_view_impl_params.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 92 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 93 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 94 | #include "content/renderer/renderer_accessibility.h" |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 95 | #include "content/renderer/renderer_accessibility_complete.h" |
| 96 | #include "content/renderer/renderer_accessibility_focus_only.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 97 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 98 | #include "content/renderer/renderer_webcolorchooser_impl.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 99 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 100 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 101 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 0a35efc | 2012-03-13 17:28:13 | [diff] [blame] | 102 | #include "content/renderer/web_intents_host.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 103 | #include "content/renderer/web_ui_bindings.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 104 | #include "content/renderer/webplugin_delegate_proxy.h" |
| 105 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 106 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 107 | #include "media/base/media_switches.h" |
[email protected] | b8032290 | 2012-03-06 01:33:50 | [diff] [blame] | 108 | #include "media/base/message_loop_factory.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 109 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 110 | #include "media/filters/gpu_video_decoder.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 111 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | #include "net/base/escape.h" |
| 113 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 114 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 115 | #include "net/http/http_util.h" |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 116 | #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 117 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | 97516a0 | 2012-10-23 18:19:25 | [diff] [blame] | 118 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h" |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 119 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h" |
| 120 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 121 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 122 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 123 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 124 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 125 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 126 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" |
| 127 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" |
| 128 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 129 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 130 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 131 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 132 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 133 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 134 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h" |
[email protected] | 592e20b | 2012-01-20 05:53:44 | [diff] [blame] | 135 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 136 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h" |
[email protected] | 69f110d6 | 2011-03-17 19:01:14 | [diff] [blame] | 137 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h" |
[email protected] | 4e1eb339 | 2012-05-18 00:08:05 | [diff] [blame] | 138 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 139 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 140 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 141 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 142 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 143 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 144 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h" |
| 145 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 146 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 147 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 148 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h" |
| 149 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 150 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 151 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 152 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 153 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 154 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 155 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
| 156 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" |
| 157 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h" |
| 158 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h" |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 159 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 160 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" |
| 161 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" |
| 162 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 163 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 164 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 165 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h" |
[email protected] | e6e90dc | 2011-12-03 00:01:37 | [diff] [blame] | 166 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 167 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 168 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h" |
| 169 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" |
| 170 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h" |
| 171 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 172 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 173 | #include "ui/base/dialogs/selected_file_info.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 174 | #include "ui/gfx/native_widget_types.h" |
| 175 | #include "ui/gfx/point.h" |
| 176 | #include "ui/gfx/rect.h" |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 177 | #include "ui/gfx/size_conversions.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 178 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 179 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 180 | #include "webkit/base/file_path_string_conversions.h" |
[email protected] | b928936b | 2012-04-13 01:16:16 | [diff] [blame] | 181 | #include "webkit/dom_storage/dom_storage_types.h" |
[email protected] | 25e18f8 | 2010-10-27 16:38:43 | [diff] [blame] | 182 | #include "webkit/glue/alt_error_page_resource_fetcher.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 183 | #include "webkit/glue/dom_operations.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 184 | #include "webkit/glue/glue_serialize.h" |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 185 | #include "webkit/glue/web_intent_service_data.h" |
[email protected] | 851334d | 2012-06-15 22:39:31 | [diff] [blame] | 186 | #include "webkit/glue/webdropdata.h" |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 187 | #include "webkit/glue/webkit_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 188 | #include "webkit/glue/webkit_glue.h" |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 189 | #include "webkit/glue/weburlresponse_extradata_impl.h" |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 190 | #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
[email protected] | a9288f5 | 2011-11-17 05:18:16 | [diff] [blame] | 191 | #include "webkit/media/webmediaplayer_impl.h" |
[email protected] | 5f04c353 | 2012-09-25 01:28:39 | [diff] [blame] | 192 | #include "webkit/media/webmediaplayer_ms.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 193 | #include "webkit/plugins/npapi/plugin_list.h" |
| 194 | #include "webkit/plugins/npapi/webplugin_delegate.h" |
| 195 | #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
| 196 | #include "webkit/plugins/npapi/webplugin_impl.h" |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 197 | #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 198 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 199 | #if defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 200 | #include "content/common/android/device_info.h" |
| 201 | #include "content/renderer/android/address_detector.h" |
| 202 | #include "content/renderer/android/content_detector.h" |
| 203 | #include "content/renderer/android/email_detector.h" |
| 204 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | dbd3d21 | 2012-07-13 02:17:22 | [diff] [blame] | 205 | #include "content/renderer/media/stream_texture_factory_impl_android.h" |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 206 | #include "content/renderer/media/webmediaplayer_proxy_impl_android.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 207 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 208 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h" |
| 209 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h" |
| 210 | #include "ui/gfx/rect_f.h" |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 211 | #include "webkit/media/android/media_player_bridge_manager_impl.h" |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 212 | #include "webkit/media/android/webmediaplayer_android.h" |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 213 | #include "webkit/media/android/webmediaplayer_impl_android.h" |
| 214 | #include "webkit/media/android/webmediaplayer_in_process_android.h" |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 215 | #include "webkit/media/android/webmediaplayer_manager_android.h" |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 216 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 217 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 218 | // * theming |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 219 | #include "ui/base/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 220 | #elif defined(USE_X11) |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 221 | #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 222 | #include "ui/base/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 223 | #elif defined(OS_MACOSX) |
| 224 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 225 | #endif |
| 226 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 227 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 228 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 229 | using WebKit::WebApplicationCacheHost; |
| 230 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 231 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 232 | using WebKit::WebColor; |
| 233 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 234 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 235 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 236 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 237 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 238 | using WebKit::WebDataSource; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 239 | using WebKit::WebDocument; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 240 | using WebKit::WebDOMEvent; |
| 241 | using WebKit::WebDOMMessageEvent; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 242 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 243 | using WebKit::WebDragOperation; |
| 244 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 245 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 246 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 247 | using WebKit::WebExternalPopupMenu; |
| 248 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 249 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 250 | using WebKit::WebFileSystem; |
| 251 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 252 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 253 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 254 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 255 | using WebKit::WebFrame; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 256 | using WebKit::WebGestureEvent; |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 257 | using WebKit::WebGraphicsContext3D; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 258 | using WebKit::WebHistoryItem; |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 259 | using WebKit::WebHTTPBody; |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 260 | using WebKit::WebIconURL; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 261 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 262 | using WebKit::WebInputElement; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 263 | using WebKit::WebInputEvent; |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 264 | using WebKit::WebIntentRequest; |
| 265 | using WebKit::WebIntentServiceInfo; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 266 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 267 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 268 | using WebKit::WebMediaPlayerClient; |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 269 | using WebKit::WebMouseEvent; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 270 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 271 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 272 | using WebKit::WebNode; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 273 | using WebKit::WebPageSerializer; |
| 274 | using WebKit::WebPageSerializerClient; |
[email protected] | 50da23d0 | 2012-04-13 17:47:48 | [diff] [blame] | 275 | using WebKit::WebPeerConnection00Handler; |
| 276 | using WebKit::WebPeerConnection00HandlerClient; |
| 277 | using WebKit::WebPeerConnectionHandler; |
| 278 | using WebKit::WebPeerConnectionHandlerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 279 | using WebKit::WebPlugin; |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 280 | using WebKit::WebPluginAction; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 281 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 282 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 283 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 284 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 285 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 286 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 287 | using WebKit::WebRect; |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 288 | using WebKit::WebReferrerPolicy; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 289 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 290 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 291 | using WebKit::WebSecurityOrigin; |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 292 | using WebKit::WebSecurityPolicy; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 293 | using WebKit::WebSerializedScriptValue; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 294 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 295 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 296 | using WebKit::WebSize; |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 297 | using WebKit::WebSocketStreamHandle; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 298 | using WebKit::WebStorageNamespace; |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 299 | using WebKit::WebStorageQuotaCallbacks; |
| 300 | using WebKit::WebStorageQuotaError; |
| 301 | using WebKit::WebStorageQuotaType; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 302 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 303 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 304 | using WebKit::WebTextDirection; |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 305 | using WebKit::WebTouchEvent; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 306 | using WebKit::WebURL; |
| 307 | using WebKit::WebURLError; |
| 308 | using WebKit::WebURLRequest; |
| 309 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 310 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 311 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 312 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 313 | using WebKit::WebWindowFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 314 | using appcache::WebApplicationCacheHostImpl; |
| 315 | using base::Time; |
| 316 | using base::TimeDelta; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 317 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 318 | using webkit_glue::AltErrorPageResourceFetcher; |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 319 | using webkit_glue::ResourceFetcher; |
[email protected] | 6717bf27 | 2012-05-11 23:31:25 | [diff] [blame] | 320 | using webkit_glue::WebPreferences; |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 321 | using webkit_glue::WebURLResponseExtraDataImpl; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 322 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 323 | #if defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 324 | using WebKit::WebContentDetectionResult; |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 325 | using WebKit::WebFloatPoint; |
| 326 | using WebKit::WebFloatRect; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 327 | using WebKit::WebHitTestResult; |
| 328 | #endif |
| 329 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 330 | namespace content { |
| 331 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 332 | //----------------------------------------------------------------------------- |
| 333 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 334 | typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 335 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 336 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 337 | // Time, in seconds, we delay before sending content state changes (such as form |
| 338 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 339 | // spamming the browser. |
| 340 | // To avoid having tab/session restore require sending a message to get the |
| 341 | // current content state during tab closing we use a shorter timeout for the |
| 342 | // foreground renderer. This means there is a small window of time from which |
| 343 | // content state is modified and not sent to session restore, but this is |
| 344 | // better than having to wake up all renderers during shutdown. |
| 345 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 346 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 347 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 348 | static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 349 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 350 | // The maximum number of popups that can be spawned from one page. |
| 351 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 352 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 353 | static const float kScalingIncrement = 0.1f; |
| 354 | |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 355 | static const float kScalingIncrementForGesture = 0.01f; |
| 356 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 357 | #if defined(OS_ANDROID) |
| 358 | // Delay between tapping in content and launching the associated android intent. |
| 359 | // Used to allow users see what has been recognized as content. |
| 360 | static const size_t kContentIntentDelayMilliseconds = 700; |
| 361 | #endif |
| 362 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 363 | static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) = |
| 364 | NULL; |
| 365 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 366 | static RenderViewImpl* FromRoutingID(int32 routing_id) { |
| 367 | return static_cast<RenderViewImpl*>( |
| 368 | ChildThread::current()->ResolveRoute(routing_id)); |
| 369 | } |
| 370 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 371 | static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { |
| 372 | for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) { |
| 373 | if (frame->identifier() == frame_id) |
| 374 | return frame; |
| 375 | } |
| 376 | return NULL; |
| 377 | } |
| 378 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 379 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 380 | // Replace any occurrences of swappedout:// with about:blank. |
| 381 | const WebURL& blank_url = GURL(chrome::kAboutBlankURL); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 382 | WebVector<WebURL> urls; |
| 383 | ds->redirectChain(urls); |
| 384 | result->reserve(urls.size()); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 385 | for (size_t i = 0; i < urls.size(); ++i) { |
| 386 | if (urls[i] != GURL(kSwappedOutURL)) |
| 387 | result->push_back(urls[i]); |
| 388 | else |
| 389 | result->push_back(blank_url); |
| 390 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 391 | } |
| 392 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 393 | // If |data_source| is non-null and has a DocumentState associated with it, |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 394 | // the AltErrorPageResourceFetcher is reset. |
| 395 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 396 | if (data_source) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 397 | DocumentState* document_state = DocumentState::FromDataSource(data_source); |
| 398 | if (document_state) |
| 399 | document_state->set_alt_error_page_fetcher(NULL); |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 403 | static bool IsReload(const ViewMsg_Navigate_Params& params) { |
| 404 | return |
| 405 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 406 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
| 407 | params.navigation_type == |
| 408 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 411 | static WebReferrerPolicy GetReferrerPolicyFromRequest( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 412 | WebFrame* frame, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 413 | const WebURLRequest& request) { |
| 414 | return request.extraData() ? |
| 415 | static_cast<RequestExtraData*>(request.extraData())->referrer_policy() : |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 416 | frame->document().referrerPolicy(); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 417 | } |
| 418 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 419 | static WebURLResponseExtraDataImpl* GetExtraDataFromResponse( |
| 420 | const WebURLResponse& response) { |
| 421 | return static_cast<WebURLResponseExtraDataImpl*>( |
| 422 | response.extraData()); |
| 423 | } |
| 424 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 425 | NOINLINE static void CrashIntentionally() { |
| 426 | // NOTE(shess): Crash directly rather than using NOTREACHED() so |
| 427 | // that the signature is easier to triage in crash reports. |
| 428 | volatile int* zero = NULL; |
| 429 | *zero = 0; |
| 430 | } |
| 431 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 432 | static void MaybeHandleDebugURL(const GURL& url) { |
| 433 | if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 434 | return; |
| 435 | if (url == GURL(chrome::kChromeUICrashURL)) { |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 436 | CrashIntentionally(); |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 437 | } else if (url == GURL(chrome::kChromeUIKillURL)) { |
| 438 | base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
| 439 | } else if (url == GURL(chrome::kChromeUIHangURL)) { |
| 440 | for (;;) { |
| 441 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 442 | } |
[email protected] | 50f86bc | 2012-11-01 19:59:13 | [diff] [blame] | 443 | } else if (url == GURL(kChromeUIShorthangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 444 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 445 | } |
| 446 | } |
| 447 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 448 | // Returns false unless this is a top-level navigation. |
| 449 | static bool IsTopLevelNavigation(WebFrame* frame) { |
| 450 | return frame->parent() == NULL; |
| 451 | } |
| 452 | |
| 453 | // Returns false unless this is a top-level navigation that crosses origins. |
| 454 | static bool IsNonLocalTopLevelNavigation(const GURL& url, |
| 455 | WebFrame* frame, |
| 456 | WebNavigationType type) { |
| 457 | if (!IsTopLevelNavigation(frame)) |
| 458 | return false; |
| 459 | |
| 460 | // Navigations initiated within Webkit are not sent out to the external host |
| 461 | // in the following cases. |
| 462 | // 1. The url scheme is not http/https |
| 463 | // 2. The origin of the url and the opener is the same in which case the |
| 464 | // opener relationship is maintained. |
| 465 | // 3. Reloads/form submits/back forward navigations |
| 466 | if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) |
| 467 | return false; |
| 468 | |
| 469 | // Not interested in reloads/form submits/resubmits/back forward navigations. |
| 470 | if (type != WebKit::WebNavigationTypeReload && |
| 471 | type != WebKit::WebNavigationTypeFormSubmitted && |
| 472 | type != WebKit::WebNavigationTypeFormResubmitted && |
| 473 | type != WebKit::WebNavigationTypeBackForward) { |
| 474 | // The opener relationship between the new window and the parent allows the |
| 475 | // new window to script the parent and vice versa. This is not allowed if |
| 476 | // the origins of the two domains are different. This can be treated as a |
| 477 | // top level navigation and routed back to the host. |
| 478 | WebKit::WebFrame* opener = frame->opener(); |
| 479 | if (!opener) { |
| 480 | return true; |
| 481 | } |
| 482 | |
| 483 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 484 | return true; |
| 485 | } |
| 486 | return false; |
| 487 | } |
| 488 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 489 | static void NotifyTimezoneChange(WebKit::WebFrame* frame) { |
| 490 | v8::HandleScope handle_scope; |
| 491 | v8::Context::Scope context_scope(frame->mainWorldScriptContext()); |
| 492 | v8::Date::DateTimeConfigurationChangeNotification(); |
| 493 | WebKit::WebFrame* child = frame->firstChild(); |
| 494 | for (; child; child = child->nextSibling()) |
| 495 | NotifyTimezoneChange(child); |
| 496 | } |
| 497 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 498 | /////////////////////////////////////////////////////////////////////////////// |
| 499 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 500 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 501 | PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c) |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 502 | : params(p), |
| 503 | completion(c) { |
| 504 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 505 | FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 506 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 507 | }; |
| 508 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 509 | namespace { |
| 510 | |
| 511 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 512 | public: |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 513 | explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 514 | : webwidget_(webwidget) {} |
| 515 | |
| 516 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 517 | if (succeeded) |
| 518 | webwidget_->didAcquirePointerLock(); |
| 519 | else |
| 520 | webwidget_->didNotAcquirePointerLock(); |
| 521 | } |
| 522 | |
| 523 | virtual void OnMouseLockLost() OVERRIDE { |
| 524 | webwidget_->didLosePointerLock(); |
| 525 | } |
| 526 | |
| 527 | virtual bool HandleMouseLockedInputEvent( |
| 528 | const WebKit::WebMouseEvent &event) OVERRIDE { |
| 529 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 530 | return false; |
| 531 | } |
| 532 | |
| 533 | private: |
| 534 | WebKit::WebWidget* webwidget_; |
| 535 | }; |
| 536 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 537 | int64 ExtractPostId(const WebHistoryItem& item) { |
| 538 | if (item.isNull()) |
| 539 | return -1; |
| 540 | |
| 541 | if (item.httpBody().isNull()) |
| 542 | return -1; |
| 543 | |
| 544 | return item.httpBody().identifier(); |
| 545 | } |
| 546 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 547 | } // namespace |
| 548 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 549 | RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) |
| 550 | : RenderWidget(WebKit::WebPopupTypeNone, |
| 551 | params->screen_info, |
| 552 | params->swapped_out), |
| 553 | webkit_preferences_(params->webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 554 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 555 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 556 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 557 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 558 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 559 | opened_by_user_gesture_(true), |
| 560 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 561 | page_id_(-1), |
| 562 | last_page_id_sent_to_browser_(-1), |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 563 | next_page_id_(params->next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 564 | history_list_offset_(-1), |
| 565 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 566 | target_url_status_(TARGET_NONE), |
[email protected] | bbef1d3 | 2011-10-25 14:36:55 | [diff] [blame] | 567 | selection_text_offset_(0), |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 568 | cached_is_main_frame_pinned_to_left_(false), |
| 569 | cached_is_main_frame_pinned_to_right_(false), |
| 570 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 571 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 572 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 573 | geolocation_dispatcher_(NULL), |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 574 | input_tag_speech_dispatcher_(NULL), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 575 | speech_recognition_dispatcher_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 576 | device_orientation_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 577 | media_stream_dispatcher_(NULL), |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 578 | media_stream_impl_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 579 | devtools_agent_(NULL), |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 580 | accessibility_mode_(AccessibilityModeOff), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 581 | renderer_accessibility_(NULL), |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 582 | java_bridge_dispatcher_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 583 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 584 | #if defined(OS_ANDROID) |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 585 | body_background_color_(SK_ColorWHITE), |
[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 586 | update_frame_info_scheduled_(false), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 587 | expected_content_intent_id_(0), |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 588 | media_player_proxy_(NULL), |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 589 | synchronous_find_active_match_ordinal_(-1), |
[email protected] | 8e603cd9 | 2012-10-23 22:29:26 | [diff] [blame] | 590 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 591 | load_progress_tracker_(new LoadProgressTracker(this))), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 592 | #endif |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 593 | session_storage_namespace_id_(params->session_storage_namespace_id), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 594 | handling_select_range_(false), |
| 595 | #if defined(OS_WIN) |
| 596 | focused_plugin_id_(-1), |
| 597 | #endif |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 598 | updating_frame_tree_(false), |
| 599 | pending_frame_tree_update_(false), |
| 600 | target_process_id_(0), |
| 601 | target_routing_id_(0), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 602 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 603 | set_throttle_input_events(params->renderer_prefs.throttle_input_events); |
| 604 | routing_id_ = params->routing_id; |
| 605 | surface_id_ = params->surface_id; |
| 606 | if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created) |
| 607 | opener_id_ = params->opener_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 608 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 609 | // Ensure we start with a valid next_page_id_ from the browser. |
| 610 | DCHECK_GE(next_page_id_, 0); |
| 611 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 612 | #if defined(ENABLE_NOTIFICATIONS) |
| 613 | notification_provider_ = new NotificationProvider(this); |
| 614 | #else |
| 615 | notification_provider_ = NULL; |
| 616 | #endif |
| 617 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 618 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 619 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 620 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 621 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 622 | |
| 623 | #if defined(OS_ANDROID) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 624 | scoped_ptr<DeviceInfo> device_info(new DeviceInfo()); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 625 | |
[email protected] | 43b0600 | 2012-10-11 17:13:26 | [diff] [blame] | 626 | webview()->setDeviceScaleFactor(device_info->GetDPIScale()); |
| 627 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 628 | const std::string region_code = |
| 629 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 630 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
| 631 | : device_info->GetNetworkCountryIso(); |
| 632 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 633 | new AddressDetector())); |
| 634 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 635 | new PhoneNumberDetector(region_code))); |
| 636 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 637 | new EmailDetector())); |
| 638 | #endif |
| 639 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 640 | if (params->counter) { |
| 641 | shared_popup_counter_ = params->counter; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 642 | // Only count this if it isn't swapped out upon creation. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 643 | if (!params->swapped_out) |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 644 | shared_popup_counter_->data++; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 645 | decrement_shared_popup_at_destruction_ = true; |
| 646 | } else { |
| 647 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 648 | decrement_shared_popup_at_destruction_ = false; |
| 649 | } |
| 650 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 651 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 652 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 653 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 654 | AddRef(); |
| 655 | |
| 656 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 657 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 658 | if (opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 659 | did_show_ = true; |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 660 | CompleteInit(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 661 | } |
| 662 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 663 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 664 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 665 | webkit_preferences_.Apply(webview()); |
| 666 | webview()->initializeMainFrame(this); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 667 | if (!params->frame_name.empty()) |
| 668 | webview()->mainFrame()->setName(params->frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 669 | webview()->settings()->setMinimumTimerInterval( |
| 670 | is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : |
| 671 | webkit_glue::kForegroundTabTimerInterval); |
| 672 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 673 | OnSetRendererPrefs(params->renderer_prefs); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 674 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 675 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 676 | if (!media_stream_dispatcher_) |
| 677 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 678 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 679 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 680 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 681 | #if defined(OS_MACOSX) |
| 682 | new TextInputClientObserver(this); |
| 683 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 684 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 685 | #if defined(OS_ANDROID) |
| 686 | media_player_manager_.reset( |
| 687 | new webkit_media::WebMediaPlayerManagerAndroid()); |
| 688 | #endif |
| 689 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 690 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 691 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 692 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 693 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 0fc7dea7 | 2012-02-09 03:47:40 | [diff] [blame] | 694 | intents_host_ = new WebIntentsHost(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 695 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 696 | // Create renderer_accessibility_ if needed. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 697 | OnSetAccessibilityMode(params->accessibility_mode); |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 698 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 699 | new IdleUserDetector(this); |
| 700 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 701 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 702 | enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION; |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 703 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 704 | ProcessViewLayoutFlags(command_line); |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 705 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 706 | GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 707 | |
| 708 | // If we have an opener_id but we weren't created by a renderer, then |
| 709 | // it's the browser asking us to set our opener to another RenderView. |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 710 | if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) { |
| 711 | RenderViewImpl* opener_view = FromRoutingID(params->opener_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 712 | if (opener_view) |
| 713 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 717 | // This ensures we are in a unique origin that others cannot script. |
| 718 | if (is_swapped_out_) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 719 | NavigateToSwappedOutURL(webview()->mainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 720 | } |
| 721 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 722 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 723 | history_page_ids_.clear(); |
| 724 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 725 | if (decrement_shared_popup_at_destruction_) |
| 726 | shared_popup_counter_->data--; |
| 727 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 728 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 729 | while (!file_chooser_completions_.empty()) { |
| 730 | if (file_chooser_completions_.front()->completion) { |
| 731 | file_chooser_completions_.front()->completion->didChooseFile( |
| 732 | WebVector<WebString>()); |
| 733 | } |
| 734 | file_chooser_completions_.pop_front(); |
| 735 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 736 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 737 | #if defined(OS_MACOSX) |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 738 | // Destroy all fake plugin window handles on the browser side. |
| 739 | while (!fake_plugin_window_handles_.empty()) { |
| 740 | // Make sure no NULL plugin window handles were inserted into this list. |
| 741 | DCHECK(*fake_plugin_window_handles_.begin()); |
| 742 | // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
| 743 | DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
| 744 | } |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 745 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 746 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 747 | #ifndef NDEBUG |
| 748 | // Make sure we are no longer referenced by the ViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 749 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 750 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 751 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 752 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 753 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 754 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 755 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 759 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 760 | ViewMap* views = g_view_map.Pointer(); |
| 761 | ViewMap::iterator it = views->find(webview); |
| 762 | return it == views->end() ? NULL : it->second; |
| 763 | } |
| 764 | |
| 765 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 766 | RenderView* RenderView::FromWebView(WebKit::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 767 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 771 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 772 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 773 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 774 | if (!visitor->Visit(it->second)) |
| 775 | return; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 780 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 781 | int32 opener_id, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 782 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 783 | const WebPreferences& webkit_prefs, |
| 784 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 785 | int32 routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 786 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 787 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 788 | const string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 789 | bool is_renderer_created, |
| 790 | bool swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 791 | int32 next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 792 | const WebKit::WebScreenInfo& screen_info, |
[email protected] | 3e3c452 | 2012-04-13 21:16:29 | [diff] [blame] | 793 | AccessibilityMode accessibility_mode) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 794 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 795 | RenderViewImplParams params( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 796 | opener_id, |
| 797 | renderer_prefs, |
| 798 | webkit_prefs, |
| 799 | counter, |
| 800 | routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 801 | surface_id, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 802 | session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 803 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 804 | is_renderer_created, |
| 805 | swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 806 | next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 807 | screen_info, |
[email protected] | 3e3c452 | 2012-04-13 21:16:29 | [diff] [blame] | 808 | accessibility_mode); |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame^] | 809 | if (g_create_render_view_impl) |
| 810 | return g_create_render_view_impl(¶ms); |
| 811 | return new RenderViewImpl(¶ms); |
| 812 | } |
| 813 | |
| 814 | // static |
| 815 | void RenderViewImpl::InstallCreateHook( |
| 816 | RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) { |
| 817 | CHECK(!g_create_render_view_impl); |
| 818 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 819 | } |
| 820 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 821 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 822 | observers_.AddObserver(observer); |
| 823 | } |
| 824 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 825 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 826 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 827 | observers_.RemoveObserver(observer); |
| 828 | } |
| 829 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 830 | WebKit::WebView* RenderViewImpl::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 831 | return static_cast<WebKit::WebView*>(webwidget()); |
| 832 | } |
| 833 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 834 | void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) { |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 835 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 836 | } |
| 837 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 838 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 839 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 840 | // If the renderer is visible, set initial visibility and focus state. |
| 841 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 842 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 843 | delegate->SetContainerVisibility(true); |
| 844 | if (webview() && webview()->isActive()) |
| 845 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 846 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 847 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 848 | // Plugins start assuming the content has focus (so that they work in |
| 849 | // environments where RenderView isn't hosting them), so we always have to |
| 850 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 851 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 852 | } |
| 853 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 854 | void RenderViewImpl::UnregisterPluginDelegate( |
| 855 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 856 | plugin_delegates_.erase(delegate); |
| 857 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 858 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 859 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 860 | const GURL& page_url, |
| 861 | const std::string& mime_type, |
| 862 | webkit::WebPluginInfo* plugin_info, |
| 863 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 864 | bool found = false; |
| 865 | Send(new ViewHostMsg_GetPluginInfo( |
| 866 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 867 | actual_mime_type)); |
| 868 | return found; |
| 869 | } |
| 870 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 871 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
| 872 | const WebKit::WebActiveWheelFlingParameters& params) { |
| 873 | if (webview()) |
| 874 | webview()->transferActiveWheelFlingAnimation(params); |
| 875 | } |
| 876 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 877 | bool RenderViewImpl::HasIMETextFocus() { |
| 878 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 879 | } |
| 880 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 881 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 882 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 883 | if (main_frame) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 884 | GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 885 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 886 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 887 | RenderViewObserver* observer; |
| 888 | while ((observer = it.GetNext()) != NULL) |
| 889 | if (observer->OnMessageReceived(message)) |
| 890 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 891 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 892 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 893 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 894 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 895 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 896 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 897 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 898 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 899 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 900 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 901 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
| 902 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 903 | IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 904 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
| 905 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 906 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 907 | IPC_MESSAGE_HANDLER(ViewMsg_ReplaceAll, OnReplaceAll) |
| 908 | IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect) |
| 909 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets, |
| 910 | OnSetEditableSelectionOffsets) |
| 911 | IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText, |
| 912 | OnSetCompositionFromExistingText) |
| 913 | IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete, |
| 914 | OnExtendSelectionAndDelete) |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 915 | IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 916 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 917 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 918 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 919 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 920 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 921 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 922 | IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 923 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 924 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 925 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 926 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 927 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 928 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 929 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 930 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 931 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 932 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 933 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 934 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 935 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 936 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 937 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 938 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
[email protected] | d098079 | 2011-02-13 19:41:40 | [diff] [blame] | 939 | IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 940 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 941 | IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect, |
| 942 | OnScrollFocusedEditableNodeIntoRect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 943 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 944 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 945 | IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 946 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 947 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 948 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 949 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 950 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 951 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 952 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 953 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 954 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 955 | OnDisassociateFromPopupCount) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 956 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 957 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 958 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 959 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 960 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 961 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 962 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 963 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 964 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 965 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 966 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 967 | IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent, |
| 968 | OnOrientationChangeEvent) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 969 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 970 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 971 | IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime, |
| 972 | OnSetNavigationStartTime) |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 973 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 974 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 975 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 976 | OnCustomContextMenuAction) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 977 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 978 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, |
| 979 | OnPpapiBrokerChannelCreated) |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 980 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, |
| 981 | OnPpapiBrokerPermissionResult) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 982 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 983 | OnGetAllSavableResourceLinksForCurrentPage) |
| 984 | IPC_MESSAGE_HANDLER( |
| 985 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 986 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 987 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 988 | // TODO(viettrungluu): Move to a separate message filter. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 989 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 990 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 991 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 992 | IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 993 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 994 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 995 | #if defined(OS_ANDROID) |
| 996 | IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult, |
| 997 | OnActivateNearestFindResult) |
| 998 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects) |
| 999 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
| 1000 | IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewMsg_SynchronousFind, OnSynchronousFind) |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1001 | IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView, |
| 1002 | OnUndoScrollFocusedEditableNodeIntoRect) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1003 | #elif defined(OS_MACOSX) |
| 1004 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
| 1005 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1006 | OnPluginImeCompositionCompleted) |
| 1007 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1008 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1009 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1010 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1011 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 1012 | IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, |
| 1013 | OnReleaseDisambiguationPopupDIB) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1014 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1015 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1016 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1017 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1018 | |
| 1019 | if (!msg_is_ok) { |
| 1020 | // The message had a handler, but its deserialization failed. |
| 1021 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1022 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1023 | } |
| 1024 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1025 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1026 | } |
| 1027 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1028 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1029 | MaybeHandleDebugURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1030 | if (!webview()) |
| 1031 | return; |
| 1032 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 1033 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 1034 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1035 | bool is_reload = IsReload(params); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1036 | |
| 1037 | // If this is a stale back/forward (due to a recent navigation the browser |
| 1038 | // didn't know about), ignore it. |
| 1039 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 1040 | return; |
| 1041 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1042 | // Swap this renderer back in if necessary. |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1043 | if (is_swapped_out_) { |
| 1044 | // We marked the view as hidden when swapping the view out, so be sure to |
| 1045 | // reset the visibility state before navigating to the new URL. |
| 1046 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1047 | SetSwappedOut(false); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1048 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1049 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1050 | history_list_offset_ = params.current_history_list_offset; |
| 1051 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1052 | if (history_list_length_ >= 0) |
| 1053 | history_page_ids_.resize(history_list_length_, -1); |
| 1054 | if (params.pending_history_list_offset >= 0 && |
| 1055 | params.pending_history_list_offset < history_list_length_) |
| 1056 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1057 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1058 | GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1059 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1060 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1061 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1062 | // We cannot reload if we do not have any history state. This happens, for |
| 1063 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1064 | // a hack since it means that reload after a crashed tab does not cause an |
| 1065 | // end-to-end cache validation. |
| 1066 | is_reload = false; |
| 1067 | } |
| 1068 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1069 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 1070 | *pending_navigation_params_.get() = params; |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 1071 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1072 | // If we are reloading, then WebKit will use the history state of the current |
| 1073 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1074 | // have history state, then we need to navigate to it, which corresponds to a |
| 1075 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1076 | if (is_reload) { |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1077 | bool reload_original_url = |
| 1078 | (params.navigation_type == |
| 1079 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1080 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 1081 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1082 | |
| 1083 | if (reload_original_url) |
| 1084 | main_frame->reloadWithOverrideURL(params.url, true); |
| 1085 | else |
| 1086 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1087 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1088 | // 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] | 1089 | DCHECK_NE(params.page_id, -1); |
[email protected] | f707573e6 | 2012-10-18 09:38:07 | [diff] [blame] | 1090 | WebHistoryItem item = webkit_glue::HistoryItemFromString(params.state); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1091 | if (!item.isNull()) { |
| 1092 | // Ensure we didn't save the swapped out URL in UpdateState, since the |
| 1093 | // browser should never be telling us to navigate to swappedout://. |
| 1094 | CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL)); |
[email protected] | f707573e6 | 2012-10-18 09:38:07 | [diff] [blame] | 1095 | main_frame->loadHistoryItem(item); |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 1096 | } |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1097 | } else if (!params.base_url_for_data_url.is_empty()) { |
| 1098 | // A loadData request with a specified base URL. |
| 1099 | std::string mime_type, charset, data; |
| 1100 | if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
| 1101 | main_frame->loadData( |
| 1102 | WebData(data.c_str(), data.length()), |
| 1103 | WebString::fromUTF8(mime_type), |
| 1104 | WebString::fromUTF8(charset), |
| 1105 | params.base_url_for_data_url, |
| 1106 | params.history_url_for_data_url, |
| 1107 | false); |
| 1108 | } else { |
| 1109 | CHECK(false) << |
| 1110 | "Invalid URL passed: " << params.url.possibly_invalid_spec(); |
| 1111 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1112 | } else { |
| 1113 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1114 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1115 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1116 | // A session history navigation should have been accompanied by state. |
[email protected] | cbc0cb7 | 2011-12-06 18:58:23 | [diff] [blame] | 1117 | CHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1118 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1119 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1120 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1121 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1122 | if (params.referrer.url.is_valid()) { |
| 1123 | WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 1124 | params.referrer.policy, |
| 1125 | params.url, |
| 1126 | WebString::fromUTF8(params.referrer.url.spec())); |
| 1127 | if (!referrer.isEmpty()) |
| 1128 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1129 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1130 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 1131 | if (!params.extra_headers.empty()) { |
| 1132 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 1133 | params.extra_headers.end(), "\n"); |
| 1134 | i.GetNext(); ) { |
| 1135 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 1136 | WebString::fromUTF8(i.values())); |
| 1137 | } |
| 1138 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1139 | |
| 1140 | if (params.is_post) { |
| 1141 | request.setHTTPMethod(WebString::fromUTF8("POST")); |
| 1142 | |
| 1143 | // Set post data. |
| 1144 | WebHTTPBody http_body; |
| 1145 | http_body.initialize(); |
| 1146 | http_body.appendData(WebData( |
| 1147 | reinterpret_cast<const char*>( |
| 1148 | ¶ms.browser_initiated_post_data.front()), |
| 1149 | params.browser_initiated_post_data.size())); |
| 1150 | request.setHTTPBody(http_body); |
| 1151 | } |
| 1152 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1153 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1154 | } |
| 1155 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1156 | // In case LoadRequest failed before DidCreateDataSource was called. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1157 | pending_navigation_params_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1158 | } |
| 1159 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1160 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1161 | const ViewMsg_Navigate_Params& params, |
| 1162 | bool is_reload) { |
| 1163 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 1164 | // or replaced from our history, before the browser knew about it. If so, |
| 1165 | // a new navigation has committed in the mean time, and we can ignore this. |
| 1166 | bool is_back_forward = !is_reload && !params.state.empty(); |
| 1167 | |
| 1168 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 1169 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 1170 | if (!is_back_forward || history_list_length_ <= 0) |
| 1171 | return false; |
| 1172 | |
| 1173 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 1174 | |
| 1175 | // Check for whether the forward history has been cropped due to a recent |
| 1176 | // navigation the browser didn't know about. |
| 1177 | if (params.pending_history_list_offset >= history_list_length_) |
| 1178 | return true; |
| 1179 | |
| 1180 | // Check for whether this entry has been replaced with a new one. |
| 1181 | int expected_page_id = |
| 1182 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 1183 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 1184 | if (params.page_id < expected_page_id) |
| 1185 | return true; |
| 1186 | |
| 1187 | // Otherwise we've removed an earlier entry and should have shifted all |
| 1188 | // entries left. For now, it's ok to lazily update the list. |
| 1189 | // TODO(creis): Notify all live renderers when we remove entries from |
| 1190 | // the front of the list, so that we don't hit this case. |
| 1191 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 1192 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1193 | |
| 1194 | return false; |
| 1195 | } |
| 1196 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1197 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1198 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 1199 | if (webview()) { |
| 1200 | WebFrame* main_frame = webview()->mainFrame(); |
| 1201 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 1202 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 1203 | // it may no longer be active. |
| 1204 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 1205 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 1206 | main_frame->stopLoading(); |
| 1207 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1208 | } |
| 1209 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1210 | // Reload current focused frame. |
| 1211 | // 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] | 1212 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1213 | if (webview() && webview()->focusedFrame()) { |
| 1214 | // We always obey the cache (ignore_cache=false) here. |
| 1215 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1216 | // a cache-ignoring reload of the frame. |
| 1217 | webview()->focusedFrame()->reload(false); |
| 1218 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1219 | } |
| 1220 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1221 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1222 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1223 | } |
| 1224 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1225 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1226 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1227 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1228 | return; |
| 1229 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1230 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1231 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1232 | } |
| 1233 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1234 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1235 | // Check if there is a targeturl waiting to be sent. |
| 1236 | if (target_url_status_ == TARGET_PENDING) { |
| 1237 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1238 | pending_target_url_)); |
| 1239 | } |
| 1240 | |
| 1241 | target_url_status_ = TARGET_NONE; |
| 1242 | } |
| 1243 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1244 | void RenderViewImpl::OnUndo() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1245 | if (!webview()) |
| 1246 | return; |
| 1247 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1248 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1249 | } |
| 1250 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1251 | void RenderViewImpl::OnRedo() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1252 | if (!webview()) |
| 1253 | return; |
| 1254 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1255 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1256 | } |
| 1257 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1258 | void RenderViewImpl::OnCut() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1259 | if (!webview()) |
| 1260 | return; |
| 1261 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1262 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1263 | } |
| 1264 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1265 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1266 | if (!webview()) |
| 1267 | return; |
| 1268 | |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 1269 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
| 1270 | context_menu_node_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1271 | } |
| 1272 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1273 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1274 | void RenderViewImpl::OnCopyToFindPboard() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1275 | if (!webview()) |
| 1276 | return; |
| 1277 | |
| 1278 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1279 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1280 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1281 | if (frame->hasSelection()) { |
| 1282 | string16 selection = frame->selectionAsText(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1283 | RenderThread::Get()->Send( |
[email protected] | 7e358974 | 2011-03-10 18:49:17 | [diff] [blame] | 1284 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1285 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1286 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1287 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1288 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1289 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1290 | if (!webview()) |
| 1291 | return; |
| 1292 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1293 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1294 | } |
| 1295 | |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1296 | void RenderViewImpl::OnPasteAndMatchStyle() { |
| 1297 | if (!webview()) |
| 1298 | return; |
| 1299 | |
| 1300 | webview()->focusedFrame()->executeCommand( |
| 1301 | WebString::fromUTF8("PasteAndMatchStyle")); |
| 1302 | } |
| 1303 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1304 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1305 | if (!webview()) |
| 1306 | return; |
| 1307 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1308 | WebFrame* frame = webview()->focusedFrame(); |
| 1309 | if (!frame->hasSelection()) |
| 1310 | frame->selectWordAroundCaret(); |
| 1311 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1312 | } |
| 1313 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1314 | void RenderViewImpl::OnDelete() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1315 | if (!webview()) |
| 1316 | return; |
| 1317 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1318 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1319 | } |
| 1320 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1321 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1322 | if (!webview()) |
| 1323 | return; |
| 1324 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1325 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1326 | WebString::fromUTF8("SelectAll")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1327 | } |
| 1328 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1329 | void RenderViewImpl::OnReplaceAll(const string16& text) { |
| 1330 | WebNode node = GetFocusedNode(); |
| 1331 | if (node.isNull() || !IsEditableNode(node)) |
| 1332 | return; |
| 1333 | |
| 1334 | OnSelectAll(); |
| 1335 | OnReplace(text); |
| 1336 | } |
| 1337 | |
| 1338 | void RenderViewImpl::OnUnselect() { |
| 1339 | if (!webview()) |
| 1340 | return; |
| 1341 | |
| 1342 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 1343 | } |
| 1344 | |
| 1345 | void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) { |
| 1346 | webview()->setEditableSelectionOffsets(start, end); |
| 1347 | } |
| 1348 | |
| 1349 | void RenderViewImpl::OnSetCompositionFromExistingText( |
| 1350 | int start, int end, |
| 1351 | const std::vector<WebKit::WebCompositionUnderline>& underlines) { |
| 1352 | if (!webview()) |
| 1353 | return; |
| 1354 | webview()->setCompositionFromExistingText(start, end, underlines); |
| 1355 | } |
| 1356 | |
| 1357 | void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) { |
| 1358 | if (!webview()) |
| 1359 | return; |
| 1360 | webview()->extendSelectionAndDelete(before, after); |
| 1361 | } |
| 1362 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1363 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 1364 | const gfx::Point& end) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1365 | if (!webview()) |
| 1366 | return; |
| 1367 | |
[email protected] | c95e53ad | 2012-08-13 17:56:16 | [diff] [blame] | 1368 | Send(new ViewHostMsg_SelectRange_ACK(routing_id_)); |
| 1369 | |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1370 | handling_select_range_ = true; |
| 1371 | webview()->focusedFrame()->selectRange(start, end); |
| 1372 | handling_select_range_ = false; |
| 1373 | } |
| 1374 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1375 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1376 | int32 minimum_page_id) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1377 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1378 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1379 | DCHECK_GE(minimum_page_id, -1); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1380 | |
| 1381 | // Generate the new list. |
| 1382 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1383 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1384 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1385 | continue; |
| 1386 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1387 | } |
| 1388 | new_history_page_ids.swap(history_page_ids_); |
| 1389 | |
| 1390 | // Update indexes. |
| 1391 | history_list_length_ = history_page_ids_.size(); |
| 1392 | history_list_offset_ = history_list_length_ - 1; |
| 1393 | } |
| 1394 | |
| 1395 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1396 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1397 | if (!webview()) |
| 1398 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1399 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1400 | } |
| 1401 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1402 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1403 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1404 | if (!webview()) |
| 1405 | return; |
| 1406 | if (in_live_resize) |
| 1407 | webview()->willStartLiveResize(); |
| 1408 | else |
| 1409 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1410 | } |
| 1411 | #endif |
| 1412 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1413 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1414 | const gfx::Rect& rect) { |
[email protected] | 13a1e4c3c | 2011-02-03 21:07:09 | [diff] [blame] | 1415 | WebKit::WebNode node = GetFocusedNode(); |
| 1416 | if (!node.isNull()) { |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1417 | if (IsEditableNode(node)) { |
| 1418 | webview()->saveScrollAndScaleState(); |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 1419 | webview()->scrollFocusedNodeIntoRect(rect); |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1420 | } |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | |
[email protected] | 9b7d11e | 2012-10-08 19:24:14 | [diff] [blame] | 1424 | #if defined(OS_ANDROID) |
| 1425 | void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() { |
| 1426 | const WebNode node = GetFocusedNode(); |
| 1427 | if (!node.isNull() && IsEditableNode(node)) |
| 1428 | webview()->restoreScrollAndScaleState(); |
| 1429 | } |
| 1430 | #endif |
| 1431 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1432 | /////////////////////////////////////////////////////////////////////////////// |
| 1433 | |
| 1434 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1435 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1436 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1437 | DCHECK(ds); |
| 1438 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1439 | const WebURLRequest& request = ds->request(); |
| 1440 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1441 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1442 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1443 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 1444 | NavigationState* navigation_state = document_state->navigation_state(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1445 | |
| 1446 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1447 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1448 | params.is_post = false; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1449 | params.post_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1450 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1451 | params.frame_id = frame->identifier(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1452 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1453 | params.socket_address.set_port(response.remotePort()); |
[email protected] | b9a7c6d4 | 2011-02-25 02:13:03 | [diff] [blame] | 1454 | params.was_fetched_via_proxy = response.wasFetchedViaProxy(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1455 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1456 | if (!document_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1457 | // SSL state specified in the request takes precedence over the one in the |
| 1458 | // response. |
| 1459 | // So far this is only intended for error pages that are not expected to be |
| 1460 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1461 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1462 | params.security_info = document_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1463 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1464 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 1468 | params.url = GetLoadingUrl(frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1469 | |
[email protected] | 5f9b871 | 2011-11-23 08:55:57 | [diff] [blame] | 1470 | if (frame->document().baseURL() != params.url) |
| 1471 | params.base_url = frame->document().baseURL(); |
| 1472 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1473 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1474 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 1475 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1476 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1477 | params.searchable_form_url = document_state->searchable_form_url(); |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1478 | params.searchable_form_encoding = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1479 | document_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1480 | |
| 1481 | const PasswordForm* password_form_data = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1482 | document_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1483 | if (password_form_data) |
| 1484 | params.password_form = *password_form_data; |
| 1485 | |
| 1486 | params.gesture = navigation_gesture_; |
| 1487 | navigation_gesture_ = NavigationGestureUnknown; |
| 1488 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1489 | // Make navigation state a part of the FrameNavigate message so that commited |
| 1490 | // entry had it at all times. |
| 1491 | const WebHistoryItem& item = frame->currentHistoryItem(); |
| 1492 | if (!item.isNull()) { |
| 1493 | params.content_state = webkit_glue::HistoryItemToString(item); |
| 1494 | } else { |
| 1495 | params.content_state = |
| 1496 | webkit_glue::CreateHistoryStateForURL(GURL(request.url())); |
| 1497 | } |
| 1498 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1499 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1500 | // Top-level navigation. |
| 1501 | |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1502 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1503 | // will also call us back which will cause us to send a message to |
| 1504 | // update WebContentsImpl. |
| 1505 | webview()->zoomLimitsChanged( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1506 | WebView::zoomFactorToZoomLevel(kMinimumZoomFactor), |
| 1507 | WebView::zoomFactorToZoomLevel(kMaximumZoomFactor)); |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1508 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1509 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1510 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1511 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1512 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1513 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1514 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1515 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1516 | } else { |
| 1517 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1518 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1519 | } |
| 1520 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1521 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1522 | // This zoom level was merely recorded transiently for this load. We can |
| 1523 | // erase it now. If at some point we reload this page, the browser will |
| 1524 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1525 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1526 | } |
| 1527 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1528 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1529 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1530 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1531 | params.transition = navigation_state->transition_type(); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1532 | if (!PageTransitionIsMainFrame(params.transition)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1533 | // If the main frame does a load, it should not be reported as a subframe |
| 1534 | // navigation. This can occur in the following case: |
| 1535 | // 1. You're on a site with frames. |
| 1536 | // 2. You do a subframe navigation. This is stored with transition type |
| 1537 | // MANUAL_SUBFRAME. |
| 1538 | // 3. You navigate to some non-frame site, say, google.com. |
| 1539 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1540 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1541 | // We don't want that, because any navigation that changes the toplevel |
| 1542 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1543 | // update the URL bar, etc). |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1544 | params.transition = PAGE_TRANSITION_LINK; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1545 | } |
| 1546 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1547 | // If we have a valid consumed client redirect source, |
| 1548 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1549 | // so we set the referrer and transition to match. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1550 | if (completed_client_redirect_src_.url.is_valid()) { |
| 1551 | DCHECK(completed_client_redirect_src_.url == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1552 | params.referrer = completed_client_redirect_src_; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1553 | params.transition = static_cast<PageTransition>( |
| 1554 | params.transition | PAGE_TRANSITION_CLIENT_REDIRECT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1555 | } else { |
| 1556 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1557 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1558 | params.referrer = Referrer(GURL( |
| 1559 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 1560 | GetReferrerPolicyFromRequest(frame, original_request)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1561 | } |
| 1562 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1563 | string16 method = request.httpMethod(); |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1564 | if (EqualsASCII(method, "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1565 | params.is_post = true; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1566 | params.post_id = ExtractPostId(item); |
| 1567 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1568 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1569 | // Send the user agent override back. |
| 1570 | params.is_overriding_user_agent = |
| 1571 | document_state->is_overriding_user_agent(); |
| 1572 | |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1573 | // Track the URL of the original request. |
| 1574 | params.original_request_url = original_request.url(); |
| 1575 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1576 | // Save some histogram data so we can compute the average memory used per |
| 1577 | // page load of the glyphs. |
| 1578 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1579 | webkit_glue::GetGlyphPageCount()); |
| 1580 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1581 | // This message needs to be sent before any of allowScripts(), |
| 1582 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1583 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1584 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1585 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1586 | } else { |
| 1587 | // Subframe navigation: the type depends on whether this navigation |
| 1588 | // generated a new session history entry. When they do generate a session |
| 1589 | // history entry, it means the user initiated the navigation and we should |
| 1590 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1591 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1592 | if (page_id_ > last_page_id_sent_to_browser_) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1593 | params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1594 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1595 | params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1596 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1597 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1598 | } |
| 1599 | |
| 1600 | last_page_id_sent_to_browser_ = |
| 1601 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1602 | |
| 1603 | // 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] | 1604 | // we don't want the transition type to persist. Just clear it. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1605 | navigation_state->set_transition_type(PAGE_TRANSITION_LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1609 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 1610 | const string16& title, |
| 1611 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1612 | // Ignore all but top level navigations. |
| 1613 | if (frame->parent()) |
| 1614 | return; |
| 1615 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1616 | string16 shortened_title = title.substr(0, kMaxTitleChars); |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1617 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 1618 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1619 | } |
| 1620 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1621 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 1622 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1623 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1624 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1625 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1626 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1627 | last_encoding_name_ = encoding_name; |
| 1628 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1629 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 1633 | // Sends the last committed session history state to the browser so it will be |
| 1634 | // saved before we navigate to a new page. This must be called *before* the |
| 1635 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1636 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1637 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1638 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1639 | // there is no past session history to record. |
| 1640 | if (page_id_ == -1) |
| 1641 | return; |
| 1642 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1643 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1644 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1645 | SendUpdateState(item); |
| 1646 | } |
| 1647 | |
| 1648 | void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1649 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1650 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1651 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1652 | // Don't send state updates for kSwappedOutURL. |
| 1653 | if (item.urlString() == WebString::fromUTF8(kSwappedOutURL)) |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1654 | return; |
| 1655 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1656 | Send(new ViewHostMsg_UpdateState( |
| 1657 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1658 | } |
| 1659 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1660 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 1661 | const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1662 | const Referrer& referrer, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1663 | WebNavigationPolicy policy) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1664 | Send(new ViewHostMsg_OpenURL( |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1665 | routing_id_, |
| 1666 | url, |
| 1667 | referrer, |
| 1668 | NavigationPolicyToDisposition(policy), |
| 1669 | frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1670 | } |
| 1671 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1672 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1673 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1674 | void RenderViewImpl::LoadNavigationErrorPage( |
| 1675 | WebFrame* frame, |
| 1676 | const WebURLRequest& failed_request, |
| 1677 | const WebURLError& error, |
| 1678 | const std::string& html, |
| 1679 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1680 | std::string alt_html; |
| 1681 | const std::string* error_html; |
| 1682 | |
| 1683 | if (!html.empty()) { |
| 1684 | error_html = &html; |
| 1685 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1686 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1687 | failed_request, error, &alt_html, NULL); |
| 1688 | error_html = &alt_html; |
| 1689 | } |
| 1690 | |
| 1691 | frame->loadHTMLString(*error_html, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1692 | GURL(kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 1693 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1694 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1695 | } |
| 1696 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1697 | bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1698 | const string16& message, |
| 1699 | const string16& default_value, |
| 1700 | const GURL& frame_url, |
| 1701 | string16* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1702 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1703 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1704 | if (!result) |
| 1705 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1706 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1707 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1708 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1709 | return success; |
| 1710 | } |
| 1711 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1712 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1713 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1714 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1715 | // it is particularly important that we do not call willEnterModalLoop as |
| 1716 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1717 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1718 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1719 | |
| 1720 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1721 | return Send(message); |
| 1722 | } |
| 1723 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1724 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1725 | |
[email protected] | 916dfb6 | 2012-03-05 03:39:37 | [diff] [blame] | 1726 | WebView* RenderViewImpl::createView( |
| 1727 | WebFrame* creator, |
| 1728 | const WebURLRequest& request, |
| 1729 | const WebWindowFeatures& features, |
| 1730 | const WebString& frame_name, |
| 1731 | WebNavigationPolicy policy) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1732 | // Check to make sure we aren't overloading on popups. |
| 1733 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1734 | return NULL; |
| 1735 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1736 | ViewHostMsg_CreateWindow_Params params; |
| 1737 | params.opener_id = routing_id_; |
| 1738 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1739 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1740 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1741 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1742 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1743 | params.opener_url = creator->document().url(); |
| 1744 | params.opener_security_origin = |
| 1745 | creator->document().securityOrigin().toString().utf8(); |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1746 | params.opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
| 1747 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1748 | if (!request.isNull()) |
| 1749 | params.target_url = request.url(); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1750 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1751 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1752 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1753 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1754 | |
[email protected] | 7c962ee3 | 2012-08-28 21:12:50 | [diff] [blame] | 1755 | creator->consumeUserGesture(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1756 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1757 | new ViewHostMsg_CreateWindow(params, |
| 1758 | &routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1759 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1760 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1761 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1762 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1763 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1764 | RenderViewImpl* view = RenderViewImpl::Create( |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1765 | routing_id_, |
| 1766 | renderer_preferences_, |
| 1767 | webkit_preferences_, |
| 1768 | shared_popup_counter_, |
| 1769 | routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1770 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1771 | cloned_session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1772 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1773 | true, |
| 1774 | false, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1775 | 1, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1776 | screen_info_, |
[email protected] | 3e3c452 | 2012-04-13 21:16:29 | [diff] [blame] | 1777 | accessibility_mode_); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1778 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1779 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1780 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1781 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1782 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1783 | // Record the security origin of the creator. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1784 | GURL creator_url(creator->document().securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1785 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1786 | creator_url = GURL(); |
| 1787 | view->creator_url_ = creator_url; |
| 1788 | |
| 1789 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1790 | // the new render view (we don't need the browser to send the URL back down). |
| 1791 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1792 | |
| 1793 | return view->webview(); |
| 1794 | } |
| 1795 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1796 | WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1797 | RenderWidget* widget = |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1798 | RenderWidget::Create(routing_id_, popup_type, screen_info_); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1799 | return widget->webwidget(); |
| 1800 | } |
| 1801 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1802 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1803 | const WebPopupMenuInfo& popup_menu_info, |
| 1804 | WebExternalPopupMenuClient* popup_menu_client) { |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 1805 | // An IPC message is sent to the browser to build and display the actual |
| 1806 | // popup. The user could have time to click a different select by the time |
| 1807 | // the popup is shown. In that case external_popup_menu_ is non NULL. |
| 1808 | // By returning NULL in that case, we instruct WebKit to cancel that new |
| 1809 | // popup. So from the user perspective, only the first one will show, and |
| 1810 | // will have to close the first one before another one can be shown. |
| 1811 | if (external_popup_menu_.get()) |
| 1812 | return NULL; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1813 | external_popup_menu_.reset( |
| 1814 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 1815 | return external_popup_menu_.get(); |
| 1816 | } |
| 1817 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1818 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 1819 | webkit::ppapi::PluginInstance* plugin) { |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1820 | GURL active_url; |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 1821 | if (webview() && webview()->mainFrame()) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1822 | active_url = GURL(webview()->mainFrame()->document().url()); |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1823 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
[email protected] | bee6eb7 | 2012-07-26 03:47:32 | [diff] [blame] | 1824 | routing_id_, plugin, active_url, screen_info_); |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1825 | widget->show(WebKit::WebNavigationPolicyIgnore); |
[email protected] | 92abcb83 | 2011-01-06 20:39:56 | [diff] [blame] | 1826 | return widget; |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1827 | } |
| 1828 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1829 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace( |
| 1830 | unsigned quota) { |
[email protected] | b928936b | 2012-04-13 01:16:16 | [diff] [blame] | 1831 | CHECK(session_storage_namespace_id_ != |
| 1832 | dom_storage::kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1833 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1834 | } |
| 1835 | |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1836 | WebKit::WebCompositorOutputSurface* RenderViewImpl::createOutputSurface() { |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1837 | // Explicitly disable antialiasing for the compositor. As of the time of |
| 1838 | // this writing, the only platform that supported antialiasing for the |
| 1839 | // compositor was Mac OS X, because the on-screen OpenGL context creation |
| 1840 | // code paths on Windows and Linux didn't yet have multisampling support. |
| 1841 | // Mac OS X essentially always behaves as though it's rendering offscreen. |
| 1842 | // Multisampling has a heavy cost especially on devices with relatively low |
| 1843 | // fill rate like most notebooks, and the Mac implementation would need to |
| 1844 | // be optimized to resolve directly into the IOSurface shared between the |
| 1845 | // GPU and browser processes. For these reasons and to avoid platform |
| 1846 | // disparities we explicitly disable antialiasing. |
| 1847 | WebKit::WebGraphicsContext3D::Attributes attributes; |
| 1848 | attributes.antialias = false; |
| 1849 | attributes.shareResources = true; |
[email protected] | 362e6d60 | 2012-10-17 16:55:06 | [diff] [blame] | 1850 | attributes.noAutomaticFlushes = true; |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1851 | WebGraphicsContext3D* context = CreateGraphicsContext3D(attributes); |
| 1852 | if (!context) |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1853 | return NULL; |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 1854 | |
[email protected] | 7d4481d1 | 2012-09-24 21:26:47 | [diff] [blame] | 1855 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1856 | if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) { |
| 1857 | // In the absence of a software-based delegating renderer, use this |
| 1858 | // stopgap adapter class to present the software renderer output using a |
| 1859 | // 3d context. |
| 1860 | return new CompositorOutputSurface(routing_id(), NULL, |
| 1861 | new CompositorSoftwareOutputDeviceGLAdapter(context)); |
| 1862 | } else |
| 1863 | return new CompositorOutputSurface(routing_id(), context, NULL); |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1864 | } |
| 1865 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1866 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1867 | const WebConsoleMessage& message, const WebString& source_name, |
| 1868 | unsigned source_line) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1869 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 1870 | switch (message.level) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1871 | case WebConsoleMessage::LevelTip: |
| 1872 | log_severity = logging::LOG_VERBOSE; |
| 1873 | break; |
| 1874 | case WebConsoleMessage::LevelLog: |
| 1875 | log_severity = logging::LOG_INFO; |
| 1876 | break; |
| 1877 | case WebConsoleMessage::LevelWarning: |
| 1878 | log_severity = logging::LOG_WARNING; |
| 1879 | break; |
| 1880 | case WebConsoleMessage::LevelError: |
| 1881 | log_severity = logging::LOG_ERROR; |
| 1882 | break; |
| 1883 | default: |
| 1884 | NOTREACHED(); |
| 1885 | } |
| 1886 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1887 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1888 | static_cast<int32>(log_severity), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1889 | message.text, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1890 | static_cast<int32>(source_line), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1891 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1892 | } |
| 1893 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1894 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 1895 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 1896 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1897 | } |
| 1898 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1899 | WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1900 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1901 | } |
| 1902 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1903 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1904 | const WebString& path, |
| 1905 | WebFileChooserCompletion* chooser_completion) { |
| 1906 | int id = enumeration_completion_id_++; |
| 1907 | enumeration_completions_[id] = chooser_completion; |
| 1908 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 1909 | routing_id_, |
| 1910 | id, |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 1911 | webkit_base::WebStringToFilePath(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1912 | } |
| 1913 | |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 1914 | void RenderViewImpl::initializeHelperPluginWebFrame( |
| 1915 | WebKit::WebHelperPlugin* plugin) { |
| 1916 | plugin->initializeFrame(this); |
| 1917 | } |
| 1918 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1919 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1920 | if (is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 1921 | DVLOG(1) << "didStartLoading called while loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1922 | return; |
| 1923 | } |
| 1924 | |
| 1925 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1926 | |
| 1927 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 1928 | |
| 1929 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1930 | } |
| 1931 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1932 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1933 | if (!is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 1934 | DVLOG(1) << "DidStopLoading called while not loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1935 | return; |
| 1936 | } |
| 1937 | |
| 1938 | is_loading_ = false; |
| 1939 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 1940 | if (pending_frame_tree_update_) { |
| 1941 | pending_frame_tree_update_ = false; |
| 1942 | SendUpdatedFrameTree(NULL); |
| 1943 | } |
| 1944 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1945 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1946 | // when done loading. This currently isn't an issue as the favicon is only |
| 1947 | // displayed when done loading. Ideally we would send notification when |
| 1948 | // finished parsing the head, but webkit doesn't support that yet. |
| 1949 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1950 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1951 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 1952 | if (load_progress_tracker_ != NULL) |
| 1953 | load_progress_tracker_->DidStopLoading(); |
| 1954 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 1955 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1956 | } |
| 1957 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1958 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 1959 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 1960 | if (load_progress_tracker_ != NULL) |
| 1961 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 1962 | } |
| 1963 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1964 | bool RenderViewImpl::isSmartInsertDeleteEnabled() { |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1965 | #if defined(OS_MACOSX) |
| 1966 | return true; |
| 1967 | #else |
| 1968 | return false; |
| 1969 | #endif |
| 1970 | } |
| 1971 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1972 | bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() { |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1973 | #if defined(OS_WIN) |
| 1974 | return true; |
| 1975 | #else |
| 1976 | return false; |
| 1977 | #endif |
| 1978 | } |
| 1979 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1980 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1981 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1982 | return; |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1983 | handling_select_range_ = false; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1984 | |
[email protected] | fca5202 | 2012-04-03 17:00:50 | [diff] [blame] | 1985 | if (is_empty_selection) |
| 1986 | selection_text_.clear(); |
| 1987 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 1988 | SyncSelectionIfRequired(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1989 | } |
| 1990 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1991 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1992 | const std::string& name = UTF16ToUTF8(command_name); |
| 1993 | if (StartsWithASCII(name, "Move", true) || |
| 1994 | StartsWithASCII(name, "Insert", true) || |
| 1995 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1996 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1997 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1998 | } |
| 1999 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2000 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2001 | if (edit_commands_.empty()) |
| 2002 | return false; |
| 2003 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2004 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2005 | if (!frame) |
| 2006 | return false; |
| 2007 | |
| 2008 | EditCommands::iterator it = edit_commands_.begin(); |
| 2009 | EditCommands::iterator end = edit_commands_.end(); |
| 2010 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2011 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2012 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2013 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2014 | // key (but it's the exception). Once one edit command is not executed, it |
| 2015 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2016 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 2017 | WebString::fromUTF8(it->value))) |
| 2018 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2019 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2020 | } |
| 2021 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2022 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2023 | } |
| 2024 | |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 2025 | void RenderViewImpl::didHandleGestureEvent(const WebGestureEvent& event, |
| 2026 | bool event_swallowed) { |
| 2027 | #if defined(OS_ANDROID) |
| 2028 | if (event.type == WebInputEvent::GestureTap || |
| 2029 | event.type == WebInputEvent::GestureLongPress) { |
| 2030 | UpdateTextInputState(SHOW_IME_IF_NEEDED); |
| 2031 | } |
| 2032 | #endif |
| 2033 | } |
| 2034 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2035 | WebKit::WebColorChooser* RenderViewImpl::createColorChooser( |
| 2036 | WebKit::WebColorChooserClient* client, |
| 2037 | const WebKit::WebColor& initial_color) { |
| 2038 | RendererWebColorChooserImpl* color_chooser = |
| 2039 | new RendererWebColorChooserImpl(this, client); |
| 2040 | color_chooser->Open(static_cast<SkColor>(initial_color)); |
| 2041 | return color_chooser; |
| 2042 | } |
| 2043 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2044 | bool RenderViewImpl::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2045 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2046 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 2047 | // Do not open the file dialog in a hidden RenderView. |
| 2048 | if (is_hidden()) |
| 2049 | return false; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2050 | FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2051 | if (params.directory) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2052 | ipc_params.mode = FileChooserParams::OpenFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2053 | else if (params.multiSelect) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2054 | ipc_params.mode = FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 2055 | else if (params.saveAs) |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2056 | ipc_params.mode = FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2057 | else |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2058 | ipc_params.mode = FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2059 | ipc_params.title = params.title; |
| 2060 | ipc_params.default_file_name = |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 2061 | webkit_base::WebStringToFilePath(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 2062 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 2063 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 2064 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
[email protected] | 2fdf235 | 2012-11-01 19:23:02 | [diff] [blame] | 2065 | #if defined(OS_ANDROID) |
| 2066 | ipc_params.capture = params.capture; |
| 2067 | #endif |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2068 | |
| 2069 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2070 | } |
| 2071 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2072 | void RenderViewImpl::runModalAlertDialog(WebFrame* frame, |
| 2073 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2074 | RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2075 | message, |
| 2076 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2077 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2078 | NULL); |
| 2079 | } |
| 2080 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2081 | bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame, |
| 2082 | const WebString& message) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2083 | return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2084 | message, |
| 2085 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2086 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2087 | NULL); |
| 2088 | } |
| 2089 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2090 | bool RenderViewImpl::runModalPromptDialog(WebFrame* frame, |
| 2091 | const WebString& message, |
| 2092 | const WebString& default_value, |
| 2093 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2094 | string16 result; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2095 | bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2096 | message, |
| 2097 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2098 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2099 | &result); |
| 2100 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2101 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2102 | return ok; |
| 2103 | } |
| 2104 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2105 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2106 | WebFrame* frame, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2107 | // If we are swapping out, we have already run the beforeunload handler. |
| 2108 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 2109 | // at all, to avoid running it twice. |
| 2110 | if (is_swapped_out_) |
| 2111 | return true; |
| 2112 | |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2113 | bool is_reload = false; |
| 2114 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2115 | if (ds) |
| 2116 | is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload); |
| 2117 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2118 | bool success = false; |
| 2119 | // This is an ignored return value, but is included so we can accept the same |
| 2120 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2121 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2122 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2123 | routing_id_, frame->document().url(), message, is_reload, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2124 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2125 | return success; |
| 2126 | } |
| 2127 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2128 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2129 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2130 | ContextMenuParams params(data); |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2131 | |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2132 | // Plugins, e.g. PDF, don't currently update the render view when their |
| 2133 | // selected text changes, but the context menu params do contain the updated |
| 2134 | // selection. If that's the case, update the render view's state just prior |
| 2135 | // to showing the context menu. |
| 2136 | // TODO(asvitkine): http://crbug.com/152432 |
[email protected] | f49f7a1 | 2012-10-26 19:16:59 | [diff] [blame] | 2137 | string16 selection_text; |
| 2138 | if (!selection_text_.empty() && !selection_range_.is_empty()) { |
| 2139 | const int start = selection_range_.GetMin() - selection_text_offset_; |
| 2140 | const size_t length = selection_range_.length(); |
| 2141 | if (start >= 0 && start + length <= selection_text_.length()) |
| 2142 | selection_text = selection_text_.substr(start, length); |
| 2143 | } |
[email protected] | eff43567da | 2012-10-25 20:57:48 | [diff] [blame] | 2144 | if (params.selection_text != selection_text) { |
[email protected] | 329266d | 2012-09-27 06:20:57 | [diff] [blame] | 2145 | selection_text_ = params.selection_text; |
| 2146 | // TODO(asvitkine): Text offset and range is not available in this case. |
| 2147 | selection_text_offset_ = 0; |
| 2148 | selection_range_ = ui::Range(0, selection_text_.length()); |
| 2149 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 2150 | selection_text_, |
| 2151 | selection_text_offset_, |
| 2152 | selection_range_)); |
| 2153 | } |
| 2154 | |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2155 | // frame is NULL if invoked by BlockedPlugin. |
| 2156 | if (frame) |
| 2157 | params.frame_id = frame->identifier(); |
| 2158 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2159 | // Serializing a GURL longer than kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2160 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2161 | // in the context menu. |
| 2162 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2163 | // data encoded images. We should have a way to save them. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2164 | if (params.src_url.spec().size() > kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2165 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 2166 | context_menu_node_ = data.node; |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2167 | |
| 2168 | #if defined(OS_ANDROID) |
| 2169 | gfx::Rect start_rect; |
| 2170 | gfx::Rect end_rect; |
| 2171 | GetSelectionBounds(&start_rect, &end_rect); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2172 | params.selection_start = |
| 2173 | gfx::Point(start_rect.x(), start_rect.bottom()) + GetScrollOffset(); |
| 2174 | params.selection_end = |
| 2175 | gfx::Point(end_rect.right(), end_rect.bottom()) + GetScrollOffset(); |
[email protected] | 44daa3b | 2012-09-27 19:26:41 | [diff] [blame] | 2176 | #endif |
| 2177 | |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2178 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2179 | |
| 2180 | FOR_EACH_OBSERVER( |
| 2181 | RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2182 | } |
| 2183 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2184 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2185 | } |
| 2186 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2187 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 2188 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2189 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2190 | if (latest_url == target_url_) |
| 2191 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2192 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2193 | // Tell the browser to display a destination link. |
| 2194 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2195 | target_url_status_ == TARGET_PENDING) { |
| 2196 | // If we have a request in-flight, save the URL to be sent when we |
| 2197 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2198 | // any existing pending sends. |
| 2199 | pending_target_url_ = latest_url; |
| 2200 | target_url_status_ = TARGET_PENDING; |
| 2201 | } else { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2202 | // URLs larger than |kMaxURLChars| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2203 | // see |ParamTraits<GURL>|. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2204 | if (latest_url.possibly_invalid_spec().size() > kMaxURLChars) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2205 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2206 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2207 | target_url_ = latest_url; |
| 2208 | target_url_status_ = TARGET_INFLIGHT; |
| 2209 | } |
| 2210 | } |
| 2211 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2212 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2213 | int delay; |
| 2214 | if (send_content_state_immediately_) |
| 2215 | delay = 0; |
| 2216 | else if (is_hidden()) |
| 2217 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2218 | else |
| 2219 | delay = kDelaySecondsForContentStateSync; |
| 2220 | |
| 2221 | if (nav_state_sync_timer_.IsRunning()) { |
| 2222 | // The timer is already running. If the delay of the timer maches the amount |
| 2223 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2224 | // gets started with the right delay. |
| 2225 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2226 | return; |
| 2227 | nav_state_sync_timer_.Stop(); |
| 2228 | } |
| 2229 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 2230 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2231 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2232 | } |
| 2233 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2234 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2235 | mouse_over_url_ = GURL(url); |
| 2236 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2237 | } |
| 2238 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2239 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2240 | focus_url_ = GURL(url); |
| 2241 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2242 | } |
| 2243 | |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 2244 | void RenderViewImpl::startDragging(WebFrame* frame, |
| 2245 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2246 | WebDragOperationsMask mask, |
| 2247 | const WebImage& image, |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2248 | const WebPoint& webImageOffset) { |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2249 | WebDropData drop_data(data); |
| 2250 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 2251 | gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2252 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2253 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2254 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 2255 | image.getSkBitmap(), |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 2256 | imageOffset, |
| 2257 | possible_drag_event_info_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2258 | } |
| 2259 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2260 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2261 | return renderer_preferences_.can_accept_load_drops; |
| 2262 | } |
| 2263 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2264 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2265 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2266 | } |
| 2267 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2268 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2269 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2270 | } |
| 2271 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2272 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 2273 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2274 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 2275 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2276 | } |
| 2277 | |
[email protected] | 572a6ca | 2012-10-11 19:38:01 | [diff] [blame] | 2278 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
| 2279 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
| 2280 | } |
| 2281 | |
| 2282 | void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) { |
| 2283 | Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
| 2284 | } |
| 2285 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2286 | void RenderViewImpl::didUpdateLayout() { |
| 2287 | // We don't always want to set up a timer, only if we've been put in that |
| 2288 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2289 | // message. |
| 2290 | if (!send_preferred_size_changes_ || !webview()) |
| 2291 | return; |
| 2292 | |
| 2293 | if (check_preferred_size_timer_.IsRunning()) |
| 2294 | return; |
| 2295 | check_preferred_size_timer_.Start(FROM_HERE, |
| 2296 | TimeDelta::FromMilliseconds(0), this, |
| 2297 | &RenderViewImpl::CheckPreferredSize); |
| 2298 | } |
| 2299 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2300 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2301 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2302 | } |
| 2303 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2304 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2305 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2306 | } |
| 2307 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2308 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2309 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2310 | } |
| 2311 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2312 | void RenderViewImpl::postAccessibilityNotification( |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2313 | const WebAccessibilityObject& obj, |
| 2314 | WebAccessibilityNotification notification) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2315 | if (renderer_accessibility_) { |
| 2316 | renderer_accessibility_->HandleWebAccessibilityNotification( |
| 2317 | obj, notification); |
| 2318 | } |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2319 | } |
| 2320 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2321 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2322 | const WebString& value) { |
| 2323 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2324 | key.utf8(), |
| 2325 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2326 | } |
| 2327 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2328 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2329 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2330 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2331 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2332 | // we won't have to test for user gesture anymore and we can |
| 2333 | // move that code back to render_widget.cc |
| 2334 | if (webview() && webview()->mainFrame() && |
| 2335 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2336 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 2337 | } |
| 2338 | } |
| 2339 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2340 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2341 | // TODO(jcivelli): see TODO above in didFocus(). |
| 2342 | if (webview() && webview()->mainFrame() && |
| 2343 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2344 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 2345 | } |
| 2346 | } |
| 2347 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2348 | // 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] | 2349 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2350 | // point to dispatch the ShowView message. |
| 2351 | // |
| 2352 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 2353 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2354 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2355 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2356 | if (did_show_) { |
| 2357 | #if defined(OS_ANDROID) |
| 2358 | // When supports_multiple_windows is disabled, popups are reusing |
| 2359 | // the same view. In some scenarios, this makes WebKit to call show() twice. |
| 2360 | if (!webkit_preferences_.supports_multiple_windows) |
| 2361 | return; |
| 2362 | #endif |
| 2363 | NOTREACHED() << "received extraneous Show call"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2364 | return; |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2365 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2366 | did_show_ = true; |
| 2367 | |
[email protected] | b2142e96 | 2012-10-30 13:59:25 | [diff] [blame] | 2368 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2369 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2370 | if (GetContentClient()->renderer()->AllowPopup(creator_url_)) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2371 | opened_by_user_gesture_ = true; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2372 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2373 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2374 | if (!opened_by_user_gesture_) { |
| 2375 | // We exempt background tabs for compat with older versions of Chrome. |
| 2376 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2377 | // we probably don't need this check. |
| 2378 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2379 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2380 | } |
| 2381 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2382 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2383 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2384 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2385 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2386 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2387 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2388 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2389 | } |
| 2390 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2391 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2392 | DCHECK(did_show_) << "should already have shown the view"; |
| 2393 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2394 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2395 | // showModalDialog to function properly. |
| 2396 | // |
| 2397 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2398 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2399 | // handed manner. |
| 2400 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2401 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2402 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2403 | |
[email protected] | 08a1c810 | 2012-05-11 23:14:26 | [diff] [blame] | 2404 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 2405 | routing_id_, opener_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2406 | } |
| 2407 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2408 | bool RenderViewImpl::enterFullScreen() { |
| 2409 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 2410 | return true; |
| 2411 | } |
| 2412 | |
| 2413 | void RenderViewImpl::exitFullScreen() { |
| 2414 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 2415 | } |
| 2416 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2417 | bool RenderViewImpl::requestPointerLock() { |
| 2418 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2419 | } |
| 2420 | |
| 2421 | void RenderViewImpl::requestPointerUnlock() { |
| 2422 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2423 | } |
| 2424 | |
| 2425 | bool RenderViewImpl::isPointerLocked() { |
| 2426 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2427 | webwidget_mouse_lock_target_.get()); |
| 2428 | } |
| 2429 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2430 | void RenderViewImpl::didActivateCompositor(int input_handler_identifier) { |
| 2431 | CompositorThread* compositor_thread = |
| 2432 | RenderThreadImpl::current()->compositor_thread(); |
| 2433 | if (compositor_thread) |
| 2434 | compositor_thread->AddInputHandler( |
| 2435 | routing_id_, input_handler_identifier, AsWeakPtr()); |
| 2436 | |
| 2437 | RenderWidget::didActivateCompositor(input_handler_identifier); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2438 | |
| 2439 | ProcessAcceleratedPinchZoomFlags(*CommandLine::ForCurrentProcess()); |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2440 | } |
| 2441 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2442 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2443 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2444 | WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 2445 | const WebPluginParams& params) { |
[email protected] | eaacd1f | 2011-09-23 02:32:55 | [diff] [blame] | 2446 | WebPlugin* plugin = NULL; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2447 | if (GetContentClient()->renderer()->OverrideCreatePlugin( |
[email protected] | eaacd1f | 2011-09-23 02:32:55 | [diff] [blame] | 2448 | this, frame, params, &plugin)) { |
| 2449 | return plugin; |
| 2450 | } |
| 2451 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2452 | if (UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType) { |
[email protected] | 6cd7c6b | 2012-10-25 03:26:23 | [diff] [blame] | 2453 | return BrowserPluginManager::Get()-> |
| 2454 | CreateBrowserPlugin(this, frame, params); |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 2455 | } |
| 2456 | |
[email protected] | a813c8e | 2011-10-08 01:34:11 | [diff] [blame] | 2457 | webkit::WebPluginInfo info; |
| 2458 | std::string mime_type; |
| 2459 | bool found = GetPluginInfo(params.url, frame->top()->document().url(), |
| 2460 | params.mimeType.utf8(), &info, &mime_type); |
| 2461 | if (!found) |
| 2462 | return NULL; |
| 2463 | |
| 2464 | WebPluginParams params_to_use = params; |
| 2465 | params_to_use.mimeType = WebString::fromUTF8(mime_type); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2466 | return CreatePlugin(frame, info, params_to_use); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2467 | } |
| 2468 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2469 | WebSharedWorker* RenderViewImpl::createSharedWorker( |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2470 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2471 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2472 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2473 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2474 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2475 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2476 | ViewHostMsg_CreateWorker_Params params; |
| 2477 | params.url = url; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2478 | params.name = name; |
| 2479 | params.document_id = document_id; |
| 2480 | params.render_view_route_id = routing_id_; |
| 2481 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2482 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2483 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2484 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2485 | if (url_mismatch) { |
| 2486 | return NULL; |
| 2487 | } else { |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2488 | return new WebSharedWorkerProxy(RenderThreadImpl::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2489 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2490 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2491 | route_id, |
| 2492 | routing_id_); |
| 2493 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2494 | } |
| 2495 | |
[email protected] | 97b150db | 2012-08-16 18:26:02 | [diff] [blame] | 2496 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
| 2497 | WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2498 | FOR_EACH_OBSERVER( |
| 2499 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 2500 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2501 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2502 | #if defined(OS_ANDROID) |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2503 | WebGraphicsContext3D* resource_context = |
| 2504 | GetWebView()->sharedGraphicsContext3D(); |
| 2505 | |
| 2506 | GpuChannelHost* gpu_channel_host = |
| 2507 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2508 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2509 | if (!gpu_channel_host) { |
| 2510 | LOG(ERROR) << "Failed to establish GPU channel for media player"; |
| 2511 | return NULL; |
| 2512 | } |
| 2513 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2514 | if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) { |
| 2515 | if (!media_bridge_manager_.get()) { |
| 2516 | media_bridge_manager_.reset( |
| 2517 | new webkit_media::MediaPlayerBridgeManagerImpl(1)); |
| 2518 | } |
| 2519 | return new webkit_media::WebMediaPlayerInProcessAndroid( |
| 2520 | frame, |
| 2521 | client, |
| 2522 | cookieJar(frame), |
| 2523 | media_player_manager_.get(), |
| 2524 | media_bridge_manager_.get(), |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2525 | new StreamTextureFactoryImpl( |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2526 | resource_context, gpu_channel_host, routing_id_), |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2527 | cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging)); |
| 2528 | } |
| 2529 | if (!media_player_proxy_) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2530 | media_player_proxy_ = new WebMediaPlayerProxyImplAndroid( |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2531 | this, media_player_manager_.get()); |
| 2532 | } |
| 2533 | return new webkit_media::WebMediaPlayerImplAndroid( |
| 2534 | frame, |
| 2535 | client, |
| 2536 | media_player_manager_.get(), |
| 2537 | media_player_proxy_, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2538 | new StreamTextureFactoryImpl( |
[email protected] | 855623ed | 2012-09-24 18:59:55 | [diff] [blame] | 2539 | resource_context, gpu_channel_host, routing_id_)); |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2540 | #endif |
| 2541 | |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2542 | media::MessageLoopFactory* message_loop_factory = |
[email protected] | b8032290 | 2012-03-06 01:33:50 | [diff] [blame] | 2543 | new media::MessageLoopFactory(); |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2544 | media::FilterCollection* collection = new media::FilterCollection(); |
| 2545 | RenderMediaLog* render_media_log = new RenderMediaLog(); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2546 | |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2547 | RenderAudioSourceProvider* audio_source_provider = NULL; |
| 2548 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2549 | // Add in any custom filter factories first. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2550 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2551 | // audio_source_provider is a "provider" to WebKit, and a sink |
| 2552 | // from the perspective of the audio renderer. |
| 2553 | audio_source_provider = new RenderAudioSourceProvider(); |
| 2554 | |
| 2555 | // Add the chrome specific audio renderer, using audio_source_provider |
| 2556 | // as the sink. |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 2557 | media::AudioRendererImpl* audio_renderer = |
| 2558 | new media::AudioRendererImpl(audio_source_provider); |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2559 | collection->AddAudioRenderer(audio_renderer); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2560 | } |
| 2561 | |
[email protected] | 15d206e | 2012-08-17 22:35:13 | [diff] [blame] | 2562 | WebGraphicsContext3DCommandBufferImpl* context3d = NULL; |
[email protected] | 5f04c353 | 2012-09-25 01:28:39 | [diff] [blame] | 2563 | if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode)) |
[email protected] | 15d206e | 2012-08-17 22:35:13 | [diff] [blame] | 2564 | context3d = RenderThreadImpl::current()->GetGpuVDAContext3D(); |
[email protected] | 851334d | 2012-06-15 22:39:31 | [diff] [blame] | 2565 | if (context3d) { |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 2566 | scoped_refptr<base::MessageLoopProxy> factories_loop = |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 2567 | RenderThreadImpl::current()->compositor_thread() ? |
| 2568 | RenderThreadImpl::current()->compositor_thread()->GetWebThread() |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 2569 | ->message_loop()->message_loop_proxy() : |
| 2570 | base::MessageLoopProxy::current(); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2571 | GpuChannelHost* gpu_channel_host = |
| 2572 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2573 | CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
[email protected] | 873da26 | 2012-08-10 22:02:47 | [diff] [blame] | 2574 | collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder( |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 2575 | base::Bind(&media::MessageLoopFactory::GetMessageLoop, |
| 2576 | base::Unretained(message_loop_factory), |
[email protected] | c462c90 | 2012-09-06 13:13:42 | [diff] [blame] | 2577 | media::MessageLoopFactory::kDecoder), |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 2578 | factories_loop, |
[email protected] | 8d435928 | 2012-01-14 00:53:31 | [diff] [blame] | 2579 | new RendererGpuVideoDecoderFactories( |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 2580 | gpu_channel_host, factories_loop, context3d))); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2581 | } |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2582 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 2583 | WebMediaPlayer* media_player = |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2584 | GetContentClient()->renderer()->OverrideCreateWebMediaPlayer( |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2585 | this, frame, client, AsWeakPtr(), collection, audio_source_provider, |
[email protected] | 1113bfdf | 2012-07-16 21:46:10 | [diff] [blame] | 2586 | audio_source_provider, message_loop_factory, media_stream_impl_, |
| 2587 | render_media_log); |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2588 | if (!media_player) { |
[email protected] | ba42ac4f | 2012-10-11 20:28:14 | [diff] [blame] | 2589 | #if defined(ENABLE_WEBRTC) |
[email protected] | 5f04c353 | 2012-09-25 01:28:39 | [diff] [blame] | 2590 | // TODO(wjia): when all patches related to WebMediaPlayerMS have been |
| 2591 | // landed, remove the switch. Refer to crbug.com/142988. |
[email protected] | 1fba73c1 | 2012-10-10 23:36:20 | [diff] [blame] | 2592 | if (!cmd_line->HasSwitch(switches::kDisableWebMediaPlayerMS) && |
| 2593 | MediaStreamImpl::CheckMediaStream(url)) { |
[email protected] | 5f04c353 | 2012-09-25 01:28:39 | [diff] [blame] | 2594 | EnsureMediaStreamImpl(); |
[email protected] | 1fba73c1 | 2012-10-10 23:36:20 | [diff] [blame] | 2595 | return new webkit_media::WebMediaPlayerMS( |
| 2596 | frame, client, AsWeakPtr(), media_stream_impl_, render_media_log); |
[email protected] | 5f04c353 | 2012-09-25 01:28:39 | [diff] [blame] | 2597 | } |
[email protected] | ba42ac4f | 2012-10-11 20:28:14 | [diff] [blame] | 2598 | #endif |
[email protected] | 5f04c353 | 2012-09-25 01:28:39 | [diff] [blame] | 2599 | |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2600 | media_player = new webkit_media::WebMediaPlayerImpl( |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2601 | frame, client, AsWeakPtr(), collection, audio_source_provider, |
[email protected] | 1113bfdf | 2012-07-16 21:46:10 | [diff] [blame] | 2602 | audio_source_provider, message_loop_factory, media_stream_impl_, |
| 2603 | render_media_log); |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2604 | } |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2605 | return media_player; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2606 | } |
| 2607 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2608 | WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost( |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2609 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
[email protected] | cdeeeb2 | 2012-01-11 07:44:23 | [diff] [blame] | 2610 | if (!frame || !frame->view()) |
| 2611 | return NULL; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2612 | return new RendererWebApplicationCacheHostImpl( |
| 2613 | FromWebView(frame->view()), client, |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2614 | RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy()); |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2615 | } |
| 2616 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2617 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 2618 | return &cookie_jar_; |
| 2619 | } |
| 2620 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2621 | void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) { |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2622 | if (!updating_frame_tree_) |
| 2623 | SendUpdatedFrameTree(NULL); |
| 2624 | } |
| 2625 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2626 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2627 | if (is_loading_) { |
| 2628 | pending_frame_tree_update_ = true; |
| 2629 | // Make sure observers are notified, even if we return right away. |
| 2630 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
| 2631 | return; |
| 2632 | } |
| 2633 | if (!updating_frame_tree_) |
| 2634 | SendUpdatedFrameTree(frame); |
| 2635 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2636 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2637 | } |
| 2638 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2639 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2640 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2641 | } |
| 2642 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2643 | void RenderViewImpl::loadURLExternally( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2644 | WebFrame* frame, const WebURLRequest& request, |
| 2645 | WebNavigationPolicy policy) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2646 | loadURLExternally(frame, request, policy, WebString()); |
| 2647 | } |
| 2648 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2649 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
| 2650 | OnMsgRepaint(size); |
| 2651 | } |
| 2652 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 2653 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 2654 | const std::string& value) { |
| 2655 | EditCommands edit_commands; |
| 2656 | edit_commands.push_back(EditCommand(name, value)); |
| 2657 | OnSetEditCommandsForNextKeyEvent(edit_commands); |
| 2658 | } |
| 2659 | |
| 2660 | void RenderViewImpl::ClearEditCommands() { |
| 2661 | edit_commands_.clear(); |
| 2662 | } |
| 2663 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2664 | void RenderViewImpl::loadURLExternally( |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2665 | WebFrame* frame, const WebURLRequest& request, |
| 2666 | WebNavigationPolicy policy, |
| 2667 | const WebString& suggested_name) { |
[email protected] | 5650554 | 2012-05-12 00:25:37 | [diff] [blame] | 2668 | Referrer referrer( |
| 2669 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 2670 | GetReferrerPolicyFromRequest(frame, request)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2671 | if (policy == WebKit::WebNavigationPolicyDownload) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2672 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer, |
| 2673 | suggested_name)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2674 | } else { |
[email protected] | 5650554 | 2012-05-12 00:25:37 | [diff] [blame] | 2675 | OpenURL(frame, request.url(), referrer, policy); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2676 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2677 | } |
| 2678 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2679 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2680 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2681 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 099df81cf | 2012-11-14 17:44:04 | [diff] [blame] | 2682 | if (request.url() != GURL(kSwappedOutURL) && |
| 2683 | GetContentClient()->renderer()->HandleNavigation(frame, request, type, |
| 2684 | default_policy, |
| 2685 | is_redirect)) { |
| 2686 | return WebKit::WebNavigationPolicyIgnore; |
| 2687 | } |
| 2688 | |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2689 | Referrer referrer( |
| 2690 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 2691 | GetReferrerPolicyFromRequest(frame, request)); |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2692 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2693 | if (is_swapped_out_) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2694 | if (request.url() != GURL(kSwappedOutURL)) { |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2695 | // Targeted links may try to navigate a swapped out frame. Allow the |
| 2696 | // browser process to navigate the tab instead. Note that it is also |
| 2697 | // possible for non-targeted navigations (from this view) to arrive |
| 2698 | // here just after we are swapped out. It's ok to send them to the |
| 2699 | // browser, as long as they're for the top level frame. |
| 2700 | // TODO(creis): Ensure this supports targeted form submissions when |
| 2701 | // fixing http://crbug.com/101395. |
| 2702 | if (frame->parent() == NULL) { |
| 2703 | OpenURL(frame, request.url(), referrer, default_policy); |
| 2704 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2705 | } |
| 2706 | |
| 2707 | // We should otherwise ignore in-process iframe navigations, if they |
| 2708 | // arrive just after we are swapped out. |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2709 | return WebKit::WebNavigationPolicyIgnore; |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2710 | } |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2711 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2712 | // Allow kSwappedOutURL to complete. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2713 | return default_policy; |
| 2714 | } |
| 2715 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2716 | // Webkit is asking whether to navigate to a new URL. |
| 2717 | // This is fine normally, except if we're showing UI from one security |
| 2718 | // context and they're trying to navigate to a different context. |
| 2719 | const GURL& url = request.url(); |
| 2720 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2721 | // A content initiated navigation may have originated from a link-click, |
| 2722 | // script, drag-n-drop operation, etc. |
| 2723 | bool is_content_initiated = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2724 | DocumentState::FromDataSource(frame->provisionalDataSource())-> |
| 2725 | navigation_state()->is_content_initiated(); |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2726 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 2727 | // Experimental: |
| 2728 | // If --enable-strict-site-isolation is enabled, send all top-level |
| 2729 | // navigations to the browser to let it swap processes when crossing site |
| 2730 | // boundaries. This is currently expected to break some script calls and |
| 2731 | // navigations, such as form submissions. |
| 2732 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2733 | if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) && |
| 2734 | !frame->parent() && (is_content_initiated || is_redirect)) { |
| 2735 | WebString origin_str = frame->document().securityOrigin().toString(); |
| 2736 | GURL frame_url(origin_str.utf8().data()); |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 2737 | // TODO(cevans): revisit whether this site check is still necessary once |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2738 | // crbug.com/101395 is fixed. |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 2739 | if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url, |
| 2740 | url) || |
| 2741 | frame_url.scheme() != url.scheme()) { |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2742 | OpenURL(frame, url, referrer, default_policy); |
| 2743 | return WebKit::WebNavigationPolicyIgnore; |
| 2744 | } |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 2745 | } |
| 2746 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 2747 | // 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] | 2748 | if (is_content_initiated) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 2749 | bool browser_handles_request = |
| 2750 | renderer_preferences_.browser_handles_non_local_top_level_requests && |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 2751 | IsNonLocalTopLevelNavigation(url, frame, type); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 2752 | if (!browser_handles_request) { |
| 2753 | browser_handles_request = |
| 2754 | renderer_preferences_.browser_handles_all_top_level_requests && |
| 2755 | IsTopLevelNavigation(frame); |
| 2756 | } |
| 2757 | |
| 2758 | if (browser_handles_request) { |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 2759 | // Reset these counters as the RenderView could be reused for the next |
| 2760 | // navigation. |
| 2761 | page_id_ = -1; |
| 2762 | last_page_id_sent_to_browser_ = -1; |
| 2763 | OpenURL(frame, url, referrer, default_policy); |
| 2764 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2765 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2766 | } |
| 2767 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 2768 | // Use the frame's original request's URL rather than the document's URL for |
| 2769 | // subsequent checks. For a popup, the document's URL may become the opener |
| 2770 | // window's URL if the opener has called document.write(). |
| 2771 | // See http://crbug.com/93517. |
| 2772 | GURL old_url(frame->dataSource()->request().url()); |
| 2773 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2774 | // 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] | 2775 | // 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] | 2776 | // top-level navigations (not iframes). But we sometimes navigate to |
| 2777 | // about:blank to clear a tab, and we want to still allow that. |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2778 | // |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2779 | // Note: this is known to break POST submissions when crossing process |
| 2780 | // boundaries until http://crbug.com/101395 is fixed. This is better for |
| 2781 | // security than loading a WebUI, extension or app page in the wrong process. |
| 2782 | // POST requests don't work because this mechanism does not preserve form |
| 2783 | // POST data. We will need to send the request's httpBody data up to the |
| 2784 | // browser process, and issue a special POST navigation in WebKit (via |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 2785 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 2786 | // for examples of how to send the httpBody data. |
[email protected] | 2762a1b | 2011-12-09 15:25:22 | [diff] [blame] | 2787 | if (!frame->parent() && is_content_initiated && |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2788 | !url.SchemeIs(chrome::kAboutScheme)) { |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2789 | bool send_referrer = false; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2790 | |
| 2791 | // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses |
| 2792 | // must be handled by the browser process so that the correct bindings and |
| 2793 | // data sources can be registered. |
| 2794 | // Similarly, navigations to view-source URLs or within ViewSource mode |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 2795 | // must be handled by the browser process (except for reloads - those are |
| 2796 | // safe to leave within the renderer). |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 2797 | // Lastly, access to file:// URLs from non-file:// URL pages must be |
| 2798 | // handled by the browser so that ordinary renderer processes don't get |
| 2799 | // blessed with file permissions. |
| 2800 | int cumulative_bindings = RenderProcess::current()->GetEnabledBindings(); |
| 2801 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2802 | bool should_fork = |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2803 | GetContentClient()->HasWebUIScheme(url) || |
| 2804 | (cumulative_bindings & BINDINGS_POLICY_WEB_UI) || |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2805 | url.SchemeIs(chrome::kViewSourceScheme) || |
[email protected] | 1c210f69 | 2012-11-06 22:31:47 | [diff] [blame] | 2806 | (frame->isViewSourceModeEnabled() && |
| 2807 | type != WebKit::WebNavigationTypeReload); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2808 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 2809 | if (!should_fork && url.SchemeIs(chrome::kFileScheme)) { |
| 2810 | // Fork non-file to file opens. Check the opener URL if this is the |
| 2811 | // initial navigation in a newly opened window. |
| 2812 | GURL source_url(old_url); |
| 2813 | if (is_initial_navigation && source_url.is_empty() && frame->opener()) |
| 2814 | source_url = frame->opener()->top()->document().url(); |
| 2815 | DCHECK(!source_url.is_empty()); |
| 2816 | should_fork = !source_url.SchemeIs(chrome::kFileScheme); |
| 2817 | } |
| 2818 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2819 | if (!should_fork) { |
| 2820 | // Give the embedder a chance. |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2821 | // For now, we skip this for POST submissions. This is because |
| 2822 | // http://crbug.com/101395 is more likely to cause compatibility issues |
| 2823 | // with hosted apps and extensions than WebUI pages. We will remove this |
| 2824 | // check when cross-process POST submissions are supported. |
| 2825 | if (request.httpMethod() == "GET") { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2826 | should_fork = GetContentClient()->renderer()->ShouldFork( |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2827 | frame, url, is_initial_navigation, &send_referrer); |
| 2828 | } |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | if (should_fork) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2832 | OpenURL( |
| 2833 | frame, url, send_referrer ? referrer : Referrer(), default_policy); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2834 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2835 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2839 | // its own process. This is done by sites like Gmail that try to open links |
| 2840 | // in new windows without script connections back to the original page. We |
| 2841 | // treat such cases as browser navigations (in which we will create a new |
| 2842 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2843 | // |
| 2844 | // We use the following heuristic to decide whether to fork a new page in its |
| 2845 | // own process: |
| 2846 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2847 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2848 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2849 | // |
| 2850 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2851 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2852 | bool is_fork = |
| 2853 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2854 | old_url == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2855 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2856 | historyBackListCount() < 1 && |
| 2857 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2858 | // The parent page must have set the child's window.opener to null before |
| 2859 | // redirecting to the desired URL. |
| 2860 | frame->opener() == NULL && |
| 2861 | // Must be a top-level frame. |
| 2862 | frame->parent() == NULL && |
| 2863 | // Must not have issued the request from this page. |
| 2864 | is_content_initiated && |
| 2865 | // Must be targeted at the current tab. |
| 2866 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2867 | // Must be a JavaScript navigation, which appears as "other". |
| 2868 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2869 | |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2870 | if (is_fork) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2871 | // Open the URL via the browser, not via WebKit. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2872 | OpenURL(frame, url, Referrer(), default_policy); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2873 | return WebKit::WebNavigationPolicyIgnore; |
| 2874 | } |
| 2875 | |
| 2876 | return default_policy; |
| 2877 | } |
| 2878 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2879 | bool RenderViewImpl::canHandleRequest( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2880 | WebFrame* frame, const WebURLRequest& request) { |
| 2881 | // We allow WebKit to think that everything can be handled even though |
| 2882 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2883 | return true; |
| 2884 | } |
| 2885 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2886 | WebURLError RenderViewImpl::cannotHandleRequestError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2887 | WebFrame* frame, const WebURLRequest& request) { |
| 2888 | NOTREACHED(); // Since we said we can handle all requests. |
| 2889 | return WebURLError(); |
| 2890 | } |
| 2891 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2892 | WebURLError RenderViewImpl::cancelledError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2893 | WebFrame* frame, const WebURLRequest& request) { |
| 2894 | WebURLError error; |
| 2895 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2896 | error.reason = net::ERR_ABORTED; |
| 2897 | error.unreachableURL = request.url(); |
| 2898 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2899 | } |
| 2900 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2901 | void RenderViewImpl::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2902 | WebFrame*, const WebURLError&) { |
| 2903 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2904 | } |
| 2905 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2906 | void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame, |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2907 | const WebKit::WebFormElement& form) { |
| 2908 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2909 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2910 | // This method gets called before any of those handlers run, so save away |
| 2911 | // a copy of the password in case it gets lost. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2912 | DocumentState* document_state = |
| 2913 | DocumentState::FromDataSource(frame->dataSource()); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2914 | document_state->set_password_form_data(CreatePasswordForm(form)); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2915 | } |
| 2916 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2917 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 2918 | const WebFormElement& form) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2919 | DocumentState* document_state = |
| 2920 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
| 2921 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2922 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2923 | if (navigation_state->transition_type() == PAGE_TRANSITION_LINK) |
| 2924 | navigation_state->set_transition_type(PAGE_TRANSITION_FORM_SUBMIT); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2925 | |
| 2926 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2927 | WebSearchableFormData web_searchable_form_data(form); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2928 | document_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2929 | document_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2930 | web_searchable_form_data.encoding().utf8()); |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 2931 | scoped_ptr<PasswordForm> password_form_data = |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2932 | CreatePasswordForm(form); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2933 | |
[email protected] | 098c95cb | 2011-04-28 16:49:01 | [diff] [blame] | 2934 | // In order to save the password that the user actually typed and not one |
| 2935 | // that may have gotten transformed by the site prior to submit, recover it |
| 2936 | // from the form contents already stored by |willSendSubmitEvent| into the |
| 2937 | // dataSource's NavigationState (as opposed to the provisionalDataSource's, |
| 2938 | // which is what we're storing into now.) |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 2939 | if (password_form_data.get()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2940 | DocumentState* old_document_state = |
| 2941 | DocumentState::FromDataSource(frame->dataSource()); |
| 2942 | if (old_document_state) { |
| 2943 | PasswordForm* old_form_data = old_document_state->password_form_data(); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2944 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2945 | password_form_data->password_value = old_form_data->password_value; |
| 2946 | } |
| 2947 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2948 | |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 2949 | document_state->set_password_form_data(password_form_data.Pass()); |
| 2950 | |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 2951 | FOR_EACH_OBSERVER( |
| 2952 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2953 | } |
| 2954 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2955 | void RenderViewImpl::willPerformClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2956 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2957 | double fire_time) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 2958 | // Replace any occurrences of swappedout:// with about:blank. |
| 2959 | const WebURL& blank_url = GURL(chrome::kAboutBlankURL); |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2960 | FOR_EACH_OBSERVER( |
| 2961 | RenderViewObserver, observers_, |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 2962 | WillPerformClientRedirect(frame, |
| 2963 | from == GURL(kSwappedOutURL) ? blank_url : from, |
| 2964 | to, interval, fire_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2965 | } |
| 2966 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2967 | void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2968 | FOR_EACH_OBSERVER( |
| 2969 | RenderViewObserver, observers_, DidCancelClientRedirect(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2970 | } |
| 2971 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2972 | void RenderViewImpl::didCompleteClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2973 | WebFrame* frame, const WebURL& from) { |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 2974 | // Replace any occurrences of swappedout:// with about:blank. |
| 2975 | const WebURL& blank_url = GURL(chrome::kAboutBlankURL); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2976 | if (!frame->parent()) { |
| 2977 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2978 | // If there's no provisional data source, it's a reference fragment |
| 2979 | // navigation. |
| 2980 | completed_client_redirect_src_ = Referrer( |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 2981 | from == GURL(kSwappedOutURL) ? blank_url : from, |
| 2982 | ds ? GetReferrerPolicyFromRequest(frame, ds->request()) : |
[email protected] | f36f409 | 2012-05-09 18:31:04 | [diff] [blame] | 2983 | frame->document().referrerPolicy()); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2984 | } |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2985 | FOR_EACH_OBSERVER( |
[email protected] | bf692cd | 2012-11-14 19:10:02 | [diff] [blame] | 2986 | RenderViewObserver, observers_, DidCompleteClientRedirect( |
| 2987 | frame, from == GURL(kSwappedOutURL) ? blank_url : from)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2988 | } |
| 2989 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2990 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2991 | bool content_initiated = !pending_navigation_params_.get(); |
| 2992 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2993 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2994 | if (!document_state) { |
| 2995 | document_state = new DocumentState; |
| 2996 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2997 | if (!content_initiated) |
| 2998 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2999 | } |
| 3000 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3001 | // Carry over the user agent override flag, if it exists. |
| 3002 | if (content_initiated && webview() && webview()->mainFrame() && |
| 3003 | webview()->mainFrame()->dataSource()) { |
| 3004 | DocumentState* old_document_state = |
| 3005 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 3006 | if (old_document_state) { |
| 3007 | document_state->set_is_overriding_user_agent( |
| 3008 | old_document_state->is_overriding_user_agent()); |
| 3009 | } |
| 3010 | } |
| 3011 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3012 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 3013 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3014 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3015 | document_state->set_navigation_state( |
| 3016 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3017 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3018 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 3019 | pending_navigation_params_.reset(); |
| 3020 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3021 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3022 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3023 | // navigating from a page that used prefetching using a link on that |
| 3024 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3025 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3026 | // this value appropriately. |
| 3027 | // TODO(gavinp): catch the important case of navigation in a new |
| 3028 | // renderer process. |
| 3029 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3030 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3031 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3032 | const GURL referrer( |
| 3033 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 3034 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3035 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3036 | old_frame->dataSource())->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 3037 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3038 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 3039 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3040 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3041 | break; |
| 3042 | } |
| 3043 | } |
| 3044 | } |
| 3045 | } |
| 3046 | } |
| 3047 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3048 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3049 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3050 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3051 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3052 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3053 | break; |
| 3054 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3055 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3056 | break; |
| 3057 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3058 | document_state->set_load_type( |
| 3059 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3060 | break; |
| 3061 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3062 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3063 | break; |
| 3064 | } |
| 3065 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3066 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 3067 | FOR_EACH_OBSERVER( |
| 3068 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3069 | } |
| 3070 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3071 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3072 | DocumentState* document_state) { |
| 3073 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3074 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3075 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3076 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme) && |
| 3077 | params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
| 3078 | // We're doing a load of a page that was restored from the last session. By |
| 3079 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 3080 | // can result in stale data for pages that are set to expire. We explicitly |
| 3081 | // override that by setting the policy here so that as necessary we load |
| 3082 | // from the network. |
| 3083 | document_state->set_cache_policy_override( |
| 3084 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | if (IsReload(params)) |
| 3088 | document_state->set_load_type(DocumentState::RELOAD); |
| 3089 | else if (!params.state.empty()) |
| 3090 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 3091 | else |
| 3092 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3093 | |
| 3094 | document_state->set_referrer_policy(params.referrer.policy); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3095 | document_state->set_is_overriding_user_agent(params.is_overriding_user_agent); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3096 | document_state->set_must_reset_scroll_and_scale_state( |
| 3097 | params.navigation_type == |
| 3098 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 3099 | document_state->set_can_load_local_resources(params.can_load_local_resources); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3100 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3101 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3102 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
| 3103 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
| 3104 | NavigationState* navigation_state = NULL; |
| 3105 | |
| 3106 | // A navigation resulting from loading a javascript URL should not be treated |
| 3107 | // as a browser initiated event. Instead, we want it to look as if the page |
| 3108 | // initiated any load resulting from JS execution. |
| 3109 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 3110 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 3111 | params.page_id, |
| 3112 | params.pending_history_list_offset, |
| 3113 | params.transition); |
| 3114 | navigation_state->set_transferred_request_child_id( |
| 3115 | params.transferred_request_child_id); |
| 3116 | navigation_state->set_transferred_request_request_id( |
| 3117 | params.transferred_request_request_id); |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3118 | navigation_state->set_allow_download(params.allow_download); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3119 | } else { |
| 3120 | navigation_state = NavigationState::CreateContentInitiated(); |
| 3121 | } |
| 3122 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3123 | } |
| 3124 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3125 | void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) { |
| 3126 | bool enable_viewport = |
[email protected] | 06ea34a | 2012-05-07 18:52:10 | [diff] [blame] | 3127 | command_line.HasSwitch(switches::kEnableViewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3128 | bool enable_fixed_layout = |
| 3129 | command_line.HasSwitch(switches::kEnableFixedLayout); |
| 3130 | |
| 3131 | webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport); |
| 3132 | webview()->settings()->setFixedElementsLayoutRelativeToFrame(true); |
| 3133 | |
| 3134 | if (enable_viewport) { |
| 3135 | webview()->settings()->setViewportEnabled(true); |
| 3136 | } else if (enable_fixed_layout) { |
| 3137 | std::string str = |
| 3138 | command_line.GetSwitchValueASCII(switches::kEnableFixedLayout); |
| 3139 | std::vector<std::string> tokens; |
| 3140 | base::SplitString(str, ',', &tokens); |
| 3141 | if (tokens.size() == 2) { |
| 3142 | int width, height; |
| 3143 | if (base::StringToInt(tokens[0], &width) && |
| 3144 | base::StringToInt(tokens[1], &height)) |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3145 | webview()->setFixedLayoutSize(WebSize(width, height)); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3146 | } |
| 3147 | } |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 3148 | |
| 3149 | ProcessAcceleratedPinchZoomFlags(command_line); |
| 3150 | } |
| 3151 | |
| 3152 | void RenderViewImpl::ProcessAcceleratedPinchZoomFlags( |
| 3153 | const CommandLine& command_line) { |
| 3154 | bool enable_viewport = |
| 3155 | command_line.HasSwitch(switches::kEnableViewport); |
| 3156 | bool enable_pinch = enable_viewport || |
| 3157 | command_line.HasSwitch(switches::kEnablePinch); |
| 3158 | bool enable_pinch_in_compositor = |
[email protected] | 65bfd997 | 2012-10-19 03:39:37 | [diff] [blame] | 3159 | command_line.HasSwitch(cc::switches::kEnablePinchInCompositor); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 3160 | |
| 3161 | if (!enable_pinch && |
| 3162 | webview()->isAcceleratedCompositingActive() && |
| 3163 | webkit_preferences_.apply_default_device_scale_factor_in_compositor && |
| 3164 | device_scale_factor_ != 1) { |
| 3165 | // Page scaling is disabled by default when applying a scale factor in the |
| 3166 | // compositor since they are currently incompatible. |
| 3167 | webview()->setPageScaleFactorLimits(1, 1); |
| 3168 | } |
| 3169 | |
| 3170 | if (enable_pinch_in_compositor && |
| 3171 | webview()->isAcceleratedCompositingActive()) |
| 3172 | webview()->setPageScaleFactorLimits(1, 4); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3173 | } |
| 3174 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3175 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3176 | WebDataSource* ds = frame->provisionalDataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3177 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3178 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3179 | // Update the request time if WebKit has better knowledge of it. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3180 | if (document_state->request_time().is_null()) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3181 | double event_time = ds->triggeringEventTime(); |
| 3182 | if (event_time != 0.0) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3183 | document_state->set_request_time(Time::FromDoubleT(event_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3184 | } |
| 3185 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3186 | // Start time is only set after request time. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3187 | document_state->set_start_load_time(Time::Now()); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3188 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3189 | bool is_top_most = !frame->parent(); |
| 3190 | if (is_top_most) { |
| 3191 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3192 | NavigationGestureUser : NavigationGestureAuto; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3193 | |
| 3194 | // Make sure redirect tracking state is clear for the new load. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3195 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3196 | } else if (frame->parent()->isLoading()) { |
| 3197 | // 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] | 3198 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3199 | document_state->navigation_state()->set_transition_type( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3200 | PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3201 | } |
| 3202 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3203 | FOR_EACH_OBSERVER( |
| 3204 | RenderViewObserver, observers_, DidStartProvisionalLoad(frame)); |
| 3205 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3206 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | d37c33e | 2012-10-12 13:35:13 | [diff] [blame] | 3207 | routing_id_, frame->identifier(), |
| 3208 | frame->parent() ? frame->parent()->identifier() : -1, |
| 3209 | is_top_most, GetOpenerUrl(), ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3210 | } |
| 3211 | |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3212 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 3213 | WebFrame* frame) { |
| 3214 | if (frame->parent()) |
| 3215 | return; |
| 3216 | // Received a redirect on the main frame. |
| 3217 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3218 | if (!data_source) { |
| 3219 | // Should only be invoked when we have a data source. |
| 3220 | NOTREACHED(); |
| 3221 | return; |
| 3222 | } |
| 3223 | std::vector<GURL> redirects; |
| 3224 | GetRedirectChain(data_source, &redirects); |
| 3225 | if (redirects.size() >= 2) { |
| 3226 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 3227 | GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back())); |
| 3228 | } |
| 3229 | } |
| 3230 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3231 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 3232 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3233 | // Notify the browser that we failed a provisional load with an error. |
| 3234 | // |
| 3235 | // Note: It is important this notification occur before DidStopLoading so the |
| 3236 | // SSL manager can react to the provisional load failure before being |
| 3237 | // notified the load stopped. |
| 3238 | // |
| 3239 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3240 | DCHECK(ds); |
| 3241 | |
| 3242 | const WebURLRequest& failed_request = ds->request(); |
| 3243 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3244 | FOR_EACH_OBSERVER( |
| 3245 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 3246 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3247 | bool show_repost_interstitial = |
| 3248 | (error.reason == net::ERR_CACHE_MISS && |
| 3249 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3250 | |
| 3251 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 3252 | params.frame_id = frame->identifier(); |
| 3253 | params.is_main_frame = !frame->parent(); |
| 3254 | params.error_code = error.reason; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3255 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3256 | failed_request, |
| 3257 | error, |
| 3258 | NULL, |
| 3259 | ¶ms.error_description); |
| 3260 | params.url = error.unreachableURL; |
| 3261 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3262 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3263 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3264 | |
| 3265 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3266 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3267 | if (error.reason == net::ERR_ABORTED) |
| 3268 | return; |
| 3269 | |
| 3270 | // Make sure we never show errors in view source mode. |
| 3271 | frame->enableViewSourceMode(false); |
| 3272 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3273 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3274 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3275 | |
| 3276 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3277 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3278 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3279 | // as session history is concerned. |
| 3280 | // |
| 3281 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3282 | // the page id. |
| 3283 | // |
| 3284 | bool replace = |
| 3285 | navigation_state->pending_page_id() != -1 || |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3286 | navigation_state->transition_type() == |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3287 | PAGE_TRANSITION_AUTO_SUBFRAME; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3288 | |
| 3289 | // If we failed on a browser initiated request, then make sure that our error |
| 3290 | // page load is regarded as the same browser initiated request. |
| 3291 | if (!navigation_state->is_content_initiated()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3292 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 3293 | pending_navigation_params_->page_id = |
| 3294 | navigation_state->pending_page_id(); |
| 3295 | pending_navigation_params_->pending_history_list_offset = |
| 3296 | navigation_state->pending_history_list_offset(); |
| 3297 | pending_navigation_params_->transition = |
| 3298 | navigation_state->transition_type(); |
| 3299 | pending_navigation_params_->request_time = |
| 3300 | document_state->request_time(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | // Provide the user with a more helpful error page? |
| 3304 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3305 | return; |
| 3306 | |
| 3307 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3308 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3309 | } |
| 3310 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3311 | void RenderViewImpl::didReceiveDocumentData( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3312 | WebFrame* frame, const char* data, size_t data_len, |
| 3313 | bool& prevent_default) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3314 | DocumentState* document_state = |
| 3315 | DocumentState::FromDataSource(frame->dataSource()); |
| 3316 | document_state->set_use_error_page(false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3317 | } |
| 3318 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3319 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 3320 | bool is_new_navigation) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3321 | DocumentState* document_state = |
| 3322 | DocumentState::FromDataSource(frame->dataSource()); |
| 3323 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3324 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3325 | if (document_state->commit_load_time().is_null()) |
| 3326 | document_state->set_commit_load_time(Time::Now()); |
| 3327 | |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3328 | if (document_state->must_reset_scroll_and_scale_state()) { |
[email protected] | c38d49c | 2012-10-24 21:46:57 | [diff] [blame] | 3329 | #if defined(OS_ANDROID) // crbug.com/153907 |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3330 | webview()->resetScrollAndScaleState(); |
[email protected] | c38d49c | 2012-10-24 21:46:57 | [diff] [blame] | 3331 | #endif |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3332 | document_state->set_must_reset_scroll_and_scale_state(false); |
| 3333 | } |
| 3334 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3335 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 3336 | // When we perform a new navigation, we need to update the last committed |
| 3337 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3338 | UpdateSessionHistory(frame); |
| 3339 | |
| 3340 | // We bump our Page ID to correspond with the new session history entry. |
| 3341 | page_id_ = next_page_id_++; |
| 3342 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3343 | // Don't update history_page_ids_ (etc) for kSwappedOutURL, since |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 3344 | // 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] | 3345 | // never come back to kSwappedOutURL. Note that we have to call |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3346 | // UpdateSessionHistory and update page_id_ even in this case, so that |
| 3347 | // the current entry gets a state update and so that we don't send a |
| 3348 | // state update to the wrong entry when we swap back in. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3349 | if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3350 | // Advance our offset in session history, applying the length limit. |
| 3351 | // There is now no forward history. |
| 3352 | history_list_offset_++; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3353 | if (history_list_offset_ >= kMaxSessionHistoryEntries) |
| 3354 | history_list_offset_ = kMaxSessionHistoryEntries - 1; |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3355 | history_list_length_ = history_list_offset_ + 1; |
| 3356 | history_page_ids_.resize(history_list_length_, -1); |
| 3357 | history_page_ids_[history_list_offset_] = page_id_; |
| 3358 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3359 | } else { |
| 3360 | // Inspect the navigation_state on this frame to see if the navigation |
| 3361 | // corresponds to a session history navigation... Note: |frame| may or |
| 3362 | // may not be the toplevel frame, but for the case of capturing session |
| 3363 | // history, the first committed frame suffices. We keep track of whether |
| 3364 | // we've seen this commit before so that only capture session history once |
| 3365 | // per navigation. |
| 3366 | // |
| 3367 | // Note that we need to check if the page ID changed. In the case of a |
| 3368 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3369 | // previous URL and the current page ID, which would be wrong. |
| 3370 | if (navigation_state->pending_page_id() != -1 && |
| 3371 | navigation_state->pending_page_id() != page_id_ && |
| 3372 | !navigation_state->request_committed()) { |
| 3373 | // This is a successful session history navigation! |
| 3374 | UpdateSessionHistory(frame); |
| 3375 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3376 | |
| 3377 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 3378 | |
| 3379 | // If the history list is valid, our list of page IDs should be correct. |
| 3380 | DCHECK(history_list_length_ <= 0 || |
| 3381 | history_list_offset_ < 0 || |
| 3382 | history_list_offset_ >= history_list_length_ || |
| 3383 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3384 | } |
| 3385 | } |
| 3386 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3387 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3388 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 3389 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3390 | // Remember that we've already processed this request, so we don't update |
| 3391 | // the session history again. We do this regardless of whether this is |
| 3392 | // a session history navigation, because if we attempted a session history |
| 3393 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3394 | // new navigation. |
| 3395 | navigation_state->set_request_committed(true); |
| 3396 | |
| 3397 | UpdateURL(frame); |
| 3398 | |
| 3399 | // If this committed load was initiated by a client redirect, we're |
| 3400 | // at the last stop now, so clear it. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3401 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3402 | |
| 3403 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3404 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 3405 | |
| 3406 | if (!frame->parent()) { // Only for top frames. |
| 3407 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 3408 | if (render_thread_impl) { // Can be NULL in tests. |
| 3409 | render_thread_impl->histogram_customizer()-> |
| 3410 | RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(), |
| 3411 | g_view_map.Get().size()); |
| 3412 | } |
| 3413 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3414 | } |
| 3415 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3416 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 3417 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3418 | DidClearWindowObject(frame)); |
| 3419 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3420 | GURL frame_url = frame->document().url(); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3421 | if ((enabled_bindings_ & BINDINGS_POLICY_WEB_UI) && |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3422 | (frame_url.SchemeIs(chrome::kChromeUIScheme) || |
| 3423 | frame_url.SchemeIs(chrome::kDataScheme))) { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 3424 | GetWebUIBindings()->BindToJavascript(frame, "chrome"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3425 | } |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3426 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3427 | if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) { |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3428 | if (!dom_automation_controller_.get()) |
| 3429 | dom_automation_controller_.reset(new DomAutomationController()); |
| 3430 | dom_automation_controller_->set_message_sender( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3431 | static_cast<RenderView*>(this)); |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3432 | dom_automation_controller_->set_routing_id(routing_id()); |
| 3433 | dom_automation_controller_->BindToJavascript(frame, |
| 3434 | "domAutomationController"); |
| 3435 | } |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 3436 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3437 | InjectDoNotTrackBindings(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3438 | } |
| 3439 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3440 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3441 | // Notify the browser about non-blank documents loading in the top frame. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3442 | GURL url = frame->document().url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 3443 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 87717d0e | 2012-04-26 02:58:43 | [diff] [blame] | 3444 | if (frame == webview()->mainFrame()) |
| 3445 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3446 | } |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3447 | |
| 3448 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3449 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3450 | } |
| 3451 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3452 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 3453 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 3454 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3455 | |
| 3456 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3457 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3458 | } |
| 3459 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3460 | void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) { |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 3461 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3462 | DidChangeIcon(frame, type)); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3463 | } |
| 3464 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3465 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3466 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3467 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3468 | document_state->set_finish_document_load_time(Time::Now()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3469 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 3470 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3471 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3472 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3473 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3474 | |
| 3475 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3476 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3477 | } |
| 3478 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3479 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3480 | if (webview()->mainFrame() == frame) { |
| 3481 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3482 | page_id_)); |
| 3483 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3484 | } |
| 3485 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3486 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3487 | WebDataSource* ds = frame->dataSource(); |
| 3488 | DCHECK(ds); |
| 3489 | |
| 3490 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3491 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3492 | |
| 3493 | const WebURLRequest& failed_request = ds->request(); |
| 3494 | string16 error_description; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3495 | GetContentClient()->renderer()->GetNavigationErrorStrings( |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3496 | failed_request, |
| 3497 | error, |
| 3498 | NULL, |
| 3499 | &error_description); |
| 3500 | Send(new ViewHostMsg_DidFailLoadWithError(routing_id_, |
| 3501 | frame->identifier(), |
| 3502 | failed_request.url(), |
| 3503 | !frame->parent(), |
| 3504 | error.reason, |
| 3505 | error_description)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3506 | } |
| 3507 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3508 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3509 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3510 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3511 | if (document_state->finish_load_time().is_null()) |
| 3512 | document_state->set_finish_load_time(Time::Now()); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3513 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3514 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 3515 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3516 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, |
| 3517 | frame->identifier(), |
| 3518 | ds->request().url(), |
| 3519 | !frame->parent())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3520 | } |
| 3521 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3522 | void RenderViewImpl::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3523 | WebFrame* frame, bool is_new_navigation) { |
| 3524 | // If this was a reference fragment navigation that we initiated, then we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3525 | // 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] | 3526 | // update the ExtraData on the datasource so that others who read the |
| 3527 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3528 | // initiate this navigation, then we need to take care to reset any pre- |
| 3529 | // existing navigation state to a content-initiated navigation state. |
| 3530 | // DidCreateDataSource conveniently takes care of this for us. |
| 3531 | didCreateDataSource(frame, frame->dataSource()); |
| 3532 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3533 | DocumentState* document_state = |
| 3534 | DocumentState::FromDataSource(frame->dataSource()); |
| 3535 | NavigationState* new_state = document_state->navigation_state(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3536 | new_state->set_was_within_same_page(true); |
| 3537 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3538 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3539 | |
[email protected] | 750fcf87 | 2011-08-03 23:10:47 | [diff] [blame] | 3540 | WebDataSource* datasource = frame->view()->mainFrame()->dataSource(); |
| 3541 | UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3542 | } |
| 3543 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3544 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3545 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3546 | } |
| 3547 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3548 | void RenderViewImpl::assignIdentifierToRequest( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3549 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3550 | // Ignore |
| 3551 | } |
| 3552 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3553 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 3554 | unsigned identifier, |
| 3555 | WebURLRequest& request, |
| 3556 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3557 | WebFrame* top_frame = frame->top(); |
| 3558 | if (!top_frame) |
| 3559 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3560 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 3561 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 3562 | WebDataSource* data_source = |
| 3563 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 3564 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3565 | PageTransition transition_type = PAGE_TRANSITION_LINK; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3566 | DocumentState* document_state = DocumentState::FromDataSource(data_source); |
[email protected] | def55e02 | 2012-07-26 01:15:29 | [diff] [blame] | 3567 | DCHECK(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3568 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3569 | transition_type = navigation_state->transition_type(); |
| 3570 | |
| 3571 | GURL request_url(request.url()); |
| 3572 | GURL new_url; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3573 | if (GetContentClient()->renderer()->WillSendRequest( |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3574 | frame, transition_type, request_url, &new_url)) { |
| 3575 | request.setURL(WebURL(new_url)); |
| 3576 | } |
| 3577 | |
[email protected] | def55e02 | 2012-07-26 01:15:29 | [diff] [blame] | 3578 | if (document_state->is_cache_policy_override_set()) |
| 3579 | request.setCachePolicy(document_state->cache_policy_override()); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3580 | |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3581 | WebKit::WebReferrerPolicy referrer_policy; |
| 3582 | if (document_state && document_state->is_referrer_policy_set()) { |
| 3583 | referrer_policy = document_state->referrer_policy(); |
| 3584 | document_state->clear_referrer_policy(); |
| 3585 | } else { |
| 3586 | referrer_policy = frame->document().referrerPolicy(); |
| 3587 | } |
| 3588 | |
[email protected] | e372f3d | 2012-07-17 19:16:44 | [diff] [blame] | 3589 | // The request's extra data may indicate that we should set a custom user |
| 3590 | // agent. This needs to be done here, after WebKit is through with setting the |
| 3591 | // user agent on its own. |
| 3592 | WebString custom_user_agent; |
| 3593 | if (request.extraData()) { |
| 3594 | webkit_glue::WebURLRequestExtraDataImpl* old_extra_data = |
| 3595 | static_cast<webkit_glue::WebURLRequestExtraDataImpl*>( |
| 3596 | request.extraData()); |
| 3597 | custom_user_agent = old_extra_data->custom_user_agent(); |
| 3598 | |
| 3599 | if (!custom_user_agent.isNull()) { |
| 3600 | if (custom_user_agent.isEmpty()) |
| 3601 | request.clearHTTPHeaderField("User-Agent"); |
| 3602 | else |
| 3603 | request.setHTTPHeaderField("User-Agent", custom_user_agent); |
| 3604 | } |
| 3605 | } |
| 3606 | |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 3607 | request.setExtraData( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3608 | new RequestExtraData(referrer_policy, |
[email protected] | e372f3d | 2012-07-17 19:16:44 | [diff] [blame] | 3609 | custom_user_agent, |
[email protected] | 537fbe0 | 2011-11-24 00:58:06 | [diff] [blame] | 3610 | (frame == top_frame), |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 3611 | frame->identifier(), |
| 3612 | frame->parent() == top_frame, |
| 3613 | frame->parent() ? frame->parent()->identifier() : -1, |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3614 | navigation_state->allow_download(), |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 3615 | transition_type, |
| 3616 | navigation_state->transferred_request_child_id(), |
| 3617 | navigation_state->transferred_request_request_id())); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 3618 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3619 | DocumentState* top_document_state = |
| 3620 | DocumentState::FromDataSource(top_data_source); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 3621 | // TODO(gavinp): separate out prefetching and prerender field trials |
| 3622 | // if the rel=prerender rel type is sticking around. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3623 | if (top_document_state && |
[email protected] | 925dec1c | 2012-05-18 05:09:00 | [diff] [blame] | 3624 | request.targetType() == WebURLRequest::TargetIsPrefetch) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3625 | top_document_state->set_was_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3626 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3627 | request.setRequestorID(routing_id_); |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3628 | request.setHasUserGesture(frame->isProcessingUserGesture()); |
| 3629 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 3630 | if (!renderer_preferences_.enable_referrers) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 3631 | request.clearHTTPHeaderField("Referer"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3632 | } |
| 3633 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3634 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3635 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3636 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3637 | // Only do this for responses that correspond to a provisional data source |
| 3638 | // of the top-most frame. If we have a provisional data source, then we |
| 3639 | // can't have any sub-resources yet, so we know that this response must |
| 3640 | // correspond to a frame load. |
| 3641 | if (!frame->provisionalDataSource() || frame->parent()) |
| 3642 | return; |
| 3643 | |
| 3644 | // 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] | 3645 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3646 | if (frame->isViewSourceModeEnabled()) |
| 3647 | return; |
| 3648 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3649 | DocumentState* document_state = |
| 3650 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3651 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3652 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3653 | // Record page load flags. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3654 | document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 3655 | document_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 3656 | WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response); |
| 3657 | if (extra_data) { |
| 3658 | document_state->set_npn_negotiated_protocol( |
| 3659 | extra_data->npn_negotiated_protocol()); |
| 3660 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3661 | document_state->set_was_alternate_protocol_available( |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 3662 | response.wasAlternateProtocolAvailable()); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3663 | document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
| 3664 | document_state->set_http_status_code(http_status_code); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3665 | // Whether or not the http status code actually corresponds to an error is |
| 3666 | // only checked when the page is done loading, if |use_error_page| is |
| 3667 | // still true. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3668 | document_state->set_use_error_page(true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3669 | } |
| 3670 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3671 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3672 | WebFrame* frame, unsigned identifier) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3673 | DocumentState* document_state = |
| 3674 | DocumentState::FromDataSource(frame->dataSource()); |
| 3675 | if (!document_state->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3676 | return; |
| 3677 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 3678 | // Do not show error page when DevTools is attached. |
| 3679 | if (devtools_agent_->IsAttached()) |
| 3680 | return; |
| 3681 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3682 | // Display error page, if appropriate. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3683 | int http_status_code = document_state->http_status_code(); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3684 | if (http_status_code == 404) { |
| 3685 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3686 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3687 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3688 | const GURL& error_page_url = |
| 3689 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3690 | if (error_page_url.is_valid()) { |
| 3691 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 3692 | original_error.domain = "http"; |
| 3693 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3694 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3695 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3696 | document_state->set_alt_error_page_fetcher( |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3697 | new AltErrorPageResourceFetcher( |
| 3698 | error_page_url, frame, original_error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 3699 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 3700 | base::Unretained(this)))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3701 | return; |
| 3702 | } |
| 3703 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3704 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3705 | std::string error_domain; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3706 | if (GetContentClient()->renderer()->HasErrorPage( |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3707 | http_status_code, &error_domain)) { |
| 3708 | WebURLError error; |
| 3709 | error.unreachableURL = frame->document().url(); |
| 3710 | error.domain = WebString::fromUTF8(error_domain); |
| 3711 | error.reason = http_status_code; |
| 3712 | |
| 3713 | LoadNavigationErrorPage( |
| 3714 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 3715 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3716 | } |
| 3717 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3718 | void RenderViewImpl::didFailResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3719 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3720 | // Ignore |
| 3721 | } |
| 3722 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3723 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3724 | WebFrame* frame, const WebURLRequest& request, |
| 3725 | const WebURLResponse& response) { |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 3726 | // The recipients of this message have no use for data: URLs: they don't |
| 3727 | // affect the page's insecure content list and are not in the disk cache. To |
| 3728 | // prevent large (1M+) data: URLs from crashing in the IPC system, we simply |
| 3729 | // filter them out here. |
| 3730 | GURL url(request.url()); |
| 3731 | if (url.SchemeIs("data")) |
| 3732 | return; |
| 3733 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3734 | // Let the browser know we loaded a resource from the memory cache. This |
| 3735 | // message is needed to display the correct SSL indicators. |
| 3736 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 3737 | routing_id_, |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 3738 | url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3739 | response.securityInfo(), |
| 3740 | request.httpMethod().utf8(), |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 3741 | response.mimeType().utf8(), |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3742 | ResourceType::FromTargetType(request.targetType()))); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3743 | } |
| 3744 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3745 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3746 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 3747 | } |
| 3748 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3749 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3750 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3751 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 3752 | routing_id_, |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3753 | origin.toString().utf8(), |
| 3754 | target)); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3755 | } |
| 3756 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3757 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3758 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3759 | } |
| 3760 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3761 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 3762 | v8::Handle<v8::Context> context, |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3763 | int extension_group, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3764 | int world_id) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3765 | GetContentClient()->renderer()->DidCreateScriptContext( |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3766 | frame, context, extension_group, world_id); |
[email protected] | 7a137c9d | 2012-10-16 20:41:20 | [diff] [blame] | 3767 | |
| 3768 | intents_host_->DidCreateScriptContext( |
| 3769 | frame, context, extension_group, world_id); |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3770 | } |
| 3771 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3772 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 3773 | v8::Handle<v8::Context> context, |
| 3774 | int world_id) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3775 | GetContentClient()->renderer()->WillReleaseScriptContext( |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 3776 | frame, context, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3777 | } |
| 3778 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3779 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3780 | // We don't always want to send the change messages over IPC, only if we've |
| 3781 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 3782 | // message. |
| 3783 | if (!send_preferred_size_changes_ || !webview()) |
| 3784 | return; |
| 3785 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3786 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3787 | webview()->mainFrame()->documentElementScrollHeight()); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 3788 | |
| 3789 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 3790 | // so we need to adjust. |
| 3791 | double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel()); |
| 3792 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 3793 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 3794 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3795 | if (size == preferred_size_) |
| 3796 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3797 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3798 | preferred_size_ = size; |
| 3799 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3800 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3801 | } |
| 3802 | |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 3803 | WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D( |
| 3804 | const WebGraphicsContext3D::Attributes& attributes) { |
| 3805 | if (!webview()) |
| 3806 | return NULL; |
| 3807 | |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 3808 | // The WebGraphicsContext3DInProcessImpl code path is used for |
| 3809 | // layout tests (though not through this code) as well as for |
| 3810 | // debugging and bringing up new ports. |
| 3811 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) { |
| 3812 | return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( |
| 3813 | attributes, true); |
| 3814 | } else { |
| 3815 | GURL url; |
| 3816 | if (webview()->mainFrame()) |
| 3817 | url = GURL(webview()->mainFrame()->document().url()); |
| 3818 | else |
[email protected] | f89e173a | 2012-08-24 01:12:26 | [diff] [blame] | 3819 | url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 3820 | |
| 3821 | scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 3822 | new WebGraphicsContext3DCommandBufferImpl( |
| 3823 | surface_id(), |
| 3824 | url, |
| 3825 | RenderThreadImpl::current(), |
| 3826 | AsWeakPtr())); |
| 3827 | |
| 3828 | if (!context->Initialize( |
| 3829 | attributes, |
| 3830 | false /* bind generates resources */, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3831 | CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 3832 | return NULL; |
| 3833 | return context.release(); |
| 3834 | } |
| 3835 | } |
| 3836 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3837 | // The browser process needs to know the shape of the tree, as well as the names |
| 3838 | // and ids of all frames. This allows it to properly route JavaScript messages |
| 3839 | // across processes and frames. The serialization format is described in the |
| 3840 | // comments of the ViewMsg_FrameTreeUpdated message. |
| 3841 | // This function sends those updates to the browser and updates the RVH |
| 3842 | // corresponding to this object. It must be called on any events that modify |
| 3843 | // the tree structure or the names of any frames. |
| 3844 | void RenderViewImpl::SendUpdatedFrameTree( |
| 3845 | WebKit::WebFrame* exclude_frame_subtree) { |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 3846 | // TODO(nasko): Frame tree updates are causing issues with postMessage, as |
| 3847 | // described in http://crbug.com/153701. Disable them until a proper fix is |
| 3848 | // in place. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame, |
| 3852 | DictionaryValue* frame_tree) { |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 3853 | // TODO(nasko): Remove once http://crbug.com/153701 is fixed. |
| 3854 | DCHECK(false); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3855 | NavigateToSwappedOutURL(frame); |
| 3856 | |
| 3857 | string16 name; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3858 | if (frame_tree->GetString(kFrameTreeNodeNameKey, &name) && !name.empty()) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3859 | frame->setName(name); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3860 | |
| 3861 | int remote_id; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3862 | if (frame_tree->GetInteger(kFrameTreeNodeIdKey, &remote_id)) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3863 | active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(), |
| 3864 | remote_id)); |
| 3865 | |
| 3866 | ListValue* children; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3867 | if (!frame_tree->GetList(kFrameTreeNodeSubtreeKey, &children)) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3868 | return; |
| 3869 | |
[email protected] | 5fa9b36b | 2012-09-21 18:14:27 | [diff] [blame] | 3870 | // Create an invisible iframe tree in the swapped out page. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3871 | base::DictionaryValue* child; |
| 3872 | for (size_t i = 0; i < children->GetSize(); ++i) { |
| 3873 | if (!children->GetDictionary(i, &child)) |
| 3874 | continue; |
| 3875 | WebElement element = frame->document().createElement("iframe"); |
[email protected] | 5fa9b36b | 2012-09-21 18:14:27 | [diff] [blame] | 3876 | element.setAttribute("width", "0"); |
| 3877 | element.setAttribute("height", "0"); |
| 3878 | element.setAttribute("frameBorder", "0"); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3879 | if (frame->document().body().appendChild(element)) { |
| 3880 | WebFrame* subframe = WebFrame::fromFrameOwnerElement(element); |
| 3881 | if (subframe) |
| 3882 | CreateFrameTree(subframe, child); |
| 3883 | } else { |
| 3884 | LOG(ERROR) << "Failed to append created iframe element."; |
| 3885 | } |
| 3886 | } |
| 3887 | } |
| 3888 | |
[email protected] | d1a59e4 | 2012-10-03 18:05:35 | [diff] [blame] | 3889 | WebKit::WebFrame* RenderViewImpl::GetFrameByRemoteID(int remote_frame_id) { |
| 3890 | std::map<int, int>::const_iterator it = active_frame_id_map_.begin(); |
| 3891 | for (; it != active_frame_id_map_.end(); ++it) { |
| 3892 | if (it->second == remote_frame_id) |
| 3893 | return FindFrameByID(webview()->mainFrame(), it->first); |
| 3894 | } |
| 3895 | return NULL; |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3896 | } |
| 3897 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3898 | void RenderViewImpl::EnsureMediaStreamImpl() { |
[email protected] | 7082fb94 | 2012-05-16 23:44:59 | [diff] [blame] | 3899 | if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
[email protected] | 0838156 | 2012-05-15 20:55:40 | [diff] [blame] | 3900 | return; |
| 3901 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 3902 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3903 | if (!media_stream_dispatcher_) |
| 3904 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 3905 | |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 3906 | if (!media_stream_impl_) { |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3907 | media_stream_impl_ = new MediaStreamImpl( |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 3908 | this, |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3909 | media_stream_dispatcher_, |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3910 | RenderThreadImpl::current()->video_capture_impl_manager(), |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 3911 | RenderThreadImpl::current()->GetMediaStreamDependencyFactory()); |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3912 | } |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 3913 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3914 | } |
| 3915 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3916 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 3917 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3918 | if (webview()->mainFrame() != frame) |
| 3919 | return; |
| 3920 | WebView* frameView = frame->view(); |
| 3921 | if (!frameView) |
| 3922 | return; |
| 3923 | |
| 3924 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 3925 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 3926 | |
| 3927 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 3928 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 3929 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 3930 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 3931 | |
| 3932 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 3933 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 3934 | } |
[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 3935 | |
| 3936 | #if defined(OS_ANDROID) |
| 3937 | ScheduleUpdateFrameInfo(); |
| 3938 | #endif |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3939 | } |
| 3940 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3941 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3942 | WebSize offset = frame->scrollOffset(); |
| 3943 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 3944 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 3945 | |
| 3946 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 3947 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 3948 | |
| 3949 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 3950 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 3951 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 3952 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 3953 | |
| 3954 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 3955 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 3956 | } |
| 3957 | } |
| 3958 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3959 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3960 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3961 | |
| 3962 | if (webview()->mainFrame() == frame) |
| 3963 | UpdateScrollState(frame); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 3964 | |
| 3965 | FOR_EACH_OBSERVER( |
| 3966 | RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 3967 | |
| 3968 | #if defined(OS_ANDROID) |
| 3969 | if (webview()->mainFrame() == frame) |
| 3970 | ScheduleUpdateFrameInfo(); |
| 3971 | #endif |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3972 | } |
| 3973 | |
[email protected] | 4d0f818 | 2012-10-19 23:14:47 | [diff] [blame] | 3974 | #if defined(OS_ANDROID) |
| 3975 | void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) { |
| 3976 | if (frame != webview()->mainFrame()) |
| 3977 | return; |
| 3978 | |
| 3979 | // Update body background color if necessary. |
| 3980 | SkColor bg_color = webwidget_->backgroundColor(); |
| 3981 | |
| 3982 | // If not initialized, default to white. Note that 0 is different from black |
| 3983 | // as black still has alpha 0xFF. |
| 3984 | if (!bg_color) |
| 3985 | bg_color = SK_ColorWHITE; |
| 3986 | |
| 3987 | if (bg_color != body_background_color_) { |
| 3988 | body_background_color_ = bg_color; |
| 3989 | Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id_, bg_color)); |
| 3990 | } |
| 3991 | } |
| 3992 | #endif |
| 3993 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 3994 | void RenderViewImpl::SendFindReply(int request_id, |
| 3995 | int match_count, |
| 3996 | int ordinal, |
| 3997 | const WebRect& selection_rect, |
| 3998 | bool final_status_update) { |
| 3999 | #if defined(OS_ANDROID) |
| 4000 | if (synchronous_find_reply_message_.get()) { |
| 4001 | if (final_status_update) { |
| 4002 | ViewMsg_SynchronousFind::WriteReplyParams( |
| 4003 | synchronous_find_reply_message_.get(), |
| 4004 | match_count, |
| 4005 | match_count ? synchronous_find_active_match_ordinal_ : 0); |
| 4006 | Send(synchronous_find_reply_message_.release()); |
| 4007 | } |
| 4008 | return; |
| 4009 | } |
| 4010 | #endif |
| 4011 | |
| 4012 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4013 | request_id, |
| 4014 | match_count, |
| 4015 | selection_rect, |
| 4016 | ordinal, |
| 4017 | final_status_update)); |
| 4018 | } |
| 4019 | |
| 4020 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, |
| 4021 | int count, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4022 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4023 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 4024 | if (!count) |
| 4025 | active_match_ordinal = 0; |
| 4026 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4027 | // Send the search result over to the browser process. |
| 4028 | SendFindReply(request_id, |
| 4029 | count, |
| 4030 | active_match_ordinal, |
| 4031 | gfx::Rect(), |
| 4032 | final_update); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4033 | } |
| 4034 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4035 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 4036 | int active_match_ordinal, |
| 4037 | const WebRect& selection_rect) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4038 | #if defined(OS_ANDROID) |
| 4039 | // If this was a SynchronousFind request, we need to remember the ordinal |
| 4040 | // value here for replying when reportFindInPageMatchCount is called. |
| 4041 | if (synchronous_find_reply_message_.get()) { |
| 4042 | synchronous_find_active_match_ordinal_ = active_match_ordinal; |
| 4043 | return; |
| 4044 | } |
| 4045 | #endif |
| 4046 | |
| 4047 | SendFindReply(request_id, |
| 4048 | -1, |
| 4049 | active_match_ordinal, |
| 4050 | selection_rect, |
| 4051 | false); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 4052 | } |
| 4053 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4054 | void RenderViewImpl::openFileSystem( |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4055 | WebFrame* frame, |
| 4056 | WebFileSystem::Type type, |
| 4057 | long long size, |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 4058 | bool create, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4059 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 4060 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4061 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4062 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4063 | if (origin.isUnique()) { |
| 4064 | // Unique origins cannot store persistent state. |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 4065 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 4066 | return; |
| 4067 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4068 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 4069 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 4070 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 4071 | size, create, new WebFileSystemCallbackDispatcher(callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4072 | } |
| 4073 | |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 4074 | void RenderViewImpl::deleteFileSystem( |
| 4075 | WebFrame* frame, |
| 4076 | WebFileSystem::Type type , |
| 4077 | WebFileSystemCallbacks* callbacks) { |
| 4078 | DCHECK(callbacks); |
| 4079 | |
| 4080 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 4081 | if (origin.isUnique()) { |
| 4082 | // Unique origins cannot store persistent state. |
| 4083 | callbacks->didSucceed(); |
| 4084 | return; |
| 4085 | } |
| 4086 | |
| 4087 | ChildThread::current()->file_system_dispatcher()->DeleteFileSystem( |
| 4088 | GURL(origin.toString()), |
| 4089 | static_cast<fileapi::FileSystemType>(type), |
| 4090 | new WebFileSystemCallbackDispatcher(callbacks)); |
| 4091 | } |
| 4092 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4093 | void RenderViewImpl::queryStorageUsageAndQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4094 | WebFrame* frame, |
| 4095 | WebStorageQuotaType type, |
| 4096 | WebStorageQuotaCallbacks* callbacks) { |
| 4097 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4098 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4099 | if (origin.isUnique()) { |
| 4100 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4101 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 4102 | return; |
| 4103 | } |
| 4104 | ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 4105 | GURL(origin.toString()), |
| 4106 | static_cast<quota::StorageType>(type), |
| 4107 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4108 | } |
| 4109 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4110 | void RenderViewImpl::requestStorageQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4111 | WebFrame* frame, |
| 4112 | WebStorageQuotaType type, |
| 4113 | unsigned long long requested_size, |
| 4114 | WebStorageQuotaCallbacks* callbacks) { |
| 4115 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4116 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4117 | if (origin.isUnique()) { |
| 4118 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4119 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 4120 | return; |
| 4121 | } |
| 4122 | ChildThread::current()->quota_dispatcher()->RequestStorageQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 4123 | routing_id(), GURL(origin.toString()), |
| 4124 | static_cast<quota::StorageType>(type), requested_size, |
| 4125 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4126 | } |
| 4127 | |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4128 | void RenderViewImpl::registerIntentService( |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4129 | WebFrame* frame, const WebIntentServiceInfo& service) { |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 4130 | webkit_glue::WebIntentServiceData data(service); |
| 4131 | if (data.title.empty()) |
| 4132 | data.title = webview()->mainFrame()->document().title(); |
| 4133 | bool user_gesture = frame->isProcessingUserGesture(); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4134 | Send(new IntentsHostMsg_RegisterIntentService(routing_id_, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 4135 | data, |
| 4136 | user_gesture)); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4137 | } |
| 4138 | |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4139 | void RenderViewImpl::dispatchIntent( |
| 4140 | WebFrame* frame, const WebIntentRequest& intentRequest) { |
| 4141 | webkit_glue::WebIntentData intent_data(intentRequest.intent()); |
[email protected] | 4e1eb339 | 2012-05-18 00:08:05 | [diff] [blame] | 4142 | |
| 4143 | // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued() |
| 4144 | WebKit::WebMessagePortChannelArray* channels = |
| 4145 | intentRequest.intent().messagePortChannelsRelease(); |
| 4146 | if (channels) { |
| 4147 | for (size_t i = 0; i < channels->size(); ++i) { |
| 4148 | WebMessagePortChannelImpl* webchannel = |
| 4149 | static_cast<WebMessagePortChannelImpl*>((*channels)[i]); |
| 4150 | intent_data.message_port_ids.push_back(webchannel->message_port_id()); |
| 4151 | DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE); |
| 4152 | } |
| 4153 | delete channels; |
| 4154 | } |
| 4155 | |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4156 | int id = intents_host_->RegisterWebIntent(intentRequest); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4157 | Send(new IntentsHostMsg_WebIntentDispatch( |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4158 | routing_id_, intent_data, id)); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4159 | } |
| 4160 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4161 | bool RenderViewImpl::willCheckAndDispatchMessageEvent( |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4162 | WebKit::WebFrame* sourceFrame, |
| 4163 | WebKit::WebFrame* targetFrame, |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4164 | WebKit::WebSecurityOrigin target_origin, |
| 4165 | WebKit::WebDOMMessageEvent event) { |
| 4166 | if (!is_swapped_out_) |
| 4167 | return false; |
| 4168 | |
| 4169 | ViewMsg_PostMessage_Params params; |
| 4170 | params.data = event.data().toString(); |
| 4171 | params.source_origin = event.origin(); |
| 4172 | if (!target_origin.isNull()) |
| 4173 | params.target_origin = target_origin.toString(); |
| 4174 | |
| 4175 | // Include the routing ID for the source frame, which the browser process |
| 4176 | // will translate into the routing ID for the equivalent frame in the target |
| 4177 | // process. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4178 | params.source_routing_id = MSG_ROUTING_NONE; |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4179 | RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4180 | if (source_view) |
| 4181 | params.source_routing_id = source_view->routing_id(); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4182 | params.source_frame_id = sourceFrame->identifier(); |
| 4183 | |
| 4184 | // Include the process, route, and frame IDs of the target frame. This allows |
| 4185 | // the browser to detect races between this message being sent and the target |
| 4186 | // frame no longer being valid. |
| 4187 | params.target_process_id = target_process_id_; |
| 4188 | params.target_routing_id = target_routing_id_; |
| 4189 | |
| 4190 | std::map<int,int>::iterator it = active_frame_id_map_.find( |
| 4191 | targetFrame->identifier()); |
| 4192 | if (it != active_frame_id_map_.end()) { |
| 4193 | params.target_frame_id = it->second; |
| 4194 | } else { |
| 4195 | params.target_frame_id = 0; |
| 4196 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4197 | |
| 4198 | Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 4199 | return true; |
| 4200 | } |
| 4201 | |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 4202 | void RenderViewImpl::willOpenSocketStream( |
| 4203 | WebSocketStreamHandle* handle) { |
| 4204 | SocketStreamHandleData::AddToHandle(handle, routing_id_); |
| 4205 | } |
| 4206 | |
[email protected] | ccee486 | 2012-10-03 18:34:26 | [diff] [blame] | 4207 | void RenderViewImpl::willStartUsingPeerConnectionHandler( |
| 4208 | WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) { |
| 4209 | #if defined(ENABLE_WEBRTC) |
| 4210 | static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame); |
| 4211 | #endif |
| 4212 | } |
| 4213 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4214 | WebKit::WebString RenderViewImpl::userAgentOverride( |
| 4215 | WebKit::WebFrame* frame, |
| 4216 | const WebKit::WebURL& url) { |
| 4217 | if (!webview() || !webview()->mainFrame() || |
| 4218 | renderer_preferences_.user_agent_override.empty()) { |
| 4219 | return WebKit::WebString(); |
| 4220 | } |
| 4221 | |
| 4222 | // If we're in the middle of committing a load, the data source we need |
| 4223 | // will still be provisional. |
| 4224 | WebFrame* main_frame = webview()->mainFrame(); |
| 4225 | WebDataSource* data_source = NULL; |
| 4226 | if (main_frame->provisionalDataSource()) |
| 4227 | data_source = main_frame->provisionalDataSource(); |
| 4228 | else |
| 4229 | data_source = main_frame->dataSource(); |
| 4230 | |
| 4231 | DocumentState* document_state = |
| 4232 | data_source ? DocumentState::FromDataSource(data_source) : NULL; |
| 4233 | if (document_state && document_state->is_overriding_user_agent()) |
| 4234 | return WebString::fromUTF8(renderer_preferences_.user_agent_override); |
| 4235 | else |
| 4236 | return WebKit::WebString(); |
| 4237 | } |
| 4238 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4239 | // WebKit::WebPageSerializerClient implementation ------------------------------ |
| 4240 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4241 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4242 | const WebURL& frame_url, |
| 4243 | const WebCString& data, |
| 4244 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4245 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4246 | routing_id(), |
| 4247 | frame_url, |
| 4248 | data.data(), |
| 4249 | static_cast<int32>(status))); |
| 4250 | } |
| 4251 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4252 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4253 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4254 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4255 | return RenderWidget::Send(message); |
| 4256 | } |
| 4257 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4258 | int RenderViewImpl::GetRoutingID() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4259 | return routing_id_; |
| 4260 | } |
| 4261 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4262 | int RenderViewImpl::GetPageId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4263 | return page_id_; |
| 4264 | } |
| 4265 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4266 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4267 | return size(); |
| 4268 | } |
| 4269 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4270 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4271 | return webkit_preferences_; |
| 4272 | } |
| 4273 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4274 | WebKit::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4275 | return webview(); |
| 4276 | } |
| 4277 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4278 | WebKit::WebNode RenderViewImpl::GetFocusedNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4279 | if (!webview()) |
| 4280 | return WebNode(); |
| 4281 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 4282 | if (focused_frame) { |
| 4283 | WebDocument doc = focused_frame->document(); |
| 4284 | if (!doc.isNull()) |
| 4285 | return doc.focusedNode(); |
| 4286 | } |
| 4287 | |
| 4288 | return WebNode(); |
| 4289 | } |
| 4290 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4291 | WebKit::WebNode RenderViewImpl::GetContextMenuNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4292 | return context_menu_node_; |
| 4293 | } |
| 4294 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4295 | bool RenderViewImpl::IsEditableNode(const WebNode& node) const { |
| 4296 | if (node.isNull()) |
| 4297 | return false; |
| 4298 | |
| 4299 | if (node.isContentEditable()) |
| 4300 | return true; |
| 4301 | |
| 4302 | if (node.isElementNode()) { |
| 4303 | const WebElement& element = node.toConst<WebElement>(); |
| 4304 | if (element.isTextFormControlElement()) |
| 4305 | return true; |
| 4306 | |
| 4307 | // Also return true if it has an ARIA role of 'textbox'. |
| 4308 | for (unsigned i = 0; i < element.attributeCount(); ++i) { |
| 4309 | if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { |
| 4310 | if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) |
| 4311 | return true; |
| 4312 | break; |
| 4313 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4314 | } |
| 4315 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4316 | |
| 4317 | return false; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4318 | } |
| 4319 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4320 | WebKit::WebPlugin* RenderViewImpl::CreatePlugin( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4321 | WebKit::WebFrame* frame, |
| 4322 | const webkit::WebPluginInfo& info, |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4323 | const WebKit::WebPluginParams& params) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4324 | bool pepper_plugin_was_registered = false; |
| 4325 | scoped_refptr<webkit::ppapi::PluginModule> pepper_module( |
| 4326 | pepper_delegate_.CreatePepperPluginModule(info, |
| 4327 | &pepper_plugin_was_registered)); |
| 4328 | if (pepper_plugin_was_registered) { |
| 4329 | if (!pepper_module) |
| 4330 | return NULL; |
| 4331 | return new webkit::ppapi::WebPluginImpl( |
| 4332 | pepper_module.get(), params, pepper_delegate_.AsWeakPtr()); |
| 4333 | } |
| 4334 | |
[email protected] | 3e076a8 | 2012-09-11 19:12:36 | [diff] [blame] | 4335 | #if defined(USE_AURA) && !defined(OS_WIN) |
[email protected] | 34b27e44 | 2012-01-20 20:07:41 | [diff] [blame] | 4336 | return NULL; |
| 4337 | #else |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4338 | return new webkit::npapi::WebPluginImpl( |
| 4339 | frame, params, info.path, AsWeakPtr()); |
[email protected] | 34b27e44 | 2012-01-20 20:07:41 | [diff] [blame] | 4340 | #endif |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4341 | } |
| 4342 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4343 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 4344 | const string16& jscript, |
| 4345 | int id, |
| 4346 | bool notify_result) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4347 | v8::Handle<v8::Value> result; |
| 4348 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4349 | if (web_frame) |
| 4350 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 4351 | if (notify_result) { |
| 4352 | ListValue list; |
| 4353 | if (!result.IsEmpty() && web_frame) { |
| 4354 | v8::HandleScope handle_scope; |
| 4355 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 4356 | v8::Context::Scope context_scope(context); |
| 4357 | V8ValueConverterImpl converter; |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 4358 | converter.SetDateAllowed(true); |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 4359 | converter.SetRegExpAllowed(true); |
| 4360 | base::Value* result_value = converter.FromV8Value(result, context); |
| 4361 | list.Set(0, result_value ? result_value : |
| 4362 | base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4363 | } else { |
| 4364 | list.Set(0, Value::CreateNullValue()); |
| 4365 | } |
| 4366 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 4367 | } |
| 4368 | } |
| 4369 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4370 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4371 | return (!send_preferred_size_changes_ || |
| 4372 | (disable_scrollbars_size_limit_.width() <= width || |
| 4373 | disable_scrollbars_size_limit_.height() <= height)); |
| 4374 | } |
| 4375 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4376 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4377 | return enabled_bindings_; |
| 4378 | } |
| 4379 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4380 | bool RenderViewImpl::GetContentStateImmediately() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4381 | return send_content_state_immediately_; |
| 4382 | } |
| 4383 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4384 | float RenderViewImpl::GetFilteredTimePerFrame() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4385 | return filtered_time_per_frame(); |
| 4386 | } |
| 4387 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4388 | int RenderViewImpl::ShowContextMenu(ContextMenuClient* client, |
| 4389 | const ContextMenuParams& params) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4390 | DCHECK(client); // A null client means "internal" when we issue callbacks. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4391 | ContextMenuParams our_params(params); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 4392 | our_params.custom_context.request_id = pending_context_menus_.Add(client); |
| 4393 | Send(new ViewHostMsg_ContextMenu(routing_id_, our_params)); |
| 4394 | return our_params.custom_context.request_id; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4395 | } |
| 4396 | |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 4397 | void RenderViewImpl::CancelContextMenu(int request_id) { |
| 4398 | DCHECK(pending_context_menus_.Lookup(request_id)); |
| 4399 | pending_context_menus_.Remove(request_id); |
| 4400 | } |
| 4401 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4402 | WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4403 | return visibilityState(); |
| 4404 | } |
| 4405 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4406 | void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame, |
| 4407 | const WebKit::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4408 | return runModalAlertDialog(frame, message); |
| 4409 | } |
| 4410 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4411 | void RenderViewImpl::LoadURLExternally( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4412 | WebKit::WebFrame* frame, |
| 4413 | const WebKit::WebURLRequest& request, |
| 4414 | WebKit::WebNavigationPolicy policy) { |
| 4415 | loadURLExternally(frame, request, policy); |
| 4416 | } |
| 4417 | |
| 4418 | // webkit_glue::WebPluginPageDelegate ------------------------------------------ |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 4419 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4420 | webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 4421 | const FilePath& file_path, |
| 4422 | const std::string& mime_type) { |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 4423 | if (!PluginChannelHost::IsListening()) { |
| 4424 | LOG(ERROR) << "PluginChannelHost isn't listening"; |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4425 | return NULL; |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 4426 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4427 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4428 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 4429 | if (in_process_plugin) { |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 4430 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 3b21be9 | 2012-11-02 06:00:02 | [diff] [blame] | 4431 | return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 4432 | #else |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 4433 | // In-proc plugins aren't supported on non-Windows. |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 4434 | NOTIMPLEMENTED(); |
| 4435 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 4436 | #endif |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4437 | } |
| 4438 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 4439 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4440 | } |
| 4441 | |
[email protected] | 6ac77cb | 2012-05-01 14:49:01 | [diff] [blame] | 4442 | WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement( |
| 4443 | const FilePath& file_path) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4444 | return GetContentClient()->renderer()->CreatePluginReplacement( |
[email protected] | 6ac77cb | 2012-05-01 14:49:01 | [diff] [blame] | 4445 | this, file_path); |
| 4446 | } |
| 4447 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4448 | void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 4449 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 4450 | Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4451 | #endif |
| 4452 | } |
| 4453 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4454 | void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 4455 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 4456 | Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4457 | #endif |
| 4458 | CleanupWindowInPluginMoves(window); |
| 4459 | } |
| 4460 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4461 | void RenderViewImpl::DidMovePlugin( |
| 4462 | const webkit::npapi::WebPluginGeometry& move) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4463 | SchedulePluginMove(move); |
| 4464 | } |
| 4465 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4466 | void RenderViewImpl::DidStartLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4467 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 4468 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4469 | } |
| 4470 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4471 | void RenderViewImpl::DidStopLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4472 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 4473 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4474 | } |
| 4475 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4476 | WebCookieJar* RenderViewImpl::GetCookieJar() { |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 4477 | return &cookie_jar_; |
| 4478 | } |
| 4479 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4480 | void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4481 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4482 | reinterpret_cast<int64>(player), |
| 4483 | player->hasVideo(), |
| 4484 | player->hasAudio(), |
| 4485 | true)); |
| 4486 | } |
| 4487 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4488 | void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4489 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4490 | reinterpret_cast<int64>(player), |
| 4491 | player->hasVideo(), |
| 4492 | player->hasAudio(), |
| 4493 | false)); |
| 4494 | } |
| 4495 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4496 | void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4497 | DidPause(player); |
| 4498 | } |
| 4499 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4500 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4501 | if (!webview()) |
| 4502 | return; |
| 4503 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4504 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 4505 | SendUpdateState(item); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4506 | } |
| 4507 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4508 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4509 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4510 | if (!frame) |
| 4511 | return; |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4512 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4513 | string16 text; |
| 4514 | size_t offset; |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4515 | ui::Range range; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4516 | |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4517 | if (pepper_delegate_.IsPluginFocused()) { |
| 4518 | pepper_delegate_.GetSurroundingText(&text, &range); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4519 | offset = 0; // Pepper API does not support offset reporting. |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4520 | // TODO(kinaba): cut as needed. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4521 | } else { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4522 | size_t location, length; |
| 4523 | if (!webview()->caretOrSelectionRange(&location, &length)) |
| 4524 | return; |
| 4525 | |
| 4526 | range = ui::Range(location, location + length); |
| 4527 | |
| 4528 | if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { |
| 4529 | // If current focused element is editable, we will send 100 more chars |
| 4530 | // before and after selection. It is for input method surrounding text |
| 4531 | // feature. |
| 4532 | if (location > kExtraCharsBeforeAndAfterSelection) |
| 4533 | offset = location - kExtraCharsBeforeAndAfterSelection; |
| 4534 | else |
| 4535 | offset = 0; |
| 4536 | length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 4537 | WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 4538 | if (!webrange.isNull()) |
| 4539 | text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 4540 | } else { |
| 4541 | offset = location; |
| 4542 | text = frame->selectionAsText(); |
| 4543 | // http://crbug.com/101435 |
| 4544 | // In some case, frame->selectionAsText() returned text's length is not |
| 4545 | // equal to the length returned from webview()->caretOrSelectionRange(). |
| 4546 | // So we have to set the range according to text.length(). |
| 4547 | range.set_end(range.start() + text.length()); |
| 4548 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4549 | } |
| 4550 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4551 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 4552 | // the selection hasn't actually changed. We don't want to report these |
| 4553 | // because it will cause us to continually claim the X clipboard. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4554 | if (selection_text_offset_ != offset || |
| 4555 | selection_range_ != range || |
| 4556 | selection_text_ != text) { |
| 4557 | selection_text_ = text; |
| 4558 | selection_text_offset_ = offset; |
| 4559 | selection_range_ = range; |
| 4560 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 4561 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4562 | } |
| 4563 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4564 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 4565 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4566 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4567 | // If the URL that failed was secure, then the embedding web page was not |
| 4568 | // expecting a network attacker to be able to manipulate its contents. As |
| 4569 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 4570 | // attacker to manipulate the contents of the response if we tried to use |
| 4571 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4572 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | // Grab the base URL from the browser process. |
| 4576 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4577 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4578 | |
| 4579 | // Strip query params from the failed URL. |
| 4580 | GURL::Replacements remove_params; |
| 4581 | remove_params.ClearUsername(); |
| 4582 | remove_params.ClearPassword(); |
| 4583 | remove_params.ClearQuery(); |
| 4584 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4585 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 4586 | std::string spec_to_send = url_to_send.spec(); |
| 4587 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 4588 | if (failed_url.has_query()) |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4589 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4590 | |
| 4591 | // Construct the query params to send to link doctor. |
| 4592 | std::string params(alternate_error_page_url_.query()); |
| 4593 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 4594 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4595 | params.append("&sourceid=chrome"); |
| 4596 | params.append("&error="); |
| 4597 | switch (error_type) { |
| 4598 | case DNS_ERROR: |
| 4599 | params.append("dnserror"); |
| 4600 | break; |
| 4601 | |
| 4602 | case HTTP_404: |
| 4603 | params.append("http404"); |
| 4604 | break; |
| 4605 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4606 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 4607 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4608 | break; |
| 4609 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4610 | default: |
| 4611 | NOTREACHED() << "unknown ErrorPageType"; |
| 4612 | } |
| 4613 | |
| 4614 | // OK, build the final url to return. |
| 4615 | GURL::Replacements link_doctor_params; |
| 4616 | link_doctor_params.SetQueryStr(params); |
| 4617 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 4618 | return url; |
| 4619 | } |
| 4620 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4621 | GURL RenderViewImpl::GetOpenerUrl() const { |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 4622 | if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_) |
| 4623 | return GURL(); |
| 4624 | else |
| 4625 | return creator_url_; |
| 4626 | } |
| 4627 | |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 4628 | GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { |
| 4629 | WebDataSource* ds = frame->dataSource(); |
| 4630 | if (ds->hasUnreachableURL()) |
| 4631 | return ds->unreachableURL(); |
| 4632 | |
| 4633 | const WebURLRequest& request = ds->request(); |
| 4634 | return request.url(); |
| 4635 | } |
| 4636 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4637 | WebUIBindings* RenderViewImpl::GetWebUIBindings() { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 4638 | if (!web_ui_bindings_.get()) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4639 | web_ui_bindings_.reset(new WebUIBindings( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4640 | static_cast<RenderView*>(this), routing_id_)); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4641 | } |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 4642 | return web_ui_bindings_.get(); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4643 | } |
| 4644 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4645 | WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4646 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4647 | } |
| 4648 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4649 | void RenderViewImpl::OnFind(int request_id, |
| 4650 | const string16& search_text, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4651 | const WebFindOptions& options) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4652 | #if defined(OS_ANDROID) |
| 4653 | // Make sure any asynchronous messages do not disrupt an ongoing synchronous |
| 4654 | // find request as it might lead to deadlocks. Also, these should be safe to |
| 4655 | // ignore since they would belong to a previous find request. |
| 4656 | if (synchronous_find_reply_message_.get()) |
| 4657 | return; |
| 4658 | #endif |
| 4659 | Find(request_id, search_text, options); |
| 4660 | } |
| 4661 | |
| 4662 | void RenderViewImpl::Find(int request_id, |
| 4663 | const string16& search_text, |
| 4664 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4665 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4666 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4667 | // Check if the plugin still exists in the document. |
| 4668 | if (main_frame->document().isPluginDocument() && |
| 4669 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4670 | if (options.findNext) { |
| 4671 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4672 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4673 | } else { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4674 | if (!GetWebPluginFromPluginDocument()->startFind( |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 4675 | search_text, options.matchCase, request_id)) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4676 | // Send "no results". |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4677 | SendFindReply(request_id, 0, 0, gfx::Rect(), true); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4678 | } |
| 4679 | } |
| 4680 | return; |
| 4681 | } |
| 4682 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4683 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4684 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4685 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4686 | |
| 4687 | bool multi_frame = (frame_after_main != main_frame); |
| 4688 | |
| 4689 | // If we have multiple frames, we don't want to wrap the search within the |
| 4690 | // frame, so we check here if we only have main_frame in the chain. |
| 4691 | bool wrap_within_frame = !multi_frame; |
| 4692 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 4693 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4694 | bool result = false; |
| 4695 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4696 | // If something is selected when we start searching it means we cannot just |
| 4697 | // increment the current match ordinal; we need to re-generate it. |
| 4698 | WebRange current_selection = focused_frame->selectionRange(); |
| 4699 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4700 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4701 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4702 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4703 | |
| 4704 | if (!result) { |
| 4705 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 4706 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4707 | |
| 4708 | // Find the next frame, but skip the invisible ones. |
| 4709 | do { |
| 4710 | // What is the next frame to search? (we might be going backwards). Note |
| 4711 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4712 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4713 | search_frame->traverseNext(true) : |
| 4714 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4715 | } while (!search_frame->hasVisibleContent() && |
| 4716 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4717 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 4718 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 4719 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4720 | |
| 4721 | // If we have multiple frames and we have wrapped back around to the |
| 4722 | // focused frame, we need to search it once more allowing wrap within |
| 4723 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 4724 | // reported matches, but no frames after the focused_frame contain a |
| 4725 | // match for the search word(s). |
| 4726 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4727 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4728 | request_id, search_text, options, true, // Force wrapping. |
| 4729 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4730 | } |
| 4731 | } |
| 4732 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4733 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4734 | } while (!result && search_frame != focused_frame); |
| 4735 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4736 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4737 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4738 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4739 | } else { |
| 4740 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4741 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4742 | // yet what is active. |
| 4743 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4744 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4745 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4746 | // If we find no matches then this will be our last status update. |
| 4747 | // Otherwise the scoping effort will send more results. |
| 4748 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4749 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4750 | SendFindReply(request_id, match_count, ordinal, selection_rect, |
| 4751 | final_status_update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4752 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4753 | // Scoping effort begins, starting with the mainframe. |
| 4754 | search_frame = main_frame; |
| 4755 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4756 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4757 | |
| 4758 | do { |
| 4759 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4760 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4761 | |
| 4762 | // We don't start another scoping effort unless at least one match has |
| 4763 | // been found. |
| 4764 | if (result) { |
| 4765 | // Start new scoping request. If the scoping function determines that it |
| 4766 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4767 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4768 | search_text, |
| 4769 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4770 | true); // reset the tickmarks |
| 4771 | } |
| 4772 | |
| 4773 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4774 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4775 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4776 | } while (search_frame != main_frame); |
| 4777 | } |
| 4778 | } |
| 4779 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4780 | void RenderViewImpl::OnStopFinding(StopFindAction action) { |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4781 | #if defined(OS_ANDROID) |
| 4782 | // Make sure any asynchronous messages do not disrupt an ongoing synchronous |
| 4783 | // find request as it might lead to deadlocks. Also, these should be safe to |
| 4784 | // ignore since they would belong to a previous find request. |
| 4785 | if (synchronous_find_reply_message_.get()) |
| 4786 | return; |
| 4787 | #endif |
| 4788 | |
| 4789 | StopFinding(action); |
| 4790 | } |
| 4791 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4792 | void RenderViewImpl::StopFinding(StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4793 | WebView* view = webview(); |
| 4794 | if (!view) |
| 4795 | return; |
| 4796 | |
| 4797 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4798 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4799 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4800 | return; |
| 4801 | } |
| 4802 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4803 | bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4804 | if (clear_selection) |
| 4805 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 4806 | |
| 4807 | WebFrame* frame = view->mainFrame(); |
| 4808 | while (frame) { |
| 4809 | frame->stopFinding(clear_selection); |
| 4810 | frame = frame->traverseNext(false); |
| 4811 | } |
| 4812 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4813 | if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4814 | WebFrame* focused_frame = view->focusedFrame(); |
| 4815 | if (focused_frame) { |
| 4816 | WebDocument doc = focused_frame->document(); |
| 4817 | if (!doc.isNull()) { |
| 4818 | WebNode node = doc.focusedNode(); |
| 4819 | if (!node.isNull()) |
| 4820 | node.simulateClick(); |
| 4821 | } |
| 4822 | } |
| 4823 | } |
| 4824 | } |
| 4825 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4826 | #if defined(OS_ANDROID) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4827 | void RenderViewImpl::OnSynchronousFind(int request_id, |
| 4828 | const string16& search_string, |
| 4829 | const WebFindOptions& options, |
| 4830 | IPC::Message* reply_msg) { |
| 4831 | // It is impossible for simultaneous blocking finds to occur. |
| 4832 | CHECK(!synchronous_find_reply_message_.get()); |
| 4833 | synchronous_find_reply_message_.reset(reply_msg); |
| 4834 | |
| 4835 | // Find next should be asynchronous in order to minimize blocking |
| 4836 | // the UI thread as much as possible. |
| 4837 | DCHECK(!options.findNext); |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4838 | StopFinding(STOP_FIND_ACTION_KEEP_SELECTION); |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4839 | synchronous_find_active_match_ordinal_ = -1; |
| 4840 | |
| 4841 | Find(request_id, search_string, options); |
| 4842 | } |
| 4843 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4844 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 4845 | float x, float y) { |
| 4846 | if (!webview()) |
| 4847 | return; |
| 4848 | |
| 4849 | WebFrame* main_frame = webview()->mainFrame(); |
| 4850 | WebRect selection_rect; |
| 4851 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 4852 | &selection_rect); |
| 4853 | if (ordinal == -1) { |
| 4854 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 4855 | // report the current match count) in case the host is waiting for a |
| 4856 | // response due to rate-limiting). |
| 4857 | main_frame->increaseMatchCount(0, request_id); |
| 4858 | return; |
| 4859 | } |
| 4860 | |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 4861 | SendFindReply(request_id, |
| 4862 | -1 /* number_of_matches */, |
| 4863 | ordinal, |
| 4864 | selection_rect, |
| 4865 | true /* final_update */); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 4869 | if (!webview()) |
| 4870 | return; |
| 4871 | |
| 4872 | WebFrame* main_frame = webview()->mainFrame(); |
| 4873 | std::vector<gfx::RectF> match_rects; |
| 4874 | |
| 4875 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 4876 | if (current_version != rects_version) { |
| 4877 | WebVector<WebFloatRect> web_match_rects; |
| 4878 | main_frame->findMatchRects(web_match_rects); |
| 4879 | match_rects.reserve(web_match_rects.size()); |
| 4880 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 4881 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 4882 | } |
| 4883 | |
| 4884 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 4885 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 4886 | rects_version, |
| 4887 | match_rects, |
| 4888 | active_rect)); |
| 4889 | } |
| 4890 | #endif |
| 4891 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4892 | void RenderViewImpl::OnZoom(PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4893 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4894 | return; |
| 4895 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4896 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 4897 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4898 | double old_zoom_level = webview()->zoomLevel(); |
| 4899 | double zoom_level; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4900 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4901 | zoom_level = 0; |
| 4902 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4903 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4904 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4905 | } else { |
| 4906 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4907 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4908 | // to go to the next whole number so that the user can always get back to |
| 4909 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4910 | if ((old_zoom_level > 1 && zoom > 0) || |
| 4911 | (old_zoom_level < 1 && zoom < 0)) { |
| 4912 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4913 | } else { |
| 4914 | // We're going towards 100%, so first go to the next whole number. |
| 4915 | zoom_level = static_cast<int>(old_zoom_level); |
| 4916 | } |
| 4917 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4918 | webview()->setZoomLevel(false, zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4919 | zoomLevelChanged(); |
| 4920 | } |
| 4921 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4922 | void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x, |
| 4923 | int zoom_center_y) { |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4924 | ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y, |
| 4925 | kScalingIncrementForGesture); |
| 4926 | } |
| 4927 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4928 | void RenderViewImpl::ZoomFactorHelper(PageZoom zoom, |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4929 | int zoom_center_x, |
| 4930 | int zoom_center_y, |
| 4931 | float scaling_increment) { |
| 4932 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4933 | return; |
| 4934 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4935 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 4936 | double page_scale_factor; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 4937 | if (zoom == PAGE_ZOOM_RESET) { |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4938 | page_scale_factor = 1.0; |
| 4939 | } else { |
| 4940 | page_scale_factor = old_page_scale_factor + |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4941 | (zoom > 0 ? scaling_increment : -scaling_increment); |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 4942 | } |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4943 | if (page_scale_factor > 0) { |
[email protected] | 8519136 | 2011-11-08 18:53:09 | [diff] [blame] | 4944 | webview()->setPageScaleFactor(page_scale_factor, |
| 4945 | WebPoint(zoom_center_x, zoom_center_y)); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4946 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4947 | } |
| 4948 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4949 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4950 | webview()->hidePopups(); |
| 4951 | webview()->setZoomLevel(false, zoom_level); |
| 4952 | zoomLevelChanged(); |
| 4953 | } |
| 4954 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4955 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 4956 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4957 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4958 | } |
| 4959 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4960 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4961 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4962 | } |
| 4963 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4964 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4965 | WebString no_encoding; |
| 4966 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4967 | } |
| 4968 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4969 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4970 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4971 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4972 | |
| 4973 | // xpath string can represent a frame deep down the tree (across multiple |
| 4974 | // frame DOMs). |
| 4975 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4976 | // should break into 2 xpaths |
| 4977 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4978 | std::vector<string16> xpaths; |
| 4979 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4980 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4981 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4982 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 4983 | frame && i != xpaths.end(); ++i) { |
| 4984 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4985 | } |
| 4986 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4987 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4988 | } |
| 4989 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4990 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 4991 | const string16& jscript, |
| 4992 | int id, |
| 4993 | bool notify_result) { |
[email protected] | 01d43ef9 | 2012-09-25 00:54:10 | [diff] [blame] | 4994 | TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest"); |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4995 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4996 | } |
| 4997 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4998 | void RenderViewImpl::OnPostMessageEvent( |
| 4999 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5000 | // Find the target frame of this message. The source tags the message with |
| 5001 | // |target_frame_id|, so use it to locate the frame. |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 5002 | // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701 |
| 5003 | // is fixed and we can rely on having frame tree updates again. |
| 5004 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5005 | |
| 5006 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5007 | WebFrame* source_frame = NULL; |
| 5008 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 5009 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 5010 | // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701 |
| 5011 | // is fixed and we can rely on having frame tree updates again. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5012 | if (source_view) |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 5013 | source_frame = source_view->webview()->mainFrame(); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | // Create an event with the message. The final parameter to initMessageEvent |
| 5017 | // is the last event ID, which is not used with postMessage. |
| 5018 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 5019 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 5020 | msg_event.initMessageEvent("message", |
| 5021 | // |canBubble| and |cancellable| are always false |
| 5022 | false, false, |
| 5023 | WebSerializedScriptValue::fromString(params.data), |
| 5024 | params.source_origin, source_frame, ""); |
| 5025 | |
| 5026 | // We must pass in the target_origin to do the security check on this side, |
| 5027 | // since it may have changed since the original postMessage call was made. |
| 5028 | WebSecurityOrigin target_origin; |
| 5029 | if (!params.target_origin.empty()) { |
| 5030 | target_origin = |
| 5031 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 5032 | } |
| 5033 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 5034 | } |
| 5035 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5036 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 5037 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 5038 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 5039 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 5040 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 5041 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 5042 | frame->document().insertUserStyleSheet( |
| 5043 | WebString::fromUTF8(css), |
| 5044 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 5045 | } |
| 5046 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5047 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 5048 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 5049 | |
| 5050 | // Keep track of the total bindings accumulated in this process. |
| 5051 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5052 | } |
| 5053 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5054 | void RenderViewImpl::OnSetWebUIProperty(const std::string& name, |
| 5055 | const std::string& value) { |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5056 | if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI) |
[email protected] | 808bda5 | 2012-03-09 22:43:32 | [diff] [blame] | 5057 | GetWebUIBindings()->SetProperty(name, value); |
| 5058 | else |
| 5059 | NOTREACHED() << "WebUI bindings not enabled."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5060 | } |
| 5061 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5062 | void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data, |
| 5063 | const gfx::Point& client_point, |
| 5064 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5065 | WebDragOperationsMask ops, |
| 5066 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5067 | WebDragOperation operation = webview()->dragTargetDragEnter( |
| 5068 | drop_data.ToDragData(), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5069 | client_point, |
| 5070 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5071 | ops, |
| 5072 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5073 | |
| 5074 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 5075 | } |
| 5076 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5077 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 5078 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5079 | WebDragOperationsMask ops, |
| 5080 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5081 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 5082 | client_point, |
| 5083 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5084 | ops, |
| 5085 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5086 | |
| 5087 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 5088 | } |
| 5089 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5090 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5091 | webview()->dragTargetDragLeave(); |
| 5092 | } |
| 5093 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5094 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 5095 | const gfx::Point& screen_point, |
| 5096 | int key_modifiers) { |
| 5097 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 5098 | |
| 5099 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 5100 | } |
| 5101 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5102 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 5103 | const gfx::Point& screen_point, |
| 5104 | bool ended, |
| 5105 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5106 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5107 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 5108 | } else { |
| 5109 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 5110 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5111 | } |
| 5112 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5113 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5114 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5115 | } |
| 5116 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5117 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 5118 | webkit_preferences_ = prefs; |
| 5119 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5120 | } |
| 5121 | |
[email protected] | 3876145 | 2012-10-18 16:31:59 | [diff] [blame] | 5122 | void RenderViewImpl::OnUpdateTimezone() { |
| 5123 | if (webview()) |
| 5124 | NotifyTimezoneChange(webview()->mainFrame()); |
| 5125 | } |
| 5126 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5127 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5128 | alternate_error_page_url_ = url; |
| 5129 | } |
| 5130 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5131 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5132 | const CustomContextMenuContext& custom_context, |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5133 | unsigned action) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5134 | if (custom_context.request_id) { |
| 5135 | // External context menu request, look in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5136 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5137 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 5138 | if (client) |
| 5139 | client->OnMenuAction(custom_context.request_id, action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5140 | } else { |
| 5141 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5142 | webview()->performCustomContextMenuAction(action); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 5143 | } |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 5144 | } |
| 5145 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5146 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5147 | int id, |
| 5148 | const std::vector<FilePath>& paths) { |
| 5149 | if (!enumeration_completions_[id]) |
| 5150 | return; |
| 5151 | |
| 5152 | WebVector<WebString> ws_file_names(paths.size()); |
| 5153 | for (size_t i = 0; i < paths.size(); ++i) |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5154 | ws_file_names[i] = webkit_base::FilePathToWebString(paths[i]); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5155 | |
| 5156 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 5157 | enumeration_completions_.erase(id); |
| 5158 | } |
| 5159 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 5160 | void RenderViewImpl::OnFileChooserResponse( |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 5161 | const std::vector<ui::SelectedFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5162 | // This could happen if we navigated to a different page before the user |
| 5163 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5164 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5165 | return; |
| 5166 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5167 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 5168 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 5169 | files.size()); |
| 5170 | for (size_t i = 0; i < files.size(); ++i) { |
| 5171 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5172 | selected_file.path = webkit_base::FilePathToWebString(files[i].local_path); |
| 5173 | selected_file.displayName = webkit_base::FilePathStringToWebString( |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5174 | files[i].display_name); |
| 5175 | selected_files[i] = selected_file; |
| 5176 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 5177 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5178 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5179 | file_chooser_completions_.front()->completion->didChooseFile( |
| 5180 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5181 | file_chooser_completions_.pop_front(); |
| 5182 | |
| 5183 | // If there are more pending file chooser requests, schedule one now. |
| 5184 | if (!file_chooser_completions_.empty()) { |
| 5185 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 5186 | file_chooser_completions_.front()->params)); |
| 5187 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5188 | } |
| 5189 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5190 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 5191 | const gfx::Size& max_size) { |
| 5192 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5193 | if (!webview()) |
| 5194 | return; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5195 | webview()->enableAutoResizeMode(min_size, max_size); |
| 5196 | } |
| 5197 | |
| 5198 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 5199 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5200 | if (!webview()) |
| 5201 | return; |
| 5202 | webview()->disableAutoResizeMode(); |
| 5203 | |
| 5204 | Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK); |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5205 | } |
| 5206 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 5207 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5208 | if (send_preferred_size_changes_) |
| 5209 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5210 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 5211 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5212 | // Start off with an initial preferred size notification (in case |
| 5213 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 5214 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 5215 | } |
| 5216 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5217 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5218 | const gfx::Size& disable_scrollbar_size_limit) { |
| 5219 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 5220 | } |
| 5221 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5222 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5223 | const RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5224 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5225 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 5226 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 5227 | #if defined(TOOLKIT_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 5228 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 5229 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 5230 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5231 | ui::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 5232 | renderer_prefs.thumb_inactive_color, |
| 5233 | renderer_prefs.thumb_active_color, |
| 5234 | renderer_prefs.track_color); |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5235 | #endif |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5236 | |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 5237 | #if defined(USE_ASH) || defined(TOOLKIT_GTK) |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5238 | if (webview()) { |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 5239 | #if defined(TOOLKIT_GTK) |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5240 | webview()->setScrollbarColors( |
| 5241 | renderer_prefs.thumb_inactive_color, |
| 5242 | renderer_prefs.thumb_active_color, |
| 5243 | renderer_prefs.track_color); |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5244 | #endif |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5245 | webview()->setSelectionColors( |
| 5246 | renderer_prefs.active_selection_bg_color, |
| 5247 | renderer_prefs.active_selection_fg_color, |
| 5248 | renderer_prefs.inactive_selection_bg_color, |
| 5249 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5250 | webview()->themeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5251 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 5252 | #endif |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5253 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5254 | // If the zoom level for this page matches the old zoom default, and this |
| 5255 | // is not a plugin, update the zoom level to match the new default. |
| 5256 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5257 | ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5258 | webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level); |
| 5259 | zoomLevelChanged(); |
| 5260 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5261 | } |
| 5262 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5263 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 5264 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 5265 | if (webview()) |
| 5266 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 5267 | } |
| 5268 | |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5269 | void RenderViewImpl::OnOrientationChangeEvent(int orientation) { |
| 5270 | webview()->mainFrame()->sendOrientationChangeEvent(orientation); |
| 5271 | } |
| 5272 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 5273 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 5274 | const WebPluginAction& action) { |
| 5275 | if (webview()) |
| 5276 | webview()->performPluginAction(action, location); |
| 5277 | } |
| 5278 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5279 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5280 | const GURL& page_url) { |
| 5281 | // Prepare list to storage all savable resource links. |
| 5282 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5283 | std::vector<GURL> referrer_urls_list; |
| 5284 | std::vector<WebKit::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5285 | std::vector<GURL> frames_list; |
| 5286 | webkit_glue::SavableResourcesResult result(&resources_list, |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5287 | &referrer_urls_list, |
| 5288 | &referrer_policies_list, |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5289 | &frames_list); |
| 5290 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5291 | // webkit/ doesn't know about Referrer. |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5292 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 5293 | webview(), |
| 5294 | page_url, |
| 5295 | &result, |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5296 | const_cast<const char**>(GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5297 | // If something is wrong when collecting all savable resource links, |
| 5298 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5299 | referrer_urls_list.clear(); |
| 5300 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5301 | resources_list.clear(); |
| 5302 | frames_list.clear(); |
| 5303 | } |
| 5304 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5305 | std::vector<Referrer> referrers_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5306 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 5307 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 5308 | referrers_list.push_back( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5309 | Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5310 | } |
| 5311 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5312 | // Send result of all savable resource links to embedder. |
| 5313 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 5314 | resources_list, |
| 5315 | referrers_list, |
| 5316 | frames_list)); |
| 5317 | } |
| 5318 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5319 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5320 | const std::vector<GURL>& links, |
| 5321 | const std::vector<FilePath>& local_paths, |
| 5322 | const FilePath& local_directory_name) { |
| 5323 | |
| 5324 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 5325 | WebVector<WebURL> weburl_links(links); |
| 5326 | |
| 5327 | // Convert std::vector of std::strings to WebVector<WebString> |
| 5328 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 5329 | for (size_t i = 0; i < local_paths.size(); i++) |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5330 | webstring_paths[i] = webkit_base::FilePathToWebString(local_paths[i]); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5331 | |
| 5332 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 5333 | webstring_paths, |
[email protected] | bb0e7947 | 2012-10-23 04:36:34 | [diff] [blame] | 5334 | webkit_base::FilePathToWebString( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5335 | local_directory_name)); |
| 5336 | } |
| 5337 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5338 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5339 | base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5340 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5341 | base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
| 5342 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
| 5343 | before_unload_start_time, |
| 5344 | before_unload_end_time)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5345 | } |
| 5346 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5347 | void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 5348 | // Ensure that no other in-progress navigation continues. |
| 5349 | OnStop(); |
| 5350 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5351 | // Only run unload if we're not swapped out yet, but send the ack either way. |
| 5352 | if (!is_swapped_out_) { |
| 5353 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 5354 | // different process. This involves running the unload handler and clearing |
| 5355 | // the page. Once WasSwappedOut is called, we also allow this process to |
| 5356 | // exit if there are no other active RenderViews in it. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5357 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5358 | // Send an UpdateState message before we get swapped out. |
| 5359 | SyncNavigationState(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5360 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5361 | // Synchronously run the unload handler before sending the ACK. |
| 5362 | webview()->dispatchUnloadEvent(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5363 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5364 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 5365 | SetSwappedOut(true); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5366 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5367 | // 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] | 5368 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 5369 | // 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] | 5370 | // beforeunload handler. For now, we just run it a second time silently. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5371 | NavigateToSwappedOutURL(webview()->mainFrame()); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 5372 | |
| 5373 | // Let WebKit know that this view is hidden so it can drop resources and |
| 5374 | // stop compositing. |
| 5375 | webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5376 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5377 | |
| 5378 | // Just echo back the params in the ACK. |
| 5379 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 5380 | } |
| 5381 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5382 | void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5383 | // We use loadRequest instead of loadHTMLString because the former commits |
| 5384 | // synchronously. Otherwise a new navigation can interrupt the navigation |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5385 | // to kSwappedOutURL. If that happens to be to the page we had been |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5386 | // showing, then WebKit will never send a commit and we'll be left spinning. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5387 | GURL swappedOutURL(kSwappedOutURL); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5388 | WebURLRequest request(swappedOutURL); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5389 | frame->loadRequest(request); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5390 | } |
| 5391 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5392 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 5393 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5394 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 5395 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 5396 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 5397 | // calling the FrameLoader's CloseURL method directly. This should be |
| 5398 | // revisited to avoid having two ways to close a page. Having a single way |
| 5399 | // to close that can run onunload is also useful for fixing |
| 5400 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5401 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5402 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5403 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5404 | } |
| 5405 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5406 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 5407 | #if defined(USE_AURA) |
| 5408 | // Aura doesn't care if we switch themes. |
| 5409 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5410 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5411 | if (webview()) |
| 5412 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 5413 | #else // defined(OS_WIN) |
| 5414 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 5415 | NOTIMPLEMENTED(); |
| 5416 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5417 | } |
| 5418 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5419 | void RenderViewImpl::OnDisassociateFromPopupCount() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 5420 | if (decrement_shared_popup_at_destruction_) |
| 5421 | shared_popup_counter_->data--; |
| 5422 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 5423 | decrement_shared_popup_at_destruction_ = false; |
| 5424 | } |
| 5425 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5426 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 5427 | const WebURLError& error, |
| 5428 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5429 | // We only show alternate error pages in the main frame. They are |
| 5430 | // intended to assist the user when navigating, so there is not much |
| 5431 | // value in showing them for failed subframes. Ideally, we would be |
| 5432 | // able to use the TYPED transition type for this, but that flag is |
| 5433 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5434 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5435 | return false; |
| 5436 | |
| 5437 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 5438 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5439 | int ec = error.reason; |
| 5440 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 5441 | ec != net::ERR_CONNECTION_FAILED && |
| 5442 | ec != net::ERR_CONNECTION_REFUSED && |
| 5443 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5444 | ec != net::ERR_CONNECTION_TIMED_OUT) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5445 | return false; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5446 | } |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5447 | |
| 5448 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5449 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5450 | if (!error_page_url.is_valid()) |
| 5451 | return false; |
| 5452 | |
| 5453 | // Load an empty page first so there is an immediate response to the error, |
| 5454 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5455 | frame->loadHTMLString(std::string(), |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5456 | GURL(kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5457 | error.unreachableURL, |
| 5458 | replace); |
| 5459 | |
| 5460 | // Now, create a fetcher for the error page and associate it with the data |
| 5461 | // source we just created via the LoadHTMLString call. That way if another |
| 5462 | // navigation occurs, the fetcher will get destroyed. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5463 | DocumentState* document_state = |
| 5464 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
| 5465 | document_state->set_alt_error_page_fetcher( |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5466 | new AltErrorPageResourceFetcher( |
| 5467 | error_page_url, frame, error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 5468 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 5469 | base::Unretained(this)))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5470 | return true; |
| 5471 | } |
| 5472 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5473 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
| 5474 | const WebURLError& original_error, |
| 5475 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5476 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5477 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5478 | // will simply display a default error page. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5479 | LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5480 | } |
| 5481 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5482 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5483 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5484 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5485 | } |
| 5486 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5487 | void RenderViewImpl::OnResize(const gfx::Size& new_size, |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 5488 | const gfx::Rect& resizer_rect, |
| 5489 | bool is_fullscreen) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5490 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5491 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5492 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 5493 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 5494 | ShouldDisplayScrollbars(new_size.width(), new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5495 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 5496 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5497 | } |
| 5498 | |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 5499 | RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5500 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 5501 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5502 | void RenderViewImpl::WillInitiatePaint() { |
| 5503 | // Notify the pepper plugins that we're about to paint. |
| 5504 | pepper_delegate_.ViewWillInitiatePaint(); |
| 5505 | } |
| 5506 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5507 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5508 | // Notify the pepper plugins that we've painted, and are waiting to flush. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5509 | pepper_delegate_.ViewInitiatedPaint(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5510 | } |
| 5511 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5512 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5513 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 5514 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 5515 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 5516 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5517 | pepper_delegate_.ViewFlushedPaint(); |
| 5518 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 5519 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 5520 | // See crbug.com/112921. |
| 5521 | if (!webview()) |
| 5522 | return; |
| 5523 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5524 | WebFrame* main_frame = webview()->mainFrame(); |
| 5525 | |
| 5526 | // If we have a provisional frame we are between the start and commit stages |
| 5527 | // of loading and we don't want to save stats. |
| 5528 | if (!main_frame->provisionalDataSource()) { |
| 5529 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5530 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5531 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5532 | // TODO(jar): The following code should all be inside a method, probably in |
| 5533 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5534 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5535 | if (document_state->first_paint_time().is_null()) { |
| 5536 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5537 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5538 | if (document_state->first_paint_after_load_time().is_null() && |
| 5539 | !document_state->finish_load_time().is_null()) { |
| 5540 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5541 | } |
| 5542 | } |
| 5543 | } |
| 5544 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5545 | void RenderViewImpl::OnViewContextSwapBuffersPosted() { |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 5546 | RenderWidget::OnSwapBuffersPosted(); |
| 5547 | } |
| 5548 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5549 | void RenderViewImpl::OnViewContextSwapBuffersComplete() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5550 | RenderWidget::OnSwapBuffersComplete(); |
| 5551 | } |
| 5552 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5553 | void RenderViewImpl::OnViewContextSwapBuffersAborted() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5554 | RenderWidget::OnSwapBuffersAborted(); |
| 5555 | } |
| 5556 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5557 | webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5558 | const gfx::Rect& paint_bounds, |
| 5559 | TransportDIB** dib, |
| 5560 | gfx::Rect* location, |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5561 | gfx::Rect* clip, |
| 5562 | float* scale_factor) { |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5563 | return pepper_delegate_.GetBitmapForOptimizedPluginPaint( |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5564 | paint_bounds, dib, location, clip, scale_factor); |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5565 | } |
| 5566 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5567 | gfx::Vector2d RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5568 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 5569 | return gfx::Vector2d(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 5570 | } |
| 5571 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5572 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5573 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5574 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5575 | } |
| 5576 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5577 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5578 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5579 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5580 | |
| 5581 | SetBackground(background); |
| 5582 | } |
| 5583 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5584 | void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) { |
| 5585 | if (accessibility_mode_ == new_mode) |
| 5586 | return; |
| 5587 | accessibility_mode_ = new_mode; |
| 5588 | if (renderer_accessibility_) { |
| 5589 | delete renderer_accessibility_; |
| 5590 | renderer_accessibility_ = NULL; |
| 5591 | } |
| 5592 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 5593 | renderer_accessibility_ = new RendererAccessibilityComplete(this); |
| 5594 | else if (accessibility_mode_ == AccessibilityModeEditableTextOnly) |
| 5595 | renderer_accessibility_ = new RendererAccessibilityFocusOnly(this); |
| 5596 | } |
| 5597 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5598 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5599 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5600 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5601 | |
| 5602 | #if defined(OS_MACOSX) |
| 5603 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5604 | for (plugin_it = plugin_delegates_.begin(); |
| 5605 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5606 | (*plugin_it)->SetWindowFocus(active); |
| 5607 | } |
| 5608 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5609 | } |
| 5610 | |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5611 | void RenderViewImpl::OnSetNavigationStartTime( |
| 5612 | const base::TimeTicks& browser_navigation_start) { |
| 5613 | if (!webview()) |
| 5614 | return; |
| 5615 | |
| 5616 | // Only the initial navigation can be a cross-renderer navigation. If we've |
| 5617 | // already navigated away from that page, we can ignore this message. |
| 5618 | if (page_id_ != -1) |
| 5619 | return; |
| 5620 | |
| 5621 | // browser_navigation_start is likely before this process existed, so we can't |
| 5622 | // use InterProcessTimeTicksConverter. Instead, the best we can do is just |
| 5623 | // ensure we don't report a bogus value in the future. |
| 5624 | base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(), |
| 5625 | browser_navigation_start); |
| 5626 | webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime( |
| 5627 | (navigation_start - base::TimeTicks()).InSecondsF()); |
| 5628 | } |
| 5629 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5630 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5631 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5632 | // Inform plugins that their container has changed visibility. |
| 5633 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5634 | for (plugin_it = plugin_delegates_.begin(); |
| 5635 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5636 | (*plugin_it)->SetContainerVisibility(visible); |
| 5637 | } |
| 5638 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5639 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5640 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 5641 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5642 | // Inform plugins that their window's frame has changed. |
| 5643 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5644 | for (plugin_it = plugin_delegates_.begin(); |
| 5645 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5646 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 5647 | } |
| 5648 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5649 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5650 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 5651 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5652 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5653 | // applies to it or not, so inform all the delegates. |
| 5654 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5655 | for (plugin_it = plugin_delegates_.begin(); |
| 5656 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5657 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5658 | } |
| 5659 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5660 | #endif // OS_MACOSX |
| 5661 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5662 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5663 | const EditCommands& edit_commands) { |
| 5664 | edit_commands_ = edit_commands; |
| 5665 | } |
| 5666 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5667 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5668 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5669 | WebView* doomed = webview(); |
| 5670 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 5671 | g_view_map.Get().erase(doomed); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5672 | } |
| 5673 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5674 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 5675 | ClearEditCommands(); |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5676 | } |
| 5677 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5678 | bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5679 | possible_drag_event_info_.event_source = |
| 5680 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 5681 | possible_drag_event_info_.event_location = |
| 5682 | gfx::Point(event.globalX, event.globalY); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 5683 | pepper_delegate_.WillHandleMouseEvent(); |
| 5684 | |
| 5685 | // If the mouse is locked, only the current owner of the mouse lock can |
| 5686 | // process mouse events. |
| 5687 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 5688 | } |
| 5689 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 5690 | bool RenderViewImpl::WillHandleGestureEvent( |
| 5691 | const WebKit::WebGestureEvent& event) { |
| 5692 | possible_drag_event_info_.event_source = |
| 5693 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 5694 | possible_drag_event_info_.event_location = |
| 5695 | gfx::Point(event.globalX, event.globalY); |
| 5696 | return false; |
| 5697 | } |
| 5698 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 5699 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5700 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5701 | } |
| 5702 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5703 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 5704 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 5705 | } |
| 5706 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5707 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5708 | RenderWidget::OnWasHidden(); |
| 5709 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5710 | #if defined(OS_ANDROID) |
| 5711 | // Inform WebMediaPlayerManagerAndroid to release all media player resources. |
| 5712 | media_player_manager_->ReleaseMediaResources(); |
| 5713 | #endif |
| 5714 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5715 | if (webview()) { |
| 5716 | webview()->settings()->setMinimumTimerInterval( |
| 5717 | webkit_glue::kBackgroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5718 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5719 | } |
| 5720 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5721 | // Inform PPAPI plugins that their page is no longer visible. |
| 5722 | pepper_delegate_.PageVisibilityChanged(false); |
| 5723 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5724 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5725 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5726 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5727 | for (plugin_it = plugin_delegates_.begin(); |
| 5728 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5729 | (*plugin_it)->SetContainerVisibility(false); |
| 5730 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5731 | #endif // OS_MACOSX |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5732 | } |
| 5733 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 5734 | void RenderViewImpl::OnWasShown(bool needs_repainting) { |
| 5735 | RenderWidget::OnWasShown(needs_repainting); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5736 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5737 | if (webview()) { |
| 5738 | webview()->settings()->setMinimumTimerInterval( |
| 5739 | webkit_glue::kForegroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5740 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5741 | } |
| 5742 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5743 | // Inform PPAPI plugins that their page is visible. |
| 5744 | pepper_delegate_.PageVisibilityChanged(true); |
| 5745 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5746 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5747 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5748 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5749 | for (plugin_it = plugin_delegates_.begin(); |
| 5750 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5751 | (*plugin_it)->SetContainerVisibility(true); |
| 5752 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5753 | #endif // OS_MACOSX |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5754 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5755 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5756 | bool RenderViewImpl::SupportsAsynchronousSwapBuffers() { |
[email protected] | 9caf09bc | 2012-06-25 21:46:28 | [diff] [blame] | 5757 | // Contexts using the command buffer support asynchronous swapbuffers. |
[email protected] | f89e173a | 2012-08-24 01:12:26 | [diff] [blame] | 5758 | // See RenderViewImpl::createOutputSurface(). |
[email protected] | 9caf09bc | 2012-06-25 21:46:28 | [diff] [blame] | 5759 | if (WebWidgetHandlesCompositorScheduling() || |
| 5760 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) |
[email protected] | 555e75d | 2011-10-08 01:23:38 | [diff] [blame] | 5761 | return false; |
| 5762 | |
[email protected] | 9caf09bc | 2012-06-25 21:46:28 | [diff] [blame] | 5763 | return true; |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5764 | } |
| 5765 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 5766 | bool RenderViewImpl::ForceCompositingModeEnabled() { |
| 5767 | return webkit_preferences_.force_compositing_mode; |
| 5768 | } |
| 5769 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5770 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5771 | RenderWidget::OnSetFocus(enable); |
| 5772 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5773 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5774 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5775 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5776 | for (plugin_it = plugin_delegates_.begin(); |
| 5777 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5778 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5779 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5780 | // activation state to change just like a call to setIsActive. |
| 5781 | if (enable) |
| 5782 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5783 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5784 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5785 | } |
| 5786 | } |
[email protected] | a01da568 | 2012-06-30 00:37:31 | [diff] [blame] | 5787 | // Notify all Pepper plugins. |
| 5788 | pepper_delegate_.OnSetFocus(enable); |
[email protected] | 32103299 | 2012-11-08 01:01:27 | [diff] [blame] | 5789 | // Notify all BrowserPlugins of the RenderView's focus state. |
| 5790 | BrowserPluginManager::Get()->SetEmbedderFocus(this, enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5791 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5792 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5793 | void RenderViewImpl::PpapiPluginFocusChanged() { |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 5794 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5795 | UpdateSelectionBounds(); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5796 | } |
| 5797 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5798 | void RenderViewImpl::PpapiPluginTextInputTypeChanged() { |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 5799 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 5800 | if (renderer_accessibility_) |
| 5801 | renderer_accessibility_->FocusedNodeChanged(WebNode()); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5802 | } |
| 5803 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5804 | void RenderViewImpl::PpapiPluginCaretPositionChanged() { |
| 5805 | UpdateSelectionBounds(); |
| 5806 | } |
| 5807 | |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 5808 | bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) { |
| 5809 | if (!pepper_delegate_.IsPluginFocused()) |
| 5810 | return false; |
| 5811 | *rect = pepper_delegate_.GetCaretBounds(); |
| 5812 | return true; |
| 5813 | } |
| 5814 | |
[email protected] | 397c2396 | 2012-05-21 07:09:32 | [diff] [blame] | 5815 | void RenderViewImpl::SimulateImeSetComposition( |
| 5816 | const string16& text, |
| 5817 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 5818 | int selection_start, |
| 5819 | int selection_end) { |
| 5820 | OnImeSetComposition(text, underlines, selection_start, selection_end); |
| 5821 | } |
| 5822 | |
| 5823 | void RenderViewImpl::SimulateImeConfirmComposition( |
| 5824 | const string16& text, |
| 5825 | const ui::Range& replacement_range) { |
| 5826 | OnImeConfirmComposition(text, replacement_range); |
| 5827 | } |
| 5828 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5829 | void RenderViewImpl::PpapiPluginCancelComposition() { |
| 5830 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 5831 | const ui::Range range(ui::Range::InvalidRange()); |
| 5832 | const std::vector<gfx::Rect> empty_bounds; |
| 5833 | UpdateCompositionInfo(range, empty_bounds); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5834 | } |
| 5835 | |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 5836 | void RenderViewImpl::PpapiPluginSelectionChanged() { |
| 5837 | SyncSelectionIfRequired(); |
| 5838 | } |
| 5839 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 5840 | void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) { |
[email protected] | 236bf85 | 2012-07-27 22:49:36 | [diff] [blame] | 5841 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 5842 | DidCreatePepperPlugin(host)); |
| 5843 | } |
| 5844 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5845 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5846 | const string16& text, |
| 5847 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 5848 | int selection_start, |
| 5849 | int selection_end) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5850 | if (pepper_delegate_.IsPluginFocused()) { |
| 5851 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 5852 | pepper_delegate_.OnImeSetComposition(text, |
| 5853 | underlines, |
| 5854 | selection_start, |
| 5855 | selection_end); |
| 5856 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5857 | #if defined(OS_WIN) |
| 5858 | // When a plug-in has focus, we create platform-specific IME data used by |
| 5859 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 5860 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 5861 | // instance ID is the same one as the specified ID.) |
| 5862 | if (focused_plugin_id_ >= 0) { |
| 5863 | std::vector<int> clauses; |
| 5864 | std::vector<int> target; |
| 5865 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 5866 | clauses.push_back(underlines[i].startOffset); |
| 5867 | clauses.push_back(underlines[i].endOffset); |
| 5868 | if (underlines[i].thick) { |
| 5869 | target.clear(); |
| 5870 | target.push_back(underlines[i].startOffset); |
| 5871 | target.push_back(underlines[i].endOffset); |
| 5872 | } |
| 5873 | } |
| 5874 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5875 | for (it = plugin_delegates_.begin(); |
| 5876 | it != plugin_delegates_.end(); ++it) { |
| 5877 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 5878 | focused_plugin_id_); |
| 5879 | } |
| 5880 | return; |
| 5881 | } |
| 5882 | #endif |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5883 | RenderWidget::OnImeSetComposition(text, |
| 5884 | underlines, |
| 5885 | selection_start, |
| 5886 | selection_end); |
| 5887 | } |
| 5888 | } |
| 5889 | |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 5890 | void RenderViewImpl::OnImeConfirmComposition( |
| 5891 | const string16& text, const ui::Range& replacement_range) { |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5892 | if (pepper_delegate_.IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5893 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 5894 | pepper_delegate_.OnImeConfirmComposition(text); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5895 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5896 | #if defined(OS_WIN) |
| 5897 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 5898 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 5899 | // it to WebKit to prevent WebKit from controlling IMEs. |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 5900 | // TODO(thakis): Honor |replacement_range| for plugins? |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5901 | if (focused_plugin_id_ >= 0) { |
| 5902 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5903 | for (it = plugin_delegates_.begin(); |
| 5904 | it != plugin_delegates_.end(); ++it) { |
| 5905 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 5906 | } |
| 5907 | return; |
| 5908 | } |
| 5909 | #endif |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5910 | if (replacement_range.IsValid() && webview()) { |
| 5911 | // Select the text in |replacement_range|, it will then be replaced by |
| 5912 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 5913 | if (WebFrame* frame = webview()->focusedFrame()) { |
[email protected] | 4bacb82 | 2011-11-02 15:10:16 | [diff] [blame] | 5914 | WebRange webrange = WebRange::fromDocumentRange( |
| 5915 | frame, replacement_range.start(), replacement_range.length()); |
| 5916 | if (!webrange.isNull()) |
[email protected] | 884f900 | 2012-08-21 19:33:58 | [diff] [blame] | 5917 | frame->selectRange(webrange); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5918 | } |
| 5919 | } |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 5920 | RenderWidget::OnImeConfirmComposition(text, replacement_range); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5921 | } |
| 5922 | } |
| 5923 | |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 5924 | void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) { |
| 5925 | RenderWidget::OnSetDeviceScaleFactor(device_scale_factor); |
| 5926 | if (webview()) |
| 5927 | webview()->setDeviceScaleFactor(device_scale_factor); |
| 5928 | } |
| 5929 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5930 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5931 | return pepper_delegate_.IsPluginFocused() ? |
| 5932 | pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType(); |
| 5933 | } |
| 5934 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5935 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
| 5936 | if (pepper_delegate_.IsPluginFocused()) { |
| 5937 | // TODO(kinaba) http://crbug.com/101101 |
| 5938 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 5939 | // use the caret position as an empty range for now. It will be updated |
| 5940 | // after Pepper API equips features related to surrounding text retrieval. |
| 5941 | gfx::Rect caret = pepper_delegate_.GetCaretBounds(); |
| 5942 | *start = caret; |
| 5943 | *end = caret; |
| 5944 | return; |
| 5945 | } |
| 5946 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 5947 | } |
| 5948 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 5949 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 5950 | std::vector<gfx::Rect>* bounds) { |
| 5951 | DCHECK(bounds); |
| 5952 | bounds->clear(); |
| 5953 | |
| 5954 | if (!webview()) |
| 5955 | return; |
| 5956 | size_t start_offset = 0; |
| 5957 | size_t character_count = 0; |
| 5958 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 5959 | return; |
| 5960 | if (character_count == 0) |
| 5961 | return; |
| 5962 | |
| 5963 | WebKit::WebFrame* frame = webview()->focusedFrame(); |
| 5964 | if (!frame) |
| 5965 | return; |
| 5966 | |
| 5967 | bounds->reserve(character_count); |
| 5968 | WebKit::WebRect webrect; |
| 5969 | for (size_t i = 0; i < character_count; ++i) { |
| 5970 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 5971 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 5972 | bounds->clear(); |
| 5973 | return; |
| 5974 | } |
| 5975 | bounds->push_back(webrect); |
| 5976 | } |
| 5977 | } |
| 5978 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5979 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5980 | return pepper_delegate_.IsPluginFocused() ? |
| 5981 | pepper_delegate_.CanComposeInline() : true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5982 | } |
| 5983 | |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5984 | #if defined(OS_WIN) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5985 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5986 | if (focused) |
| 5987 | focused_plugin_id_ = plugin_id; |
| 5988 | else |
| 5989 | focused_plugin_id_ = -1; |
| 5990 | } |
| 5991 | #endif |
| 5992 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5993 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5994 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5995 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5996 | } |
| 5997 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5998 | void RenderViewImpl::StartPluginIme() { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5999 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 6000 | // This message can be sent during event-handling, and needs to be delivered |
| 6001 | // within that context. |
| 6002 | msg->set_unblock(true); |
| 6003 | Send(msg); |
| 6004 | } |
| 6005 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6006 | gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 6007 | bool opaque, bool root) { |
[email protected] | b296829 | 2012-03-28 01:35:51 | [diff] [blame] | 6008 | gfx::PluginWindowHandle window = gfx::kNullPluginWindow; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 6009 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 6010 | routing_id(), opaque, root, &window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 6011 | if (window) { |
| 6012 | fake_plugin_window_handles_.insert(window); |
| 6013 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 6014 | return window; |
| 6015 | } |
| 6016 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6017 | void RenderViewImpl::DestroyFakePluginWindowHandle( |
| 6018 | gfx::PluginWindowHandle window) { |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 6019 | if (window && fake_plugin_window_handles_.find(window) != |
| 6020 | fake_plugin_window_handles_.end()) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 6021 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 6022 | fake_plugin_window_handles_.erase(window); |
| 6023 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 6024 | } |
| 6025 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6026 | void RenderViewImpl::AcceleratedSurfaceSetIOSurface( |
| 6027 | gfx::PluginWindowHandle window, |
| 6028 | int32 width, |
| 6029 | int32 height, |
| 6030 | uint64 io_surface_identifier) { |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 6031 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 6032 | routing_id(), window, width, height, io_surface_identifier)); |
| 6033 | } |
| 6034 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6035 | void RenderViewImpl::AcceleratedSurfaceSetTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 6036 | gfx::PluginWindowHandle window, |
| 6037 | int32 width, |
| 6038 | int32 height, |
| 6039 | TransportDIB::Handle transport_dib) { |
| 6040 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 6041 | routing_id(), window, width, height, transport_dib)); |
| 6042 | } |
| 6043 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6044 | TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 6045 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 6046 | TransportDIB::Handle dib_handle; |
| 6047 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 6048 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 6049 | return dib_handle; |
| 6050 | // Return an invalid handle if Send() fails. |
| 6051 | return TransportDIB::DefaultHandleValue(); |
| 6052 | } |
| 6053 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6054 | void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB( |
| 6055 | TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 6056 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 6057 | } |
| 6058 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6059 | void RenderViewImpl::AcceleratedSurfaceBuffersSwapped( |
[email protected] | 7de8fb7 | 2012-03-14 04:24:32 | [diff] [blame] | 6060 | gfx::PluginWindowHandle window, uint64 surface_handle) { |
[email protected] | f35d667 | 2010-10-28 21:39:14 | [diff] [blame] | 6061 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped( |
[email protected] | 7de8fb7 | 2012-03-14 04:24:32 | [diff] [blame] | 6062 | routing_id(), window, surface_handle)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 6063 | } |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 6064 | #endif // defined(OS_MACOSX) |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 6065 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6066 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6067 | const FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 6068 | WebFileChooserCompletion* completion) { |
| 6069 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 6070 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 6071 | // This sanity check prevents too many file choose requests from getting |
| 6072 | // queued which could DoS the user. Getting these is most likely a |
| 6073 | // programming error (there are many ways to DoS the user so it's not |
| 6074 | // considered a "real" security check), either in JS requesting many file |
| 6075 | // choosers to pop up, or in a plugin. |
| 6076 | // |
| 6077 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 6078 | // a file picker, which will address this issue in a better way. |
| 6079 | return false; |
| 6080 | } |
| 6081 | |
| 6082 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 6083 | new PendingFileChooser(params, completion))); |
| 6084 | if (file_chooser_completions_.size() == 1) { |
| 6085 | // Actually show the browse dialog when this is the first request. |
| 6086 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 6087 | } |
| 6088 | return true; |
| 6089 | } |
| 6090 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6091 | WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6092 | if (!geolocation_dispatcher_) |
| 6093 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 6094 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 6095 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6096 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6097 | WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6098 | WebKit::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6099 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6100 | if (!input_tag_speech_dispatcher_) |
| 6101 | input_tag_speech_dispatcher_ = |
| 6102 | new InputTagSpeechDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 6103 | #endif |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 6104 | return input_tag_speech_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6105 | } |
| 6106 | |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 6107 | WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
| 6108 | #if defined(ENABLE_INPUT_SPEECH) |
| 6109 | if (!speech_recognition_dispatcher_) |
| 6110 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
| 6111 | #endif |
| 6112 | return speech_recognition_dispatcher_; |
| 6113 | } |
| 6114 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6115 | WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 6116 | if (!device_orientation_dispatcher_) |
| 6117 | device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this); |
| 6118 | return device_orientation_dispatcher_; |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 6119 | } |
| 6120 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6121 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 6122 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6123 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 6124 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 6125 | // different). |
| 6126 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 6127 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6128 | int minimum_percent = static_cast<int>( |
| 6129 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 6130 | int maximum_percent = static_cast<int>( |
| 6131 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6132 | |
| 6133 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 6134 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 6135 | } |
| 6136 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6137 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6138 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6139 | float zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 6140 | |
| 6141 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged()); |
| 6142 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6143 | // Tell the browser which url got zoomed so it can update the menu and the |
| 6144 | // saved values if necessary |
| 6145 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 6146 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 6147 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6148 | } |
| 6149 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6150 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 6151 | const WebString& base_url, |
| 6152 | const WebString& url, |
| 6153 | const WebString& title) { |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6154 | bool user_gesture = (webview()->focusedFrame() && |
| 6155 | webview()->focusedFrame()->isProcessingUserGesture()); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6156 | GURL base(base_url); |
| 6157 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 6158 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 6159 | return; |
| 6160 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 6161 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 6162 | UTF16ToUTF8(scheme), |
| 6163 | absolute_url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6164 | title, |
| 6165 | user_gesture)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6166 | } |
| 6167 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6168 | WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6169 | WebKit::WebPageVisibilityState current_state = is_hidden() ? |
| 6170 | WebKit::WebPageVisibilityStateHidden : |
| 6171 | WebKit::WebPageVisibilityStateVisible; |
| 6172 | WebKit::WebPageVisibilityState override_state = current_state; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6173 | if (GetContentClient()->renderer()-> |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6174 | ShouldOverridePageVisibilityState(this, |
| 6175 | &override_state)) |
| 6176 | return override_state; |
| 6177 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 6178 | } |
| 6179 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6180 | WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6181 | EnsureMediaStreamImpl(); |
| 6182 | return media_stream_impl_; |
| 6183 | } |
| 6184 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 6185 | void RenderViewImpl::draggableRegionsChanged() { |
| 6186 | FOR_EACH_OBSERVER( |
| 6187 | RenderViewObserver, |
| 6188 | observers_, |
| 6189 | DraggableRegionsChanged(webview()->mainFrame())); |
| 6190 | } |
| 6191 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6192 | #if defined(OS_ANDROID) |
| 6193 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 6194 | const WebHitTestResult& touch_hit) { |
| 6195 | DCHECK(!touch_hit.isNull()); |
| 6196 | DCHECK(!touch_hit.node().isNull()); |
| 6197 | DCHECK(touch_hit.node().isTextNode()); |
| 6198 | |
| 6199 | // Process the position with all the registered content detectors until |
| 6200 | // a match is found. Priority is provided by their relative order. |
| 6201 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 6202 | it != content_detectors_.end(); ++it) { |
| 6203 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 6204 | if (content.valid) { |
| 6205 | return WebContentDetectionResult(content.content_boundaries, |
| 6206 | UTF8ToUTF16(content.text), content.intent_url); |
| 6207 | } |
| 6208 | } |
| 6209 | return WebContentDetectionResult(); |
| 6210 | } |
| 6211 | |
| 6212 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 6213 | // Introduce a short delay so that the user can notice the content. |
| 6214 | MessageLoop::current()->PostDelayedTask( |
| 6215 | FROM_HERE, |
| 6216 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(), |
| 6217 | intent, expected_content_intent_id_), |
| 6218 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 6219 | } |
| 6220 | |
| 6221 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 6222 | ++expected_content_intent_id_; |
| 6223 | } |
| 6224 | |
| 6225 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 6226 | size_t request_id) { |
| 6227 | if (request_id != expected_content_intent_id_) |
| 6228 | return; |
| 6229 | |
| 6230 | // Remove the content highlighting if any. |
| 6231 | scheduleComposite(); |
| 6232 | |
| 6233 | if (!intent.is_empty()) |
| 6234 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 6235 | } |
| 6236 | #endif |
| 6237 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6238 | void RenderViewImpl::OnAsyncFileOpened( |
| 6239 | base::PlatformFileError error_code, |
| 6240 | IPC::PlatformFileForTransit file_for_transit, |
| 6241 | int message_id) { |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 6242 | pepper_delegate_.OnAsyncFileOpened( |
| 6243 | error_code, |
| 6244 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 6245 | message_id); |
| 6246 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6247 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6248 | void RenderViewImpl::OnPpapiBrokerChannelCreated( |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6249 | int request_id, |
[email protected] | d5430507 | 2011-06-22 20:58:43 | [diff] [blame] | 6250 | const IPC::ChannelHandle& handle) { |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6251 | pepper_delegate_.OnPpapiBrokerChannelCreated(request_id, |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6252 | handle); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 6253 | } |
| 6254 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 6255 | void RenderViewImpl::OnPpapiBrokerPermissionResult( |
| 6256 | int request_id, |
| 6257 | bool result) { |
| 6258 | pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result); |
| 6259 | } |
| 6260 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6261 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6262 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 6263 | if (external_popup_menu_ == NULL) { |
| 6264 | // Crash reports from the field indicate that we can be notified with a |
| 6265 | // NULL external popup menu (we probably get notified twice). |
| 6266 | // If you hit this please file a bug against jcivelli and include the page |
| 6267 | // and steps to repro. |
| 6268 | NOTREACHED(); |
| 6269 | return; |
| 6270 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6271 | external_popup_menu_->DidSelectItem(selected_index); |
| 6272 | external_popup_menu_.reset(); |
| 6273 | } |
| 6274 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 6275 | |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6276 | #if defined(OS_ANDROID) |
| 6277 | void RenderViewImpl::OnSelectPopupMenuItems( |
| 6278 | bool canceled, |
| 6279 | const std::vector<int>& selected_indices) { |
| 6280 | // It is possible to receive more than one of these calls if the user presses |
| 6281 | // a select faster than it takes for the show-select-popup IPC message to make |
| 6282 | // it to the browser UI thread. Ignore the extra-messages. |
| 6283 | // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
| 6284 | if (!external_popup_menu_.get()) |
| 6285 | return; |
| 6286 | |
| 6287 | external_popup_menu_->DidSelectItems(canceled, selected_indices); |
| 6288 | external_popup_menu_.reset(); |
| 6289 | } |
| 6290 | #endif |
| 6291 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6292 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6293 | const CustomContextMenuContext& custom_context) { |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6294 | if (custom_context.request_id) { |
| 6295 | // External request, should be in our map. |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6296 | ContextMenuClient* client = |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6297 | pending_context_menus_.Lookup(custom_context.request_id); |
[email protected] | e0fd0eb | 2012-10-17 21:11:46 | [diff] [blame] | 6298 | if (client) { |
| 6299 | client->OnMenuClosed(custom_context.request_id); |
| 6300 | pending_context_menus_.Remove(custom_context.request_id); |
| 6301 | } |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6302 | } else { |
| 6303 | // Internal request, forward to WebKit. |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 6304 | context_menu_node_.reset(); |
[email protected] | 860ee64 | 2012-10-13 03:46:25 | [diff] [blame] | 6305 | } |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 6306 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6307 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6308 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6309 | if (!webview()) |
| 6310 | return; |
| 6311 | WebFrame* main_frame = webview()->mainFrame(); |
| 6312 | if (!main_frame) |
| 6313 | return; |
| 6314 | main_frame->enableViewSourceMode(true); |
| 6315 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 6316 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6317 | bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
[email protected] | ab21f2c | 2011-11-19 00:50:08 | [diff] [blame] | 6318 | return !!RenderThreadImpl::current()->compositor_thread(); |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 6319 | } |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 6320 | |
[email protected] | 64d0e19 | 2011-12-09 14:44:20 | [diff] [blame] | 6321 | void RenderViewImpl::OnJavaBridgeInit() { |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6322 | DCHECK(!java_bridge_dispatcher_); |
[email protected] | 464750f | 2011-10-24 23:16:18 | [diff] [blame] | 6323 | #if defined(ENABLE_JAVA_BRIDGE) |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6324 | java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
[email protected] | 464750f | 2011-10-24 23:16:18 | [diff] [blame] | 6325 | #endif |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 6326 | } |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 6327 | |
| 6328 | void RenderViewImpl::OnUpdatedFrameTree( |
| 6329 | int process_id, |
| 6330 | int route_id, |
| 6331 | const std::string& frame_tree) { |
[email protected] | e12dbe6f | 2012-10-04 22:11:19 | [diff] [blame] | 6332 | // TODO(nasko): Remove once http://crbug.com/153701 is fixed. |
| 6333 | DCHECK(false); |
[email protected] | 5fa9b36b | 2012-09-21 18:14:27 | [diff] [blame] | 6334 | // We should only act on this message if we are swapped out. It's possible |
| 6335 | // for this to happen due to races. |
| 6336 | if (!is_swapped_out_) |
| 6337 | return; |
| 6338 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 6339 | base::DictionaryValue* frames = NULL; |
| 6340 | scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree)); |
| 6341 | if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY)) |
| 6342 | tree->GetAsDictionary(&frames); |
| 6343 | |
| 6344 | updating_frame_tree_ = true; |
| 6345 | active_frame_id_map_.clear(); |
| 6346 | |
| 6347 | target_process_id_ = process_id; |
| 6348 | target_routing_id_ = route_id; |
| 6349 | CreateFrameTree(webview()->mainFrame(), frames); |
| 6350 | |
| 6351 | updating_frame_tree_ = false; |
| 6352 | } |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6353 | |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6354 | #if defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6355 | bool RenderViewImpl::didTapMultipleTargets( |
| 6356 | const WebKit::WebGestureEvent& event, |
| 6357 | const WebVector<WebRect>& target_rects) { |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6358 | gfx::Rect finger_rect( |
| 6359 | event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2, |
| 6360 | event.data.tap.width, event.data.tap.height); |
| 6361 | gfx::Rect zoom_rect; |
| 6362 | float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
| 6363 | finger_rect, target_rects, GetSize(), &zoom_rect); |
| 6364 | if (!scale) |
| 6365 | return false; |
| 6366 | |
| 6367 | gfx::Size canvas_size = zoom_rect.size(); |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 6368 | canvas_size = ToCeiledSize(gfx::ScaleSize(canvas_size, scale)); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6369 | TransportDIB* transport_dib = NULL; |
| 6370 | { |
| 6371 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 6372 | RenderProcess::current()->GetDrawingCanvas(&transport_dib, |
| 6373 | gfx::Rect(canvas_size))); |
| 6374 | if (!canvas.get()) |
| 6375 | return false; |
| 6376 | |
| 6377 | canvas->scale(scale, scale); |
| 6378 | |
| 6379 | canvas->translate(-zoom_rect.x(), -zoom_rect.y()); |
| 6380 | webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect, |
| 6381 | WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent); |
| 6382 | } |
| 6383 | Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_, |
| 6384 | zoom_rect, |
| 6385 | canvas_size, |
| 6386 | transport_dib->id())); |
| 6387 | |
| 6388 | return true; |
| 6389 | } |
[email protected] | efd7e47f | 2012-10-19 20:37:51 | [diff] [blame] | 6390 | #endif |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 6391 | |
| 6392 | void RenderViewImpl::OnReleaseDisambiguationPopupDIB( |
| 6393 | TransportDIB::Handle dib_handle) { |
| 6394 | TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| 6395 | RenderProcess::current()->ReleaseTransportDIB(dib); |
| 6396 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 6397 | |
| 6398 | } // namespace content |