[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 | #include <string> |
| 10 | #include <vector> |
| 11 | |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 12 | #include "base/bind.h" |
| 13 | #include "base/bind_helpers.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | e7ca289 | 2012-09-01 00:52:15 | [diff] [blame] | 16 | #include "base/debug/trace_event.h" |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 17 | #include "base/json/json_reader.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 19 | #include "base/lazy_instance.h" |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 20 | #include "base/message_loop_proxy.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 21 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 22 | #include "base/path_service.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 23 | #include "base/process_util.h" |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 24 | #include "base/string_number_conversions.h" |
[email protected] | 0a35efc | 2012-03-13 17:28:13 | [diff] [blame] | 25 | #include "base/string_piece.h" |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 26 | #include "base/string_split.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | #include "base/string_util.h" |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 28 | #include "base/sys_string_conversions.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 29 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 30 | #include "base/utf_string_conversions.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] | bac466e | 2012-07-31 02:10:54 | [diff] [blame] | 42 | #include "content/common/old_browser_plugin_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 43 | #include "content/common/pepper_messages.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 44 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 45 | #include "content/common/quota_dispatcher.h" |
[email protected] | 940895b | 2011-08-20 00:50:05 | [diff] [blame] | 46 | #include "content/common/request_extra_data.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 47 | #include "content/common/socket_stream_handle_data.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 48 | #include "content/common/view_messages.h" |
[email protected] | 4e1eb339 | 2012-05-18 00:08:05 | [diff] [blame] | 49 | #include "content/common/webmessageportchannel_impl.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 50 | #include "content/public/common/bindings_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 51 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 52 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 53 | #include "content/public/common/content_switches.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 54 | #include "content/public/common/context_menu_params.h" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 55 | #include "content/public/common/file_chooser_params.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 56 | #include "content/public/common/url_constants.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 57 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 58 | #include "content/public/renderer/document_state.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 59 | #include "content/public/renderer/navigation_state.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] | cc510d7e | 2012-08-08 04:40:10 | [diff] [blame] | 64 | #include "content/renderer/browser_plugin/old/old_browser_plugin.h" |
[email protected] | 14cf0f1 | 2012-06-18 17:15:57 | [diff] [blame] | 65 | #include "content/renderer/browser_plugin/old/browser_plugin_channel_manager.h" |
| 66 | #include "content/renderer/browser_plugin/old/browser_plugin_constants.h" |
| 67 | #include "content/renderer/browser_plugin/old/guest_to_embedder_channel.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 68 | #include "content/renderer/device_orientation_dispatcher.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 69 | #include "content/renderer/devtools_agent.h" |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 70 | #include "content/renderer/dom_automation_controller.h" |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 71 | #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 72 | #include "content/renderer/external_popup_menu.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 73 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 74 | #include "content/renderer/gpu/compositor_thread.h" |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 75 | #include "content/renderer/gpu/compositor_output_surface.h" |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 76 | #include "content/renderer/idle_user_detector.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 77 | #include "content/renderer/input_tag_speech_dispatcher.h" |
[email protected] | 0716190 | 2011-11-11 09:57:42 | [diff] [blame] | 78 | #include "content/renderer/java/java_bridge_dispatcher.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 79 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 80 | #include "content/renderer/media/media_stream_dependency_factory.h" |
| 81 | #include "content/renderer/media/media_stream_dispatcher.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 82 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 6048d51 | 2012-01-28 03:14:48 | [diff] [blame] | 83 | #include "content/renderer/media/render_audiosourceprovider.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 84 | #include "content/renderer/media/render_media_log.h" |
[email protected] | 6048d51 | 2012-01-28 03:14:48 | [diff] [blame] | 85 | #include "content/renderer/media/renderer_gpu_video_decoder_factories.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] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 91 | #include "content/renderer/render_view_mouse_lock_dispatcher.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 92 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 93 | #include "content/renderer/renderer_accessibility.h" |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 94 | #include "content/renderer/renderer_accessibility_complete.h" |
| 95 | #include "content/renderer/renderer_accessibility_focus_only.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 96 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 97 | #include "content/renderer/renderer_webcolorchooser_impl.h" |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 98 | #include "content/renderer/speech_recognition_dispatcher.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 99 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 100 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 0a35efc | 2012-03-13 17:28:13 | [diff] [blame] | 101 | #include "content/renderer/web_intents_host.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 102 | #include "content/renderer/web_ui_bindings.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 103 | #include "content/renderer/webplugin_delegate_proxy.h" |
| 104 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 105 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 106 | #include "media/base/media_switches.h" |
[email protected] | b8032290 | 2012-03-06 01:33:50 | [diff] [blame] | 107 | #include "media/base/message_loop_factory.h" |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 108 | #include "media/filters/audio_renderer_impl.h" |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 109 | #include "media/filters/gpu_video_decoder.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 110 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 111 | #include "net/base/escape.h" |
| 112 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame^] | 113 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 114 | #include "net/http/http_util.h" |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 115 | #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 116 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 117 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h" |
| 118 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 119 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 120 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 121 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 122 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 123 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 124 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" |
| 125 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" |
| 126 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 127 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 128 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 129 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 130 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 131 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 132 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h" |
[email protected] | 592e20b | 2012-01-20 05:53:44 | [diff] [blame] | 133 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 134 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h" |
[email protected] | 69f110d6 | 2011-03-17 19:01:14 | [diff] [blame] | 135 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h" |
[email protected] | 4e1eb339 | 2012-05-18 00:08:05 | [diff] [blame] | 136 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 137 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 138 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 139 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 140 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 141 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 142 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h" |
| 143 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 144 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 145 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 146 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h" |
| 147 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 148 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 149 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 150 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 151 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 152 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 153 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
| 154 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" |
| 155 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h" |
| 156 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h" |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 157 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 158 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" |
[email protected] | 50da23d0 | 2012-04-13 17:47:48 | [diff] [blame] | 159 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h" |
| 160 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 161 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h" |
| 162 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 163 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" |
| 164 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 165 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 166 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 167 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h" |
[email protected] | e6e90dc | 2011-12-03 00:01:37 | [diff] [blame] | 168 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 169 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 170 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h" |
| 171 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" |
| 172 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h" |
| 173 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 174 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 175 | #include "ui/base/dialogs/selected_file_info.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 176 | #include "ui/gfx/native_widget_types.h" |
| 177 | #include "ui/gfx/point.h" |
| 178 | #include "ui/gfx/rect.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 179 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 180 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | b928936b | 2012-04-13 01:16:16 | [diff] [blame] | 181 | #include "webkit/dom_storage/dom_storage_types.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 182 | #include "webkit/forms/form_data.h" |
| 183 | #include "webkit/forms/form_field.h" |
| 184 | #include "webkit/forms/password_form_dom_manager.h" |
[email protected] | 25e18f8 | 2010-10-27 16:38:43 | [diff] [blame] | 185 | #include "webkit/glue/alt_error_page_resource_fetcher.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 186 | #include "webkit/glue/dom_operations.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 187 | #include "webkit/glue/glue_serialize.h" |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 188 | #include "webkit/glue/web_intent_service_data.h" |
[email protected] | 851334d | 2012-06-15 22:39:31 | [diff] [blame] | 189 | #include "webkit/glue/webdropdata.h" |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 190 | #include "webkit/glue/webkit_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 191 | #include "webkit/glue/webkit_glue.h" |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 192 | #include "webkit/glue/weburlresponse_extradata_impl.h" |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 193 | #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
[email protected] | a9288f5 | 2011-11-17 05:18:16 | [diff] [blame] | 194 | #include "webkit/media/webmediaplayer_impl.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 195 | #include "webkit/plugins/npapi/plugin_list.h" |
| 196 | #include "webkit/plugins/npapi/webplugin_delegate.h" |
| 197 | #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
| 198 | #include "webkit/plugins/npapi/webplugin_impl.h" |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 199 | #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 200 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 201 | #if defined(OS_ANDROID) |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 202 | #include "content/common/android/device_info.h" |
| 203 | #include "content/renderer/android/address_detector.h" |
| 204 | #include "content/renderer/android/content_detector.h" |
| 205 | #include "content/renderer/android/email_detector.h" |
| 206 | #include "content/renderer/android/phone_number_detector.h" |
[email protected] | dbd3d21 | 2012-07-13 02:17:22 | [diff] [blame] | 207 | #include "content/renderer/media/stream_texture_factory_impl_android.h" |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 208 | #include "content/renderer/media/webmediaplayer_proxy_impl_android.h" |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 209 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 210 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h" |
| 211 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h" |
| 212 | #include "ui/gfx/rect_f.h" |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 213 | #include "webkit/media/android/media_player_bridge_manager_impl.h" |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 214 | #include "webkit/media/android/webmediaplayer_android.h" |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 215 | #include "webkit/media/android/webmediaplayer_impl_android.h" |
| 216 | #include "webkit/media/android/webmediaplayer_in_process_android.h" |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 217 | #include "webkit/media/android/webmediaplayer_manager_android.h" |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 218 | #elif defined(OS_WIN) |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 219 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 220 | // * theming |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 221 | #include "ui/base/native_theme/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 222 | #elif defined(USE_X11) |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 223 | #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 224 | #include "ui/base/native_theme/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 225 | #elif defined(OS_MACOSX) |
| 226 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 227 | #endif |
| 228 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 229 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 230 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 231 | using WebKit::WebApplicationCacheHost; |
| 232 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 233 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 234 | using WebKit::WebColor; |
| 235 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 236 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 237 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 238 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 239 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 240 | using WebKit::WebDataSource; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 241 | using WebKit::WebDocument; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 242 | using WebKit::WebDOMEvent; |
| 243 | using WebKit::WebDOMMessageEvent; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 244 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 245 | using WebKit::WebDragOperation; |
| 246 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 247 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 248 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 249 | using WebKit::WebExternalPopupMenu; |
| 250 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 251 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 252 | using WebKit::WebFileSystem; |
| 253 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 254 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 255 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 256 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 257 | using WebKit::WebFrame; |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 258 | using WebKit::WebGraphicsContext3D; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 259 | using WebKit::WebHistoryItem; |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 260 | using WebKit::WebHTTPBody; |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 261 | using WebKit::WebIconURL; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 262 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 263 | using WebKit::WebInputElement; |
[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] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 317 | using content::DocumentState; |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 318 | using content::NavigationState; |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 319 | using content::Referrer; |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 320 | using content::RenderThread; |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 321 | using content::RenderViewObserver; |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 322 | using content::RenderViewVisitor; |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 323 | using content::RendererAccessibilityComplete; |
| 324 | using content::RendererAccessibilityFocusOnly; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 325 | using content::V8ValueConverter; |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 326 | using webkit::forms::FormField; |
| 327 | using webkit::forms::PasswordForm; |
| 328 | using webkit::forms::PasswordFormDomManager; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 329 | using webkit_glue::AltErrorPageResourceFetcher; |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 330 | using webkit_glue::ResourceFetcher; |
[email protected] | 6717bf27 | 2012-05-11 23:31:25 | [diff] [blame] | 331 | using webkit_glue::WebPreferences; |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 332 | using webkit_glue::WebURLResponseExtraDataImpl; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 333 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 334 | #if defined(OS_ANDROID) |
| 335 | using content::AddressDetector; |
| 336 | using content::ContentDetector; |
| 337 | using content::EmailDetector; |
| 338 | using content::PhoneNumberDetector; |
| 339 | using WebKit::WebContentDetectionResult; |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 340 | using WebKit::WebFloatPoint; |
| 341 | using WebKit::WebFloatRect; |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 342 | using WebKit::WebHitTestResult; |
| 343 | #endif |
| 344 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 345 | //----------------------------------------------------------------------------- |
| 346 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 347 | typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 348 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 349 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 350 | // Time, in seconds, we delay before sending content state changes (such as form |
| 351 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 352 | // spamming the browser. |
| 353 | // To avoid having tab/session restore require sending a message to get the |
| 354 | // current content state during tab closing we use a shorter timeout for the |
| 355 | // foreground renderer. This means there is a small window of time from which |
| 356 | // content state is modified and not sent to session restore, but this is |
| 357 | // better than having to wake up all renderers during shutdown. |
| 358 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 359 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 360 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 361 | static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 362 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 363 | // The maximum number of popups that can be spawned from one page. |
| 364 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 365 | |
[email protected] | c514d63 | 2011-08-16 22:54:44 | [diff] [blame] | 366 | static const float kScalingIncrement = 0.1f; |
| 367 | |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 368 | static const float kScalingIncrementForGesture = 0.01f; |
| 369 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 370 | #if defined(OS_ANDROID) |
| 371 | // Delay between tapping in content and launching the associated android intent. |
| 372 | // Used to allow users see what has been recognized as content. |
| 373 | static const size_t kContentIntentDelayMilliseconds = 700; |
| 374 | #endif |
| 375 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 376 | static RenderViewImpl* FromRoutingID(int32 routing_id) { |
| 377 | return static_cast<RenderViewImpl*>( |
| 378 | ChildThread::current()->ResolveRoute(routing_id)); |
| 379 | } |
| 380 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 381 | static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) { |
| 382 | for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) { |
| 383 | if (frame->identifier() == frame_id) |
| 384 | return frame; |
| 385 | } |
| 386 | return NULL; |
| 387 | } |
| 388 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 389 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 390 | WebVector<WebURL> urls; |
| 391 | ds->redirectChain(urls); |
| 392 | result->reserve(urls.size()); |
| 393 | for (size_t i = 0; i < urls.size(); ++i) |
| 394 | result->push_back(urls[i]); |
| 395 | } |
| 396 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 397 | // If |data_source| is non-null and has a DocumentState associated with it, |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 398 | // the AltErrorPageResourceFetcher is reset. |
| 399 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 400 | if (data_source) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 401 | DocumentState* document_state = DocumentState::FromDataSource(data_source); |
| 402 | if (document_state) |
| 403 | document_state->set_alt_error_page_fetcher(NULL); |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 407 | static bool IsReload(const ViewMsg_Navigate_Params& params) { |
| 408 | return |
| 409 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 410 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE || |
| 411 | params.navigation_type == |
| 412 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 413 | } |
| 414 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 415 | static WebReferrerPolicy GetReferrerPolicyFromRequest( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 416 | WebFrame* frame, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 417 | const WebURLRequest& request) { |
| 418 | return request.extraData() ? |
| 419 | static_cast<RequestExtraData*>(request.extraData())->referrer_policy() : |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 420 | frame->document().referrerPolicy(); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 423 | static WebURLResponseExtraDataImpl* GetExtraDataFromResponse( |
| 424 | const WebURLResponse& response) { |
| 425 | return static_cast<WebURLResponseExtraDataImpl*>( |
| 426 | response.extraData()); |
| 427 | } |
| 428 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 429 | NOINLINE static void CrashIntentionally() { |
| 430 | // NOTE(shess): Crash directly rather than using NOTREACHED() so |
| 431 | // that the signature is easier to triage in crash reports. |
| 432 | volatile int* zero = NULL; |
| 433 | *zero = 0; |
| 434 | } |
| 435 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 436 | static void MaybeHandleDebugURL(const GURL& url) { |
| 437 | if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 438 | return; |
| 439 | if (url == GURL(chrome::kChromeUICrashURL)) { |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 440 | CrashIntentionally(); |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 441 | } else if (url == GURL(chrome::kChromeUIKillURL)) { |
| 442 | base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
| 443 | } else if (url == GURL(chrome::kChromeUIHangURL)) { |
| 444 | for (;;) { |
| 445 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 446 | } |
| 447 | } else if (url == GURL(chrome::kChromeUIShorthangURL)) { |
| 448 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 449 | } |
| 450 | } |
| 451 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 452 | // Returns false unless this is a top-level navigation. |
| 453 | static bool IsTopLevelNavigation(WebFrame* frame) { |
| 454 | return frame->parent() == NULL; |
| 455 | } |
| 456 | |
| 457 | // Returns false unless this is a top-level navigation that crosses origins. |
| 458 | static bool IsNonLocalTopLevelNavigation(const GURL& url, |
| 459 | WebFrame* frame, |
| 460 | WebNavigationType type) { |
| 461 | if (!IsTopLevelNavigation(frame)) |
| 462 | return false; |
| 463 | |
| 464 | // Navigations initiated within Webkit are not sent out to the external host |
| 465 | // in the following cases. |
| 466 | // 1. The url scheme is not http/https |
| 467 | // 2. The origin of the url and the opener is the same in which case the |
| 468 | // opener relationship is maintained. |
| 469 | // 3. Reloads/form submits/back forward navigations |
| 470 | if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) |
| 471 | return false; |
| 472 | |
| 473 | // Not interested in reloads/form submits/resubmits/back forward navigations. |
| 474 | if (type != WebKit::WebNavigationTypeReload && |
| 475 | type != WebKit::WebNavigationTypeFormSubmitted && |
| 476 | type != WebKit::WebNavigationTypeFormResubmitted && |
| 477 | type != WebKit::WebNavigationTypeBackForward) { |
| 478 | // The opener relationship between the new window and the parent allows the |
| 479 | // new window to script the parent and vice versa. This is not allowed if |
| 480 | // the origins of the two domains are different. This can be treated as a |
| 481 | // top level navigation and routed back to the host. |
| 482 | WebKit::WebFrame* opener = frame->opener(); |
| 483 | if (!opener) { |
| 484 | return true; |
| 485 | } |
| 486 | |
| 487 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 488 | return true; |
| 489 | } |
| 490 | return false; |
| 491 | } |
| 492 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 493 | // Recursively walks the frame tree and serializes it to JSON as described in |
| 494 | // the comment for ViewMsg_UpdateFrameTree. If |exclude_frame_subtree| is not |
| 495 | // NULL, the subtree for the frame is not included in the serialized form. |
| 496 | // This is used when a frame is going to be removed from the tree. |
| 497 | static void ConstructFrameTree(WebKit::WebFrame* frame, |
| 498 | WebKit::WebFrame* exclude_frame_subtree, |
| 499 | base::DictionaryValue* dict) { |
| 500 | dict->SetString(content::kFrameTreeNodeNameKey, |
| 501 | UTF16ToUTF8(frame->assignedName()).c_str()); |
| 502 | dict->SetInteger(content::kFrameTreeNodeIdKey, frame->identifier()); |
| 503 | |
| 504 | WebFrame* child = frame->firstChild(); |
| 505 | ListValue* children = new ListValue(); |
| 506 | for (; child; child = child->nextSibling()) { |
| 507 | if (child == exclude_frame_subtree) |
| 508 | continue; |
| 509 | |
| 510 | base::DictionaryValue* d = new base::DictionaryValue(); |
| 511 | ConstructFrameTree(child, exclude_frame_subtree, d); |
| 512 | children->Append(d); |
| 513 | } |
| 514 | if (children->GetSize() > 0) |
| 515 | dict->Set(content::kFrameTreeNodeSubtreeKey, children); |
| 516 | } |
| 517 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 518 | /////////////////////////////////////////////////////////////////////////////// |
| 519 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 520 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 521 | PendingFileChooser(const content::FileChooserParams& p, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 522 | WebFileChooserCompletion* c) |
| 523 | : params(p), |
| 524 | completion(c) { |
| 525 | } |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 526 | content::FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 527 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 528 | }; |
| 529 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 530 | namespace { |
| 531 | |
| 532 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 533 | public: |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 534 | explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget) |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 535 | : webwidget_(webwidget) {} |
| 536 | |
| 537 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 538 | if (succeeded) |
| 539 | webwidget_->didAcquirePointerLock(); |
| 540 | else |
| 541 | webwidget_->didNotAcquirePointerLock(); |
| 542 | } |
| 543 | |
| 544 | virtual void OnMouseLockLost() OVERRIDE { |
| 545 | webwidget_->didLosePointerLock(); |
| 546 | } |
| 547 | |
| 548 | virtual bool HandleMouseLockedInputEvent( |
| 549 | const WebKit::WebMouseEvent &event) OVERRIDE { |
| 550 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | private: |
| 555 | WebKit::WebWidget* webwidget_; |
| 556 | }; |
| 557 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 558 | int64 ExtractPostId(const WebHistoryItem& item) { |
| 559 | if (item.isNull()) |
| 560 | return -1; |
| 561 | |
| 562 | if (item.httpBody().isNull()) |
| 563 | return -1; |
| 564 | |
| 565 | return item.httpBody().identifier(); |
| 566 | } |
| 567 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 568 | } // namespace |
| 569 | |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 570 | RenderViewImpl::RenderViewImpl( |
| 571 | gfx::NativeViewId parent_hwnd, |
| 572 | int32 opener_id, |
| 573 | const content::RendererPreferences& renderer_prefs, |
| 574 | const WebPreferences& webkit_prefs, |
| 575 | SharedRenderViewCounter* counter, |
| 576 | int32 routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 577 | int32 surface_id, |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 578 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 579 | const string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 580 | bool is_renderer_created, |
| 581 | bool swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 582 | int32 next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 583 | const WebKit::WebScreenInfo& screen_info, |
[email protected] | cb25aa1 | 2012-08-07 19:13:43 | [diff] [blame] | 584 | content::old::GuestToEmbedderChannel* guest_to_embedder_channel, |
[email protected] | 3e3c452 | 2012-04-13 21:16:29 | [diff] [blame] | 585 | AccessibilityMode accessibility_mode) |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 586 | : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 587 | webkit_preferences_(webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 588 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 589 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 590 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 591 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 592 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 593 | opened_by_user_gesture_(true), |
| 594 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 595 | page_id_(-1), |
| 596 | last_page_id_sent_to_browser_(-1), |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 597 | next_page_id_(next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 598 | history_list_offset_(-1), |
| 599 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 600 | target_url_status_(TARGET_NONE), |
[email protected] | bbef1d3 | 2011-10-25 14:36:55 | [diff] [blame] | 601 | selection_text_offset_(0), |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 602 | cached_is_main_frame_pinned_to_left_(false), |
| 603 | cached_is_main_frame_pinned_to_right_(false), |
| 604 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 605 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 606 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 607 | geolocation_dispatcher_(NULL), |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 608 | input_tag_speech_dispatcher_(NULL), |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 609 | speech_recognition_dispatcher_(NULL), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 610 | device_orientation_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 611 | media_stream_dispatcher_(NULL), |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 612 | media_stream_impl_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 613 | devtools_agent_(NULL), |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 614 | accessibility_mode_(AccessibilityModeOff), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 615 | renderer_accessibility_(NULL), |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 616 | java_bridge_dispatcher_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 617 | mouse_lock_dispatcher_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 618 | #if defined(OS_ANDROID) |
| 619 | expected_content_intent_id_(0), |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 620 | media_player_proxy_(NULL), |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 621 | #endif |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 622 | session_storage_namespace_id_(session_storage_namespace_id), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 623 | handling_select_range_(false), |
| 624 | #if defined(OS_WIN) |
| 625 | focused_plugin_id_(-1), |
| 626 | #endif |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 627 | guest_to_embedder_channel_(guest_to_embedder_channel), |
| 628 | guest_pp_instance_(0), |
| 629 | guest_uninitialized_context_(NULL), |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 630 | updating_frame_tree_(false), |
| 631 | pending_frame_tree_update_(false), |
| 632 | target_process_id_(0), |
| 633 | target_routing_id_(0), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 634 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
[email protected] | ce2b28e | 2012-08-09 15:53:57 | [diff] [blame] | 635 | set_throttle_input_events(renderer_prefs.throttle_input_events); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 636 | routing_id_ = routing_id; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 637 | surface_id_ = surface_id; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 638 | if (opener_id != MSG_ROUTING_NONE && is_renderer_created) |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 639 | opener_id_ = opener_id; |
| 640 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 641 | // Ensure we start with a valid next_page_id_ from the browser. |
| 642 | DCHECK_GE(next_page_id_, 0); |
| 643 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 644 | #if defined(ENABLE_NOTIFICATIONS) |
| 645 | notification_provider_ = new NotificationProvider(this); |
| 646 | #else |
| 647 | notification_provider_ = NULL; |
| 648 | #endif |
| 649 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 650 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 651 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 652 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 653 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 654 | |
| 655 | #if defined(OS_ANDROID) |
| 656 | scoped_ptr<content::DeviceInfo> device_info(new content::DeviceInfo()); |
| 657 | |
| 658 | const std::string region_code = |
| 659 | command_line.HasSwitch(switches::kNetworkCountryIso) |
| 660 | ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) |
| 661 | : device_info->GetNetworkCountryIso(); |
| 662 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 663 | new AddressDetector())); |
| 664 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 665 | new PhoneNumberDetector(region_code))); |
| 666 | content_detectors_.push_back(linked_ptr<ContentDetector>( |
| 667 | new EmailDetector())); |
| 668 | #endif |
| 669 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 670 | if (counter) { |
| 671 | shared_popup_counter_ = counter; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 672 | // Only count this if it isn't swapped out upon creation. |
| 673 | if (!swapped_out) |
| 674 | shared_popup_counter_->data++; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 675 | decrement_shared_popup_at_destruction_ = true; |
| 676 | } else { |
| 677 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 678 | decrement_shared_popup_at_destruction_ = false; |
| 679 | } |
| 680 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 681 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 682 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 683 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 684 | AddRef(); |
| 685 | |
| 686 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 687 | // completing initialization. Otherwise, we can finish it now. |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 688 | if (!guest_to_embedder_channel && opener_id_ == MSG_ROUTING_NONE) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 689 | did_show_ = true; |
[email protected] | 2d7c855 | 2011-06-27 19:21:55 | [diff] [blame] | 690 | CompleteInit(parent_hwnd); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 691 | } |
| 692 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 693 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 694 | webview()->setDeviceScaleFactor(device_scale_factor_); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 695 | webkit_preferences_.Apply(webview()); |
| 696 | webview()->initializeMainFrame(this); |
[email protected] | 2024c92 | 2011-09-02 23:34:35 | [diff] [blame] | 697 | if (!frame_name.empty()) |
| 698 | webview()->mainFrame()->setName(frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 699 | webview()->settings()->setMinimumTimerInterval( |
| 700 | is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : |
| 701 | webkit_glue::kForegroundTabTimerInterval); |
| 702 | |
| 703 | OnSetRendererPrefs(renderer_prefs); |
| 704 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 705 | host_window_ = parent_hwnd; |
| 706 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 707 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 708 | if (!media_stream_dispatcher_) |
| 709 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 710 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 711 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 712 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 713 | #if defined(OS_MACOSX) |
| 714 | new TextInputClientObserver(this); |
| 715 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 716 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 717 | #if defined(OS_ANDROID) |
| 718 | media_player_manager_.reset( |
| 719 | new webkit_media::WebMediaPlayerManagerAndroid()); |
| 720 | #endif |
| 721 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 722 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 723 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 724 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 725 | mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this); |
[email protected] | 0fc7dea7 | 2012-02-09 03:47:40 | [diff] [blame] | 726 | intents_host_ = new WebIntentsHost(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 727 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 728 | // Create renderer_accessibility_ if needed. |
| 729 | OnSetAccessibilityMode(accessibility_mode); |
| 730 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 731 | new IdleUserDetector(this); |
| 732 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 733 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 734 | enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION; |
| 735 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 736 | ProcessViewLayoutFlags(command_line); |
[email protected] | 7ddea980 | 2012-02-22 23:08:05 | [diff] [blame] | 737 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 738 | content::GetContentClient()->renderer()->RenderViewCreated(this); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 739 | |
| 740 | // If we have an opener_id but we weren't created by a renderer, then |
| 741 | // it's the browser asking us to set our opener to another RenderView. |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 742 | if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) { |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 743 | RenderViewImpl* opener_view = FromRoutingID(opener_id); |
| 744 | if (opener_view) |
| 745 | webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | // If we are initially swapped out, navigate to kSwappedOutURL. |
| 749 | // This ensures we are in a unique origin that others cannot script. |
| 750 | if (is_swapped_out_) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 751 | NavigateToSwappedOutURL(webview()->mainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 752 | } |
| 753 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 754 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 755 | history_page_ids_.clear(); |
| 756 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 757 | if (decrement_shared_popup_at_destruction_) |
| 758 | shared_popup_counter_->data--; |
| 759 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 760 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 761 | while (!file_chooser_completions_.empty()) { |
| 762 | if (file_chooser_completions_.front()->completion) { |
| 763 | file_chooser_completions_.front()->completion->didChooseFile( |
| 764 | WebVector<WebString>()); |
| 765 | } |
| 766 | file_chooser_completions_.pop_front(); |
| 767 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 768 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 769 | #if defined(OS_MACOSX) |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 770 | // Destroy all fake plugin window handles on the browser side. |
| 771 | while (!fake_plugin_window_handles_.empty()) { |
| 772 | // Make sure no NULL plugin window handles were inserted into this list. |
| 773 | DCHECK(*fake_plugin_window_handles_.begin()); |
| 774 | // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
| 775 | DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
| 776 | } |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 777 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 778 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 779 | #ifndef NDEBUG |
| 780 | // Make sure we are no longer referenced by the ViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 781 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 782 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 783 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 784 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 785 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 786 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 787 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 791 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 792 | ViewMap* views = g_view_map.Pointer(); |
| 793 | ViewMap::iterator it = views->find(webview); |
| 794 | return it == views->end() ? NULL : it->second; |
| 795 | } |
| 796 | |
| 797 | /*static*/ |
| 798 | content::RenderView* |
| 799 | content::RenderView::FromWebView(WebKit::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 800 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /*static*/ |
| 804 | void content::RenderView::ForEach(content::RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 805 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 806 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 807 | if (!visitor->Visit(it->second)) |
| 808 | return; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 813 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 814 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 815 | int32 opener_id, |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 816 | const content::RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 817 | const WebPreferences& webkit_prefs, |
| 818 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 819 | int32 routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 820 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 821 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 822 | const string16& frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 823 | bool is_renderer_created, |
| 824 | bool swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 825 | int32 next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 826 | const WebKit::WebScreenInfo& screen_info, |
[email protected] | cb25aa1 | 2012-08-07 19:13:43 | [diff] [blame] | 827 | content::old::GuestToEmbedderChannel* guest_to_embedder_channel, |
[email protected] | 3e3c452 | 2012-04-13 21:16:29 | [diff] [blame] | 828 | AccessibilityMode accessibility_mode) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 829 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 830 | return new RenderViewImpl( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 831 | parent_hwnd, |
| 832 | opener_id, |
| 833 | renderer_prefs, |
| 834 | webkit_prefs, |
| 835 | counter, |
| 836 | routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 837 | surface_id, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 838 | session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 839 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 840 | is_renderer_created, |
| 841 | swapped_out, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 842 | next_page_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 843 | screen_info, |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 844 | guest_to_embedder_channel, |
[email protected] | 3e3c452 | 2012-04-13 21:16:29 | [diff] [blame] | 845 | accessibility_mode); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 846 | } |
| 847 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 848 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 849 | observers_.AddObserver(observer); |
| 850 | } |
| 851 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 852 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 853 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 854 | observers_.RemoveObserver(observer); |
| 855 | } |
| 856 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 857 | WebKit::WebView* RenderViewImpl::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 858 | return static_cast<WebKit::WebView*>(webwidget()); |
| 859 | } |
| 860 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 861 | void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) { |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 862 | if (!enabled) { |
| 863 | load_progress_tracker_.reset(NULL); |
| 864 | return; |
| 865 | } |
| 866 | if (load_progress_tracker_ == NULL) |
| 867 | load_progress_tracker_.reset(new LoadProgressTracker(this)); |
| 868 | } |
| 869 | |
[email protected] | cb25aa1 | 2012-08-07 19:13:43 | [diff] [blame] | 870 | content::old::GuestToEmbedderChannel* |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 871 | RenderViewImpl::GetGuestToEmbedderChannel() const { |
| 872 | return guest_to_embedder_channel_; |
| 873 | } |
| 874 | |
| 875 | void RenderViewImpl::SetGuestToEmbedderChannel( |
[email protected] | cb25aa1 | 2012-08-07 19:13:43 | [diff] [blame] | 876 | content::old::GuestToEmbedderChannel* channel) { |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 877 | guest_to_embedder_channel_ = channel; |
| 878 | } |
| 879 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 880 | void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) { |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 881 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 882 | } |
| 883 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 884 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 885 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 886 | // If the renderer is visible, set initial visibility and focus state. |
| 887 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 888 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 889 | delegate->SetContainerVisibility(true); |
| 890 | if (webview() && webview()->isActive()) |
| 891 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 892 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 893 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 894 | // Plugins start assuming the content has focus (so that they work in |
| 895 | // environments where RenderView isn't hosting them), so we always have to |
| 896 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 897 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 900 | void RenderViewImpl::UnregisterPluginDelegate( |
| 901 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 902 | plugin_delegates_.erase(delegate); |
| 903 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 904 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 905 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 906 | const GURL& page_url, |
| 907 | const std::string& mime_type, |
| 908 | webkit::WebPluginInfo* plugin_info, |
| 909 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 910 | bool found = false; |
| 911 | Send(new ViewHostMsg_GetPluginInfo( |
| 912 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 913 | actual_mime_type)); |
| 914 | return found; |
| 915 | } |
| 916 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 917 | void RenderViewImpl::TransferActiveWheelFlingAnimation( |
| 918 | const WebKit::WebActiveWheelFlingParameters& params) { |
| 919 | if (webview()) |
| 920 | webview()->transferActiveWheelFlingAnimation(params); |
| 921 | } |
| 922 | |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 923 | bool RenderViewImpl::HasIMETextFocus() { |
| 924 | return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
| 925 | } |
| 926 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 927 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 928 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 929 | if (main_frame) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 930 | content::GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 931 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 932 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 933 | RenderViewObserver* observer; |
| 934 | while ((observer = it.GetNext()) != NULL) |
| 935 | if (observer->OnMessageReceived(message)) |
| 936 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 937 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 938 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 939 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 940 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 941 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 942 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 943 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 944 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 945 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 946 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 947 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 948 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 949 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 950 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 951 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 952 | IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 953 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
| 954 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 955 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 956 | IPC_MESSAGE_HANDLER(ViewMsg_ReplaceAll, OnReplaceAll) |
| 957 | IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect) |
| 958 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets, |
| 959 | OnSetEditableSelectionOffsets) |
| 960 | IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText, |
| 961 | OnSetCompositionFromExistingText) |
| 962 | IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete, |
| 963 | OnExtendSelectionAndDelete) |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 964 | IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 965 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 966 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 967 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 968 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 969 | #if defined(OS_ANDROID) |
| 970 | IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult, |
| 971 | OnActivateNearestFindResult) |
| 972 | IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, |
| 973 | OnFindMatchRects) |
| 974 | #endif |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 975 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 976 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 977 | IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 978 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 979 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 980 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 981 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 982 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 983 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 984 | IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 985 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 986 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 987 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 988 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 989 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 990 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 991 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 992 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 993 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
[email protected] | d098079 | 2011-02-13 19:41:40 | [diff] [blame] | 994 | IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 995 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 996 | IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect, |
| 997 | OnScrollFocusedEditableNodeIntoRect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 998 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 999 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 1000 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1001 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1002 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1003 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 1004 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1005 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1006 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 1007 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1008 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 1009 | OnDisassociateFromPopupCount) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1010 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 1011 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1012 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1013 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1014 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1015 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1016 | IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1017 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1018 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1019 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 1020 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 1021 | IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent, |
| 1022 | OnOrientationChangeEvent) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1023 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 1024 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 1025 | IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime, |
| 1026 | OnSetNavigationStartTime) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 1027 | #if defined(OS_MACOSX) |
| 1028 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 1029 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 1030 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 1031 | OnPluginImeCompositionCompleted) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 1032 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 1033 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 1034 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 1035 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 1036 | OnCustomContextMenuAction) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 1037 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 1038 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, |
| 1039 | OnPpapiBrokerChannelCreated) |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 1040 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult, |
| 1041 | OnPpapiBrokerPermissionResult) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 1042 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 1043 | OnGetAllSavableResourceLinksForCurrentPage) |
| 1044 | IPC_MESSAGE_HANDLER( |
| 1045 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 1046 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1047 | #if defined(OS_MACOSX) |
| 1048 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 1049 | #elif defined(OS_ANDROID) |
| 1050 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1051 | #endif |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 1052 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 1053 | // TODO(viettrungluu): Move to a separate message filter. |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1054 | #if defined(OS_MACOSX) |
| 1055 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1056 | #endif |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1057 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 1058 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 1059 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 1060 | IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 1061 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 1062 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1063 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1064 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1065 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1066 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1067 | |
| 1068 | if (!msg_is_ok) { |
| 1069 | // The message had a handler, but its deserialization failed. |
| 1070 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1071 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1072 | } |
| 1073 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1074 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1075 | } |
| 1076 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1077 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 1078 | // If we don't have guest-to-embedder channel associated with this RenderView |
| 1079 | // but we need one, grab one now. |
| 1080 | if (!params.embedder_channel_name.empty() && !GetGuestToEmbedderChannel()) { |
[email protected] | cb25aa1 | 2012-08-07 19:13:43 | [diff] [blame] | 1081 | content::old::GuestToEmbedderChannel* embedder_channel = |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 1082 | RenderThreadImpl::current()->browser_plugin_channel_manager()-> |
| 1083 | GetChannelByName(params.embedder_channel_name); |
| 1084 | DCHECK(embedder_channel); |
| 1085 | SetGuestToEmbedderChannel(embedder_channel); |
| 1086 | host_window_set_ = false; |
| 1087 | // TODO(fsamuel): This is test code. Need to find a better way to tell |
| 1088 | // a WebView to drop its context. This needs to change in |
| 1089 | // GuestToEmbedderChannel::OnContextLost. |
| 1090 | GetWebView()->loseCompositorContext(1); |
| 1091 | RenderThreadImpl::current()->browser_plugin_channel_manager()-> |
| 1092 | ReportChannelToEmbedder(this, |
| 1093 | embedder_channel->embedder_channel_handle(), |
| 1094 | params.embedder_channel_name, |
| 1095 | params.embedder_container_id); |
| 1096 | } |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1097 | MaybeHandleDebugURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1098 | if (!webview()) |
| 1099 | return; |
| 1100 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 1101 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 1102 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1103 | bool is_reload = IsReload(params); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1104 | |
| 1105 | // If this is a stale back/forward (due to a recent navigation the browser |
| 1106 | // didn't know about), ignore it. |
| 1107 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 1108 | return; |
| 1109 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1110 | // Swap this renderer back in if necessary. |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1111 | if (is_swapped_out_) { |
| 1112 | // We marked the view as hidden when swapping the view out, so be sure to |
| 1113 | // reset the visibility state before navigating to the new URL. |
| 1114 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1115 | SetSwappedOut(false); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 1116 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1117 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1118 | history_list_offset_ = params.current_history_list_offset; |
| 1119 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1120 | if (history_list_length_ >= 0) |
| 1121 | history_page_ids_.resize(history_list_length_, -1); |
| 1122 | if (params.pending_history_list_offset >= 0 && |
| 1123 | params.pending_history_list_offset < history_list_length_) |
| 1124 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1125 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 1126 | content::GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1127 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1128 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1129 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1130 | // We cannot reload if we do not have any history state. This happens, for |
| 1131 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1132 | // a hack since it means that reload after a crashed tab does not cause an |
| 1133 | // end-to-end cache validation. |
| 1134 | is_reload = false; |
| 1135 | } |
| 1136 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1137 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 1138 | *pending_navigation_params_.get() = params; |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 1139 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1140 | // If we are reloading, then WebKit will use the history state of the current |
| 1141 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1142 | // have history state, then we need to navigate to it, which corresponds to a |
| 1143 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1144 | if (is_reload) { |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1145 | bool reload_original_url = |
| 1146 | (params.navigation_type == |
| 1147 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1148 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 1149 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1150 | |
| 1151 | if (reload_original_url) |
| 1152 | main_frame->reloadWithOverrideURL(params.url, true); |
| 1153 | else |
| 1154 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1155 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1156 | // 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] | 1157 | DCHECK_NE(params.page_id, -1); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1158 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1159 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 1160 | } else if (!params.base_url_for_data_url.is_empty()) { |
| 1161 | // A loadData request with a specified base URL. |
| 1162 | std::string mime_type, charset, data; |
| 1163 | if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
| 1164 | main_frame->loadData( |
| 1165 | WebData(data.c_str(), data.length()), |
| 1166 | WebString::fromUTF8(mime_type), |
| 1167 | WebString::fromUTF8(charset), |
| 1168 | params.base_url_for_data_url, |
| 1169 | params.history_url_for_data_url, |
| 1170 | false); |
| 1171 | } else { |
| 1172 | CHECK(false) << |
| 1173 | "Invalid URL passed: " << params.url.possibly_invalid_spec(); |
| 1174 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1175 | } else { |
| 1176 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1177 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1178 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1179 | // A session history navigation should have been accompanied by state. |
[email protected] | cbc0cb7 | 2011-12-06 18:58:23 | [diff] [blame] | 1180 | CHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1181 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1182 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1183 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1184 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1185 | if (params.referrer.url.is_valid()) { |
| 1186 | WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 1187 | params.referrer.policy, |
| 1188 | params.url, |
| 1189 | WebString::fromUTF8(params.referrer.url.spec())); |
| 1190 | if (!referrer.isEmpty()) |
| 1191 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1192 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1193 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 1194 | if (!params.extra_headers.empty()) { |
| 1195 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 1196 | params.extra_headers.end(), "\n"); |
| 1197 | i.GetNext(); ) { |
| 1198 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 1199 | WebString::fromUTF8(i.values())); |
| 1200 | } |
| 1201 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1202 | |
| 1203 | if (params.is_post) { |
| 1204 | request.setHTTPMethod(WebString::fromUTF8("POST")); |
| 1205 | |
| 1206 | // Set post data. |
| 1207 | WebHTTPBody http_body; |
| 1208 | http_body.initialize(); |
| 1209 | http_body.appendData(WebData( |
| 1210 | reinterpret_cast<const char*>( |
| 1211 | ¶ms.browser_initiated_post_data.front()), |
| 1212 | params.browser_initiated_post_data.size())); |
| 1213 | request.setHTTPBody(http_body); |
| 1214 | } |
| 1215 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1216 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1217 | } |
| 1218 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1219 | // In case LoadRequest failed before DidCreateDataSource was called. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1220 | pending_navigation_params_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1221 | } |
| 1222 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1223 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1224 | const ViewMsg_Navigate_Params& params, |
| 1225 | bool is_reload) { |
| 1226 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 1227 | // or replaced from our history, before the browser knew about it. If so, |
| 1228 | // a new navigation has committed in the mean time, and we can ignore this. |
| 1229 | bool is_back_forward = !is_reload && !params.state.empty(); |
| 1230 | |
| 1231 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 1232 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 1233 | if (!is_back_forward || history_list_length_ <= 0) |
| 1234 | return false; |
| 1235 | |
| 1236 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 1237 | |
| 1238 | // Check for whether the forward history has been cropped due to a recent |
| 1239 | // navigation the browser didn't know about. |
| 1240 | if (params.pending_history_list_offset >= history_list_length_) |
| 1241 | return true; |
| 1242 | |
| 1243 | // Check for whether this entry has been replaced with a new one. |
| 1244 | int expected_page_id = |
| 1245 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 1246 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 1247 | if (params.page_id < expected_page_id) |
| 1248 | return true; |
| 1249 | |
| 1250 | // Otherwise we've removed an earlier entry and should have shifted all |
| 1251 | // entries left. For now, it's ok to lazily update the list. |
| 1252 | // TODO(creis): Notify all live renderers when we remove entries from |
| 1253 | // the front of the list, so that we don't hit this case. |
| 1254 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 1255 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 1256 | |
| 1257 | return false; |
| 1258 | } |
| 1259 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1260 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1261 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 1262 | if (webview()) { |
| 1263 | WebFrame* main_frame = webview()->mainFrame(); |
| 1264 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 1265 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 1266 | // it may no longer be active. |
| 1267 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 1268 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 1269 | main_frame->stopLoading(); |
| 1270 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1271 | } |
| 1272 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1273 | // Reload current focused frame. |
| 1274 | // 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] | 1275 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1276 | if (webview() && webview()->focusedFrame()) { |
| 1277 | // We always obey the cache (ignore_cache=false) here. |
| 1278 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1279 | // a cache-ignoring reload of the frame. |
| 1280 | webview()->focusedFrame()->reload(false); |
| 1281 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1282 | } |
| 1283 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1284 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1285 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1286 | } |
| 1287 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1288 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1289 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1290 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1291 | return; |
| 1292 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1293 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1294 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1295 | } |
| 1296 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1297 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1298 | // Check if there is a targeturl waiting to be sent. |
| 1299 | if (target_url_status_ == TARGET_PENDING) { |
| 1300 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1301 | pending_target_url_)); |
| 1302 | } |
| 1303 | |
| 1304 | target_url_status_ = TARGET_NONE; |
| 1305 | } |
| 1306 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1307 | void RenderViewImpl::OnUndo() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1308 | if (!webview()) |
| 1309 | return; |
| 1310 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1311 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
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::OnRedo() { |
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("Redo")); |
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::OnCut() { |
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(WebString::fromUTF8("Cut")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1326 | } |
| 1327 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1328 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1329 | if (!webview()) |
| 1330 | return; |
| 1331 | |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 1332 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
| 1333 | context_menu_node_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1334 | } |
| 1335 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1336 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1337 | void RenderViewImpl::OnCopyToFindPboard() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1338 | if (!webview()) |
| 1339 | return; |
| 1340 | |
| 1341 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1342 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1343 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1344 | if (frame->hasSelection()) { |
| 1345 | string16 selection = frame->selectionAsText(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1346 | RenderThread::Get()->Send( |
[email protected] | 7e358974 | 2011-03-10 18:49:17 | [diff] [blame] | 1347 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1348 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1349 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1350 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1351 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1352 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1353 | if (!webview()) |
| 1354 | return; |
| 1355 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1356 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1357 | } |
| 1358 | |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1359 | void RenderViewImpl::OnPasteAndMatchStyle() { |
| 1360 | if (!webview()) |
| 1361 | return; |
| 1362 | |
| 1363 | webview()->focusedFrame()->executeCommand( |
| 1364 | WebString::fromUTF8("PasteAndMatchStyle")); |
| 1365 | } |
| 1366 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1367 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1368 | if (!webview()) |
| 1369 | return; |
| 1370 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1371 | WebFrame* frame = webview()->focusedFrame(); |
| 1372 | if (!frame->hasSelection()) |
| 1373 | frame->selectWordAroundCaret(); |
| 1374 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1375 | } |
| 1376 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1377 | void RenderViewImpl::OnDelete() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1378 | if (!webview()) |
| 1379 | return; |
| 1380 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1381 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1382 | } |
| 1383 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1384 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1385 | if (!webview()) |
| 1386 | return; |
| 1387 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1388 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1389 | WebString::fromUTF8("SelectAll")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1390 | } |
| 1391 | |
[email protected] | 45a59906 | 2012-09-07 20:09:06 | [diff] [blame] | 1392 | void RenderViewImpl::OnReplaceAll(const string16& text) { |
| 1393 | WebNode node = GetFocusedNode(); |
| 1394 | if (node.isNull() || !IsEditableNode(node)) |
| 1395 | return; |
| 1396 | |
| 1397 | OnSelectAll(); |
| 1398 | OnReplace(text); |
| 1399 | } |
| 1400 | |
| 1401 | void RenderViewImpl::OnUnselect() { |
| 1402 | if (!webview()) |
| 1403 | return; |
| 1404 | |
| 1405 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 1406 | } |
| 1407 | |
| 1408 | void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) { |
| 1409 | webview()->setEditableSelectionOffsets(start, end); |
| 1410 | } |
| 1411 | |
| 1412 | void RenderViewImpl::OnSetCompositionFromExistingText( |
| 1413 | int start, int end, |
| 1414 | const std::vector<WebKit::WebCompositionUnderline>& underlines) { |
| 1415 | if (!webview()) |
| 1416 | return; |
| 1417 | webview()->setCompositionFromExistingText(start, end, underlines); |
| 1418 | } |
| 1419 | |
| 1420 | void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) { |
| 1421 | if (!webview()) |
| 1422 | return; |
| 1423 | webview()->extendSelectionAndDelete(before, after); |
| 1424 | } |
| 1425 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1426 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 1427 | const gfx::Point& end) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1428 | if (!webview()) |
| 1429 | return; |
| 1430 | |
[email protected] | c95e53ad | 2012-08-13 17:56:16 | [diff] [blame] | 1431 | Send(new ViewHostMsg_SelectRange_ACK(routing_id_)); |
| 1432 | |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1433 | handling_select_range_ = true; |
| 1434 | webview()->focusedFrame()->selectRange(start, end); |
| 1435 | handling_select_range_ = false; |
| 1436 | } |
| 1437 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1438 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1439 | int32 minimum_page_id) { |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1440 | DCHECK_GE(history_length, 0); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1441 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 1442 | DCHECK_GE(minimum_page_id, -1); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1443 | |
| 1444 | // Generate the new list. |
| 1445 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1446 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1447 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1448 | continue; |
| 1449 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1450 | } |
| 1451 | new_history_page_ids.swap(history_page_ids_); |
| 1452 | |
| 1453 | // Update indexes. |
| 1454 | history_list_length_ = history_page_ids_.size(); |
| 1455 | history_list_offset_ = history_list_length_ - 1; |
| 1456 | } |
| 1457 | |
| 1458 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1459 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1460 | if (!webview()) |
| 1461 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1462 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1463 | } |
| 1464 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1465 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1466 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1467 | if (!webview()) |
| 1468 | return; |
| 1469 | if (in_live_resize) |
| 1470 | webview()->willStartLiveResize(); |
| 1471 | else |
| 1472 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1473 | } |
| 1474 | #endif |
| 1475 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1476 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1477 | const gfx::Rect& rect) { |
[email protected] | 13a1e4c3c | 2011-02-03 21:07:09 | [diff] [blame] | 1478 | WebKit::WebNode node = GetFocusedNode(); |
| 1479 | if (!node.isNull()) { |
| 1480 | if (IsEditableNode(node)) |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 1481 | webview()->scrollFocusedNodeIntoRect(rect); |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1485 | /////////////////////////////////////////////////////////////////////////////// |
| 1486 | |
| 1487 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1488 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1489 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1490 | DCHECK(ds); |
| 1491 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1492 | const WebURLRequest& request = ds->request(); |
| 1493 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1494 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1495 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1496 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 1497 | NavigationState* navigation_state = document_state->navigation_state(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1498 | |
| 1499 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1500 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1501 | params.is_post = false; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1502 | params.post_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1503 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1504 | params.frame_id = frame->identifier(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1505 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1506 | params.socket_address.set_port(response.remotePort()); |
[email protected] | b9a7c6d4 | 2011-02-25 02:13:03 | [diff] [blame] | 1507 | params.was_fetched_via_proxy = response.wasFetchedViaProxy(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1508 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1509 | if (!document_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1510 | // SSL state specified in the request takes precedence over the one in the |
| 1511 | // response. |
| 1512 | // So far this is only intended for error pages that are not expected to be |
| 1513 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1514 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1515 | params.security_info = document_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1516 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1517 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 1521 | params.url = GetLoadingUrl(frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1522 | |
[email protected] | 5f9b871 | 2011-11-23 08:55:57 | [diff] [blame] | 1523 | if (frame->document().baseURL() != params.url) |
| 1524 | params.base_url = frame->document().baseURL(); |
| 1525 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1526 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1527 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 1528 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1529 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1530 | params.searchable_form_url = document_state->searchable_form_url(); |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1531 | params.searchable_form_encoding = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1532 | document_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1533 | |
| 1534 | const PasswordForm* password_form_data = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1535 | document_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1536 | if (password_form_data) |
| 1537 | params.password_form = *password_form_data; |
| 1538 | |
| 1539 | params.gesture = navigation_gesture_; |
| 1540 | navigation_gesture_ = NavigationGestureUnknown; |
| 1541 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1542 | // Make navigation state a part of the FrameNavigate message so that commited |
| 1543 | // entry had it at all times. |
| 1544 | const WebHistoryItem& item = frame->currentHistoryItem(); |
| 1545 | if (!item.isNull()) { |
| 1546 | params.content_state = webkit_glue::HistoryItemToString(item); |
| 1547 | } else { |
| 1548 | params.content_state = |
| 1549 | webkit_glue::CreateHistoryStateForURL(GURL(request.url())); |
| 1550 | } |
| 1551 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1552 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1553 | // Top-level navigation. |
| 1554 | |
[email protected] | d00a797 | 2012-08-07 06:09:58 | [diff] [blame] | 1555 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1556 | // will also call us back which will cause us to send a message to |
| 1557 | // update WebContentsImpl. |
| 1558 | webview()->zoomLimitsChanged( |
| 1559 | WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor), |
| 1560 | WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor)); |
| 1561 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1562 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1563 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1564 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1565 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1566 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1567 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1568 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1569 | } else { |
| 1570 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1571 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1572 | } |
| 1573 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1574 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1575 | // This zoom level was merely recorded transiently for this load. We can |
| 1576 | // erase it now. If at some point we reload this page, the browser will |
| 1577 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1578 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1579 | } |
| 1580 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1581 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1582 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1583 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1584 | params.transition = navigation_state->transition_type(); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1585 | if (!content::PageTransitionIsMainFrame(params.transition)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1586 | // If the main frame does a load, it should not be reported as a subframe |
| 1587 | // navigation. This can occur in the following case: |
| 1588 | // 1. You're on a site with frames. |
| 1589 | // 2. You do a subframe navigation. This is stored with transition type |
| 1590 | // MANUAL_SUBFRAME. |
| 1591 | // 3. You navigate to some non-frame site, say, google.com. |
| 1592 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1593 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1594 | // We don't want that, because any navigation that changes the toplevel |
| 1595 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1596 | // update the URL bar, etc). |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1597 | params.transition = content::PAGE_TRANSITION_LINK; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1598 | } |
| 1599 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1600 | // If we have a valid consumed client redirect source, |
| 1601 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1602 | // so we set the referrer and transition to match. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1603 | if (completed_client_redirect_src_.url.is_valid()) { |
| 1604 | DCHECK(completed_client_redirect_src_.url == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1605 | params.referrer = completed_client_redirect_src_; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1606 | params.transition = static_cast<content::PageTransition>( |
| 1607 | params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1608 | } else { |
| 1609 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1610 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1611 | params.referrer = Referrer(GURL( |
| 1612 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 1613 | GetReferrerPolicyFromRequest(frame, original_request)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1614 | } |
| 1615 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1616 | string16 method = request.httpMethod(); |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1617 | if (EqualsASCII(method, "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1618 | params.is_post = true; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1619 | params.post_id = ExtractPostId(item); |
| 1620 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1621 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1622 | // Send the user agent override back. |
| 1623 | params.is_overriding_user_agent = |
| 1624 | document_state->is_overriding_user_agent(); |
| 1625 | |
[email protected] | 7c16976c | 2012-08-04 02:38:23 | [diff] [blame] | 1626 | // Track the URL of the original request. |
| 1627 | params.original_request_url = original_request.url(); |
| 1628 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1629 | // Save some histogram data so we can compute the average memory used per |
| 1630 | // page load of the glyphs. |
| 1631 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1632 | webkit_glue::GetGlyphPageCount()); |
| 1633 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1634 | // This message needs to be sent before any of allowScripts(), |
| 1635 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1636 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1637 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1638 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1639 | } else { |
| 1640 | // Subframe navigation: the type depends on whether this navigation |
| 1641 | // generated a new session history entry. When they do generate a session |
| 1642 | // history entry, it means the user initiated the navigation and we should |
| 1643 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1644 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1645 | if (page_id_ > last_page_id_sent_to_browser_) |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1646 | params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1647 | else |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1648 | params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1649 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1650 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1651 | } |
| 1652 | |
| 1653 | last_page_id_sent_to_browser_ = |
| 1654 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1655 | |
| 1656 | // 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] | 1657 | // we don't want the transition type to persist. Just clear it. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1658 | navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1662 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 1663 | const string16& title, |
| 1664 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1665 | // Ignore all but top level navigations. |
| 1666 | if (frame->parent()) |
| 1667 | return; |
| 1668 | |
| 1669 | string16 shortened_title = title.substr(0, content::kMaxTitleChars); |
| 1670 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 1671 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1672 | } |
| 1673 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1674 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 1675 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1676 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1677 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1678 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1679 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1680 | last_encoding_name_ = encoding_name; |
| 1681 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1682 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 1686 | // Sends the last committed session history state to the browser so it will be |
| 1687 | // saved before we navigate to a new page. This must be called *before* the |
| 1688 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1689 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1690 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1691 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1692 | // there is no past session history to record. |
| 1693 | if (page_id_ == -1) |
| 1694 | return; |
| 1695 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1696 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1697 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1698 | SendUpdateState(item); |
| 1699 | } |
| 1700 | |
| 1701 | void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1702 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1703 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1704 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 1705 | // Don't send state updates for content::kSwappedOutURL. |
| 1706 | if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL)) |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 1707 | return; |
| 1708 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1709 | Send(new ViewHostMsg_UpdateState( |
| 1710 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1711 | } |
| 1712 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1713 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 1714 | const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1715 | const Referrer& referrer, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1716 | WebNavigationPolicy policy) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1717 | Send(new ViewHostMsg_OpenURL( |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1718 | routing_id_, |
| 1719 | url, |
| 1720 | referrer, |
| 1721 | NavigationPolicyToDisposition(policy), |
| 1722 | frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1723 | } |
| 1724 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1725 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1726 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1727 | void RenderViewImpl::LoadNavigationErrorPage( |
| 1728 | WebFrame* frame, |
| 1729 | const WebURLRequest& failed_request, |
| 1730 | const WebURLError& error, |
| 1731 | const std::string& html, |
| 1732 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1733 | std::string alt_html; |
| 1734 | const std::string* error_html; |
| 1735 | |
| 1736 | if (!html.empty()) { |
| 1737 | error_html = &html; |
| 1738 | } else { |
| 1739 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 1740 | failed_request, error, &alt_html, NULL); |
| 1741 | error_html = &alt_html; |
| 1742 | } |
| 1743 | |
| 1744 | frame->loadHTMLString(*error_html, |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 1745 | GURL(content::kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 1746 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1747 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1748 | } |
| 1749 | |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 1750 | bool RenderViewImpl::RunJavaScriptMessage(content::JavaScriptMessageType type, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1751 | const string16& message, |
| 1752 | const string16& default_value, |
| 1753 | const GURL& frame_url, |
| 1754 | string16* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1755 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1756 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1757 | if (!result) |
| 1758 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1759 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1760 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1761 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1762 | return success; |
| 1763 | } |
| 1764 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1765 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1766 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1767 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1768 | // it is particularly important that we do not call willEnterModalLoop as |
| 1769 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1770 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1771 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1772 | |
| 1773 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1774 | return Send(message); |
| 1775 | } |
| 1776 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1777 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1778 | |
[email protected] | 916dfb6 | 2012-03-05 03:39:37 | [diff] [blame] | 1779 | WebView* RenderViewImpl::createView( |
| 1780 | WebFrame* creator, |
| 1781 | const WebURLRequest& request, |
| 1782 | const WebWindowFeatures& features, |
| 1783 | const WebString& frame_name, |
| 1784 | WebNavigationPolicy policy) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1785 | // Check to make sure we aren't overloading on popups. |
| 1786 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1787 | return NULL; |
| 1788 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1789 | ViewHostMsg_CreateWindow_Params params; |
| 1790 | params.opener_id = routing_id_; |
| 1791 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1792 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1793 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1794 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1795 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1796 | params.opener_url = creator->document().url(); |
| 1797 | params.opener_security_origin = |
| 1798 | creator->document().securityOrigin().toString().utf8(); |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1799 | params.opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
| 1800 | params.disposition = NavigationPolicyToDisposition(policy); |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1801 | if (!request.isNull()) |
| 1802 | params.target_url = request.url(); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1803 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1804 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1805 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1806 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1807 | |
[email protected] | 7c962ee3 | 2012-08-28 21:12:50 | [diff] [blame] | 1808 | creator->consumeUserGesture(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1809 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1810 | new ViewHostMsg_CreateWindow(params, |
| 1811 | &routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1812 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1813 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1814 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1815 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1816 | |
[email protected] | 8cca3da | 2012-03-20 08:26:34 | [diff] [blame] | 1817 | // TODO(fsamuel): The host renderer needs to be able to control whether |
| 1818 | // the guest renderer is allowed to do this or not. This current |
| 1819 | // behavior is not well defined. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1820 | RenderViewImpl* view = RenderViewImpl::Create( |
| 1821 | 0, |
| 1822 | routing_id_, |
| 1823 | renderer_preferences_, |
| 1824 | webkit_preferences_, |
| 1825 | shared_popup_counter_, |
| 1826 | routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1827 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1828 | cloned_session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1829 | frame_name, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1830 | true, |
| 1831 | false, |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1832 | 1, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1833 | screen_info_, |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 1834 | guest_to_embedder_channel_, |
[email protected] | 3e3c452 | 2012-04-13 21:16:29 | [diff] [blame] | 1835 | accessibility_mode_); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1836 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1837 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1838 | // Record whether the creator frame is trying to suppress the opener field. |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 1839 | view->opener_suppressed_ = params.opener_suppressed; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1840 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1841 | // Record the security origin of the creator. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1842 | GURL creator_url(creator->document().securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1843 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1844 | creator_url = GURL(); |
| 1845 | view->creator_url_ = creator_url; |
| 1846 | |
| 1847 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1848 | // the new render view (we don't need the browser to send the URL back down). |
| 1849 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1850 | |
| 1851 | return view->webview(); |
| 1852 | } |
| 1853 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1854 | WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 1855 | RenderWidget* widget = |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1856 | RenderWidget::Create(routing_id_, popup_type, screen_info_); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1857 | return widget->webwidget(); |
| 1858 | } |
| 1859 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1860 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1861 | const WebPopupMenuInfo& popup_menu_info, |
| 1862 | WebExternalPopupMenuClient* popup_menu_client) { |
[email protected] | 8de2f88 | 2012-05-30 00:32:27 | [diff] [blame] | 1863 | // An IPC message is sent to the browser to build and display the actual |
| 1864 | // popup. The user could have time to click a different select by the time |
| 1865 | // the popup is shown. In that case external_popup_menu_ is non NULL. |
| 1866 | // By returning NULL in that case, we instruct WebKit to cancel that new |
| 1867 | // popup. So from the user perspective, only the first one will show, and |
| 1868 | // will have to close the first one before another one can be shown. |
| 1869 | if (external_popup_menu_.get()) |
| 1870 | return NULL; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1871 | external_popup_menu_.reset( |
| 1872 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 1873 | return external_popup_menu_.get(); |
| 1874 | } |
| 1875 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1876 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 1877 | webkit::ppapi::PluginInstance* plugin) { |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1878 | GURL active_url; |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 1879 | if (webview() && webview()->mainFrame()) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1880 | active_url = GURL(webview()->mainFrame()->document().url()); |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1881 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
[email protected] | bee6eb7 | 2012-07-26 03:47:32 | [diff] [blame] | 1882 | routing_id_, plugin, active_url, screen_info_); |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1883 | widget->show(WebKit::WebNavigationPolicyIgnore); |
[email protected] | 92abcb83 | 2011-01-06 20:39:56 | [diff] [blame] | 1884 | return widget; |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1885 | } |
| 1886 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1887 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace( |
| 1888 | unsigned quota) { |
[email protected] | b928936b | 2012-04-13 01:16:16 | [diff] [blame] | 1889 | CHECK(session_storage_namespace_id_ != |
| 1890 | dom_storage::kInvalidSessionStorageNamespaceId); |
[email protected] | 1910fe8 | 2012-05-10 00:04:10 | [diff] [blame] | 1891 | return new WebStorageNamespaceImpl(session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1892 | } |
| 1893 | |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1894 | WebKit::WebCompositorOutputSurface* RenderViewImpl::createOutputSurface() { |
| 1895 | // TODO(aelias): if force-software-mode is on, create an output surface |
| 1896 | // without a 3D context. |
| 1897 | |
| 1898 | // Explicitly disable antialiasing for the compositor. As of the time of |
| 1899 | // this writing, the only platform that supported antialiasing for the |
| 1900 | // compositor was Mac OS X, because the on-screen OpenGL context creation |
| 1901 | // code paths on Windows and Linux didn't yet have multisampling support. |
| 1902 | // Mac OS X essentially always behaves as though it's rendering offscreen. |
| 1903 | // Multisampling has a heavy cost especially on devices with relatively low |
| 1904 | // fill rate like most notebooks, and the Mac implementation would need to |
| 1905 | // be optimized to resolve directly into the IOSurface shared between the |
| 1906 | // GPU and browser processes. For these reasons and to avoid platform |
| 1907 | // disparities we explicitly disable antialiasing. |
| 1908 | WebKit::WebGraphicsContext3D::Attributes attributes; |
| 1909 | attributes.antialias = false; |
| 1910 | attributes.shareResources = true; |
| 1911 | WebGraphicsContext3D* context = CreateGraphicsContext3D(attributes); |
| 1912 | if (!context) |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1913 | return NULL; |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 1914 | |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 1915 | return new CompositorOutputSurface(routing_id(), context); |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1916 | } |
| 1917 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1918 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1919 | const WebConsoleMessage& message, const WebString& source_name, |
| 1920 | unsigned source_line) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1921 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 1922 | switch (message.level) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1923 | case WebConsoleMessage::LevelTip: |
| 1924 | log_severity = logging::LOG_VERBOSE; |
| 1925 | break; |
| 1926 | case WebConsoleMessage::LevelLog: |
| 1927 | log_severity = logging::LOG_INFO; |
| 1928 | break; |
| 1929 | case WebConsoleMessage::LevelWarning: |
| 1930 | log_severity = logging::LOG_WARNING; |
| 1931 | break; |
| 1932 | case WebConsoleMessage::LevelError: |
| 1933 | log_severity = logging::LOG_ERROR; |
| 1934 | break; |
| 1935 | default: |
| 1936 | NOTREACHED(); |
| 1937 | } |
| 1938 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1939 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1940 | static_cast<int32>(log_severity), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1941 | message.text, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1942 | static_cast<int32>(source_line), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1943 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1944 | } |
| 1945 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1946 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 1947 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 1948 | PrintPage(frame, handling_input_event_)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1949 | } |
| 1950 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1951 | WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1952 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1953 | } |
| 1954 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1955 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1956 | const WebString& path, |
| 1957 | WebFileChooserCompletion* chooser_completion) { |
| 1958 | int id = enumeration_completion_id_++; |
| 1959 | enumeration_completions_[id] = chooser_completion; |
| 1960 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 1961 | routing_id_, |
| 1962 | id, |
| 1963 | webkit_glue::WebStringToFilePath(path))); |
| 1964 | } |
| 1965 | |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 1966 | void RenderViewImpl::initializeHelperPluginWebFrame( |
| 1967 | WebKit::WebHelperPlugin* plugin) { |
| 1968 | plugin->initializeFrame(this); |
| 1969 | } |
| 1970 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1971 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1972 | if (is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 1973 | DVLOG(1) << "didStartLoading called while loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1974 | return; |
| 1975 | } |
| 1976 | |
| 1977 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1978 | |
| 1979 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 1980 | |
| 1981 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1982 | } |
| 1983 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1984 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1985 | if (!is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 1986 | DVLOG(1) << "DidStopLoading called while not loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1987 | return; |
| 1988 | } |
| 1989 | |
| 1990 | is_loading_ = false; |
| 1991 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 1992 | if (pending_frame_tree_update_) { |
| 1993 | pending_frame_tree_update_ = false; |
| 1994 | SendUpdatedFrameTree(NULL); |
| 1995 | } |
| 1996 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1997 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1998 | // when done loading. This currently isn't an issue as the favicon is only |
| 1999 | // displayed when done loading. Ideally we would send notification when |
| 2000 | // finished parsing the head, but webkit doesn't support that yet. |
| 2001 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2002 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 2003 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2004 | if (load_progress_tracker_ != NULL) |
| 2005 | load_progress_tracker_->DidStopLoading(); |
| 2006 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 2007 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2008 | } |
| 2009 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2010 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 2011 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 2012 | if (load_progress_tracker_ != NULL) |
| 2013 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 2014 | } |
| 2015 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2016 | bool RenderViewImpl::isSmartInsertDeleteEnabled() { |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 2017 | #if defined(OS_MACOSX) |
| 2018 | return true; |
| 2019 | #else |
| 2020 | return false; |
| 2021 | #endif |
| 2022 | } |
| 2023 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2024 | bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() { |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2025 | #if defined(OS_WIN) |
| 2026 | return true; |
| 2027 | #else |
| 2028 | return false; |
| 2029 | #endif |
| 2030 | } |
| 2031 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2032 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 2033 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2034 | return; |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 2035 | handling_select_range_ = false; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 2036 | |
[email protected] | fca5202 | 2012-04-03 17:00:50 | [diff] [blame] | 2037 | if (is_empty_selection) |
| 2038 | selection_text_.clear(); |
| 2039 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 2040 | SyncSelectionIfRequired(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2041 | } |
| 2042 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2043 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 2044 | const std::string& name = UTF16ToUTF8(command_name); |
| 2045 | if (StartsWithASCII(name, "Move", true) || |
| 2046 | StartsWithASCII(name, "Insert", true) || |
| 2047 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2048 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2049 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2050 | } |
| 2051 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2052 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2053 | if (edit_commands_.empty()) |
| 2054 | return false; |
| 2055 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2056 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2057 | if (!frame) |
| 2058 | return false; |
| 2059 | |
| 2060 | EditCommands::iterator it = edit_commands_.begin(); |
| 2061 | EditCommands::iterator end = edit_commands_.end(); |
| 2062 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2063 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2064 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2065 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2066 | // key (but it's the exception). Once one edit command is not executed, it |
| 2067 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2068 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 2069 | WebString::fromUTF8(it->value))) |
| 2070 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2071 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2072 | } |
| 2073 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2074 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2075 | } |
| 2076 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2077 | WebKit::WebColorChooser* RenderViewImpl::createColorChooser( |
| 2078 | WebKit::WebColorChooserClient* client, |
| 2079 | const WebKit::WebColor& initial_color) { |
| 2080 | RendererWebColorChooserImpl* color_chooser = |
| 2081 | new RendererWebColorChooserImpl(this, client); |
| 2082 | color_chooser->Open(static_cast<SkColor>(initial_color)); |
| 2083 | return color_chooser; |
| 2084 | } |
| 2085 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2086 | bool RenderViewImpl::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2087 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2088 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 2089 | // Do not open the file dialog in a hidden RenderView. |
| 2090 | if (is_hidden()) |
| 2091 | return false; |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 2092 | content::FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2093 | if (params.directory) |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 2094 | ipc_params.mode = content::FileChooserParams::OpenFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2095 | else if (params.multiSelect) |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 2096 | ipc_params.mode = content::FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 2097 | else if (params.saveAs) |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 2098 | ipc_params.mode = content::FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2099 | else |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 2100 | ipc_params.mode = content::FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2101 | ipc_params.title = params.title; |
| 2102 | ipc_params.default_file_name = |
| 2103 | webkit_glue::WebStringToFilePath(params.initialValue); |
[email protected] | f9a4c41a | 2012-05-30 00:05:32 | [diff] [blame] | 2104 | ipc_params.accept_types.reserve(params.acceptTypes.size()); |
| 2105 | for (size_t i = 0; i < params.acceptTypes.size(); ++i) |
| 2106 | ipc_params.accept_types.push_back(params.acceptTypes[i]); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2107 | |
| 2108 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2109 | } |
| 2110 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2111 | void RenderViewImpl::runModalAlertDialog(WebFrame* frame, |
| 2112 | const WebString& message) { |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 2113 | RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_ALERT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2114 | message, |
| 2115 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2116 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2117 | NULL); |
| 2118 | } |
| 2119 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2120 | bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame, |
| 2121 | const WebString& message) { |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 2122 | return RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2123 | message, |
| 2124 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2125 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2126 | NULL); |
| 2127 | } |
| 2128 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2129 | bool RenderViewImpl::runModalPromptDialog(WebFrame* frame, |
| 2130 | const WebString& message, |
| 2131 | const WebString& default_value, |
| 2132 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2133 | string16 result; |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 2134 | bool ok = RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2135 | message, |
| 2136 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2137 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2138 | &result); |
| 2139 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2140 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2141 | return ok; |
| 2142 | } |
| 2143 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2144 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2145 | WebFrame* frame, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2146 | // If we are swapping out, we have already run the beforeunload handler. |
| 2147 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 2148 | // at all, to avoid running it twice. |
| 2149 | if (is_swapped_out_) |
| 2150 | return true; |
| 2151 | |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2152 | bool is_reload = false; |
| 2153 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2154 | if (ds) |
| 2155 | is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload); |
| 2156 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2157 | bool success = false; |
| 2158 | // This is an ignored return value, but is included so we can accept the same |
| 2159 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2160 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2161 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2162 | routing_id_, frame->document().url(), message, is_reload, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2163 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2164 | return success; |
| 2165 | } |
| 2166 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2167 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2168 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | 8f635f8 | 2012-06-22 22:02:44 | [diff] [blame] | 2169 | // TODO(fsamuel): In the future, we might want the embedder to be able to |
| 2170 | // decide whether the guest can show a context menu or not. See |
| 2171 | // http://www.crbug.com/134207 |
| 2172 | if (GetGuestToEmbedderChannel()) |
| 2173 | return; |
| 2174 | |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 2175 | content::ContextMenuParams params(data); |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 2176 | |
| 2177 | // frame is NULL if invoked by BlockedPlugin. |
| 2178 | if (frame) |
| 2179 | params.frame_id = frame->identifier(); |
| 2180 | |
[email protected] | db803aae | 2011-03-05 02:00:42 | [diff] [blame] | 2181 | // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2182 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2183 | // in the context menu. |
| 2184 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2185 | // data encoded images. We should have a way to save them. |
[email protected] | db803aae | 2011-03-05 02:00:42 | [diff] [blame] | 2186 | if (params.src_url.spec().size() > content::kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2187 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 2188 | context_menu_node_ = data.node; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2189 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2190 | } |
| 2191 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2192 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2193 | } |
| 2194 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2195 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 2196 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2197 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2198 | if (latest_url == target_url_) |
| 2199 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2200 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2201 | // Tell the browser to display a destination link. |
| 2202 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2203 | target_url_status_ == TARGET_PENDING) { |
| 2204 | // If we have a request in-flight, save the URL to be sent when we |
| 2205 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2206 | // any existing pending sends. |
| 2207 | pending_target_url_ = latest_url; |
| 2208 | target_url_status_ = TARGET_PENDING; |
| 2209 | } else { |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 2210 | // URLs larger than |content::kMaxURLChars| cannot be sent through IPC - |
| 2211 | // see |ParamTraits<GURL>|. |
| 2212 | if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars) |
| 2213 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2214 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2215 | target_url_ = latest_url; |
| 2216 | target_url_status_ = TARGET_INFLIGHT; |
| 2217 | } |
| 2218 | } |
| 2219 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2220 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2221 | int delay; |
| 2222 | if (send_content_state_immediately_) |
| 2223 | delay = 0; |
| 2224 | else if (is_hidden()) |
| 2225 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2226 | else |
| 2227 | delay = kDelaySecondsForContentStateSync; |
| 2228 | |
| 2229 | if (nav_state_sync_timer_.IsRunning()) { |
| 2230 | // The timer is already running. If the delay of the timer maches the amount |
| 2231 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2232 | // gets started with the right delay. |
| 2233 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2234 | return; |
| 2235 | nav_state_sync_timer_.Stop(); |
| 2236 | } |
| 2237 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 2238 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2239 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2240 | } |
| 2241 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2242 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2243 | mouse_over_url_ = GURL(url); |
| 2244 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2245 | } |
| 2246 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2247 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2248 | focus_url_ = GURL(url); |
| 2249 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2250 | } |
| 2251 | |
[email protected] | 0407e42 | 2012-05-18 19:51:25 | [diff] [blame] | 2252 | void RenderViewImpl::startDragging(WebFrame* frame, |
| 2253 | const WebDragData& data, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2254 | WebDragOperationsMask mask, |
| 2255 | const WebImage& image, |
| 2256 | const WebPoint& imageOffset) { |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2257 | WebDropData drop_data(data); |
| 2258 | drop_data.referrer_policy = frame->document().referrerPolicy(); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 2259 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | b67151d | 2012-05-25 23:23:24 | [diff] [blame] | 2260 | drop_data, |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2261 | mask, |
[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 2262 | image.getSkBitmap(), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2263 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2264 | } |
| 2265 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2266 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2267 | return renderer_preferences_.can_accept_load_drops; |
| 2268 | } |
| 2269 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2270 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2271 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2272 | } |
| 2273 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2274 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2275 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2276 | } |
| 2277 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2278 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 2279 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2280 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 2281 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2282 | } |
| 2283 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 2284 | void RenderViewImpl::didUpdateLayout() { |
| 2285 | // We don't always want to set up a timer, only if we've been put in that |
| 2286 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2287 | // message. |
| 2288 | if (!send_preferred_size_changes_ || !webview()) |
| 2289 | return; |
| 2290 | |
| 2291 | if (check_preferred_size_timer_.IsRunning()) |
| 2292 | return; |
| 2293 | check_preferred_size_timer_.Start(FROM_HERE, |
| 2294 | TimeDelta::FromMilliseconds(0), this, |
| 2295 | &RenderViewImpl::CheckPreferredSize); |
| 2296 | } |
| 2297 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2298 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2299 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2300 | } |
| 2301 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2302 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2303 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2304 | } |
| 2305 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2306 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2307 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2308 | } |
| 2309 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2310 | void RenderViewImpl::postAccessibilityNotification( |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2311 | const WebAccessibilityObject& obj, |
| 2312 | WebAccessibilityNotification notification) { |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 2313 | if (renderer_accessibility_) { |
| 2314 | renderer_accessibility_->HandleWebAccessibilityNotification( |
| 2315 | obj, notification); |
| 2316 | } |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 2317 | } |
| 2318 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2319 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2320 | const WebString& value) { |
| 2321 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2322 | key.utf8(), |
| 2323 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2324 | } |
| 2325 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2326 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2327 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2328 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2329 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2330 | // we won't have to test for user gesture anymore and we can |
| 2331 | // move that code back to render_widget.cc |
| 2332 | if (webview() && webview()->mainFrame() && |
| 2333 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2334 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 2335 | } |
| 2336 | } |
| 2337 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2338 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2339 | // TODO(jcivelli): see TODO above in didFocus(). |
| 2340 | if (webview() && webview()->mainFrame() && |
| 2341 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2342 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 2343 | } |
| 2344 | } |
| 2345 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2346 | // 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] | 2347 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2348 | // point to dispatch the ShowView message. |
| 2349 | // |
| 2350 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 2351 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2352 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2353 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2354 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 2355 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2356 | |
| 2357 | if (did_show_) |
| 2358 | return; |
| 2359 | did_show_ = true; |
| 2360 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 2361 | if (content::GetContentClient()->renderer()->AllowPopup(creator_url_)) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2362 | opened_by_user_gesture_ = true; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2363 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2364 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2365 | if (!opened_by_user_gesture_) { |
| 2366 | // We exempt background tabs for compat with older versions of Chrome. |
| 2367 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2368 | // we probably don't need this check. |
| 2369 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2370 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2371 | } |
| 2372 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2373 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2374 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2375 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2376 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2377 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2378 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2379 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2380 | } |
| 2381 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2382 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2383 | DCHECK(did_show_) << "should already have shown the view"; |
| 2384 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2385 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2386 | // showModalDialog to function properly. |
| 2387 | // |
| 2388 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2389 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2390 | // handed manner. |
| 2391 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2392 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2393 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2394 | |
[email protected] | 08a1c810 | 2012-05-11 23:14:26 | [diff] [blame] | 2395 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal( |
| 2396 | routing_id_, opener_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2397 | } |
| 2398 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2399 | bool RenderViewImpl::enterFullScreen() { |
| 2400 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 2401 | return true; |
| 2402 | } |
| 2403 | |
| 2404 | void RenderViewImpl::exitFullScreen() { |
| 2405 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 2406 | } |
| 2407 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2408 | bool RenderViewImpl::requestPointerLock() { |
| 2409 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2410 | } |
| 2411 | |
| 2412 | void RenderViewImpl::requestPointerUnlock() { |
| 2413 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2414 | } |
| 2415 | |
| 2416 | bool RenderViewImpl::isPointerLocked() { |
| 2417 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2418 | webwidget_mouse_lock_target_.get()); |
| 2419 | } |
| 2420 | |
[email protected] | 7a1ec28a | 2012-03-28 21:10:24 | [diff] [blame] | 2421 | void RenderViewImpl::didActivateCompositor(int input_handler_identifier) { |
| 2422 | CompositorThread* compositor_thread = |
| 2423 | RenderThreadImpl::current()->compositor_thread(); |
| 2424 | if (compositor_thread) |
| 2425 | compositor_thread->AddInputHandler( |
| 2426 | routing_id_, input_handler_identifier, AsWeakPtr()); |
| 2427 | |
| 2428 | RenderWidget::didActivateCompositor(input_handler_identifier); |
| 2429 | } |
| 2430 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2431 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2432 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2433 | WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 2434 | const WebPluginParams& params) { |
[email protected] | eaacd1f | 2011-09-23 02:32:55 | [diff] [blame] | 2435 | WebPlugin* plugin = NULL; |
| 2436 | if (content::GetContentClient()->renderer()->OverrideCreatePlugin( |
| 2437 | this, frame, params, &plugin)) { |
| 2438 | return plugin; |
| 2439 | } |
| 2440 | |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 2441 | // TODO(fsamuel): Remove this once upstreaming of the new browser plugin is |
| 2442 | // complete. |
| 2443 | if (UTF16ToASCII(params.mimeType) == content::kBrowserPluginNewMimeType) { |
| 2444 | return content::BrowserPluginManager::Get()-> |
| 2445 | CreateBrowserPlugin(this, frame, params); |
| 2446 | } |
| 2447 | |
[email protected] | c64e4d5 | 2012-06-20 23:09:06 | [diff] [blame] | 2448 | if (UTF16ToASCII(params.mimeType) == content::kBrowserPluginMimeType) |
[email protected] | cb25aa1 | 2012-08-07 19:13:43 | [diff] [blame] | 2449 | return content::old::BrowserPlugin::Create(this, frame, params); |
[email protected] | b1c4de4c | 2012-06-08 00:04:56 | [diff] [blame] | 2450 | |
[email protected] | a813c8e | 2011-10-08 01:34:11 | [diff] [blame] | 2451 | webkit::WebPluginInfo info; |
| 2452 | std::string mime_type; |
| 2453 | bool found = GetPluginInfo(params.url, frame->top()->document().url(), |
| 2454 | params.mimeType.utf8(), &info, &mime_type); |
| 2455 | if (!found) |
| 2456 | return NULL; |
| 2457 | |
| 2458 | WebPluginParams params_to_use = params; |
| 2459 | params_to_use.mimeType = WebString::fromUTF8(mime_type); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2460 | return CreatePlugin(frame, info, params_to_use); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2461 | } |
| 2462 | |
[email protected] | 6ac77cb | 2012-05-01 14:49:01 | [diff] [blame] | 2463 | WebPlugin* RenderViewImpl::createPluginReplacement( |
| 2464 | WebFrame* frame, |
| 2465 | const WebPluginParams& params) { |
| 2466 | webkit::WebPluginInfo info; |
| 2467 | std::string mime_type; |
| 2468 | GetPluginInfo(params.url, frame->top()->document().url(), |
| 2469 | params.mimeType.utf8(), &info, &mime_type); |
| 2470 | return content::GetContentClient()->renderer()->CreatePluginReplacement( |
| 2471 | this, info.path); |
| 2472 | } |
| 2473 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2474 | WebSharedWorker* RenderViewImpl::createSharedWorker( |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2475 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2476 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2477 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2478 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2479 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2480 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2481 | ViewHostMsg_CreateWorker_Params params; |
| 2482 | params.url = url; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2483 | params.name = name; |
| 2484 | params.document_id = document_id; |
| 2485 | params.render_view_route_id = routing_id_; |
| 2486 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2487 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2488 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2489 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2490 | if (url_mismatch) { |
| 2491 | return NULL; |
| 2492 | } else { |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2493 | return new WebSharedWorkerProxy(RenderThreadImpl::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2494 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2495 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2496 | route_id, |
| 2497 | routing_id_); |
| 2498 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2499 | } |
| 2500 | |
[email protected] | 97b150db | 2012-08-16 18:26:02 | [diff] [blame] | 2501 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
| 2502 | WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2503 | FOR_EACH_OBSERVER( |
| 2504 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 2505 | |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2506 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2507 | #if defined(OS_ANDROID) |
[email protected] | dbd3d21 | 2012-07-13 02:17:22 | [diff] [blame] | 2508 | // TODO(qinmin): upstream the implementation of getting WebGraphicsContext3D |
| 2509 | // and GpuChannelHost here to replace the NULL params. |
[email protected] | 780fc824 | 2012-09-19 20:28:52 | [diff] [blame] | 2510 | if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) { |
| 2511 | if (!media_bridge_manager_.get()) { |
| 2512 | media_bridge_manager_.reset( |
| 2513 | new webkit_media::MediaPlayerBridgeManagerImpl(1)); |
| 2514 | } |
| 2515 | return new webkit_media::WebMediaPlayerInProcessAndroid( |
| 2516 | frame, |
| 2517 | client, |
| 2518 | cookieJar(frame), |
| 2519 | media_player_manager_.get(), |
| 2520 | media_bridge_manager_.get(), |
| 2521 | new content::StreamTextureFactoryImpl( |
| 2522 | NULL, NULL, routing_id_), |
| 2523 | cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging)); |
| 2524 | } |
| 2525 | if (!media_player_proxy_) { |
| 2526 | media_player_proxy_ = new content::WebMediaPlayerProxyImplAndroid( |
| 2527 | this, media_player_manager_.get()); |
| 2528 | } |
| 2529 | return new webkit_media::WebMediaPlayerImplAndroid( |
| 2530 | frame, |
| 2531 | client, |
| 2532 | media_player_manager_.get(), |
| 2533 | media_player_proxy_, |
| 2534 | new content::StreamTextureFactoryImpl( |
| 2535 | NULL, NULL, routing_id_)); |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 2536 | #endif |
| 2537 | |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2538 | media::MessageLoopFactory* message_loop_factory = |
[email protected] | b8032290 | 2012-03-06 01:33:50 | [diff] [blame] | 2539 | new media::MessageLoopFactory(); |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2540 | media::FilterCollection* collection = new media::FilterCollection(); |
| 2541 | RenderMediaLog* render_media_log = new RenderMediaLog(); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2542 | |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2543 | RenderAudioSourceProvider* audio_source_provider = NULL; |
| 2544 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2545 | // Add in any custom filter factories first. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2546 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2547 | // audio_source_provider is a "provider" to WebKit, and a sink |
| 2548 | // from the perspective of the audio renderer. |
| 2549 | audio_source_provider = new RenderAudioSourceProvider(); |
| 2550 | |
| 2551 | // Add the chrome specific audio renderer, using audio_source_provider |
| 2552 | // as the sink. |
[email protected] | 37136d16 | 2012-04-09 23:39:19 | [diff] [blame] | 2553 | media::AudioRendererImpl* audio_renderer = |
| 2554 | new media::AudioRendererImpl(audio_source_provider); |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2555 | collection->AddAudioRenderer(audio_renderer); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2556 | } |
| 2557 | |
[email protected] | 15d206e | 2012-08-17 22:35:13 | [diff] [blame] | 2558 | WebGraphicsContext3DCommandBufferImpl* context3d = NULL; |
| 2559 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 2560 | switches::kDisableAcceleratedVideoDecode)) |
| 2561 | context3d = RenderThreadImpl::current()->GetGpuVDAContext3D(); |
[email protected] | 851334d | 2012-06-15 22:39:31 | [diff] [blame] | 2562 | if (context3d) { |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 2563 | scoped_refptr<base::MessageLoopProxy> factories_loop = |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 2564 | RenderThreadImpl::current()->compositor_thread() ? |
| 2565 | RenderThreadImpl::current()->compositor_thread()->GetWebThread() |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 2566 | ->message_loop()->message_loop_proxy() : |
| 2567 | base::MessageLoopProxy::current(); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2568 | GpuChannelHost* gpu_channel_host = |
| 2569 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
| 2570 | content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
[email protected] | 873da26 | 2012-08-10 22:02:47 | [diff] [blame] | 2571 | collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder( |
[email protected] | 084c855 | 2012-08-12 22:51:20 | [diff] [blame] | 2572 | base::Bind(&media::MessageLoopFactory::GetMessageLoop, |
| 2573 | base::Unretained(message_loop_factory), |
[email protected] | c462c90 | 2012-09-06 13:13:42 | [diff] [blame] | 2574 | media::MessageLoopFactory::kDecoder), |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 2575 | factories_loop, |
[email protected] | 8d435928 | 2012-01-14 00:53:31 | [diff] [blame] | 2576 | new RendererGpuVideoDecoderFactories( |
[email protected] | 84a83e19 | 2012-03-09 18:43:40 | [diff] [blame] | 2577 | gpu_channel_host, factories_loop, context3d))); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2578 | } |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2579 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 2580 | WebMediaPlayer* media_player = |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2581 | content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer( |
| 2582 | this, frame, client, AsWeakPtr(), collection, audio_source_provider, |
[email protected] | 1113bfdf | 2012-07-16 21:46:10 | [diff] [blame] | 2583 | audio_source_provider, message_loop_factory, media_stream_impl_, |
| 2584 | render_media_log); |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2585 | if (!media_player) { |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2586 | media_player = new webkit_media::WebMediaPlayerImpl( |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2587 | frame, client, AsWeakPtr(), collection, audio_source_provider, |
[email protected] | 1113bfdf | 2012-07-16 21:46:10 | [diff] [blame] | 2588 | audio_source_provider, message_loop_factory, media_stream_impl_, |
| 2589 | render_media_log); |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2590 | } |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2591 | return media_player; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2592 | } |
| 2593 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2594 | WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost( |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2595 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
[email protected] | cdeeeb2 | 2012-01-11 07:44:23 | [diff] [blame] | 2596 | if (!frame || !frame->view()) |
| 2597 | return NULL; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2598 | return new RendererWebApplicationCacheHostImpl( |
| 2599 | FromWebView(frame->view()), client, |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2600 | RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy()); |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2601 | } |
| 2602 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2603 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 2604 | return &cookie_jar_; |
| 2605 | } |
| 2606 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2607 | void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) { |
| 2608 | if (is_loading_) { |
| 2609 | pending_frame_tree_update_ = true; |
| 2610 | return; |
| 2611 | } |
| 2612 | if (!updating_frame_tree_) |
| 2613 | SendUpdatedFrameTree(NULL); |
| 2614 | } |
| 2615 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2616 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 2617 | if (is_loading_) { |
| 2618 | pending_frame_tree_update_ = true; |
| 2619 | // Make sure observers are notified, even if we return right away. |
| 2620 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
| 2621 | return; |
| 2622 | } |
| 2623 | if (!updating_frame_tree_) |
| 2624 | SendUpdatedFrameTree(frame); |
| 2625 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2626 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2627 | } |
| 2628 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2629 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2630 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2631 | } |
| 2632 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2633 | void RenderViewImpl::loadURLExternally( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2634 | WebFrame* frame, const WebURLRequest& request, |
| 2635 | WebNavigationPolicy policy) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2636 | loadURLExternally(frame, request, policy, WebString()); |
| 2637 | } |
| 2638 | |
[email protected] | 5e92282f | 2012-08-17 08:11:57 | [diff] [blame] | 2639 | void RenderViewImpl::Repaint(const gfx::Size& size) { |
| 2640 | OnMsgRepaint(size); |
| 2641 | } |
| 2642 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2643 | void RenderViewImpl::loadURLExternally( |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2644 | WebFrame* frame, const WebURLRequest& request, |
| 2645 | WebNavigationPolicy policy, |
| 2646 | const WebString& suggested_name) { |
[email protected] | 5650554 | 2012-05-12 00:25:37 | [diff] [blame] | 2647 | Referrer referrer( |
| 2648 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 2649 | GetReferrerPolicyFromRequest(frame, request)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2650 | if (policy == WebKit::WebNavigationPolicyDownload) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2651 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer, |
| 2652 | suggested_name)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2653 | } else { |
[email protected] | 5650554 | 2012-05-12 00:25:37 | [diff] [blame] | 2654 | OpenURL(frame, request.url(), referrer, policy); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2655 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2656 | } |
| 2657 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2658 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2659 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2660 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2661 | Referrer referrer( |
| 2662 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 2663 | GetReferrerPolicyFromRequest(frame, request)); |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2664 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2665 | if (is_swapped_out_) { |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 2666 | if (request.url() != GURL(content::kSwappedOutURL)) { |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2667 | // Targeted links may try to navigate a swapped out frame. Allow the |
| 2668 | // browser process to navigate the tab instead. Note that it is also |
| 2669 | // possible for non-targeted navigations (from this view) to arrive |
| 2670 | // here just after we are swapped out. It's ok to send them to the |
| 2671 | // browser, as long as they're for the top level frame. |
| 2672 | // TODO(creis): Ensure this supports targeted form submissions when |
| 2673 | // fixing http://crbug.com/101395. |
| 2674 | if (frame->parent() == NULL) { |
| 2675 | OpenURL(frame, request.url(), referrer, default_policy); |
| 2676 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2677 | } |
| 2678 | |
| 2679 | // We should otherwise ignore in-process iframe navigations, if they |
| 2680 | // arrive just after we are swapped out. |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2681 | return WebKit::WebNavigationPolicyIgnore; |
[email protected] | 0639c063a | 2012-03-22 20:55:33 | [diff] [blame] | 2682 | } |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2683 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 2684 | // Allow content::kSwappedOutURL to complete. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2685 | return default_policy; |
| 2686 | } |
| 2687 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2688 | // Webkit is asking whether to navigate to a new URL. |
| 2689 | // This is fine normally, except if we're showing UI from one security |
| 2690 | // context and they're trying to navigate to a different context. |
| 2691 | const GURL& url = request.url(); |
| 2692 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2693 | // A content initiated navigation may have originated from a link-click, |
| 2694 | // script, drag-n-drop operation, etc. |
| 2695 | bool is_content_initiated = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2696 | DocumentState::FromDataSource(frame->provisionalDataSource())-> |
| 2697 | navigation_state()->is_content_initiated(); |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2698 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 2699 | // Experimental: |
| 2700 | // If --enable-strict-site-isolation is enabled, send all top-level |
| 2701 | // navigations to the browser to let it swap processes when crossing site |
| 2702 | // boundaries. This is currently expected to break some script calls and |
| 2703 | // navigations, such as form submissions. |
| 2704 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2705 | if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) && |
| 2706 | !frame->parent() && (is_content_initiated || is_redirect)) { |
| 2707 | WebString origin_str = frame->document().securityOrigin().toString(); |
| 2708 | GURL frame_url(origin_str.utf8().data()); |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame^] | 2709 | // TODO(cevans): revisit whether this site check is still necessary once |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2710 | // crbug.com/101395 is fixed. |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame^] | 2711 | if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url, |
| 2712 | url) || |
| 2713 | frame_url.scheme() != url.scheme()) { |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2714 | OpenURL(frame, url, referrer, default_policy); |
| 2715 | return WebKit::WebNavigationPolicyIgnore; |
| 2716 | } |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 2717 | } |
| 2718 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 2719 | // 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] | 2720 | if (is_content_initiated) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 2721 | bool browser_handles_request = |
| 2722 | renderer_preferences_.browser_handles_non_local_top_level_requests && |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 2723 | IsNonLocalTopLevelNavigation(url, frame, type); |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 2724 | if (!browser_handles_request) { |
| 2725 | browser_handles_request = |
| 2726 | renderer_preferences_.browser_handles_all_top_level_requests && |
| 2727 | IsTopLevelNavigation(frame); |
| 2728 | } |
| 2729 | |
| 2730 | if (browser_handles_request) { |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 2731 | // Reset these counters as the RenderView could be reused for the next |
| 2732 | // navigation. |
| 2733 | page_id_ = -1; |
| 2734 | last_page_id_sent_to_browser_ = -1; |
| 2735 | OpenURL(frame, url, referrer, default_policy); |
| 2736 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2737 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2738 | } |
| 2739 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 2740 | // Use the frame's original request's URL rather than the document's URL for |
| 2741 | // subsequent checks. For a popup, the document's URL may become the opener |
| 2742 | // window's URL if the opener has called document.write(). |
| 2743 | // See http://crbug.com/93517. |
| 2744 | GURL old_url(frame->dataSource()->request().url()); |
| 2745 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2746 | // 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] | 2747 | // 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] | 2748 | // top-level navigations (not iframes). But we sometimes navigate to |
| 2749 | // about:blank to clear a tab, and we want to still allow that. |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2750 | // |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2751 | // Note: this is known to break POST submissions when crossing process |
| 2752 | // boundaries until http://crbug.com/101395 is fixed. This is better for |
| 2753 | // security than loading a WebUI, extension or app page in the wrong process. |
| 2754 | // POST requests don't work because this mechanism does not preserve form |
| 2755 | // POST data. We will need to send the request's httpBody data up to the |
| 2756 | // browser process, and issue a special POST navigation in WebKit (via |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 2757 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 2758 | // for examples of how to send the httpBody data. |
[email protected] | 2762a1b | 2011-12-09 15:25:22 | [diff] [blame] | 2759 | if (!frame->parent() && is_content_initiated && |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2760 | !url.SchemeIs(chrome::kAboutScheme)) { |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2761 | bool send_referrer = false; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2762 | |
| 2763 | // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses |
| 2764 | // must be handled by the browser process so that the correct bindings and |
| 2765 | // data sources can be registered. |
| 2766 | // Similarly, navigations to view-source URLs or within ViewSource mode |
| 2767 | // must be handled by the browser process. |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 2768 | // Lastly, access to file:// URLs from non-file:// URL pages must be |
| 2769 | // handled by the browser so that ordinary renderer processes don't get |
| 2770 | // blessed with file permissions. |
| 2771 | int cumulative_bindings = RenderProcess::current()->GetEnabledBindings(); |
| 2772 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2773 | bool should_fork = |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2774 | content::GetContentClient()->HasWebUIScheme(url) || |
| 2775 | (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) || |
| 2776 | url.SchemeIs(chrome::kViewSourceScheme) || |
| 2777 | frame->isViewSourceModeEnabled(); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2778 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 2779 | if (!should_fork && url.SchemeIs(chrome::kFileScheme)) { |
| 2780 | // Fork non-file to file opens. Check the opener URL if this is the |
| 2781 | // initial navigation in a newly opened window. |
| 2782 | GURL source_url(old_url); |
| 2783 | if (is_initial_navigation && source_url.is_empty() && frame->opener()) |
| 2784 | source_url = frame->opener()->top()->document().url(); |
| 2785 | DCHECK(!source_url.is_empty()); |
| 2786 | should_fork = !source_url.SchemeIs(chrome::kFileScheme); |
| 2787 | } |
| 2788 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2789 | if (!should_fork) { |
| 2790 | // Give the embedder a chance. |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2791 | // For now, we skip this for POST submissions. This is because |
| 2792 | // http://crbug.com/101395 is more likely to cause compatibility issues |
| 2793 | // with hosted apps and extensions than WebUI pages. We will remove this |
| 2794 | // check when cross-process POST submissions are supported. |
| 2795 | if (request.httpMethod() == "GET") { |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 2796 | should_fork = content::GetContentClient()->renderer()->ShouldFork( |
| 2797 | frame, url, is_initial_navigation, &send_referrer); |
| 2798 | } |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | if (should_fork) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2802 | OpenURL( |
| 2803 | frame, url, send_referrer ? referrer : Referrer(), default_policy); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2804 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2805 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2809 | // its own process. This is done by sites like Gmail that try to open links |
| 2810 | // in new windows without script connections back to the original page. We |
| 2811 | // treat such cases as browser navigations (in which we will create a new |
| 2812 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2813 | // |
| 2814 | // We use the following heuristic to decide whether to fork a new page in its |
| 2815 | // own process: |
| 2816 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2817 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2818 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2819 | // |
| 2820 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2821 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2822 | bool is_fork = |
| 2823 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2824 | old_url == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2825 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2826 | historyBackListCount() < 1 && |
| 2827 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2828 | // The parent page must have set the child's window.opener to null before |
| 2829 | // redirecting to the desired URL. |
| 2830 | frame->opener() == NULL && |
| 2831 | // Must be a top-level frame. |
| 2832 | frame->parent() == NULL && |
| 2833 | // Must not have issued the request from this page. |
| 2834 | is_content_initiated && |
| 2835 | // Must be targeted at the current tab. |
| 2836 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2837 | // Must be a JavaScript navigation, which appears as "other". |
| 2838 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2839 | |
[email protected] | f92ce2b | 2012-03-06 18:02:59 | [diff] [blame] | 2840 | if (is_fork) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2841 | // Open the URL via the browser, not via WebKit. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2842 | OpenURL(frame, url, Referrer(), default_policy); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2843 | return WebKit::WebNavigationPolicyIgnore; |
| 2844 | } |
| 2845 | |
| 2846 | return default_policy; |
| 2847 | } |
| 2848 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2849 | bool RenderViewImpl::canHandleRequest( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2850 | WebFrame* frame, const WebURLRequest& request) { |
| 2851 | // We allow WebKit to think that everything can be handled even though |
| 2852 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2853 | return true; |
| 2854 | } |
| 2855 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2856 | WebURLError RenderViewImpl::cannotHandleRequestError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2857 | WebFrame* frame, const WebURLRequest& request) { |
| 2858 | NOTREACHED(); // Since we said we can handle all requests. |
| 2859 | return WebURLError(); |
| 2860 | } |
| 2861 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2862 | WebURLError RenderViewImpl::cancelledError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2863 | WebFrame* frame, const WebURLRequest& request) { |
| 2864 | WebURLError error; |
| 2865 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2866 | error.reason = net::ERR_ABORTED; |
| 2867 | error.unreachableURL = request.url(); |
| 2868 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2869 | } |
| 2870 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2871 | void RenderViewImpl::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2872 | WebFrame*, const WebURLError&) { |
| 2873 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2874 | } |
| 2875 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2876 | void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame, |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2877 | const WebKit::WebFormElement& form) { |
| 2878 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2879 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2880 | // This method gets called before any of those handlers run, so save away |
| 2881 | // a copy of the password in case it gets lost. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2882 | DocumentState* document_state = |
| 2883 | DocumentState::FromDataSource(frame->dataSource()); |
| 2884 | document_state->set_password_form_data( |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2885 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2886 | } |
| 2887 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2888 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 2889 | const WebFormElement& form) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2890 | DocumentState* document_state = |
| 2891 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
| 2892 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2893 | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2894 | if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK) |
| 2895 | navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2896 | |
| 2897 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2898 | WebSearchableFormData web_searchable_form_data(form); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2899 | document_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2900 | document_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2901 | web_searchable_form_data.encoding().utf8()); |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 2902 | scoped_ptr<PasswordForm> password_form_data = |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2903 | PasswordFormDomManager::CreatePasswordForm(form); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2904 | |
[email protected] | 098c95cb | 2011-04-28 16:49:01 | [diff] [blame] | 2905 | // In order to save the password that the user actually typed and not one |
| 2906 | // that may have gotten transformed by the site prior to submit, recover it |
| 2907 | // from the form contents already stored by |willSendSubmitEvent| into the |
| 2908 | // dataSource's NavigationState (as opposed to the provisionalDataSource's, |
| 2909 | // which is what we're storing into now.) |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 2910 | if (password_form_data.get()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2911 | DocumentState* old_document_state = |
| 2912 | DocumentState::FromDataSource(frame->dataSource()); |
| 2913 | if (old_document_state) { |
| 2914 | PasswordForm* old_form_data = old_document_state->password_form_data(); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2915 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2916 | password_form_data->password_value = old_form_data->password_value; |
| 2917 | } |
| 2918 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2919 | |
[email protected] | a045f4e3 | 2012-08-31 09:36:07 | [diff] [blame] | 2920 | document_state->set_password_form_data(password_form_data.Pass()); |
| 2921 | |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 2922 | FOR_EACH_OBSERVER( |
| 2923 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2924 | } |
| 2925 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2926 | void RenderViewImpl::willPerformClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2927 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2928 | double fire_time) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2929 | FOR_EACH_OBSERVER( |
| 2930 | RenderViewObserver, observers_, |
| 2931 | WillPerformClientRedirect(frame, from, to, interval, fire_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2932 | } |
| 2933 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2934 | void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2935 | FOR_EACH_OBSERVER( |
| 2936 | RenderViewObserver, observers_, DidCancelClientRedirect(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2937 | } |
| 2938 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2939 | void RenderViewImpl::didCompleteClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2940 | WebFrame* frame, const WebURL& from) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2941 | if (!frame->parent()) { |
| 2942 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2943 | // If there's no provisional data source, it's a reference fragment |
| 2944 | // navigation. |
| 2945 | completed_client_redirect_src_ = Referrer( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 2946 | from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) : |
[email protected] | f36f409 | 2012-05-09 18:31:04 | [diff] [blame] | 2947 | frame->document().referrerPolicy()); |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2948 | } |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2949 | FOR_EACH_OBSERVER( |
| 2950 | RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2951 | } |
| 2952 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2953 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2954 | bool content_initiated = !pending_navigation_params_.get(); |
| 2955 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2956 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2957 | if (!document_state) { |
| 2958 | document_state = new DocumentState; |
| 2959 | ds->setExtraData(document_state); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2960 | if (!content_initiated) |
| 2961 | PopulateDocumentStateFromPending(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2962 | } |
| 2963 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 2964 | // Carry over the user agent override flag, if it exists. |
| 2965 | if (content_initiated && webview() && webview()->mainFrame() && |
| 2966 | webview()->mainFrame()->dataSource()) { |
| 2967 | DocumentState* old_document_state = |
| 2968 | DocumentState::FromDataSource(webview()->mainFrame()->dataSource()); |
| 2969 | if (old_document_state) { |
| 2970 | document_state->set_is_overriding_user_agent( |
| 2971 | old_document_state->is_overriding_user_agent()); |
| 2972 | } |
| 2973 | } |
| 2974 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2975 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2976 | // non-null NavigationState. |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 2977 | if (content_initiated) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2978 | document_state->set_navigation_state( |
| 2979 | NavigationState::CreateContentInitiated()); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 2980 | } else { |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 2981 | document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 2982 | pending_navigation_params_.reset(); |
| 2983 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2984 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2985 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2986 | // navigating from a page that used prefetching using a link on that |
| 2987 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2988 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2989 | // this value appropriately. |
| 2990 | // TODO(gavinp): catch the important case of navigation in a new |
| 2991 | // renderer process. |
| 2992 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2993 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2994 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2995 | const GURL referrer( |
| 2996 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2997 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2998 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2999 | old_frame->dataSource())->was_prefetcher()) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 3000 | for (; old_frame; old_frame = old_frame->traverseNext(false)) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3001 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 3002 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3003 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3004 | break; |
| 3005 | } |
| 3006 | } |
| 3007 | } |
| 3008 | } |
| 3009 | } |
| 3010 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3011 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3012 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3013 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3014 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3015 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3016 | break; |
| 3017 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3018 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3019 | break; |
| 3020 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3021 | document_state->set_load_type( |
| 3022 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3023 | break; |
| 3024 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3025 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3026 | break; |
| 3027 | } |
| 3028 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3029 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 3030 | FOR_EACH_OBSERVER( |
| 3031 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3032 | } |
| 3033 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3034 | void RenderViewImpl::PopulateDocumentStateFromPending( |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3035 | DocumentState* document_state) { |
| 3036 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3037 | document_state->set_request_time(params.request_time); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3038 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3039 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme) && |
| 3040 | params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
| 3041 | // We're doing a load of a page that was restored from the last session. By |
| 3042 | // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which |
| 3043 | // can result in stale data for pages that are set to expire. We explicitly |
| 3044 | // override that by setting the policy here so that as necessary we load |
| 3045 | // from the network. |
| 3046 | document_state->set_cache_policy_override( |
| 3047 | WebURLRequest::UseProtocolCachePolicy); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | if (IsReload(params)) |
| 3051 | document_state->set_load_type(DocumentState::RELOAD); |
| 3052 | else if (!params.state.empty()) |
| 3053 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 3054 | else |
| 3055 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3056 | |
| 3057 | document_state->set_referrer_policy(params.referrer.policy); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 3058 | document_state->set_is_overriding_user_agent(params.is_overriding_user_agent); |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3059 | document_state->set_must_reset_scroll_and_scale_state( |
| 3060 | params.navigation_type == |
| 3061 | ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3062 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3063 | |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3064 | NavigationState* RenderViewImpl::CreateNavigationStateFromPending() { |
| 3065 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
| 3066 | NavigationState* navigation_state = NULL; |
| 3067 | |
| 3068 | // A navigation resulting from loading a javascript URL should not be treated |
| 3069 | // as a browser initiated event. Instead, we want it to look as if the page |
| 3070 | // initiated any load resulting from JS execution. |
| 3071 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 3072 | navigation_state = NavigationState::CreateBrowserInitiated( |
| 3073 | params.page_id, |
| 3074 | params.pending_history_list_offset, |
| 3075 | params.transition); |
| 3076 | navigation_state->set_transferred_request_child_id( |
| 3077 | params.transferred_request_child_id); |
| 3078 | navigation_state->set_transferred_request_request_id( |
| 3079 | params.transferred_request_request_id); |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3080 | navigation_state->set_allow_download(params.allow_download); |
[email protected] | 45d83a1 | 2012-04-06 22:57:57 | [diff] [blame] | 3081 | } else { |
| 3082 | navigation_state = NavigationState::CreateContentInitiated(); |
| 3083 | } |
| 3084 | return navigation_state; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3085 | } |
| 3086 | |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3087 | void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) { |
| 3088 | bool enable_viewport = |
[email protected] | 06ea34a | 2012-05-07 18:52:10 | [diff] [blame] | 3089 | command_line.HasSwitch(switches::kEnableViewport); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3090 | bool enable_fixed_layout = |
| 3091 | command_line.HasSwitch(switches::kEnableFixedLayout); |
[email protected] | 4ef6104a | 2012-06-06 18:15:32 | [diff] [blame] | 3092 | bool enable_pinch = enable_viewport || |
| 3093 | command_line.HasSwitch(switches::kEnablePinch); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3094 | |
| 3095 | webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport); |
| 3096 | webview()->settings()->setFixedElementsLayoutRelativeToFrame(true); |
[email protected] | 4ef6104a | 2012-06-06 18:15:32 | [diff] [blame] | 3097 | if (!enable_pinch && |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 3098 | webview()->isAcceleratedCompositingActive() && |
[email protected] | 4ef6104a | 2012-06-06 18:15:32 | [diff] [blame] | 3099 | webkit_preferences_.apply_default_device_scale_factor_in_compositor && |
[email protected] | 60051ec | 2012-06-08 22:40:57 | [diff] [blame] | 3100 | device_scale_factor_ != 1) { |
[email protected] | 4ef6104a | 2012-06-06 18:15:32 | [diff] [blame] | 3101 | // Page scaling is disabled by default when applying a scale factor in the |
| 3102 | // compositor since they are currently incompatible. |
| 3103 | webview()->setPageScaleFactorLimits(1, 1); |
| 3104 | } |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3105 | |
| 3106 | if (enable_viewport) { |
| 3107 | webview()->settings()->setViewportEnabled(true); |
| 3108 | } else if (enable_fixed_layout) { |
| 3109 | std::string str = |
| 3110 | command_line.GetSwitchValueASCII(switches::kEnableFixedLayout); |
| 3111 | std::vector<std::string> tokens; |
| 3112 | base::SplitString(str, ',', &tokens); |
| 3113 | if (tokens.size() == 2) { |
| 3114 | int width, height; |
| 3115 | if (base::StringToInt(tokens[0], &width) && |
| 3116 | base::StringToInt(tokens[1], &height)) |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3117 | webview()->setFixedLayoutSize(WebSize(width, height)); |
[email protected] | 5b52cd2f71 | 2012-03-28 02:12:48 | [diff] [blame] | 3118 | } |
| 3119 | } |
| 3120 | } |
| 3121 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3122 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3123 | WebDataSource* ds = frame->provisionalDataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3124 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3125 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3126 | // Update the request time if WebKit has better knowledge of it. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3127 | if (document_state->request_time().is_null()) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3128 | double event_time = ds->triggeringEventTime(); |
| 3129 | if (event_time != 0.0) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3130 | document_state->set_request_time(Time::FromDoubleT(event_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3131 | } |
| 3132 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3133 | // Start time is only set after request time. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3134 | document_state->set_start_load_time(Time::Now()); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3135 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3136 | bool is_top_most = !frame->parent(); |
| 3137 | if (is_top_most) { |
| 3138 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3139 | NavigationGestureUser : NavigationGestureAuto; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3140 | |
| 3141 | // Make sure redirect tracking state is clear for the new load. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3142 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3143 | } else if (frame->parent()->isLoading()) { |
| 3144 | // 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] | 3145 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3146 | document_state->navigation_state()->set_transition_type( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3147 | content::PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3148 | } |
| 3149 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3150 | FOR_EACH_OBSERVER( |
| 3151 | RenderViewObserver, observers_, DidStartProvisionalLoad(frame)); |
| 3152 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3153 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 3154 | routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(), |
[email protected] | eacb080b | 2011-05-22 19:40:26 | [diff] [blame] | 3155 | ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3156 | } |
| 3157 | |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3158 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 3159 | WebFrame* frame) { |
| 3160 | if (frame->parent()) |
| 3161 | return; |
| 3162 | // Received a redirect on the main frame. |
| 3163 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3164 | if (!data_source) { |
| 3165 | // Should only be invoked when we have a data source. |
| 3166 | NOTREACHED(); |
| 3167 | return; |
| 3168 | } |
| 3169 | std::vector<GURL> redirects; |
| 3170 | GetRedirectChain(data_source, &redirects); |
| 3171 | if (redirects.size() >= 2) { |
| 3172 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 3173 | GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back())); |
| 3174 | } |
| 3175 | } |
| 3176 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3177 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 3178 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3179 | // Notify the browser that we failed a provisional load with an error. |
| 3180 | // |
| 3181 | // Note: It is important this notification occur before DidStopLoading so the |
| 3182 | // SSL manager can react to the provisional load failure before being |
| 3183 | // notified the load stopped. |
| 3184 | // |
| 3185 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3186 | DCHECK(ds); |
| 3187 | |
| 3188 | const WebURLRequest& failed_request = ds->request(); |
| 3189 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3190 | FOR_EACH_OBSERVER( |
| 3191 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 3192 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3193 | bool show_repost_interstitial = |
| 3194 | (error.reason == net::ERR_CACHE_MISS && |
| 3195 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3196 | |
| 3197 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 3198 | params.frame_id = frame->identifier(); |
| 3199 | params.is_main_frame = !frame->parent(); |
| 3200 | params.error_code = error.reason; |
| 3201 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 3202 | failed_request, |
| 3203 | error, |
| 3204 | NULL, |
| 3205 | ¶ms.error_description); |
| 3206 | params.url = error.unreachableURL; |
| 3207 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3208 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 3209 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3210 | |
| 3211 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3212 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3213 | if (error.reason == net::ERR_ABORTED) |
| 3214 | return; |
| 3215 | |
| 3216 | // Make sure we never show errors in view source mode. |
| 3217 | frame->enableViewSourceMode(false); |
| 3218 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3219 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3220 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3221 | |
| 3222 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3223 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3224 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3225 | // as session history is concerned. |
| 3226 | // |
| 3227 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3228 | // the page id. |
| 3229 | // |
| 3230 | bool replace = |
| 3231 | navigation_state->pending_page_id() != -1 || |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3232 | navigation_state->transition_type() == |
| 3233 | content::PAGE_TRANSITION_AUTO_SUBFRAME; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3234 | |
| 3235 | // If we failed on a browser initiated request, then make sure that our error |
| 3236 | // page load is regarded as the same browser initiated request. |
| 3237 | if (!navigation_state->is_content_initiated()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3238 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 3239 | pending_navigation_params_->page_id = |
| 3240 | navigation_state->pending_page_id(); |
| 3241 | pending_navigation_params_->pending_history_list_offset = |
| 3242 | navigation_state->pending_history_list_offset(); |
| 3243 | pending_navigation_params_->transition = |
| 3244 | navigation_state->transition_type(); |
| 3245 | pending_navigation_params_->request_time = |
| 3246 | document_state->request_time(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | // Provide the user with a more helpful error page? |
| 3250 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3251 | return; |
| 3252 | |
| 3253 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3254 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3255 | } |
| 3256 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3257 | void RenderViewImpl::didReceiveDocumentData( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3258 | WebFrame* frame, const char* data, size_t data_len, |
| 3259 | bool& prevent_default) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3260 | DocumentState* document_state = |
| 3261 | DocumentState::FromDataSource(frame->dataSource()); |
| 3262 | document_state->set_use_error_page(false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3263 | } |
| 3264 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3265 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 3266 | bool is_new_navigation) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3267 | DocumentState* document_state = |
| 3268 | DocumentState::FromDataSource(frame->dataSource()); |
| 3269 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3270 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3271 | if (document_state->commit_load_time().is_null()) |
| 3272 | document_state->set_commit_load_time(Time::Now()); |
| 3273 | |
[email protected] | a3a5397d | 2012-09-12 06:50:34 | [diff] [blame] | 3274 | if (document_state->must_reset_scroll_and_scale_state()) { |
| 3275 | webview()->resetScrollAndScaleState(); |
| 3276 | document_state->set_must_reset_scroll_and_scale_state(false); |
| 3277 | } |
| 3278 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3279 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 3280 | // When we perform a new navigation, we need to update the last committed |
| 3281 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3282 | UpdateSessionHistory(frame); |
| 3283 | |
| 3284 | // We bump our Page ID to correspond with the new session history entry. |
| 3285 | page_id_ = next_page_id_++; |
| 3286 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 3287 | // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since |
[email protected] | 58436a1 | 2012-03-21 17:10:26 | [diff] [blame] | 3288 | // we don't want to forget the entry that was there, and since we will |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 3289 | // never come back to content::kSwappedOutURL. Note that we have to call |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3290 | // UpdateSessionHistory and update page_id_ even in this case, so that |
| 3291 | // the current entry gets a state update and so that we don't send a |
| 3292 | // state update to the wrong entry when we swap back in. |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 3293 | if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 3294 | // Advance our offset in session history, applying the length limit. |
| 3295 | // There is now no forward history. |
| 3296 | history_list_offset_++; |
| 3297 | if (history_list_offset_ >= content::kMaxSessionHistoryEntries) |
| 3298 | history_list_offset_ = content::kMaxSessionHistoryEntries - 1; |
| 3299 | history_list_length_ = history_list_offset_ + 1; |
| 3300 | history_page_ids_.resize(history_list_length_, -1); |
| 3301 | history_page_ids_[history_list_offset_] = page_id_; |
| 3302 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3303 | } else { |
| 3304 | // Inspect the navigation_state on this frame to see if the navigation |
| 3305 | // corresponds to a session history navigation... Note: |frame| may or |
| 3306 | // may not be the toplevel frame, but for the case of capturing session |
| 3307 | // history, the first committed frame suffices. We keep track of whether |
| 3308 | // we've seen this commit before so that only capture session history once |
| 3309 | // per navigation. |
| 3310 | // |
| 3311 | // Note that we need to check if the page ID changed. In the case of a |
| 3312 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3313 | // previous URL and the current page ID, which would be wrong. |
| 3314 | if (navigation_state->pending_page_id() != -1 && |
| 3315 | navigation_state->pending_page_id() != page_id_ && |
| 3316 | !navigation_state->request_committed()) { |
| 3317 | // This is a successful session history navigation! |
| 3318 | UpdateSessionHistory(frame); |
| 3319 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3320 | |
| 3321 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 3322 | |
| 3323 | // If the history list is valid, our list of page IDs should be correct. |
| 3324 | DCHECK(history_list_length_ <= 0 || |
| 3325 | history_list_offset_ < 0 || |
| 3326 | history_list_offset_ >= history_list_length_ || |
| 3327 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3331 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3332 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 3333 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3334 | // Remember that we've already processed this request, so we don't update |
| 3335 | // the session history again. We do this regardless of whether this is |
| 3336 | // a session history navigation, because if we attempted a session history |
| 3337 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3338 | // new navigation. |
| 3339 | navigation_state->set_request_committed(true); |
| 3340 | |
| 3341 | UpdateURL(frame); |
| 3342 | |
| 3343 | // If this committed load was initiated by a client redirect, we're |
| 3344 | // at the last stop now, so clear it. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 3345 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3346 | |
| 3347 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3348 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 3349 | |
| 3350 | if (!frame->parent()) { // Only for top frames. |
| 3351 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 3352 | if (render_thread_impl) { // Can be NULL in tests. |
| 3353 | render_thread_impl->histogram_customizer()-> |
| 3354 | RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(), |
| 3355 | g_view_map.Get().size()); |
| 3356 | } |
| 3357 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3358 | } |
| 3359 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3360 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 3361 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3362 | DidClearWindowObject(frame)); |
| 3363 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3364 | GURL frame_url = frame->document().url(); |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 3365 | if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) && |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3366 | (frame_url.SchemeIs(chrome::kChromeUIScheme) || |
| 3367 | frame_url.SchemeIs(chrome::kDataScheme))) { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 3368 | GetWebUIBindings()->BindToJavascript(frame, "chrome"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3369 | } |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 3370 | |
| 3371 | if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) { |
| 3372 | if (!dom_automation_controller_.get()) |
| 3373 | dom_automation_controller_.reset(new DomAutomationController()); |
| 3374 | dom_automation_controller_->set_message_sender( |
| 3375 | static_cast<content::RenderView*>(this)); |
| 3376 | dom_automation_controller_->set_routing_id(routing_id()); |
| 3377 | dom_automation_controller_->BindToJavascript(frame, |
| 3378 | "domAutomationController"); |
| 3379 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3380 | } |
| 3381 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3382 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3383 | // Notify the browser about non-blank documents loading in the top frame. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3384 | GURL url = frame->document().url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 3385 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 87717d0e | 2012-04-26 02:58:43 | [diff] [blame] | 3386 | if (frame == webview()->mainFrame()) |
| 3387 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3388 | } |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 3389 | |
| 3390 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3391 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3392 | } |
| 3393 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3394 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 3395 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 3396 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3397 | |
| 3398 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3399 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3400 | } |
| 3401 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3402 | void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) { |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 3403 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3404 | DidChangeIcon(frame, type)); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3405 | } |
| 3406 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3407 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3408 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3409 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3410 | document_state->set_finish_document_load_time(Time::Now()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3411 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 3412 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3413 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3414 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3415 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3416 | |
| 3417 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3418 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3419 | } |
| 3420 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3421 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3422 | if (webview()->mainFrame() == frame) { |
| 3423 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3424 | page_id_)); |
| 3425 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3426 | } |
| 3427 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3428 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3429 | WebDataSource* ds = frame->dataSource(); |
| 3430 | DCHECK(ds); |
| 3431 | |
| 3432 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 3433 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3434 | |
| 3435 | const WebURLRequest& failed_request = ds->request(); |
| 3436 | string16 error_description; |
| 3437 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 3438 | failed_request, |
| 3439 | error, |
| 3440 | NULL, |
| 3441 | &error_description); |
| 3442 | Send(new ViewHostMsg_DidFailLoadWithError(routing_id_, |
| 3443 | frame->identifier(), |
| 3444 | failed_request.url(), |
| 3445 | !frame->parent(), |
| 3446 | error.reason, |
| 3447 | error_description)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3448 | } |
| 3449 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3450 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3451 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3452 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 3453 | if (document_state->finish_load_time().is_null()) |
| 3454 | document_state->set_finish_load_time(Time::Now()); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3455 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 3456 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 3457 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3458 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, |
| 3459 | frame->identifier(), |
| 3460 | ds->request().url(), |
| 3461 | !frame->parent())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3462 | } |
| 3463 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3464 | void RenderViewImpl::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3465 | WebFrame* frame, bool is_new_navigation) { |
| 3466 | // If this was a reference fragment navigation that we initiated, then we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3467 | // 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] | 3468 | // update the ExtraData on the datasource so that others who read the |
| 3469 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3470 | // initiate this navigation, then we need to take care to reset any pre- |
| 3471 | // existing navigation state to a content-initiated navigation state. |
| 3472 | // DidCreateDataSource conveniently takes care of this for us. |
| 3473 | didCreateDataSource(frame, frame->dataSource()); |
| 3474 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3475 | DocumentState* document_state = |
| 3476 | DocumentState::FromDataSource(frame->dataSource()); |
| 3477 | NavigationState* new_state = document_state->navigation_state(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3478 | new_state->set_was_within_same_page(true); |
| 3479 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3480 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3481 | |
[email protected] | 750fcf87 | 2011-08-03 23:10:47 | [diff] [blame] | 3482 | WebDataSource* datasource = frame->view()->mainFrame()->dataSource(); |
| 3483 | UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection()); |
[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::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3487 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3488 | } |
| 3489 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3490 | void RenderViewImpl::assignIdentifierToRequest( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3491 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3492 | // Ignore |
| 3493 | } |
| 3494 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3495 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 3496 | unsigned identifier, |
| 3497 | WebURLRequest& request, |
| 3498 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3499 | WebFrame* top_frame = frame->top(); |
| 3500 | if (!top_frame) |
| 3501 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3502 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 3503 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 3504 | WebDataSource* data_source = |
| 3505 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 3506 | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 3507 | content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3508 | DocumentState* document_state = DocumentState::FromDataSource(data_source); |
[email protected] | def55e02 | 2012-07-26 01:15:29 | [diff] [blame] | 3509 | DCHECK(document_state); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3510 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | e1ed5a1 | 2012-08-08 19:57:44 | [diff] [blame] | 3511 | transition_type = navigation_state->transition_type(); |
| 3512 | |
| 3513 | GURL request_url(request.url()); |
| 3514 | GURL new_url; |
| 3515 | if (content::GetContentClient()->renderer()->WillSendRequest( |
| 3516 | frame, transition_type, request_url, &new_url)) { |
| 3517 | request.setURL(WebURL(new_url)); |
| 3518 | } |
| 3519 | |
[email protected] | def55e02 | 2012-07-26 01:15:29 | [diff] [blame] | 3520 | if (document_state->is_cache_policy_override_set()) |
| 3521 | request.setCachePolicy(document_state->cache_policy_override()); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3522 | |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3523 | WebKit::WebReferrerPolicy referrer_policy; |
| 3524 | if (document_state && document_state->is_referrer_policy_set()) { |
| 3525 | referrer_policy = document_state->referrer_policy(); |
| 3526 | document_state->clear_referrer_policy(); |
| 3527 | } else { |
| 3528 | referrer_policy = frame->document().referrerPolicy(); |
| 3529 | } |
| 3530 | |
[email protected] | e372f3d | 2012-07-17 19:16:44 | [diff] [blame] | 3531 | // The request's extra data may indicate that we should set a custom user |
| 3532 | // agent. This needs to be done here, after WebKit is through with setting the |
| 3533 | // user agent on its own. |
| 3534 | WebString custom_user_agent; |
| 3535 | if (request.extraData()) { |
| 3536 | webkit_glue::WebURLRequestExtraDataImpl* old_extra_data = |
| 3537 | static_cast<webkit_glue::WebURLRequestExtraDataImpl*>( |
| 3538 | request.extraData()); |
| 3539 | custom_user_agent = old_extra_data->custom_user_agent(); |
| 3540 | |
| 3541 | if (!custom_user_agent.isNull()) { |
| 3542 | if (custom_user_agent.isEmpty()) |
| 3543 | request.clearHTTPHeaderField("User-Agent"); |
| 3544 | else |
| 3545 | request.setHTTPHeaderField("User-Agent", custom_user_agent); |
| 3546 | } |
| 3547 | } |
| 3548 | |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 3549 | request.setExtraData( |
[email protected] | ca66282 | 2012-05-11 17:53:59 | [diff] [blame] | 3550 | new RequestExtraData(referrer_policy, |
[email protected] | e372f3d | 2012-07-17 19:16:44 | [diff] [blame] | 3551 | custom_user_agent, |
[email protected] | 537fbe0 | 2011-11-24 00:58:06 | [diff] [blame] | 3552 | (frame == top_frame), |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 3553 | frame->identifier(), |
| 3554 | frame->parent() == top_frame, |
| 3555 | frame->parent() ? frame->parent()->identifier() : -1, |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 3556 | navigation_state->allow_download(), |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 3557 | transition_type, |
| 3558 | navigation_state->transferred_request_child_id(), |
| 3559 | navigation_state->transferred_request_request_id())); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 3560 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3561 | DocumentState* top_document_state = |
| 3562 | DocumentState::FromDataSource(top_data_source); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 3563 | // TODO(gavinp): separate out prefetching and prerender field trials |
| 3564 | // if the rel=prerender rel type is sticking around. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3565 | if (top_document_state && |
[email protected] | 925dec1c | 2012-05-18 05:09:00 | [diff] [blame] | 3566 | request.targetType() == WebURLRequest::TargetIsPrefetch) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3567 | top_document_state->set_was_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3568 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3569 | request.setRequestorID(routing_id_); |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 3570 | request.setHasUserGesture(frame->isProcessingUserGesture()); |
| 3571 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 3572 | if (!renderer_preferences_.enable_referrers) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 3573 | request.clearHTTPHeaderField("Referer"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3574 | } |
| 3575 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3576 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3577 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3578 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3579 | // Only do this for responses that correspond to a provisional data source |
| 3580 | // of the top-most frame. If we have a provisional data source, then we |
| 3581 | // can't have any sub-resources yet, so we know that this response must |
| 3582 | // correspond to a frame load. |
| 3583 | if (!frame->provisionalDataSource() || frame->parent()) |
| 3584 | return; |
| 3585 | |
| 3586 | // 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] | 3587 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3588 | if (frame->isViewSourceModeEnabled()) |
| 3589 | return; |
| 3590 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3591 | DocumentState* document_state = |
| 3592 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3593 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3594 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3595 | // Record page load flags. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3596 | document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 3597 | document_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
[email protected] | b9fd01ba | 2012-02-28 01:50:40 | [diff] [blame] | 3598 | WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response); |
| 3599 | if (extra_data) { |
| 3600 | document_state->set_npn_negotiated_protocol( |
| 3601 | extra_data->npn_negotiated_protocol()); |
| 3602 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3603 | document_state->set_was_alternate_protocol_available( |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 3604 | response.wasAlternateProtocolAvailable()); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3605 | document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
| 3606 | document_state->set_http_status_code(http_status_code); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3607 | // Whether or not the http status code actually corresponds to an error is |
| 3608 | // only checked when the page is done loading, if |use_error_page| is |
| 3609 | // still true. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3610 | document_state->set_use_error_page(true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3611 | } |
| 3612 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3613 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3614 | WebFrame* frame, unsigned identifier) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3615 | DocumentState* document_state = |
| 3616 | DocumentState::FromDataSource(frame->dataSource()); |
| 3617 | if (!document_state->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3618 | return; |
| 3619 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 3620 | // Do not show error page when DevTools is attached. |
| 3621 | if (devtools_agent_->IsAttached()) |
| 3622 | return; |
| 3623 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3624 | // Display error page, if appropriate. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3625 | int http_status_code = document_state->http_status_code(); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3626 | if (http_status_code == 404) { |
| 3627 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3628 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3629 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3630 | const GURL& error_page_url = |
| 3631 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3632 | if (error_page_url.is_valid()) { |
| 3633 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 3634 | original_error.domain = "http"; |
| 3635 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3636 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3637 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3638 | document_state->set_alt_error_page_fetcher( |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3639 | new AltErrorPageResourceFetcher( |
| 3640 | error_page_url, frame, original_error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 3641 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 3642 | base::Unretained(this)))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3643 | return; |
| 3644 | } |
| 3645 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3646 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3647 | std::string error_domain; |
| 3648 | if (content::GetContentClient()->renderer()->HasErrorPage( |
| 3649 | http_status_code, &error_domain)) { |
| 3650 | WebURLError error; |
| 3651 | error.unreachableURL = frame->document().url(); |
| 3652 | error.domain = WebString::fromUTF8(error_domain); |
| 3653 | error.reason = http_status_code; |
| 3654 | |
| 3655 | LoadNavigationErrorPage( |
| 3656 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 3657 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3658 | } |
| 3659 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3660 | void RenderViewImpl::didFailResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3661 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3662 | // Ignore |
| 3663 | } |
| 3664 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3665 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3666 | WebFrame* frame, const WebURLRequest& request, |
| 3667 | const WebURLResponse& response) { |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 3668 | // The recipients of this message have no use for data: URLs: they don't |
| 3669 | // affect the page's insecure content list and are not in the disk cache. To |
| 3670 | // prevent large (1M+) data: URLs from crashing in the IPC system, we simply |
| 3671 | // filter them out here. |
| 3672 | GURL url(request.url()); |
| 3673 | if (url.SchemeIs("data")) |
| 3674 | return; |
| 3675 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3676 | // Let the browser know we loaded a resource from the memory cache. This |
| 3677 | // message is needed to display the correct SSL indicators. |
| 3678 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 3679 | routing_id_, |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 3680 | url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3681 | response.securityInfo(), |
| 3682 | request.httpMethod().utf8(), |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 3683 | response.mimeType().utf8(), |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3684 | ResourceType::FromTargetType(request.targetType()))); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3685 | } |
| 3686 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3687 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3688 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 3689 | } |
| 3690 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3691 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3692 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3693 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 3694 | routing_id_, |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3695 | origin.toString().utf8(), |
| 3696 | target)); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3697 | } |
| 3698 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3699 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3700 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3701 | } |
| 3702 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3703 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 3704 | v8::Handle<v8::Context> context, |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3705 | int extension_group, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3706 | int world_id) { |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 3707 | content::GetContentClient()->renderer()->DidCreateScriptContext( |
[email protected] | a00fe69 | 2012-02-27 05:52:58 | [diff] [blame] | 3708 | frame, context, extension_group, world_id); |
| 3709 | } |
| 3710 | |
| 3711 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 3712 | v8::Handle<v8::Context> context, |
| 3713 | int world_id) { |
| 3714 | content::GetContentClient()->renderer()->DidCreateScriptContext( |
| 3715 | frame, context, -1, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3716 | } |
| 3717 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3718 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 3719 | v8::Handle<v8::Context> context, |
| 3720 | int world_id) { |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 3721 | content::GetContentClient()->renderer()->WillReleaseScriptContext( |
| 3722 | frame, context, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3723 | } |
| 3724 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3725 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3726 | // We don't always want to send the change messages over IPC, only if we've |
| 3727 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 3728 | // message. |
| 3729 | if (!send_preferred_size_changes_ || !webview()) |
| 3730 | return; |
| 3731 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3732 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3733 | webview()->mainFrame()->documentElementScrollHeight()); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 3734 | |
| 3735 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 3736 | // so we need to adjust. |
| 3737 | double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel()); |
| 3738 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 3739 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 3740 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3741 | if (size == preferred_size_) |
| 3742 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3743 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3744 | preferred_size_ = size; |
| 3745 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3746 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3747 | } |
| 3748 | |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 3749 | WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D( |
| 3750 | const WebGraphicsContext3D::Attributes& attributes) { |
| 3751 | if (!webview()) |
| 3752 | return NULL; |
| 3753 | |
| 3754 | if (GetGuestToEmbedderChannel()) { |
| 3755 | WebGraphicsContext3DCommandBufferImpl* context = |
| 3756 | GetGuestToEmbedderChannel()->CreateWebGraphicsContext3D( |
| 3757 | this, attributes, false); |
| 3758 | if (!guest_pp_instance()) { |
| 3759 | guest_uninitialized_context_ = context; |
| 3760 | guest_attributes_ = attributes; |
| 3761 | } |
| 3762 | return context; |
| 3763 | } |
| 3764 | |
| 3765 | // The WebGraphicsContext3DInProcessImpl code path is used for |
| 3766 | // layout tests (though not through this code) as well as for |
| 3767 | // debugging and bringing up new ports. |
| 3768 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) { |
| 3769 | return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( |
| 3770 | attributes, true); |
| 3771 | } else { |
| 3772 | GURL url; |
| 3773 | if (webview()->mainFrame()) |
| 3774 | url = GURL(webview()->mainFrame()->document().url()); |
| 3775 | else |
[email protected] | f89e173a | 2012-08-24 01:12:26 | [diff] [blame] | 3776 | url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
[email protected] | 1842fe2 | 2012-08-13 23:24:35 | [diff] [blame] | 3777 | |
| 3778 | scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 3779 | new WebGraphicsContext3DCommandBufferImpl( |
| 3780 | surface_id(), |
| 3781 | url, |
| 3782 | RenderThreadImpl::current(), |
| 3783 | AsWeakPtr())); |
| 3784 | |
| 3785 | if (!context->Initialize( |
| 3786 | attributes, |
| 3787 | false /* bind generates resources */, |
| 3788 | content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) |
| 3789 | return NULL; |
| 3790 | return context.release(); |
| 3791 | } |
| 3792 | } |
| 3793 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3794 | // The browser process needs to know the shape of the tree, as well as the names |
| 3795 | // and ids of all frames. This allows it to properly route JavaScript messages |
| 3796 | // across processes and frames. The serialization format is described in the |
| 3797 | // comments of the ViewMsg_FrameTreeUpdated message. |
| 3798 | // This function sends those updates to the browser and updates the RVH |
| 3799 | // corresponding to this object. It must be called on any events that modify |
| 3800 | // the tree structure or the names of any frames. |
| 3801 | void RenderViewImpl::SendUpdatedFrameTree( |
| 3802 | WebKit::WebFrame* exclude_frame_subtree) { |
| 3803 | std::string json; |
| 3804 | base::DictionaryValue tree; |
| 3805 | |
| 3806 | ConstructFrameTree(webview()->mainFrame(), exclude_frame_subtree, &tree); |
| 3807 | base::JSONWriter::Write(&tree, &json); |
| 3808 | |
| 3809 | Send(new ViewHostMsg_FrameTreeUpdated(routing_id_, json)); |
| 3810 | } |
| 3811 | |
| 3812 | void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame, |
| 3813 | DictionaryValue* frame_tree) { |
| 3814 | NavigateToSwappedOutURL(frame); |
| 3815 | |
| 3816 | string16 name; |
| 3817 | if (frame_tree->GetString(content::kFrameTreeNodeNameKey, &name) && |
[email protected] | 5604fb5c | 2012-09-20 03:29:31 | [diff] [blame] | 3818 | !name.empty()) { |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 3819 | frame->setName(name); |
| 3820 | } |
| 3821 | |
| 3822 | int remote_id; |
| 3823 | if (frame_tree->GetInteger(content::kFrameTreeNodeIdKey, &remote_id)) |
| 3824 | active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(), |
| 3825 | remote_id)); |
| 3826 | |
| 3827 | ListValue* children; |
| 3828 | if (!frame_tree->GetList(content::kFrameTreeNodeSubtreeKey, &children)) |
| 3829 | return; |
| 3830 | |
| 3831 | base::DictionaryValue* child; |
| 3832 | for (size_t i = 0; i < children->GetSize(); ++i) { |
| 3833 | if (!children->GetDictionary(i, &child)) |
| 3834 | continue; |
| 3835 | WebElement element = frame->document().createElement("iframe"); |
| 3836 | if (frame->document().body().appendChild(element)) { |
| 3837 | WebFrame* subframe = WebFrame::fromFrameOwnerElement(element); |
| 3838 | if (subframe) |
| 3839 | CreateFrameTree(subframe, child); |
| 3840 | } else { |
| 3841 | LOG(ERROR) << "Failed to append created iframe element."; |
| 3842 | } |
| 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | WebKit::WebFrame* RenderViewImpl::GetFrameByMappedID(int frame_id) { |
| 3847 | std::map<int, int>::iterator it = active_frame_id_map_.find(frame_id); |
| 3848 | if (it == active_frame_id_map_.end()) |
| 3849 | return NULL; |
| 3850 | |
| 3851 | return FindFrameByID(webview()->mainFrame(), it->second); |
| 3852 | } |
| 3853 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3854 | void RenderViewImpl::EnsureMediaStreamImpl() { |
[email protected] | 7082fb94 | 2012-05-16 23:44:59 | [diff] [blame] | 3855 | if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
[email protected] | 0838156 | 2012-05-15 20:55:40 | [diff] [blame] | 3856 | return; |
| 3857 | |
[email protected] | 4fb0f20 | 2012-05-30 22:44:53 | [diff] [blame] | 3858 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3859 | if (!media_stream_dispatcher_) |
| 3860 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 3861 | |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 3862 | if (!media_stream_impl_) { |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3863 | media_stream_impl_ = new MediaStreamImpl( |
[email protected] | 1bc65a4 | 2012-04-23 09:31:25 | [diff] [blame] | 3864 | this, |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3865 | media_stream_dispatcher_, |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3866 | RenderThreadImpl::current()->video_capture_impl_manager(), |
[email protected] | 6ee10bd | 2012-09-13 09:01:53 | [diff] [blame] | 3867 | RenderThreadImpl::current()->GetMediaStreamDependencyFactory()); |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3868 | } |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 3869 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3870 | } |
| 3871 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3872 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 3873 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3874 | if (webview()->mainFrame() != frame) |
| 3875 | return; |
| 3876 | WebView* frameView = frame->view(); |
| 3877 | if (!frameView) |
| 3878 | return; |
| 3879 | |
| 3880 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 3881 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 3882 | |
| 3883 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 3884 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 3885 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 3886 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 3887 | |
| 3888 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 3889 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 3890 | } |
| 3891 | } |
| 3892 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3893 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3894 | WebSize offset = frame->scrollOffset(); |
| 3895 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 3896 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 3897 | |
| 3898 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 3899 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 3900 | |
| 3901 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 3902 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 3903 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 3904 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 3905 | |
| 3906 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 3907 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 3908 | } |
| 3909 | } |
| 3910 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3911 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3912 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3913 | |
| 3914 | if (webview()->mainFrame() == frame) |
| 3915 | UpdateScrollState(frame); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 3916 | |
| 3917 | FOR_EACH_OBSERVER( |
| 3918 | RenderViewObserver, observers_, DidChangeScrollOffset(frame)); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3919 | } |
| 3920 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3921 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3922 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3923 | } |
| 3924 | |
[email protected] | c8ac905 | 2012-07-20 21:43:40 | [diff] [blame] | 3925 | void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) { |
| 3926 | Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
| 3927 | } |
| 3928 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3929 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count, |
| 3930 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3931 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 3932 | if (!count) |
| 3933 | active_match_ordinal = 0; |
| 3934 | |
[email protected] | 733a58f | 2012-08-11 03:49:01 | [diff] [blame] | 3935 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3936 | request_id, |
| 3937 | count, |
| 3938 | gfx::Rect(), |
| 3939 | active_match_ordinal, |
| 3940 | final_update)); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3941 | } |
| 3942 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3943 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 3944 | int active_match_ordinal, |
| 3945 | const WebRect& selection_rect) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3946 | // Send the search result over to the browser process. |
| 3947 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3948 | request_id, |
| 3949 | -1, |
| 3950 | selection_rect, |
| 3951 | active_match_ordinal, |
| 3952 | false)); |
| 3953 | } |
| 3954 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3955 | void RenderViewImpl::openFileSystem( |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3956 | WebFrame* frame, |
| 3957 | WebFileSystem::Type type, |
| 3958 | long long size, |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 3959 | bool create, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3960 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3961 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3962 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3963 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 3964 | if (origin.isUnique()) { |
| 3965 | // Unique origins cannot store persistent state. |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3966 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 3967 | return; |
| 3968 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3969 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3970 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 3971 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 3972 | size, create, new WebFileSystemCallbackDispatcher(callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3973 | } |
| 3974 | |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 3975 | void RenderViewImpl::deleteFileSystem( |
| 3976 | WebFrame* frame, |
| 3977 | WebFileSystem::Type type , |
| 3978 | WebFileSystemCallbacks* callbacks) { |
| 3979 | DCHECK(callbacks); |
| 3980 | |
| 3981 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 3982 | if (origin.isUnique()) { |
| 3983 | // Unique origins cannot store persistent state. |
| 3984 | callbacks->didSucceed(); |
| 3985 | return; |
| 3986 | } |
| 3987 | |
| 3988 | ChildThread::current()->file_system_dispatcher()->DeleteFileSystem( |
| 3989 | GURL(origin.toString()), |
| 3990 | static_cast<fileapi::FileSystemType>(type), |
| 3991 | new WebFileSystemCallbackDispatcher(callbacks)); |
| 3992 | } |
| 3993 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3994 | void RenderViewImpl::queryStorageUsageAndQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 3995 | WebFrame* frame, |
| 3996 | WebStorageQuotaType type, |
| 3997 | WebStorageQuotaCallbacks* callbacks) { |
| 3998 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3999 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4000 | if (origin.isUnique()) { |
| 4001 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4002 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 4003 | return; |
| 4004 | } |
| 4005 | ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 4006 | GURL(origin.toString()), |
| 4007 | static_cast<quota::StorageType>(type), |
| 4008 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4009 | } |
| 4010 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4011 | void RenderViewImpl::requestStorageQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4012 | WebFrame* frame, |
| 4013 | WebStorageQuotaType type, |
| 4014 | unsigned long long requested_size, |
| 4015 | WebStorageQuotaCallbacks* callbacks) { |
| 4016 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4017 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 4018 | if (origin.isUnique()) { |
| 4019 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4020 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 4021 | return; |
| 4022 | } |
| 4023 | ChildThread::current()->quota_dispatcher()->RequestStorageQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 4024 | routing_id(), GURL(origin.toString()), |
| 4025 | static_cast<quota::StorageType>(type), requested_size, |
| 4026 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 4027 | } |
| 4028 | |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4029 | void RenderViewImpl::registerIntentService( |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4030 | WebFrame* frame, const WebIntentServiceInfo& service) { |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 4031 | webkit_glue::WebIntentServiceData data(service); |
| 4032 | if (data.title.empty()) |
| 4033 | data.title = webview()->mainFrame()->document().title(); |
| 4034 | bool user_gesture = frame->isProcessingUserGesture(); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4035 | Send(new IntentsHostMsg_RegisterIntentService(routing_id_, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 4036 | data, |
| 4037 | user_gesture)); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4038 | } |
| 4039 | |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4040 | void RenderViewImpl::dispatchIntent( |
| 4041 | WebFrame* frame, const WebIntentRequest& intentRequest) { |
| 4042 | webkit_glue::WebIntentData intent_data(intentRequest.intent()); |
[email protected] | 4e1eb339 | 2012-05-18 00:08:05 | [diff] [blame] | 4043 | |
| 4044 | // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued() |
| 4045 | WebKit::WebMessagePortChannelArray* channels = |
| 4046 | intentRequest.intent().messagePortChannelsRelease(); |
| 4047 | if (channels) { |
| 4048 | for (size_t i = 0; i < channels->size(); ++i) { |
| 4049 | WebMessagePortChannelImpl* webchannel = |
| 4050 | static_cast<WebMessagePortChannelImpl*>((*channels)[i]); |
| 4051 | intent_data.message_port_ids.push_back(webchannel->message_port_id()); |
| 4052 | DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE); |
| 4053 | } |
| 4054 | delete channels; |
| 4055 | } |
| 4056 | |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4057 | int id = intents_host_->RegisterWebIntent(intentRequest); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4058 | Send(new IntentsHostMsg_WebIntentDispatch( |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 4059 | routing_id_, intent_data, id)); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 4060 | } |
| 4061 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4062 | bool RenderViewImpl::willCheckAndDispatchMessageEvent( |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4063 | WebKit::WebFrame* sourceFrame, |
| 4064 | WebKit::WebFrame* targetFrame, |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4065 | WebKit::WebSecurityOrigin target_origin, |
| 4066 | WebKit::WebDOMMessageEvent event) { |
| 4067 | if (!is_swapped_out_) |
| 4068 | return false; |
| 4069 | |
| 4070 | ViewMsg_PostMessage_Params params; |
| 4071 | params.data = event.data().toString(); |
| 4072 | params.source_origin = event.origin(); |
| 4073 | if (!target_origin.isNull()) |
| 4074 | params.target_origin = target_origin.toString(); |
| 4075 | |
| 4076 | // Include the routing ID for the source frame, which the browser process |
| 4077 | // will translate into the routing ID for the equivalent frame in the target |
| 4078 | // process. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4079 | params.source_routing_id = MSG_ROUTING_NONE; |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4080 | RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4081 | if (source_view) |
| 4082 | params.source_routing_id = source_view->routing_id(); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4083 | params.source_frame_id = sourceFrame->identifier(); |
| 4084 | |
| 4085 | // Include the process, route, and frame IDs of the target frame. This allows |
| 4086 | // the browser to detect races between this message being sent and the target |
| 4087 | // frame no longer being valid. |
| 4088 | params.target_process_id = target_process_id_; |
| 4089 | params.target_routing_id = target_routing_id_; |
| 4090 | |
| 4091 | std::map<int,int>::iterator it = active_frame_id_map_.find( |
| 4092 | targetFrame->identifier()); |
| 4093 | if (it != active_frame_id_map_.end()) { |
| 4094 | params.target_frame_id = it->second; |
| 4095 | } else { |
| 4096 | params.target_frame_id = 0; |
| 4097 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4098 | |
| 4099 | Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 4100 | return true; |
| 4101 | } |
| 4102 | |
[email protected] | 5fa3a06 | 2012-03-21 15:39:34 | [diff] [blame] | 4103 | void RenderViewImpl::willOpenSocketStream( |
| 4104 | WebSocketStreamHandle* handle) { |
| 4105 | SocketStreamHandleData::AddToHandle(handle, routing_id_); |
| 4106 | } |
| 4107 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 4108 | WebKit::WebString RenderViewImpl::userAgentOverride( |
| 4109 | WebKit::WebFrame* frame, |
| 4110 | const WebKit::WebURL& url) { |
| 4111 | if (!webview() || !webview()->mainFrame() || |
| 4112 | renderer_preferences_.user_agent_override.empty()) { |
| 4113 | return WebKit::WebString(); |
| 4114 | } |
| 4115 | |
| 4116 | // If we're in the middle of committing a load, the data source we need |
| 4117 | // will still be provisional. |
| 4118 | WebFrame* main_frame = webview()->mainFrame(); |
| 4119 | WebDataSource* data_source = NULL; |
| 4120 | if (main_frame->provisionalDataSource()) |
| 4121 | data_source = main_frame->provisionalDataSource(); |
| 4122 | else |
| 4123 | data_source = main_frame->dataSource(); |
| 4124 | |
| 4125 | DocumentState* document_state = |
| 4126 | data_source ? DocumentState::FromDataSource(data_source) : NULL; |
| 4127 | if (document_state && document_state->is_overriding_user_agent()) |
| 4128 | return WebString::fromUTF8(renderer_preferences_.user_agent_override); |
| 4129 | else |
| 4130 | return WebKit::WebString(); |
| 4131 | } |
| 4132 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4133 | // WebKit::WebPageSerializerClient implementation ------------------------------ |
| 4134 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4135 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4136 | const WebURL& frame_url, |
| 4137 | const WebCString& data, |
| 4138 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4139 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4140 | routing_id(), |
| 4141 | frame_url, |
| 4142 | data.data(), |
| 4143 | static_cast<int32>(status))); |
| 4144 | } |
| 4145 | |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4146 | // content::RenderView implementation ------------------------------------------ |
| 4147 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4148 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4149 | return RenderWidget::Send(message); |
| 4150 | } |
| 4151 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4152 | int RenderViewImpl::GetRoutingID() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4153 | return routing_id_; |
| 4154 | } |
| 4155 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4156 | int RenderViewImpl::GetPageId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4157 | return page_id_; |
| 4158 | } |
| 4159 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4160 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4161 | return size(); |
| 4162 | } |
| 4163 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4164 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4165 | return webkit_preferences_; |
| 4166 | } |
| 4167 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4168 | WebKit::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4169 | return webview(); |
| 4170 | } |
| 4171 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4172 | WebKit::WebNode RenderViewImpl::GetFocusedNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4173 | if (!webview()) |
| 4174 | return WebNode(); |
| 4175 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 4176 | if (focused_frame) { |
| 4177 | WebDocument doc = focused_frame->document(); |
| 4178 | if (!doc.isNull()) |
| 4179 | return doc.focusedNode(); |
| 4180 | } |
| 4181 | |
| 4182 | return WebNode(); |
| 4183 | } |
| 4184 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4185 | WebKit::WebNode RenderViewImpl::GetContextMenuNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4186 | return context_menu_node_; |
| 4187 | } |
| 4188 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4189 | bool RenderViewImpl::IsEditableNode(const WebNode& node) const { |
| 4190 | if (node.isNull()) |
| 4191 | return false; |
| 4192 | |
| 4193 | if (node.isContentEditable()) |
| 4194 | return true; |
| 4195 | |
| 4196 | if (node.isElementNode()) { |
| 4197 | const WebElement& element = node.toConst<WebElement>(); |
| 4198 | if (element.isTextFormControlElement()) |
| 4199 | return true; |
| 4200 | |
| 4201 | // Also return true if it has an ARIA role of 'textbox'. |
| 4202 | for (unsigned i = 0; i < element.attributeCount(); ++i) { |
| 4203 | if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) { |
| 4204 | if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox")) |
| 4205 | return true; |
| 4206 | break; |
| 4207 | } |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4208 | } |
| 4209 | } |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 4210 | |
| 4211 | return false; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4212 | } |
| 4213 | |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 4214 | void RenderViewImpl::GuestReady(PP_Instance instance) { |
| 4215 | guest_pp_instance_ = instance; |
| 4216 | if (guest_uninitialized_context_) { |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 4217 | bool success = GetGuestToEmbedderChannel()->CreateGraphicsContext( |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 4218 | guest_uninitialized_context_, |
| 4219 | guest_attributes_, |
| 4220 | false, |
| 4221 | this); |
| 4222 | DCHECK(success); |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 4223 | CompleteInit(host_window_); |
| 4224 | guest_uninitialized_context_ = NULL; |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 4225 | } |
[email protected] | 468e490 | 2012-05-23 01:49:31 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | webkit::ppapi::WebPluginImpl* RenderViewImpl::CreateBrowserPlugin( |
| 4229 | const IPC::ChannelHandle& channel_handle, |
| 4230 | int guest_process_id, |
| 4231 | const WebKit::WebPluginParams& params) { |
| 4232 | scoped_refptr<webkit::ppapi::PluginModule> pepper_module( |
| 4233 | pepper_delegate_.CreateBrowserPluginModule(channel_handle, |
| 4234 | guest_process_id)); |
| 4235 | return new webkit::ppapi::WebPluginImpl( |
| 4236 | pepper_module.get(), params, pepper_delegate_.AsWeakPtr()); |
| 4237 | } |
| 4238 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4239 | WebKit::WebPlugin* RenderViewImpl::CreatePlugin( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4240 | WebKit::WebFrame* frame, |
| 4241 | const webkit::WebPluginInfo& info, |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4242 | const WebKit::WebPluginParams& params) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4243 | bool pepper_plugin_was_registered = false; |
| 4244 | scoped_refptr<webkit::ppapi::PluginModule> pepper_module( |
| 4245 | pepper_delegate_.CreatePepperPluginModule(info, |
| 4246 | &pepper_plugin_was_registered)); |
| 4247 | if (pepper_plugin_was_registered) { |
| 4248 | if (!pepper_module) |
| 4249 | return NULL; |
| 4250 | return new webkit::ppapi::WebPluginImpl( |
| 4251 | pepper_module.get(), params, pepper_delegate_.AsWeakPtr()); |
| 4252 | } |
| 4253 | |
[email protected] | 3e076a8 | 2012-09-11 19:12:36 | [diff] [blame] | 4254 | #if defined(USE_AURA) && !defined(OS_WIN) |
[email protected] | 34b27e44 | 2012-01-20 20:07:41 | [diff] [blame] | 4255 | return NULL; |
| 4256 | #else |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4257 | return new webkit::npapi::WebPluginImpl( |
| 4258 | frame, params, info.path, AsWeakPtr()); |
[email protected] | 34b27e44 | 2012-01-20 20:07:41 | [diff] [blame] | 4259 | #endif |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4260 | } |
| 4261 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4262 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 4263 | const string16& jscript, |
| 4264 | int id, |
| 4265 | bool notify_result) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4266 | v8::Handle<v8::Value> result; |
| 4267 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4268 | if (web_frame) |
| 4269 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 4270 | if (notify_result) { |
| 4271 | ListValue list; |
| 4272 | if (!result.IsEmpty() && web_frame) { |
| 4273 | v8::HandleScope handle_scope; |
| 4274 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 4275 | v8::Context::Scope context_scope(context); |
| 4276 | V8ValueConverterImpl converter; |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 4277 | converter.SetDateAllowed(true); |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 4278 | converter.SetRegExpAllowed(true); |
| 4279 | base::Value* result_value = converter.FromV8Value(result, context); |
| 4280 | list.Set(0, result_value ? result_value : |
| 4281 | base::Value::CreateNullValue()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4282 | } else { |
| 4283 | list.Set(0, Value::CreateNullValue()); |
| 4284 | } |
| 4285 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 4286 | } |
| 4287 | } |
| 4288 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4289 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4290 | return (!send_preferred_size_changes_ || |
| 4291 | (disable_scrollbars_size_limit_.width() <= width || |
| 4292 | disable_scrollbars_size_limit_.height() <= height)); |
| 4293 | } |
| 4294 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4295 | int RenderViewImpl::GetEnabledBindings() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4296 | return enabled_bindings_; |
| 4297 | } |
| 4298 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4299 | bool RenderViewImpl::GetContentStateImmediately() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4300 | return send_content_state_immediately_; |
| 4301 | } |
| 4302 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4303 | float RenderViewImpl::GetFilteredTimePerFrame() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4304 | return filtered_time_per_frame(); |
| 4305 | } |
| 4306 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4307 | void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame, |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4308 | const WebKit::WebContextMenuData& data) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4309 | showContextMenu(frame, data); |
| 4310 | } |
| 4311 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4312 | WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4313 | return visibilityState(); |
| 4314 | } |
| 4315 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4316 | void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame, |
| 4317 | const WebKit::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4318 | return runModalAlertDialog(frame, message); |
| 4319 | } |
| 4320 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4321 | void RenderViewImpl::LoadURLExternally( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4322 | WebKit::WebFrame* frame, |
| 4323 | const WebKit::WebURLRequest& request, |
| 4324 | WebKit::WebNavigationPolicy policy) { |
| 4325 | loadURLExternally(frame, request, policy); |
| 4326 | } |
| 4327 | |
| 4328 | // webkit_glue::WebPluginPageDelegate ------------------------------------------ |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 4329 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4330 | webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 4331 | const FilePath& file_path, |
| 4332 | const std::string& mime_type) { |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 4333 | if (!PluginChannelHost::IsListening()) { |
| 4334 | LOG(ERROR) << "PluginChannelHost isn't listening"; |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4335 | return NULL; |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 4336 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4337 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4338 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 4339 | if (in_process_plugin) { |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 4340 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 4341 | return webkit::npapi::WebPluginDelegateImpl::Create( |
| 4342 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 4343 | #else |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 4344 | // In-proc plugins aren't supported on non-Windows. |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 4345 | NOTIMPLEMENTED(); |
| 4346 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 4347 | #endif |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4348 | } |
| 4349 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 4350 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4351 | } |
| 4352 | |
[email protected] | 6ac77cb | 2012-05-01 14:49:01 | [diff] [blame] | 4353 | WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement( |
| 4354 | const FilePath& file_path) { |
| 4355 | return content::GetContentClient()->renderer()->CreatePluginReplacement( |
| 4356 | this, file_path); |
| 4357 | } |
| 4358 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4359 | void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 4360 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 4361 | Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4362 | #endif |
| 4363 | } |
| 4364 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4365 | void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 4366 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 4367 | Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4368 | #endif |
| 4369 | CleanupWindowInPluginMoves(window); |
| 4370 | } |
| 4371 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4372 | void RenderViewImpl::DidMovePlugin( |
| 4373 | const webkit::npapi::WebPluginGeometry& move) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4374 | SchedulePluginMove(move); |
| 4375 | } |
| 4376 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4377 | void RenderViewImpl::DidStartLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4378 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 4379 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4380 | } |
| 4381 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4382 | void RenderViewImpl::DidStopLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4383 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 4384 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4385 | } |
| 4386 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4387 | WebCookieJar* RenderViewImpl::GetCookieJar() { |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 4388 | return &cookie_jar_; |
| 4389 | } |
| 4390 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4391 | void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4392 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4393 | reinterpret_cast<int64>(player), |
| 4394 | player->hasVideo(), |
| 4395 | player->hasAudio(), |
| 4396 | true)); |
| 4397 | } |
| 4398 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4399 | void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4400 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 4401 | reinterpret_cast<int64>(player), |
| 4402 | player->hasVideo(), |
| 4403 | player->hasAudio(), |
| 4404 | false)); |
| 4405 | } |
| 4406 | |
[email protected] | 5d65fe9 | 2012-06-02 00:48:55 | [diff] [blame] | 4407 | void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 4408 | DidPause(player); |
| 4409 | } |
| 4410 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4411 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4412 | if (!webview()) |
| 4413 | return; |
| 4414 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4415 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | 6459800a | 2012-03-27 23:57:05 | [diff] [blame] | 4416 | SendUpdateState(item); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4417 | } |
| 4418 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4419 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4420 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4421 | if (!frame) |
| 4422 | return; |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4423 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4424 | string16 text; |
| 4425 | size_t offset; |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4426 | ui::Range range; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4427 | |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4428 | if (pepper_delegate_.IsPluginFocused()) { |
| 4429 | pepper_delegate_.GetSurroundingText(&text, &range); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4430 | offset = 0; // Pepper API does not support offset reporting. |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4431 | // TODO(kinaba): cut as needed. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4432 | } else { |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 4433 | size_t location, length; |
| 4434 | if (!webview()->caretOrSelectionRange(&location, &length)) |
| 4435 | return; |
| 4436 | |
| 4437 | range = ui::Range(location, location + length); |
| 4438 | |
| 4439 | if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { |
| 4440 | // If current focused element is editable, we will send 100 more chars |
| 4441 | // before and after selection. It is for input method surrounding text |
| 4442 | // feature. |
| 4443 | if (location > kExtraCharsBeforeAndAfterSelection) |
| 4444 | offset = location - kExtraCharsBeforeAndAfterSelection; |
| 4445 | else |
| 4446 | offset = 0; |
| 4447 | length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 4448 | WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 4449 | if (!webrange.isNull()) |
| 4450 | text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 4451 | } else { |
| 4452 | offset = location; |
| 4453 | text = frame->selectionAsText(); |
| 4454 | // http://crbug.com/101435 |
| 4455 | // In some case, frame->selectionAsText() returned text's length is not |
| 4456 | // equal to the length returned from webview()->caretOrSelectionRange(). |
| 4457 | // So we have to set the range according to text.length(). |
| 4458 | range.set_end(range.start() + text.length()); |
| 4459 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4460 | } |
| 4461 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4462 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 4463 | // the selection hasn't actually changed. We don't want to report these |
| 4464 | // because it will cause us to continually claim the X clipboard. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4465 | if (selection_text_offset_ != offset || |
| 4466 | selection_range_ != range || |
| 4467 | selection_text_ != text) { |
| 4468 | selection_text_ = text; |
| 4469 | selection_text_offset_ = offset; |
| 4470 | selection_range_ = range; |
| 4471 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 4472 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 4473 | } |
| 4474 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4475 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 4476 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4477 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4478 | // If the URL that failed was secure, then the embedding web page was not |
| 4479 | // expecting a network attacker to be able to manipulate its contents. As |
| 4480 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 4481 | // attacker to manipulate the contents of the response if we tried to use |
| 4482 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4483 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | // Grab the base URL from the browser process. |
| 4487 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 4488 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4489 | |
| 4490 | // Strip query params from the failed URL. |
| 4491 | GURL::Replacements remove_params; |
| 4492 | remove_params.ClearUsername(); |
| 4493 | remove_params.ClearPassword(); |
| 4494 | remove_params.ClearQuery(); |
| 4495 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4496 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 4497 | std::string spec_to_send = url_to_send.spec(); |
| 4498 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 4499 | if (failed_url.has_query()) |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 4500 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4501 | |
| 4502 | // Construct the query params to send to link doctor. |
| 4503 | std::string params(alternate_error_page_url_.query()); |
| 4504 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 4505 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4506 | params.append("&sourceid=chrome"); |
| 4507 | params.append("&error="); |
| 4508 | switch (error_type) { |
| 4509 | case DNS_ERROR: |
| 4510 | params.append("dnserror"); |
| 4511 | break; |
| 4512 | |
| 4513 | case HTTP_404: |
| 4514 | params.append("http404"); |
| 4515 | break; |
| 4516 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4517 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 4518 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 4519 | break; |
| 4520 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4521 | default: |
| 4522 | NOTREACHED() << "unknown ErrorPageType"; |
| 4523 | } |
| 4524 | |
| 4525 | // OK, build the final url to return. |
| 4526 | GURL::Replacements link_doctor_params; |
| 4527 | link_doctor_params.SetQueryStr(params); |
| 4528 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 4529 | return url; |
| 4530 | } |
| 4531 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4532 | GURL RenderViewImpl::GetOpenerUrl() const { |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 4533 | if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_) |
| 4534 | return GURL(); |
| 4535 | else |
| 4536 | return creator_url_; |
| 4537 | } |
| 4538 | |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 4539 | GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { |
| 4540 | WebDataSource* ds = frame->dataSource(); |
| 4541 | if (ds->hasUnreachableURL()) |
| 4542 | return ds->unreachableURL(); |
| 4543 | |
| 4544 | const WebURLRequest& request = ds->request(); |
| 4545 | return request.url(); |
| 4546 | } |
| 4547 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4548 | WebUIBindings* RenderViewImpl::GetWebUIBindings() { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 4549 | if (!web_ui_bindings_.get()) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4550 | web_ui_bindings_.reset(new WebUIBindings( |
| 4551 | static_cast<content::RenderView*>(this), routing_id_)); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4552 | } |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 4553 | return web_ui_bindings_.get(); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4554 | } |
| 4555 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4556 | WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4557 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4558 | } |
| 4559 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4560 | void RenderViewImpl::OnFind(int request_id, const string16& search_text, |
| 4561 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4562 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4563 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4564 | // Check if the plugin still exists in the document. |
| 4565 | if (main_frame->document().isPluginDocument() && |
| 4566 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4567 | if (options.findNext) { |
| 4568 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4569 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4570 | } else { |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 4571 | if (GetWebPluginFromPluginDocument()->startFind( |
| 4572 | search_text, options.matchCase, request_id)) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4573 | } else { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4574 | // Send "no results". |
| 4575 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4576 | request_id, |
| 4577 | 0, |
| 4578 | gfx::Rect(), |
| 4579 | 0, |
| 4580 | true)); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4581 | } |
| 4582 | } |
| 4583 | return; |
| 4584 | } |
| 4585 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4586 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4587 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4588 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4589 | |
| 4590 | bool multi_frame = (frame_after_main != main_frame); |
| 4591 | |
| 4592 | // If we have multiple frames, we don't want to wrap the search within the |
| 4593 | // frame, so we check here if we only have main_frame in the chain. |
| 4594 | bool wrap_within_frame = !multi_frame; |
| 4595 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 4596 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4597 | bool result = false; |
| 4598 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4599 | // If something is selected when we start searching it means we cannot just |
| 4600 | // increment the current match ordinal; we need to re-generate it. |
| 4601 | WebRange current_selection = focused_frame->selectionRange(); |
| 4602 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4603 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4604 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4605 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4606 | |
| 4607 | if (!result) { |
| 4608 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 4609 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4610 | |
| 4611 | // Find the next frame, but skip the invisible ones. |
| 4612 | do { |
| 4613 | // What is the next frame to search? (we might be going backwards). Note |
| 4614 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4615 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4616 | search_frame->traverseNext(true) : |
| 4617 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4618 | } while (!search_frame->hasVisibleContent() && |
| 4619 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4620 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 4621 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 4622 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4623 | |
| 4624 | // If we have multiple frames and we have wrapped back around to the |
| 4625 | // focused frame, we need to search it once more allowing wrap within |
| 4626 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 4627 | // reported matches, but no frames after the focused_frame contain a |
| 4628 | // match for the search word(s). |
| 4629 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4630 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4631 | request_id, search_text, options, true, // Force wrapping. |
| 4632 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4633 | } |
| 4634 | } |
| 4635 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4636 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4637 | } while (!result && search_frame != focused_frame); |
| 4638 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4639 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4640 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4641 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4642 | } else { |
| 4643 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4644 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4645 | // yet what is active. |
| 4646 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4647 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4648 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4649 | // If we find no matches then this will be our last status update. |
| 4650 | // Otherwise the scoping effort will send more results. |
| 4651 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4652 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4653 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 4654 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4655 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4656 | match_count, |
| 4657 | selection_rect, |
| 4658 | ordinal, |
| 4659 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4660 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4661 | // Scoping effort begins, starting with the mainframe. |
| 4662 | search_frame = main_frame; |
| 4663 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4664 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4665 | |
| 4666 | do { |
| 4667 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4668 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4669 | |
| 4670 | // We don't start another scoping effort unless at least one match has |
| 4671 | // been found. |
| 4672 | if (result) { |
| 4673 | // Start new scoping request. If the scoping function determines that it |
| 4674 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4675 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4676 | search_text, |
| 4677 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4678 | true); // reset the tickmarks |
| 4679 | } |
| 4680 | |
| 4681 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4682 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4683 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4684 | } while (search_frame != main_frame); |
| 4685 | } |
| 4686 | } |
| 4687 | |
[email protected] | 815dd987 | 2011-11-23 18:40:30 | [diff] [blame] | 4688 | void RenderViewImpl::OnStopFinding(content::StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4689 | WebView* view = webview(); |
| 4690 | if (!view) |
| 4691 | return; |
| 4692 | |
| 4693 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 4694 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4695 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4696 | return; |
| 4697 | } |
| 4698 | |
[email protected] | 815dd987 | 2011-11-23 18:40:30 | [diff] [blame] | 4699 | bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4700 | if (clear_selection) |
| 4701 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 4702 | |
| 4703 | WebFrame* frame = view->mainFrame(); |
| 4704 | while (frame) { |
| 4705 | frame->stopFinding(clear_selection); |
| 4706 | frame = frame->traverseNext(false); |
| 4707 | } |
| 4708 | |
[email protected] | 815dd987 | 2011-11-23 18:40:30 | [diff] [blame] | 4709 | if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4710 | WebFrame* focused_frame = view->focusedFrame(); |
| 4711 | if (focused_frame) { |
| 4712 | WebDocument doc = focused_frame->document(); |
| 4713 | if (!doc.isNull()) { |
| 4714 | WebNode node = doc.focusedNode(); |
| 4715 | if (!node.isNull()) |
| 4716 | node.simulateClick(); |
| 4717 | } |
| 4718 | } |
| 4719 | } |
| 4720 | } |
| 4721 | |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4722 | #if defined(OS_ANDROID) |
| 4723 | void RenderViewImpl::OnActivateNearestFindResult(int request_id, |
| 4724 | float x, float y) { |
| 4725 | if (!webview()) |
| 4726 | return; |
| 4727 | |
| 4728 | WebFrame* main_frame = webview()->mainFrame(); |
| 4729 | WebRect selection_rect; |
| 4730 | int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y), |
| 4731 | &selection_rect); |
| 4732 | if (ordinal == -1) { |
| 4733 | // Something went wrong, so send a no-op reply (force the main_frame to |
| 4734 | // report the current match count) in case the host is waiting for a |
| 4735 | // response due to rate-limiting). |
| 4736 | main_frame->increaseMatchCount(0, request_id); |
| 4737 | return; |
| 4738 | } |
| 4739 | |
| 4740 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4741 | request_id, |
| 4742 | -1 /* number_of_matches */, |
| 4743 | selection_rect, |
| 4744 | ordinal, |
| 4745 | true /* final_update */)); |
| 4746 | } |
| 4747 | |
| 4748 | void RenderViewImpl::OnFindMatchRects(int current_version) { |
| 4749 | if (!webview()) |
| 4750 | return; |
| 4751 | |
| 4752 | WebFrame* main_frame = webview()->mainFrame(); |
| 4753 | std::vector<gfx::RectF> match_rects; |
| 4754 | |
| 4755 | int rects_version = main_frame->findMatchMarkersVersion(); |
| 4756 | if (current_version != rects_version) { |
| 4757 | WebVector<WebFloatRect> web_match_rects; |
| 4758 | main_frame->findMatchRects(web_match_rects); |
| 4759 | match_rects.reserve(web_match_rects.size()); |
| 4760 | for (size_t i = 0; i < web_match_rects.size(); ++i) |
| 4761 | match_rects.push_back(gfx::RectF(web_match_rects[i])); |
| 4762 | } |
| 4763 | |
| 4764 | gfx::RectF active_rect = main_frame->activeFindMatchRect(); |
| 4765 | Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_, |
| 4766 | rects_version, |
| 4767 | match_rects, |
| 4768 | active_rect)); |
| 4769 | } |
| 4770 | #endif |
| 4771 | |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4772 | void RenderViewImpl::OnZoom(content::PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4773 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4774 | return; |
| 4775 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4776 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 4777 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4778 | double old_zoom_level = webview()->zoomLevel(); |
| 4779 | double zoom_level; |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4780 | if (zoom == content::PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4781 | zoom_level = 0; |
| 4782 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4783 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4784 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4785 | } else { |
| 4786 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4787 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4788 | // to go to the next whole number so that the user can always get back to |
| 4789 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4790 | if ((old_zoom_level > 1 && zoom > 0) || |
| 4791 | (old_zoom_level < 1 && zoom < 0)) { |
| 4792 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4793 | } else { |
| 4794 | // We're going towards 100%, so first go to the next whole number. |
| 4795 | zoom_level = static_cast<int>(old_zoom_level); |
| 4796 | } |
| 4797 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4798 | webview()->setZoomLevel(false, zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4799 | zoomLevelChanged(); |
| 4800 | } |
| 4801 | |
| 4802 | void RenderViewImpl::OnZoomFactor(content::PageZoom zoom, |
| 4803 | int zoom_center_x, int zoom_center_y) { |
| 4804 | ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y, |
| 4805 | kScalingIncrementForGesture); |
| 4806 | } |
| 4807 | |
| 4808 | void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom, |
| 4809 | int zoom_center_x, |
| 4810 | int zoom_center_y, |
| 4811 | float scaling_increment) { |
| 4812 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4813 | return; |
| 4814 | |
[email protected] | c514d63 | 2011-08-16 22:54:44 | [diff] [blame] | 4815 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 4816 | double page_scale_factor; |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 4817 | if (zoom == content::PAGE_ZOOM_RESET) { |
[email protected] | c514d63 | 2011-08-16 22:54:44 | [diff] [blame] | 4818 | page_scale_factor = 1.0; |
| 4819 | } else { |
| 4820 | page_scale_factor = old_page_scale_factor + |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4821 | (zoom > 0 ? scaling_increment : -scaling_increment); |
[email protected] | c514d63 | 2011-08-16 22:54:44 | [diff] [blame] | 4822 | } |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4823 | if (page_scale_factor > 0) { |
[email protected] | 8519136 | 2011-11-08 18:53:09 | [diff] [blame] | 4824 | webview()->setPageScaleFactor(page_scale_factor, |
| 4825 | WebPoint(zoom_center_x, zoom_center_y)); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 4826 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4827 | } |
| 4828 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4829 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4830 | webview()->hidePopups(); |
| 4831 | webview()->setZoomLevel(false, zoom_level); |
| 4832 | zoomLevelChanged(); |
| 4833 | } |
| 4834 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4835 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 4836 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4837 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4838 | } |
| 4839 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4840 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4841 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4842 | } |
| 4843 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4844 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4845 | WebString no_encoding; |
| 4846 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4847 | } |
| 4848 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4849 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4850 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4851 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4852 | |
| 4853 | // xpath string can represent a frame deep down the tree (across multiple |
| 4854 | // frame DOMs). |
| 4855 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4856 | // should break into 2 xpaths |
| 4857 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4858 | std::vector<string16> xpaths; |
| 4859 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4860 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4861 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 4862 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 4863 | frame && i != xpaths.end(); ++i) { |
| 4864 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4865 | } |
| 4866 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4867 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4868 | } |
| 4869 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4870 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 4871 | const string16& jscript, |
| 4872 | int id, |
| 4873 | bool notify_result) { |
[email protected] | f074608 | 2012-09-06 00:18:38 | [diff] [blame] | 4874 | UNSHIPPED_TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest"); |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4875 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4876 | } |
| 4877 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4878 | void RenderViewImpl::OnPostMessageEvent( |
| 4879 | const ViewMsg_PostMessage_Params& params) { |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4880 | // Find the target frame of this message. The source tags the message with |
| 4881 | // |target_frame_id|, so use it to locate the frame. |
| 4882 | WebFrame* frame = FindFrameByID(webview()->mainFrame(), |
| 4883 | params.target_frame_id); |
| 4884 | if (!frame) |
| 4885 | return; |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4886 | |
| 4887 | // Find the source frame if it exists. |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4888 | WebFrame* source_frame = NULL; |
| 4889 | if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 4890 | RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
| 4891 | if (source_view) |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 4892 | source_frame = source_view->GetFrameByMappedID(params.source_frame_id); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4893 | } |
| 4894 | |
| 4895 | // Create an event with the message. The final parameter to initMessageEvent |
| 4896 | // is the last event ID, which is not used with postMessage. |
| 4897 | WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
| 4898 | WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 4899 | msg_event.initMessageEvent("message", |
| 4900 | // |canBubble| and |cancellable| are always false |
| 4901 | false, false, |
| 4902 | WebSerializedScriptValue::fromString(params.data), |
| 4903 | params.source_origin, source_frame, ""); |
| 4904 | |
| 4905 | // We must pass in the target_origin to do the security check on this side, |
| 4906 | // since it may have changed since the original postMessage call was made. |
| 4907 | WebSecurityOrigin target_origin; |
| 4908 | if (!params.target_origin.empty()) { |
| 4909 | target_origin = |
| 4910 | WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 4911 | } |
| 4912 | frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 4913 | } |
| 4914 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4915 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 4916 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4917 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 4918 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 4919 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4920 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 4921 | frame->document().insertUserStyleSheet( |
| 4922 | WebString::fromUTF8(css), |
| 4923 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4924 | } |
| 4925 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4926 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4927 | enabled_bindings_ |= enabled_bindings_flags; |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 4928 | |
| 4929 | // Keep track of the total bindings accumulated in this process. |
| 4930 | RenderProcess::current()->AddBindings(enabled_bindings_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4931 | } |
| 4932 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4933 | void RenderViewImpl::OnSetWebUIProperty(const std::string& name, |
| 4934 | const std::string& value) { |
[email protected] | 808bda5 | 2012-03-09 22:43:32 | [diff] [blame] | 4935 | if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) |
| 4936 | GetWebUIBindings()->SetProperty(name, value); |
| 4937 | else |
| 4938 | NOTREACHED() << "WebUI bindings not enabled."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4939 | } |
| 4940 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4941 | void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data, |
| 4942 | const gfx::Point& client_point, |
| 4943 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4944 | WebDragOperationsMask ops, |
| 4945 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4946 | WebDragOperation operation = webview()->dragTargetDragEnter( |
| 4947 | drop_data.ToDragData(), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4948 | client_point, |
| 4949 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4950 | ops, |
| 4951 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4952 | |
| 4953 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 4954 | } |
| 4955 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4956 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 4957 | const gfx::Point& screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4958 | WebDragOperationsMask ops, |
| 4959 | int key_modifiers) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4960 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 4961 | client_point, |
| 4962 | screen_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4963 | ops, |
| 4964 | key_modifiers); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4965 | |
| 4966 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 4967 | } |
| 4968 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4969 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4970 | webview()->dragTargetDragLeave(); |
| 4971 | } |
| 4972 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4973 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
[email protected] | 1f2230b | 2012-05-17 23:43:42 | [diff] [blame] | 4974 | const gfx::Point& screen_point, |
| 4975 | int key_modifiers) { |
| 4976 | webview()->dragTargetDrop(client_point, screen_point, key_modifiers); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 4977 | |
| 4978 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4979 | } |
| 4980 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4981 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 4982 | const gfx::Point& screen_point, |
| 4983 | bool ended, |
| 4984 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4985 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4986 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 4987 | } else { |
| 4988 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4989 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4990 | } |
| 4991 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4992 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4993 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4994 | } |
| 4995 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4996 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 4997 | webkit_preferences_ = prefs; |
| 4998 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4999 | } |
| 5000 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5001 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5002 | alternate_error_page_url_ = url; |
| 5003 | } |
| 5004 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5005 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 5006 | const content::CustomContextMenuContext& custom_context, |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5007 | unsigned action) { |
| 5008 | if (custom_context.is_pepper_menu) |
| 5009 | pepper_delegate_.OnCustomContextMenuAction(custom_context, action); |
| 5010 | else |
| 5011 | webview()->performCustomContextMenuAction(action); |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 5012 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 5013 | ContextMenuAction(action)); |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 5014 | } |
| 5015 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5016 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 5017 | int id, |
| 5018 | const std::vector<FilePath>& paths) { |
| 5019 | if (!enumeration_completions_[id]) |
| 5020 | return; |
| 5021 | |
| 5022 | WebVector<WebString> ws_file_names(paths.size()); |
| 5023 | for (size_t i = 0; i < paths.size(); ++i) |
| 5024 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
| 5025 | |
| 5026 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 5027 | enumeration_completions_.erase(id); |
| 5028 | } |
| 5029 | |
[email protected] | fb11b6a4 | 2012-03-14 07:25:12 | [diff] [blame] | 5030 | void RenderViewImpl::OnFileChooserResponse( |
[email protected] | ddb034b | 2012-06-26 20:31:39 | [diff] [blame] | 5031 | const std::vector<ui::SelectedFileInfo>& files) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5032 | // This could happen if we navigated to a different page before the user |
| 5033 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5034 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 5035 | return; |
| 5036 | |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5037 | // Convert Chrome's SelectedFileInfo list to WebKit's. |
| 5038 | WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files( |
| 5039 | files.size()); |
| 5040 | for (size_t i = 0; i < files.size(); ++i) { |
| 5041 | WebFileChooserCompletion::SelectedFileInfo selected_file; |
[email protected] | 53f04c8 | 2012-07-26 02:31:09 | [diff] [blame] | 5042 | selected_file.path = webkit_glue::FilePathToWebString(files[i].local_path); |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5043 | selected_file.displayName = webkit_glue::FilePathStringToWebString( |
| 5044 | files[i].display_name); |
| 5045 | selected_files[i] = selected_file; |
| 5046 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 5047 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5048 | if (file_chooser_completions_.front()->completion) |
[email protected] | b518852 | 2012-03-15 00:18:04 | [diff] [blame] | 5049 | file_chooser_completions_.front()->completion->didChooseFile( |
| 5050 | selected_files); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5051 | file_chooser_completions_.pop_front(); |
| 5052 | |
| 5053 | // If there are more pending file chooser requests, schedule one now. |
| 5054 | if (!file_chooser_completions_.empty()) { |
| 5055 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 5056 | file_chooser_completions_.front()->params)); |
| 5057 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5058 | } |
| 5059 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5060 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 5061 | const gfx::Size& max_size) { |
| 5062 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5063 | if (!webview()) |
| 5064 | return; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 5065 | webview()->enableAutoResizeMode(min_size, max_size); |
| 5066 | } |
| 5067 | |
| 5068 | void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) { |
| 5069 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 5070 | if (!webview()) |
| 5071 | return; |
| 5072 | webview()->disableAutoResizeMode(); |
| 5073 | |
| 5074 | Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK); |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 5075 | } |
| 5076 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 5077 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5078 | if (send_preferred_size_changes_) |
| 5079 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 5080 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 5081 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5082 | // Start off with an initial preferred size notification (in case |
| 5083 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 5084 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 5085 | } |
| 5086 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5087 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5088 | const gfx::Size& disable_scrollbar_size_limit) { |
| 5089 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 5090 | } |
| 5091 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5092 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 5093 | const content::RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5094 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5095 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 5096 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 5097 | #if defined(TOOLKIT_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 5098 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 5099 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 5100 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5101 | ui::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 5102 | renderer_prefs.thumb_inactive_color, |
| 5103 | renderer_prefs.thumb_active_color, |
| 5104 | renderer_prefs.track_color); |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5105 | #endif |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5106 | |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 5107 | #if defined(USE_ASH) || defined(TOOLKIT_GTK) |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5108 | if (webview()) { |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 5109 | #if defined(TOOLKIT_GTK) |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 5110 | webview()->setScrollbarColors( |
| 5111 | renderer_prefs.thumb_inactive_color, |
| 5112 | renderer_prefs.thumb_active_color, |
| 5113 | renderer_prefs.track_color); |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5114 | #endif |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5115 | webview()->setSelectionColors( |
| 5116 | renderer_prefs.active_selection_bg_color, |
| 5117 | renderer_prefs.active_selection_fg_color, |
| 5118 | renderer_prefs.inactive_selection_bg_color, |
| 5119 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5120 | webview()->themeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 5121 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 5122 | #endif |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 5123 | |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 5124 | // If the zoom level for this page matches the old zoom default, and this |
| 5125 | // is not a plugin, update the zoom level to match the new default. |
| 5126 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
| 5127 | content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
| 5128 | webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level); |
| 5129 | zoomLevelChanged(); |
| 5130 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5131 | } |
| 5132 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5133 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 5134 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 5135 | if (webview()) |
| 5136 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 5137 | } |
| 5138 | |
[email protected] | 7782964 | 2012-05-15 14:47:17 | [diff] [blame] | 5139 | void RenderViewImpl::OnOrientationChangeEvent(int orientation) { |
| 5140 | webview()->mainFrame()->sendOrientationChangeEvent(orientation); |
| 5141 | } |
| 5142 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 5143 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 5144 | const WebPluginAction& action) { |
| 5145 | if (webview()) |
| 5146 | webview()->performPluginAction(action, location); |
| 5147 | } |
| 5148 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5149 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5150 | const GURL& page_url) { |
| 5151 | // Prepare list to storage all savable resource links. |
| 5152 | std::vector<GURL> resources_list; |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5153 | std::vector<GURL> referrer_urls_list; |
| 5154 | std::vector<WebKit::WebReferrerPolicy> referrer_policies_list; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5155 | std::vector<GURL> frames_list; |
| 5156 | webkit_glue::SavableResourcesResult result(&resources_list, |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5157 | &referrer_urls_list, |
| 5158 | &referrer_policies_list, |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5159 | &frames_list); |
| 5160 | |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5161 | // webkit/ doesn't know about content::Referrer. |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5162 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 5163 | webview(), |
| 5164 | page_url, |
| 5165 | &result, |
[email protected] | 1de7a17 | 2012-05-28 18:36:43 | [diff] [blame] | 5166 | const_cast<const char**>(content::GetSavableSchemes()))) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5167 | // If something is wrong when collecting all savable resource links, |
| 5168 | // send empty list to embedder(browser) to tell it failed. |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5169 | referrer_urls_list.clear(); |
| 5170 | referrer_policies_list.clear(); |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5171 | resources_list.clear(); |
| 5172 | frames_list.clear(); |
| 5173 | } |
| 5174 | |
[email protected] | c2d98651 | 2012-05-12 00:22:46 | [diff] [blame] | 5175 | std::vector<content::Referrer> referrers_list; |
| 5176 | CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size()); |
| 5177 | for (unsigned i = 0; i < referrer_urls_list.size(); ++i) { |
| 5178 | referrers_list.push_back( |
| 5179 | content::Referrer(referrer_urls_list[i], referrer_policies_list[i])); |
| 5180 | } |
| 5181 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5182 | // Send result of all savable resource links to embedder. |
| 5183 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 5184 | resources_list, |
| 5185 | referrers_list, |
| 5186 | frames_list)); |
| 5187 | } |
| 5188 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5189 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 5190 | const std::vector<GURL>& links, |
| 5191 | const std::vector<FilePath>& local_paths, |
| 5192 | const FilePath& local_directory_name) { |
| 5193 | |
| 5194 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 5195 | WebVector<WebURL> weburl_links(links); |
| 5196 | |
| 5197 | // Convert std::vector of std::strings to WebVector<WebString> |
| 5198 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 5199 | for (size_t i = 0; i < local_paths.size(); i++) |
| 5200 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 5201 | |
| 5202 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 5203 | webstring_paths, |
| 5204 | webkit_glue::FilePathToWebString( |
| 5205 | local_directory_name)); |
| 5206 | } |
| 5207 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5208 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5209 | base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5210 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5211 | base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
| 5212 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
| 5213 | before_unload_start_time, |
| 5214 | before_unload_end_time)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5215 | } |
| 5216 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5217 | void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame] | 5218 | // Ensure that no other in-progress navigation continues. |
| 5219 | OnStop(); |
| 5220 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5221 | // Only run unload if we're not swapped out yet, but send the ack either way. |
| 5222 | if (!is_swapped_out_) { |
| 5223 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 5224 | // different process. This involves running the unload handler and clearing |
| 5225 | // the page. Once WasSwappedOut is called, we also allow this process to |
| 5226 | // exit if there are no other active RenderViews in it. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5227 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5228 | // Send an UpdateState message before we get swapped out. |
| 5229 | SyncNavigationState(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5230 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5231 | // Synchronously run the unload handler before sending the ACK. |
| 5232 | webview()->dispatchUnloadEvent(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5233 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5234 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 5235 | SetSwappedOut(true); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5236 | |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5237 | // 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] | 5238 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 5239 | // 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] | 5240 | // beforeunload handler. For now, we just run it a second time silently. |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5241 | NavigateToSwappedOutURL(webview()->mainFrame()); |
[email protected] | 961541a9 | 2012-06-01 21:15:28 | [diff] [blame] | 5242 | |
| 5243 | // Let WebKit know that this view is hidden so it can drop resources and |
| 5244 | // stop compositing. |
| 5245 | webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5246 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5247 | |
| 5248 | // Just echo back the params in the ACK. |
| 5249 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 5250 | } |
| 5251 | |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5252 | void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5253 | // We use loadRequest instead of loadHTMLString because the former commits |
| 5254 | // synchronously. Otherwise a new navigation can interrupt the navigation |
| 5255 | // to content::kSwappedOutURL. If that happens to be to the page we had been |
| 5256 | // showing, then WebKit will never send a commit and we'll be left spinning. |
| 5257 | GURL swappedOutURL(content::kSwappedOutURL); |
| 5258 | WebURLRequest request(swappedOutURL); |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 5259 | frame->loadRequest(request); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5260 | } |
| 5261 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5262 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 5263 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5264 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 5265 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 5266 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 5267 | // calling the FrameLoader's CloseURL method directly. This should be |
| 5268 | // revisited to avoid having two ways to close a page. Having a single way |
| 5269 | // to close that can run onunload is also useful for fixing |
| 5270 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5271 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5272 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5273 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5274 | } |
| 5275 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5276 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 5277 | #if defined(USE_AURA) |
| 5278 | // Aura doesn't care if we switch themes. |
| 5279 | #elif defined(OS_WIN) |
[email protected] | f78452f | 2012-05-15 02:07:52 | [diff] [blame] | 5280 | ui::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 5281 | if (webview()) |
| 5282 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 5283 | #else // defined(OS_WIN) |
| 5284 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 5285 | NOTIMPLEMENTED(); |
| 5286 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 5287 | } |
| 5288 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5289 | void RenderViewImpl::OnDisassociateFromPopupCount() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 5290 | if (decrement_shared_popup_at_destruction_) |
| 5291 | shared_popup_counter_->data--; |
| 5292 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 5293 | decrement_shared_popup_at_destruction_ = false; |
| 5294 | } |
| 5295 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5296 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 5297 | const WebURLError& error, |
| 5298 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5299 | // We only show alternate error pages in the main frame. They are |
| 5300 | // intended to assist the user when navigating, so there is not much |
| 5301 | // value in showing them for failed subframes. Ideally, we would be |
| 5302 | // able to use the TYPED transition type for this, but that flag is |
| 5303 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5304 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5305 | return false; |
| 5306 | |
| 5307 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 5308 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5309 | int ec = error.reason; |
| 5310 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 5311 | ec != net::ERR_CONNECTION_FAILED && |
| 5312 | ec != net::ERR_CONNECTION_REFUSED && |
| 5313 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5314 | ec != net::ERR_CONNECTION_TIMED_OUT) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5315 | return false; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5316 | } |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5317 | |
| 5318 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5319 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5320 | if (!error_page_url.is_valid()) |
| 5321 | return false; |
| 5322 | |
| 5323 | // Load an empty page first so there is an immediate response to the error, |
| 5324 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 5325 | frame->loadHTMLString(std::string(), |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 5326 | GURL(content::kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5327 | error.unreachableURL, |
| 5328 | replace); |
| 5329 | |
| 5330 | // Now, create a fetcher for the error page and associate it with the data |
| 5331 | // source we just created via the LoadHTMLString call. That way if another |
| 5332 | // navigation occurs, the fetcher will get destroyed. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5333 | DocumentState* document_state = |
| 5334 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
| 5335 | document_state->set_alt_error_page_fetcher( |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5336 | new AltErrorPageResourceFetcher( |
| 5337 | error_page_url, frame, error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 5338 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 5339 | base::Unretained(this)))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5340 | return true; |
| 5341 | } |
| 5342 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5343 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
| 5344 | const WebURLError& original_error, |
| 5345 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5346 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5347 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 5348 | // will simply display a default error page. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 5349 | LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 5350 | } |
| 5351 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5352 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5353 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5354 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5355 | } |
| 5356 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5357 | void RenderViewImpl::OnResize(const gfx::Size& new_size, |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 5358 | const gfx::Rect& resizer_rect, |
| 5359 | bool is_fullscreen) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5360 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 5361 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5362 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 5363 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 5364 | ShouldDisplayScrollbars(new_size.width(), new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5365 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 5366 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 5367 | } |
| 5368 | |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 5369 | RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 5370 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 5371 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5372 | void RenderViewImpl::WillInitiatePaint() { |
| 5373 | // Notify the pepper plugins that we're about to paint. |
| 5374 | pepper_delegate_.ViewWillInitiatePaint(); |
| 5375 | } |
| 5376 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5377 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 5378 | // Notify the pepper plugins that we've painted, and are waiting to flush. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5379 | pepper_delegate_.ViewInitiatedPaint(); |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 5380 | if (GetGuestToEmbedderChannel()) |
| 5381 | GetGuestToEmbedderChannel()->IssueSwapBuffers(guest_graphics_resource()); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5382 | } |
| 5383 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5384 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5385 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 5386 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 5387 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 5388 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 5389 | pepper_delegate_.ViewFlushedPaint(); |
| 5390 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 5391 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 5392 | // See crbug.com/112921. |
| 5393 | if (!webview()) |
| 5394 | return; |
| 5395 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5396 | WebFrame* main_frame = webview()->mainFrame(); |
| 5397 | |
| 5398 | // If we have a provisional frame we are between the start and commit stages |
| 5399 | // of loading and we don't want to save stats. |
| 5400 | if (!main_frame->provisionalDataSource()) { |
| 5401 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5402 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5403 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5404 | // TODO(jar): The following code should all be inside a method, probably in |
| 5405 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5406 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5407 | if (document_state->first_paint_time().is_null()) { |
| 5408 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5409 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 5410 | if (document_state->first_paint_after_load_time().is_null() && |
| 5411 | !document_state->finish_load_time().is_null()) { |
| 5412 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 5413 | } |
| 5414 | } |
| 5415 | } |
| 5416 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5417 | void RenderViewImpl::OnViewContextSwapBuffersPosted() { |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 5418 | RenderWidget::OnSwapBuffersPosted(); |
| 5419 | } |
| 5420 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5421 | void RenderViewImpl::OnViewContextSwapBuffersComplete() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5422 | RenderWidget::OnSwapBuffersComplete(); |
| 5423 | } |
| 5424 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5425 | void RenderViewImpl::OnViewContextSwapBuffersAborted() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5426 | RenderWidget::OnSwapBuffersAborted(); |
| 5427 | } |
| 5428 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5429 | webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5430 | const gfx::Rect& paint_bounds, |
| 5431 | TransportDIB** dib, |
| 5432 | gfx::Rect* location, |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5433 | gfx::Rect* clip, |
| 5434 | float* scale_factor) { |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5435 | return pepper_delegate_.GetBitmapForOptimizedPluginPaint( |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 5436 | paint_bounds, dib, location, clip, scale_factor); |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 5437 | } |
| 5438 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5439 | gfx::Point RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 5440 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | bcaf227 | 2011-02-15 15:29:43 | [diff] [blame] | 5441 | return gfx::Point(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 5442 | } |
| 5443 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5444 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5445 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5446 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5447 | } |
| 5448 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5449 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5450 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5451 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 5452 | |
| 5453 | SetBackground(background); |
| 5454 | } |
| 5455 | |
[email protected] | 2a84f9d | 2012-06-05 21:50:43 | [diff] [blame] | 5456 | void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) { |
| 5457 | if (accessibility_mode_ == new_mode) |
| 5458 | return; |
| 5459 | accessibility_mode_ = new_mode; |
| 5460 | if (renderer_accessibility_) { |
| 5461 | delete renderer_accessibility_; |
| 5462 | renderer_accessibility_ = NULL; |
| 5463 | } |
| 5464 | if (accessibility_mode_ == AccessibilityModeComplete) |
| 5465 | renderer_accessibility_ = new RendererAccessibilityComplete(this); |
| 5466 | else if (accessibility_mode_ == AccessibilityModeEditableTextOnly) |
| 5467 | renderer_accessibility_ = new RendererAccessibilityFocusOnly(this); |
| 5468 | } |
| 5469 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5470 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5471 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 5472 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 5473 | |
| 5474 | #if defined(OS_MACOSX) |
| 5475 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5476 | for (plugin_it = plugin_delegates_.begin(); |
| 5477 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5478 | (*plugin_it)->SetWindowFocus(active); |
| 5479 | } |
| 5480 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 5481 | } |
| 5482 | |
[email protected] | 7a17bac0 | 2012-03-07 21:58:12 | [diff] [blame] | 5483 | void RenderViewImpl::OnSetNavigationStartTime( |
| 5484 | const base::TimeTicks& browser_navigation_start) { |
| 5485 | if (!webview()) |
| 5486 | return; |
| 5487 | |
| 5488 | // Only the initial navigation can be a cross-renderer navigation. If we've |
| 5489 | // already navigated away from that page, we can ignore this message. |
| 5490 | if (page_id_ != -1) |
| 5491 | return; |
| 5492 | |
| 5493 | // browser_navigation_start is likely before this process existed, so we can't |
| 5494 | // use InterProcessTimeTicksConverter. Instead, the best we can do is just |
| 5495 | // ensure we don't report a bogus value in the future. |
| 5496 | base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(), |
| 5497 | browser_navigation_start); |
| 5498 | webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime( |
| 5499 | (navigation_start - base::TimeTicks()).InSecondsF()); |
| 5500 | } |
| 5501 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5502 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5503 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5504 | // Inform plugins that their container has changed visibility. |
| 5505 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5506 | for (plugin_it = plugin_delegates_.begin(); |
| 5507 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5508 | (*plugin_it)->SetContainerVisibility(visible); |
| 5509 | } |
| 5510 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5511 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5512 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 5513 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5514 | // Inform plugins that their window's frame has changed. |
| 5515 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5516 | for (plugin_it = plugin_delegates_.begin(); |
| 5517 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5518 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 5519 | } |
| 5520 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5521 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5522 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 5523 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5524 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5525 | // applies to it or not, so inform all the delegates. |
| 5526 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5527 | for (plugin_it = plugin_delegates_.begin(); |
| 5528 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5529 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5530 | } |
| 5531 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5532 | #endif // OS_MACOSX |
| 5533 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5534 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5535 | const EditCommands& edit_commands) { |
| 5536 | edit_commands_ = edit_commands; |
| 5537 | } |
| 5538 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5539 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5540 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5541 | WebView* doomed = webview(); |
| 5542 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 5543 | g_view_map.Get().erase(doomed); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5544 | } |
| 5545 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5546 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5547 | edit_commands_.clear(); |
| 5548 | } |
| 5549 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5550 | bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 5551 | pepper_delegate_.WillHandleMouseEvent(); |
| 5552 | |
| 5553 | // If the mouse is locked, only the current owner of the mouse lock can |
| 5554 | // process mouse events. |
| 5555 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 5556 | } |
| 5557 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 5558 | void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5559 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5560 | } |
| 5561 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5562 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 5563 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 5564 | } |
| 5565 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5566 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5567 | RenderWidget::OnWasHidden(); |
| 5568 | |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 5569 | #if defined(OS_ANDROID) |
| 5570 | // Inform WebMediaPlayerManagerAndroid to release all media player resources. |
| 5571 | media_player_manager_->ReleaseMediaResources(); |
| 5572 | #endif |
| 5573 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5574 | if (webview()) { |
| 5575 | webview()->settings()->setMinimumTimerInterval( |
| 5576 | webkit_glue::kBackgroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5577 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5578 | } |
| 5579 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5580 | // Inform PPAPI plugins that their page is no longer visible. |
| 5581 | pepper_delegate_.PageVisibilityChanged(false); |
| 5582 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5583 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5584 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5585 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5586 | for (plugin_it = plugin_delegates_.begin(); |
| 5587 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5588 | (*plugin_it)->SetContainerVisibility(false); |
| 5589 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5590 | #endif // OS_MACOSX |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5591 | } |
| 5592 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 5593 | void RenderViewImpl::OnWasShown(bool needs_repainting) { |
| 5594 | RenderWidget::OnWasShown(needs_repainting); |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5595 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5596 | if (webview()) { |
| 5597 | webview()->settings()->setMinimumTimerInterval( |
| 5598 | webkit_glue::kForegroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 5599 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5600 | } |
| 5601 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5602 | // Inform PPAPI plugins that their page is visible. |
| 5603 | pepper_delegate_.PageVisibilityChanged(true); |
| 5604 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5605 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 5606 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5607 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5608 | for (plugin_it = plugin_delegates_.begin(); |
| 5609 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5610 | (*plugin_it)->SetContainerVisibility(true); |
| 5611 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5612 | #endif // OS_MACOSX |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 5613 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5614 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5615 | bool RenderViewImpl::SupportsAsynchronousSwapBuffers() { |
[email protected] | 9caf09bc | 2012-06-25 21:46:28 | [diff] [blame] | 5616 | // Contexts using the command buffer support asynchronous swapbuffers. |
[email protected] | f89e173a | 2012-08-24 01:12:26 | [diff] [blame] | 5617 | // See RenderViewImpl::createOutputSurface(). |
[email protected] | 9caf09bc | 2012-06-25 21:46:28 | [diff] [blame] | 5618 | if (WebWidgetHandlesCompositorScheduling() || |
| 5619 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) |
[email protected] | 555e75d | 2011-10-08 01:23:38 | [diff] [blame] | 5620 | return false; |
| 5621 | |
[email protected] | 9caf09bc | 2012-06-25 21:46:28 | [diff] [blame] | 5622 | return true; |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 5623 | } |
| 5624 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5625 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5626 | RenderWidget::OnSetFocus(enable); |
| 5627 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5628 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5629 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5630 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5631 | for (plugin_it = plugin_delegates_.begin(); |
| 5632 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5633 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5634 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5635 | // activation state to change just like a call to setIsActive. |
| 5636 | if (enable) |
| 5637 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5638 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5639 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5640 | } |
| 5641 | } |
[email protected] | a01da568 | 2012-06-30 00:37:31 | [diff] [blame] | 5642 | // Notify all Pepper plugins. |
| 5643 | pepper_delegate_.OnSetFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5644 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5645 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5646 | void RenderViewImpl::PpapiPluginFocusChanged() { |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 5647 | UpdateTextInputState(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5648 | UpdateSelectionBounds(); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5649 | } |
| 5650 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5651 | void RenderViewImpl::PpapiPluginTextInputTypeChanged() { |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 5652 | UpdateTextInputState(); |
[email protected] | 8fe8f74 | 2012-06-14 00:36:08 | [diff] [blame] | 5653 | if (renderer_accessibility_) |
| 5654 | renderer_accessibility_->FocusedNodeChanged(WebNode()); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5655 | } |
| 5656 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5657 | void RenderViewImpl::PpapiPluginCaretPositionChanged() { |
| 5658 | UpdateSelectionBounds(); |
| 5659 | } |
| 5660 | |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 5661 | bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) { |
| 5662 | if (!pepper_delegate_.IsPluginFocused()) |
| 5663 | return false; |
| 5664 | *rect = pepper_delegate_.GetCaretBounds(); |
| 5665 | return true; |
| 5666 | } |
| 5667 | |
[email protected] | 397c2396 | 2012-05-21 07:09:32 | [diff] [blame] | 5668 | void RenderViewImpl::SimulateImeSetComposition( |
| 5669 | const string16& text, |
| 5670 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 5671 | int selection_start, |
| 5672 | int selection_end) { |
| 5673 | OnImeSetComposition(text, underlines, selection_start, selection_end); |
| 5674 | } |
| 5675 | |
| 5676 | void RenderViewImpl::SimulateImeConfirmComposition( |
| 5677 | const string16& text, |
| 5678 | const ui::Range& replacement_range) { |
| 5679 | OnImeConfirmComposition(text, replacement_range); |
| 5680 | } |
| 5681 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5682 | void RenderViewImpl::PpapiPluginCancelComposition() { |
| 5683 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 5684 | const ui::Range range(ui::Range::InvalidRange()); |
| 5685 | const std::vector<gfx::Rect> empty_bounds; |
| 5686 | UpdateCompositionInfo(range, empty_bounds); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5687 | } |
| 5688 | |
[email protected] | 3c8c74c | 2012-03-15 07:34:52 | [diff] [blame] | 5689 | void RenderViewImpl::PpapiPluginSelectionChanged() { |
| 5690 | SyncSelectionIfRequired(); |
| 5691 | } |
| 5692 | |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 5693 | void RenderViewImpl::PpapiPluginCreated(content::RendererPpapiHost* host) { |
[email protected] | 236bf85 | 2012-07-27 22:49:36 | [diff] [blame] | 5694 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 5695 | DidCreatePepperPlugin(host)); |
| 5696 | } |
| 5697 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5698 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5699 | const string16& text, |
| 5700 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 5701 | int selection_start, |
| 5702 | int selection_end) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5703 | if (pepper_delegate_.IsPluginFocused()) { |
| 5704 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 5705 | pepper_delegate_.OnImeSetComposition(text, |
| 5706 | underlines, |
| 5707 | selection_start, |
| 5708 | selection_end); |
| 5709 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5710 | #if defined(OS_WIN) |
| 5711 | // When a plug-in has focus, we create platform-specific IME data used by |
| 5712 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 5713 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 5714 | // instance ID is the same one as the specified ID.) |
| 5715 | if (focused_plugin_id_ >= 0) { |
| 5716 | std::vector<int> clauses; |
| 5717 | std::vector<int> target; |
| 5718 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 5719 | clauses.push_back(underlines[i].startOffset); |
| 5720 | clauses.push_back(underlines[i].endOffset); |
| 5721 | if (underlines[i].thick) { |
| 5722 | target.clear(); |
| 5723 | target.push_back(underlines[i].startOffset); |
| 5724 | target.push_back(underlines[i].endOffset); |
| 5725 | } |
| 5726 | } |
| 5727 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5728 | for (it = plugin_delegates_.begin(); |
| 5729 | it != plugin_delegates_.end(); ++it) { |
| 5730 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 5731 | focused_plugin_id_); |
| 5732 | } |
| 5733 | return; |
| 5734 | } |
| 5735 | #endif |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5736 | RenderWidget::OnImeSetComposition(text, |
| 5737 | underlines, |
| 5738 | selection_start, |
| 5739 | selection_end); |
| 5740 | } |
| 5741 | } |
| 5742 | |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 5743 | void RenderViewImpl::OnImeConfirmComposition( |
| 5744 | const string16& text, const ui::Range& replacement_range) { |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5745 | if (pepper_delegate_.IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5746 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 5747 | pepper_delegate_.OnImeConfirmComposition(text); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5748 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5749 | #if defined(OS_WIN) |
| 5750 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 5751 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 5752 | // it to WebKit to prevent WebKit from controlling IMEs. |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 5753 | // TODO(thakis): Honor |replacement_range| for plugins? |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5754 | if (focused_plugin_id_ >= 0) { |
| 5755 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 5756 | for (it = plugin_delegates_.begin(); |
| 5757 | it != plugin_delegates_.end(); ++it) { |
| 5758 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 5759 | } |
| 5760 | return; |
| 5761 | } |
| 5762 | #endif |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5763 | if (replacement_range.IsValid() && webview()) { |
| 5764 | // Select the text in |replacement_range|, it will then be replaced by |
| 5765 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 5766 | if (WebFrame* frame = webview()->focusedFrame()) { |
[email protected] | 4bacb82 | 2011-11-02 15:10:16 | [diff] [blame] | 5767 | WebRange webrange = WebRange::fromDocumentRange( |
| 5768 | frame, replacement_range.start(), replacement_range.length()); |
| 5769 | if (!webrange.isNull()) |
[email protected] | 884f900 | 2012-08-21 19:33:58 | [diff] [blame] | 5770 | frame->selectRange(webrange); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 5771 | } |
| 5772 | } |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 5773 | RenderWidget::OnImeConfirmComposition(text, replacement_range); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5774 | } |
| 5775 | } |
| 5776 | |
[email protected] | dea5e768 | 2012-06-14 05:21:24 | [diff] [blame] | 5777 | void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) { |
| 5778 | RenderWidget::OnSetDeviceScaleFactor(device_scale_factor); |
| 5779 | if (webview()) |
| 5780 | webview()->setDeviceScaleFactor(device_scale_factor); |
| 5781 | } |
| 5782 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5783 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5784 | return pepper_delegate_.IsPluginFocused() ? |
| 5785 | pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType(); |
| 5786 | } |
| 5787 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 5788 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
| 5789 | if (pepper_delegate_.IsPluginFocused()) { |
| 5790 | // TODO(kinaba) http://crbug.com/101101 |
| 5791 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 5792 | // use the caret position as an empty range for now. It will be updated |
| 5793 | // after Pepper API equips features related to surrounding text retrieval. |
| 5794 | gfx::Rect caret = pepper_delegate_.GetCaretBounds(); |
| 5795 | *start = caret; |
| 5796 | *end = caret; |
| 5797 | return; |
| 5798 | } |
| 5799 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 5800 | } |
| 5801 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 5802 | void RenderViewImpl::GetCompositionCharacterBounds( |
| 5803 | std::vector<gfx::Rect>* bounds) { |
| 5804 | DCHECK(bounds); |
| 5805 | bounds->clear(); |
| 5806 | |
| 5807 | if (!webview()) |
| 5808 | return; |
| 5809 | size_t start_offset = 0; |
| 5810 | size_t character_count = 0; |
| 5811 | if (!webview()->compositionRange(&start_offset, &character_count)) |
| 5812 | return; |
| 5813 | if (character_count == 0) |
| 5814 | return; |
| 5815 | |
| 5816 | WebKit::WebFrame* frame = webview()->focusedFrame(); |
| 5817 | if (!frame) |
| 5818 | return; |
| 5819 | |
| 5820 | bounds->reserve(character_count); |
| 5821 | WebKit::WebRect webrect; |
| 5822 | for (size_t i = 0; i < character_count; ++i) { |
| 5823 | if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { |
| 5824 | DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| 5825 | bounds->clear(); |
| 5826 | return; |
| 5827 | } |
| 5828 | bounds->push_back(webrect); |
| 5829 | } |
| 5830 | } |
| 5831 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5832 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 5833 | return pepper_delegate_.IsPluginFocused() ? |
| 5834 | pepper_delegate_.CanComposeInline() : true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 5835 | } |
| 5836 | |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5837 | #if defined(OS_WIN) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5838 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 5839 | if (focused) |
| 5840 | focused_plugin_id_ = plugin_id; |
| 5841 | else |
| 5842 | focused_plugin_id_ = -1; |
| 5843 | } |
| 5844 | #endif |
| 5845 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5846 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5847 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5848 | Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id)); |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5849 | } |
| 5850 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5851 | void RenderViewImpl::StartPluginIme() { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 5852 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5853 | // This message can be sent during event-handling, and needs to be delivered |
| 5854 | // within that context. |
| 5855 | msg->set_unblock(true); |
| 5856 | Send(msg); |
| 5857 | } |
| 5858 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5859 | gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5860 | bool opaque, bool root) { |
[email protected] | b296829 | 2012-03-28 01:35:51 | [diff] [blame] | 5861 | gfx::PluginWindowHandle window = gfx::kNullPluginWindow; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5862 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5863 | routing_id(), opaque, root, &window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5864 | if (window) { |
| 5865 | fake_plugin_window_handles_.insert(window); |
| 5866 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5867 | return window; |
| 5868 | } |
| 5869 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5870 | void RenderViewImpl::DestroyFakePluginWindowHandle( |
| 5871 | gfx::PluginWindowHandle window) { |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5872 | if (window && fake_plugin_window_handles_.find(window) != |
| 5873 | fake_plugin_window_handles_.end()) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5874 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5875 | fake_plugin_window_handles_.erase(window); |
| 5876 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5877 | } |
| 5878 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5879 | void RenderViewImpl::AcceleratedSurfaceSetIOSurface( |
| 5880 | gfx::PluginWindowHandle window, |
| 5881 | int32 width, |
| 5882 | int32 height, |
| 5883 | uint64 io_surface_identifier) { |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5884 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5885 | routing_id(), window, width, height, io_surface_identifier)); |
| 5886 | } |
| 5887 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5888 | void RenderViewImpl::AcceleratedSurfaceSetTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5889 | gfx::PluginWindowHandle window, |
| 5890 | int32 width, |
| 5891 | int32 height, |
| 5892 | TransportDIB::Handle transport_dib) { |
| 5893 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5894 | routing_id(), window, width, height, transport_dib)); |
| 5895 | } |
| 5896 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5897 | TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5898 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5899 | TransportDIB::Handle dib_handle; |
| 5900 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 5901 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5902 | return dib_handle; |
| 5903 | // Return an invalid handle if Send() fails. |
| 5904 | return TransportDIB::DefaultHandleValue(); |
| 5905 | } |
| 5906 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5907 | void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB( |
| 5908 | TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5909 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 5910 | } |
| 5911 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5912 | void RenderViewImpl::AcceleratedSurfaceBuffersSwapped( |
[email protected] | 7de8fb7 | 2012-03-14 04:24:32 | [diff] [blame] | 5913 | gfx::PluginWindowHandle window, uint64 surface_handle) { |
[email protected] | f35d667 | 2010-10-28 21:39:14 | [diff] [blame] | 5914 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped( |
[email protected] | 7de8fb7 | 2012-03-14 04:24:32 | [diff] [blame] | 5915 | routing_id(), window, surface_handle)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5916 | } |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 5917 | #endif // defined(OS_MACOSX) |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5918 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5919 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 5920 | const content::FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5921 | WebFileChooserCompletion* completion) { |
| 5922 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 5923 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 5924 | // This sanity check prevents too many file choose requests from getting |
| 5925 | // queued which could DoS the user. Getting these is most likely a |
| 5926 | // programming error (there are many ways to DoS the user so it's not |
| 5927 | // considered a "real" security check), either in JS requesting many file |
| 5928 | // choosers to pop up, or in a plugin. |
| 5929 | // |
| 5930 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 5931 | // a file picker, which will address this issue in a better way. |
| 5932 | return false; |
| 5933 | } |
| 5934 | |
| 5935 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 5936 | new PendingFileChooser(params, completion))); |
| 5937 | if (file_chooser_completions_.size() == 1) { |
| 5938 | // Actually show the browse dialog when this is the first request. |
| 5939 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 5940 | } |
| 5941 | return true; |
| 5942 | } |
| 5943 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5944 | WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5945 | if (!geolocation_dispatcher_) |
| 5946 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 5947 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 5948 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5949 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5950 | WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 5951 | WebKit::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 5952 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 5953 | if (!input_tag_speech_dispatcher_) |
| 5954 | input_tag_speech_dispatcher_ = |
| 5955 | new InputTagSpeechDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 5956 | #endif |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 5957 | return input_tag_speech_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 5958 | } |
| 5959 | |
[email protected] | 64d0922 | 2012-05-25 10:10:34 | [diff] [blame] | 5960 | WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() { |
| 5961 | #if defined(ENABLE_INPUT_SPEECH) |
| 5962 | if (!speech_recognition_dispatcher_) |
| 5963 | speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this); |
| 5964 | #endif |
| 5965 | return speech_recognition_dispatcher_; |
| 5966 | } |
| 5967 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5968 | WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 5969 | if (!device_orientation_dispatcher_) |
| 5970 | device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this); |
| 5971 | return device_orientation_dispatcher_; |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 5972 | } |
| 5973 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5974 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 5975 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5976 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 5977 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 5978 | // different). |
| 5979 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 5980 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5981 | int minimum_percent = static_cast<int>( |
| 5982 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 5983 | int maximum_percent = static_cast<int>( |
| 5984 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5985 | |
| 5986 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 5987 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 5988 | } |
| 5989 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5990 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5991 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 5992 | float zoom_level = webview()->zoomLevel(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 5993 | |
| 5994 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged()); |
| 5995 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5996 | // Tell the browser which url got zoomed so it can update the menu and the |
| 5997 | // saved values if necessary |
| 5998 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 5999 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 6000 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6001 | } |
| 6002 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6003 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 6004 | const WebString& base_url, |
| 6005 | const WebString& url, |
| 6006 | const WebString& title) { |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6007 | bool user_gesture = (webview()->focusedFrame() && |
| 6008 | webview()->focusedFrame()->isProcessingUserGesture()); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6009 | GURL base(base_url); |
| 6010 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 6011 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 6012 | return; |
| 6013 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 6014 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 6015 | UTF16ToUTF8(scheme), |
| 6016 | absolute_url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 6017 | title, |
| 6018 | user_gesture)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 6019 | } |
| 6020 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6021 | WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 6022 | WebKit::WebPageVisibilityState current_state = is_hidden() ? |
| 6023 | WebKit::WebPageVisibilityStateHidden : |
| 6024 | WebKit::WebPageVisibilityStateVisible; |
| 6025 | WebKit::WebPageVisibilityState override_state = current_state; |
| 6026 | if (content::GetContentClient()->renderer()-> |
| 6027 | ShouldOverridePageVisibilityState(this, |
| 6028 | &override_state)) |
| 6029 | return override_state; |
| 6030 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 6031 | } |
| 6032 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6033 | WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 6034 | EnsureMediaStreamImpl(); |
| 6035 | return media_stream_impl_; |
| 6036 | } |
| 6037 | |
[email protected] | a0629af9 | 2012-08-08 00:39:37 | [diff] [blame] | 6038 | void RenderViewImpl::draggableRegionsChanged() { |
| 6039 | FOR_EACH_OBSERVER( |
| 6040 | RenderViewObserver, |
| 6041 | observers_, |
| 6042 | DraggableRegionsChanged(webview()->mainFrame())); |
| 6043 | } |
| 6044 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 6045 | #if defined(OS_ANDROID) |
| 6046 | WebContentDetectionResult RenderViewImpl::detectContentAround( |
| 6047 | const WebHitTestResult& touch_hit) { |
| 6048 | DCHECK(!touch_hit.isNull()); |
| 6049 | DCHECK(!touch_hit.node().isNull()); |
| 6050 | DCHECK(touch_hit.node().isTextNode()); |
| 6051 | |
| 6052 | // Process the position with all the registered content detectors until |
| 6053 | // a match is found. Priority is provided by their relative order. |
| 6054 | for (ContentDetectorList::const_iterator it = content_detectors_.begin(); |
| 6055 | it != content_detectors_.end(); ++it) { |
| 6056 | ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); |
| 6057 | if (content.valid) { |
| 6058 | return WebContentDetectionResult(content.content_boundaries, |
| 6059 | UTF8ToUTF16(content.text), content.intent_url); |
| 6060 | } |
| 6061 | } |
| 6062 | return WebContentDetectionResult(); |
| 6063 | } |
| 6064 | |
| 6065 | void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { |
| 6066 | // Introduce a short delay so that the user can notice the content. |
| 6067 | MessageLoop::current()->PostDelayedTask( |
| 6068 | FROM_HERE, |
| 6069 | base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(), |
| 6070 | intent, expected_content_intent_id_), |
| 6071 | base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); |
| 6072 | } |
| 6073 | |
| 6074 | void RenderViewImpl::cancelScheduledContentIntents() { |
| 6075 | ++expected_content_intent_id_; |
| 6076 | } |
| 6077 | |
| 6078 | void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, |
| 6079 | size_t request_id) { |
| 6080 | if (request_id != expected_content_intent_id_) |
| 6081 | return; |
| 6082 | |
| 6083 | // Remove the content highlighting if any. |
| 6084 | scheduleComposite(); |
| 6085 | |
| 6086 | if (!intent.is_empty()) |
| 6087 | Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); |
| 6088 | } |
| 6089 | #endif |
| 6090 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6091 | void RenderViewImpl::OnAsyncFileOpened( |
| 6092 | base::PlatformFileError error_code, |
| 6093 | IPC::PlatformFileForTransit file_for_transit, |
| 6094 | int message_id) { |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 6095 | pepper_delegate_.OnAsyncFileOpened( |
| 6096 | error_code, |
| 6097 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 6098 | message_id); |
| 6099 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6100 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6101 | void RenderViewImpl::OnPpapiBrokerChannelCreated( |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6102 | int request_id, |
[email protected] | d5430507 | 2011-06-22 20:58:43 | [diff] [blame] | 6103 | const IPC::ChannelHandle& handle) { |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6104 | pepper_delegate_.OnPpapiBrokerChannelCreated(request_id, |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 6105 | handle); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 6106 | } |
| 6107 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 6108 | void RenderViewImpl::OnPpapiBrokerPermissionResult( |
| 6109 | int request_id, |
| 6110 | bool result) { |
| 6111 | pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result); |
| 6112 | } |
| 6113 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6114 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6115 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 6116 | if (external_popup_menu_ == NULL) { |
| 6117 | // Crash reports from the field indicate that we can be notified with a |
| 6118 | // NULL external popup menu (we probably get notified twice). |
| 6119 | // If you hit this please file a bug against jcivelli and include the page |
| 6120 | // and steps to repro. |
| 6121 | NOTREACHED(); |
| 6122 | return; |
| 6123 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6124 | external_popup_menu_->DidSelectItem(selected_index); |
| 6125 | external_popup_menu_.reset(); |
| 6126 | } |
| 6127 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 6128 | |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 6129 | #if defined(OS_ANDROID) |
| 6130 | void RenderViewImpl::OnSelectPopupMenuItems( |
| 6131 | bool canceled, |
| 6132 | const std::vector<int>& selected_indices) { |
| 6133 | // It is possible to receive more than one of these calls if the user presses |
| 6134 | // a select faster than it takes for the show-select-popup IPC message to make |
| 6135 | // it to the browser UI thread. Ignore the extra-messages. |
| 6136 | // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
| 6137 | if (!external_popup_menu_.get()) |
| 6138 | return; |
| 6139 | |
| 6140 | external_popup_menu_->DidSelectItems(canceled, selected_indices); |
| 6141 | external_popup_menu_.reset(); |
| 6142 | } |
| 6143 | #endif |
| 6144 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6145 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 6146 | const content::CustomContextMenuContext& custom_context) { |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 6147 | if (custom_context.is_pepper_menu) |
| 6148 | pepper_delegate_.OnContextMenuClosed(custom_context); |
| 6149 | else |
| 6150 | context_menu_node_.reset(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 6151 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6152 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6153 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 6154 | if (!webview()) |
| 6155 | return; |
| 6156 | WebFrame* main_frame = webview()->mainFrame(); |
| 6157 | if (!main_frame) |
| 6158 | return; |
| 6159 | main_frame->enableViewSourceMode(true); |
| 6160 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 6161 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 6162 | bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
[email protected] | ab21f2c | 2011-11-19 00:50:08 | [diff] [blame] | 6163 | return !!RenderThreadImpl::current()->compositor_thread(); |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 6164 | } |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 6165 | |
[email protected] | 64d0e19 | 2011-12-09 14:44:20 | [diff] [blame] | 6166 | void RenderViewImpl::OnJavaBridgeInit() { |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6167 | DCHECK(!java_bridge_dispatcher_); |
[email protected] | 464750f | 2011-10-24 23:16:18 | [diff] [blame] | 6168 | #if defined(ENABLE_JAVA_BRIDGE) |
[email protected] | 7e9c5bb0 | 2012-05-14 13:58:31 | [diff] [blame] | 6169 | java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
[email protected] | 464750f | 2011-10-24 23:16:18 | [diff] [blame] | 6170 | #endif |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 6171 | } |
[email protected] | 0720b53 | 2012-08-28 19:23:37 | [diff] [blame] | 6172 | |
| 6173 | void RenderViewImpl::OnUpdatedFrameTree( |
| 6174 | int process_id, |
| 6175 | int route_id, |
| 6176 | const std::string& frame_tree) { |
| 6177 | base::DictionaryValue* frames = NULL; |
| 6178 | scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree)); |
| 6179 | if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY)) |
| 6180 | tree->GetAsDictionary(&frames); |
| 6181 | |
| 6182 | updating_frame_tree_ = true; |
| 6183 | active_frame_id_map_.clear(); |
| 6184 | |
| 6185 | target_process_id_ = process_id; |
| 6186 | target_routing_id_ = route_id; |
| 6187 | CreateFrameTree(webview()->mainFrame(), frames); |
| 6188 | |
| 6189 | updating_frame_tree_ = false; |
| 6190 | } |