[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] | 005bab0 | 2011-10-07 18:36:00 | [diff] [blame] | 16 | #include "base/json/json_value_serializer.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 17 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 18 | #include "base/lazy_instance.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 19 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 20 | #include "base/path_service.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 21 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | #include "base/string_piece.h" |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 23 | #include "base/string_split.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | #include "base/string_util.h" |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 25 | #include "base/sys_string_conversions.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 26 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 27 | #include "base/utf_string_conversions.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 28 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 29 | #include "content/common/clipboard_messages.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 30 | #include "content/common/database_messages.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 31 | #include "content/common/drag_messages.h" |
[email protected] | 7ef40ffe1 | 2011-03-08 05:05:28 | [diff] [blame] | 32 | #include "content/common/file_system/file_system_dispatcher.h" |
| 33 | #include "content/common/file_system/webfilesystem_callback_dispatcher.h" |
[email protected] | c26ad88 | 2012-02-07 06:41:20 | [diff] [blame] | 34 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 35 | #include "content/common/intents_messages.h" |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 36 | #include "content/common/java_bridge_messages.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 37 | #include "content/common/pepper_messages.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 38 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 39 | #include "content/common/quota_dispatcher.h" |
[email protected] | 940895b | 2011-08-20 00:50:05 | [diff] [blame] | 40 | #include "content/common/request_extra_data.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 41 | #include "content/common/view_messages.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 42 | #include "content/public/common/bindings_policy.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 43 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 44 | #include "content/public/common/content_switches.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 45 | #include "content/public/common/context_menu_params.h" |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 46 | #include "content/public/common/file_chooser_params.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 47 | #include "content/public/common/url_constants.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 48 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 49 | #include "content/public/renderer/document_state.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 50 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 51 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 52 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 53 | #include "content/renderer/device_orientation_dispatcher.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 54 | #include "content/renderer/devtools_agent.h" |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 55 | #include "content/renderer/dom_automation_controller.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 56 | #include "content/renderer/external_popup_menu.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 57 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 58 | #include "content/renderer/idle_user_detector.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 59 | #include "content/renderer/web_intents_host.h" |
[email protected] | 0716190 | 2011-11-11 09:57:42 | [diff] [blame] | 60 | #include "content/renderer/java/java_bridge_dispatcher.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 61 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 25803d15 | 2011-06-14 01:18:08 | [diff] [blame] | 62 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | ccc70d8e | 2011-03-16 20:40:37 | [diff] [blame] | 63 | #include "content/renderer/media/audio_renderer_impl.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 64 | #include "content/renderer/media/media_stream_dependency_factory.h" |
| 65 | #include "content/renderer/media/media_stream_dispatcher.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 66 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 6048d51 | 2012-01-28 03:14:48 | [diff] [blame] | 67 | #include "content/renderer/media/render_audiosourceprovider.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 68 | #include "content/renderer/media/render_media_log.h" |
[email protected] | 6048d51 | 2012-01-28 03:14:48 | [diff] [blame] | 69 | #include "content/renderer/media/renderer_gpu_video_decoder_factories.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 70 | #include "content/renderer/mhtml_generator.h" |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 71 | #include "content/renderer/mouse_lock_dispatcher.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 72 | #include "content/renderer/notification_provider.h" |
[email protected] | ccc70d8e | 2011-03-16 20:40:37 | [diff] [blame] | 73 | #include "content/renderer/p2p/socket_dispatcher.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 74 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 75 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 76 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 77 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 78 | #include "content/renderer/renderer_accessibility.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 79 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
| 80 | #include "content/renderer/renderer_webstoragenamespace_impl.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 81 | #include "content/renderer/speech_input_dispatcher.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 82 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 83 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 84 | #include "content/renderer/web_ui_bindings.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 85 | #include "content/renderer/webplugin_delegate_proxy.h" |
| 86 | #include "content/renderer/websharedworker_proxy.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 87 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 88 | #include "media/base/media_switches.h" |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 89 | #include "media/base/message_loop_factory_impl.h" |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 90 | #include "media/filters/gpu_video_decoder.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 91 | #include "net/base/escape.h" |
| 92 | #include "net/base/net_errors.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 93 | #include "net/http/http_util.h" |
[email protected] | 9d9f1bb | 2011-02-23 22:10:57 | [diff] [blame] | 94 | #include "ppapi/c/private/ppb_flash_net_connector.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 95 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 96 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 97 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 98 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 99 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 100 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 101 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" |
| 102 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" |
| 103 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 104 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 105 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 106 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 107 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 108 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h" |
[email protected] | 592e20b | 2012-01-20 05:53:44 | [diff] [blame] | 109 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 110 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h" |
[email protected] | 69f110d6 | 2011-03-17 19:01:14 | [diff] [blame] | 111 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 112 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 113 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 114 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 115 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 116 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 117 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h" |
| 118 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 119 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 120 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 121 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h" |
| 122 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 123 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 124 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 125 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 126 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 127 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 128 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 129 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
| 130 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" |
| 131 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h" |
| 132 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h" |
| 133 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 134 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h" |
| 135 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 136 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" |
| 137 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 138 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
[email protected] | e6e90dc | 2011-12-03 00:01:37 | [diff] [blame] | 139 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 140 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 141 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h" |
| 142 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" |
| 143 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h" |
| 144 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 145 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 146 | #include "ui/base/javascript_message_type.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 147 | #include "ui/gfx/native_widget_types.h" |
| 148 | #include "ui/gfx/point.h" |
| 149 | #include "ui/gfx/rect.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 150 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 151 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 152 | #include "webkit/forms/form_data.h" |
| 153 | #include "webkit/forms/form_field.h" |
| 154 | #include "webkit/forms/password_form_dom_manager.h" |
[email protected] | 25e18f8 | 2010-10-27 16:38:43 | [diff] [blame] | 155 | #include "webkit/glue/alt_error_page_resource_fetcher.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 156 | #include "webkit/glue/dom_operations.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 157 | #include "webkit/glue/glue_serialize.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | #include "webkit/glue/webdropdata.h" |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 159 | #include "webkit/glue/webkit_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | #include "webkit/glue/webkit_glue.h" |
[email protected] | b00ba70 | 2011-08-17 01:41:03 | [diff] [blame] | 161 | #include "webkit/glue/weburlloader_impl.h" |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 162 | #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
[email protected] | a9288f5 | 2011-11-17 05:18:16 | [diff] [blame] | 163 | #include "webkit/media/webmediaplayer_impl.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 164 | #include "webkit/plugins/npapi/plugin_list.h" |
| 165 | #include "webkit/plugins/npapi/webplugin_delegate.h" |
| 166 | #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
| 167 | #include "webkit/plugins/npapi/webplugin_impl.h" |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 168 | #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 169 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 170 | #if defined(OS_WIN) |
| 171 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 172 | // * theming |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 173 | #include "ui/gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 174 | #elif defined(USE_X11) |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 175 | #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 42e5c86 | 2011-04-07 22:13:51 | [diff] [blame] | 176 | #include "ui/gfx/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 177 | #elif defined(OS_MACOSX) |
| 178 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 179 | #endif |
| 180 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 181 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 182 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 183 | using WebKit::WebApplicationCacheHost; |
| 184 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 185 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 186 | using WebKit::WebColor; |
| 187 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 188 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 189 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 190 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 191 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 192 | using WebKit::WebDataSource; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 193 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 194 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 195 | using WebKit::WebDragOperation; |
| 196 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 197 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 198 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 199 | using WebKit::WebExternalPopupMenu; |
| 200 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 201 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 202 | using WebKit::WebFileSystem; |
| 203 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 204 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 205 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 206 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 207 | using WebKit::WebFrame; |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 208 | using WebKit::WebGraphicsContext3D; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 209 | using WebKit::WebHistoryItem; |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 210 | using WebKit::WebIconURL; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 211 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 212 | using WebKit::WebInputElement; |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 213 | using WebKit::WebIntentRequest; |
| 214 | using WebKit::WebIntentServiceInfo; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 215 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 216 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 217 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 218 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 219 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 220 | using WebKit::WebNode; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 221 | using WebKit::WebPageSerializer; |
| 222 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 223 | using WebKit::WebPlugin; |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 224 | using WebKit::WebPluginAction; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 225 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 226 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 227 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 228 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 229 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 230 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 231 | using WebKit::WebRect; |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 232 | using WebKit::WebReferrerPolicy; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 233 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 234 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 235 | using WebKit::WebSecurityOrigin; |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 236 | using WebKit::WebSecurityPolicy; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 237 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 238 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 239 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 240 | using WebKit::WebStorageNamespace; |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 241 | using WebKit::WebStorageQuotaCallbacks; |
| 242 | using WebKit::WebStorageQuotaError; |
| 243 | using WebKit::WebStorageQuotaType; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 244 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 245 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 246 | using WebKit::WebTextDirection; |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 247 | using WebKit::WebTouchEvent; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 248 | using WebKit::WebURL; |
| 249 | using WebKit::WebURLError; |
| 250 | using WebKit::WebURLRequest; |
| 251 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 252 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 253 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 254 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 255 | using WebKit::WebWindowFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 256 | using appcache::WebApplicationCacheHostImpl; |
| 257 | using base::Time; |
| 258 | using base::TimeDelta; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 259 | using content::DocumentState; |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 260 | using content::NavigationState; |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 261 | using content::RenderThread; |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 262 | using content::RenderViewObserver; |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 263 | using content::RenderViewVisitor; |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 264 | using content::Referrer; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 265 | using content::V8ValueConverter; |
[email protected] | 9c4bf23 | 2011-12-15 02:25:08 | [diff] [blame] | 266 | using webkit::forms::FormField; |
| 267 | using webkit::forms::PasswordForm; |
| 268 | using webkit::forms::PasswordFormDomManager; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 269 | using webkit_glue::AltErrorPageResourceFetcher; |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 270 | using webkit_glue::ResourceFetcher; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 271 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | //----------------------------------------------------------------------------- |
| 273 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 274 | typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 275 | static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 276 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 277 | // Time, in seconds, we delay before sending content state changes (such as form |
| 278 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 279 | // spamming the browser. |
| 280 | // To avoid having tab/session restore require sending a message to get the |
| 281 | // current content state during tab closing we use a shorter timeout for the |
| 282 | // foreground renderer. This means there is a small window of time from which |
| 283 | // content state is modified and not sent to session restore, but this is |
| 284 | // better than having to wake up all renderers during shutdown. |
| 285 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 286 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 287 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 288 | static const size_t kExtraCharsBeforeAndAfterSelection = 100; |
| 289 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 290 | // The maximum number of popups that can be spawned from one page. |
| 291 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 292 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 293 | static const float kScalingIncrement = 0.1f; |
| 294 | |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 295 | static const float kScalingIncrementForGesture = 0.01f; |
| 296 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 297 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 298 | WebVector<WebURL> urls; |
| 299 | ds->redirectChain(urls); |
| 300 | result->reserve(urls.size()); |
| 301 | for (size_t i = 0; i < urls.size(); ++i) |
| 302 | result->push_back(urls[i]); |
| 303 | } |
| 304 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 305 | // If |data_source| is non-null and has a DocumentState associated with it, |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 306 | // the AltErrorPageResourceFetcher is reset. |
| 307 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 308 | if (data_source) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 309 | DocumentState* document_state = DocumentState::FromDataSource(data_source); |
| 310 | if (document_state) |
| 311 | document_state->set_alt_error_page_fetcher(NULL); |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 315 | static bool IsReload(const ViewMsg_Navigate_Params& params) { |
| 316 | return |
| 317 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
| 318 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; |
| 319 | } |
| 320 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 321 | static WebReferrerPolicy getReferrerPolicyFromRequest( |
| 322 | const WebURLRequest& request) { |
| 323 | return request.extraData() ? |
| 324 | static_cast<RequestExtraData*>(request.extraData())->referrer_policy() : |
| 325 | WebKit::WebReferrerPolicyDefault; |
| 326 | } |
| 327 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 328 | NOINLINE static void CrashIntentionally() { |
| 329 | // NOTE(shess): Crash directly rather than using NOTREACHED() so |
| 330 | // that the signature is easier to triage in crash reports. |
| 331 | volatile int* zero = NULL; |
| 332 | *zero = 0; |
| 333 | } |
| 334 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 335 | static void MaybeHandleDebugURL(const GURL& url) { |
| 336 | if (!url.SchemeIs(chrome::kChromeUIScheme)) |
| 337 | return; |
| 338 | if (url == GURL(chrome::kChromeUICrashURL)) { |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 339 | CrashIntentionally(); |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 340 | } else if (url == GURL(chrome::kChromeUIKillURL)) { |
| 341 | base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
| 342 | } else if (url == GURL(chrome::kChromeUIHangURL)) { |
| 343 | for (;;) { |
| 344 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 345 | } |
| 346 | } else if (url == GURL(chrome::kChromeUIShorthangURL)) { |
| 347 | base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 348 | } |
| 349 | } |
| 350 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | /////////////////////////////////////////////////////////////////////////////// |
| 352 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 353 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 354 | PendingFileChooser(const content::FileChooserParams& p, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 355 | WebFileChooserCompletion* c) |
| 356 | : params(p), |
| 357 | completion(c) { |
| 358 | } |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 359 | content::FileChooserParams params; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 360 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 361 | }; |
| 362 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 363 | namespace { |
| 364 | |
| 365 | class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget { |
| 366 | public: |
| 367 | WebWidgetLockTarget (WebKit::WebWidget* webwidget) |
| 368 | : webwidget_(webwidget) {} |
| 369 | |
| 370 | virtual void OnLockMouseACK(bool succeeded) OVERRIDE { |
| 371 | if (succeeded) |
| 372 | webwidget_->didAcquirePointerLock(); |
| 373 | else |
| 374 | webwidget_->didNotAcquirePointerLock(); |
| 375 | } |
| 376 | |
| 377 | virtual void OnMouseLockLost() OVERRIDE { |
| 378 | webwidget_->didLosePointerLock(); |
| 379 | } |
| 380 | |
| 381 | virtual bool HandleMouseLockedInputEvent( |
| 382 | const WebKit::WebMouseEvent &event) OVERRIDE { |
| 383 | // The WebWidget handles mouse lock in WebKit's handleInputEvent(). |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | private: |
| 388 | WebKit::WebWidget* webwidget_; |
| 389 | }; |
| 390 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 391 | int64 ExtractPostId(const WebHistoryItem& item) { |
| 392 | if (item.isNull()) |
| 393 | return -1; |
| 394 | |
| 395 | if (item.httpBody().isNull()) |
| 396 | return -1; |
| 397 | |
| 398 | return item.httpBody().identifier(); |
| 399 | } |
| 400 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 401 | } // namespace |
| 402 | |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 403 | RenderViewImpl::RenderViewImpl( |
| 404 | gfx::NativeViewId parent_hwnd, |
| 405 | int32 opener_id, |
| 406 | const content::RendererPreferences& renderer_prefs, |
| 407 | const WebPreferences& webkit_prefs, |
| 408 | SharedRenderViewCounter* counter, |
| 409 | int32 routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 410 | int32 surface_id, |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 411 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 412 | const string16& frame_name, |
| 413 | int32 next_page_id) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 414 | : RenderWidget(WebKit::WebPopupTypeNone), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 415 | webkit_preferences_(webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 416 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 417 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 418 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 419 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 420 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 421 | opened_by_user_gesture_(true), |
| 422 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 423 | page_id_(-1), |
| 424 | last_page_id_sent_to_browser_(-1), |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 425 | next_page_id_(next_page_id), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 426 | history_list_offset_(-1), |
| 427 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 428 | target_url_status_(TARGET_NONE), |
[email protected] | bbef1d3 | 2011-10-25 14:36:55 | [diff] [blame] | 429 | selection_text_offset_(0), |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 430 | cached_is_main_frame_pinned_to_left_(false), |
| 431 | cached_is_main_frame_pinned_to_right_(false), |
| 432 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 433 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 434 | context_has_swapbuffers_complete_callback_(false), |
| 435 | queried_for_swapbuffers_complete_callback_(false), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 436 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 437 | geolocation_dispatcher_(NULL), |
| 438 | speech_input_dispatcher_(NULL), |
| 439 | device_orientation_dispatcher_(NULL), |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 440 | media_stream_dispatcher_(NULL), |
[email protected] | cae8c849 | 2011-03-03 11:12:18 | [diff] [blame] | 441 | p2p_socket_dispatcher_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 442 | devtools_agent_(NULL), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 443 | renderer_accessibility_(NULL), |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 444 | mouse_lock_dispatcher_(NULL), |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 445 | session_storage_namespace_id_(session_storage_namespace_id), |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 446 | handling_select_range_(false), |
| 447 | #if defined(OS_WIN) |
| 448 | focused_plugin_id_(-1), |
| 449 | #endif |
| 450 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 451 | routing_id_ = routing_id; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 452 | surface_id_ = surface_id; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 453 | if (opener_id != MSG_ROUTING_NONE) |
| 454 | opener_id_ = opener_id; |
| 455 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 456 | // Ensure we start with a valid next_page_id_ from the browser. |
| 457 | DCHECK_GE(next_page_id_, 0); |
| 458 | |
[email protected] | 21b3a6ae | 2011-11-30 00:45:29 | [diff] [blame] | 459 | #if defined(ENABLE_NOTIFICATIONS) |
| 460 | notification_provider_ = new NotificationProvider(this); |
| 461 | #else |
| 462 | notification_provider_ = NULL; |
| 463 | #endif |
| 464 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 465 | webwidget_ = WebView::create(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 466 | webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 467 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 468 | if (counter) { |
| 469 | shared_popup_counter_ = counter; |
| 470 | shared_popup_counter_->data++; |
| 471 | decrement_shared_popup_at_destruction_ = true; |
| 472 | } else { |
| 473 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 474 | decrement_shared_popup_at_destruction_ = false; |
| 475 | } |
| 476 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 477 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 478 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 479 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 480 | AddRef(); |
| 481 | |
| 482 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 483 | // completing initialization. Otherwise, we can finish it now. |
| 484 | if (opener_id == MSG_ROUTING_NONE) { |
| 485 | did_show_ = true; |
[email protected] | 2d7c855 | 2011-06-27 19:21:55 | [diff] [blame] | 486 | CompleteInit(parent_hwnd); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 487 | } |
| 488 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 489 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
| 490 | webkit_preferences_.Apply(webview()); |
| 491 | webview()->initializeMainFrame(this); |
[email protected] | 2024c92 | 2011-09-02 23:34:35 | [diff] [blame] | 492 | if (!frame_name.empty()) |
| 493 | webview()->mainFrame()->setName(frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 494 | webview()->settings()->setMinimumTimerInterval( |
| 495 | is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : |
| 496 | webkit_glue::kForegroundTabTimerInterval); |
| 497 | |
| 498 | OnSetRendererPrefs(renderer_prefs); |
| 499 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 500 | host_window_ = parent_hwnd; |
| 501 | |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 502 | #if defined(ENABLE_P2P_APIS) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 503 | if (!p2p_socket_dispatcher_) |
| 504 | p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 505 | #endif |
[email protected] | cae8c849 | 2011-03-03 11:12:18 | [diff] [blame] | 506 | |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 507 | #if defined(ENABLE_WEBRTC) |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 508 | if (!media_stream_dispatcher_) |
| 509 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 510 | #endif |
[email protected] | 735873d | 2012-01-25 23:31:02 | [diff] [blame] | 511 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 512 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 513 | #if defined(OS_MACOSX) |
| 514 | new TextInputClientObserver(this); |
| 515 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 516 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 517 | // The next group of objects all implement RenderViewObserver, so are deleted |
| 518 | // along with the RenderView automatically. |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 519 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 520 | renderer_accessibility_ = new RendererAccessibility(this); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 521 | mouse_lock_dispatcher_ = new MouseLockDispatcher(this); |
[email protected] | 0fc7dea7 | 2012-02-09 03:47:40 | [diff] [blame] | 522 | intents_host_ = new WebIntentsHost(this); |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 523 | |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 524 | new IdleUserDetector(this); |
| 525 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 526 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 527 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 528 | enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION; |
| 529 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 530 | content::GetContentClient()->renderer()->RenderViewCreated(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 531 | } |
| 532 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 533 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 534 | history_page_ids_.clear(); |
| 535 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 536 | if (decrement_shared_popup_at_destruction_) |
| 537 | shared_popup_counter_->data--; |
| 538 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 539 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 540 | while (!file_chooser_completions_.empty()) { |
| 541 | if (file_chooser_completions_.front()->completion) { |
| 542 | file_chooser_completions_.front()->completion->didChooseFile( |
| 543 | WebVector<WebString>()); |
| 544 | } |
| 545 | file_chooser_completions_.pop_front(); |
| 546 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 547 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 548 | #if defined(OS_MACOSX) |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 549 | // Destroy all fake plugin window handles on the browser side. |
| 550 | while (!fake_plugin_window_handles_.empty()) { |
| 551 | // Make sure no NULL plugin window handles were inserted into this list. |
| 552 | DCHECK(*fake_plugin_window_handles_.begin()); |
| 553 | // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
| 554 | DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
| 555 | } |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 556 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 557 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 558 | #ifndef NDEBUG |
| 559 | // Make sure we are no longer referenced by the ViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 560 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 561 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 562 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 563 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 564 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 565 | // MediaStreamImpl holds weak references to RenderViewObserver objects, |
| 566 | // ensure it's deleted before the observers. |
| 567 | media_stream_impl_ = NULL; |
| 568 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 569 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 570 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 574 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 575 | ViewMap* views = g_view_map.Pointer(); |
| 576 | ViewMap::iterator it = views->find(webview); |
| 577 | return it == views->end() ? NULL : it->second; |
| 578 | } |
| 579 | |
| 580 | /*static*/ |
| 581 | content::RenderView* |
| 582 | content::RenderView::FromWebView(WebKit::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 583 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /*static*/ |
| 587 | void content::RenderView::ForEach(content::RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 588 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 589 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 590 | if (!visitor->Visit(it->second)) |
| 591 | return; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 596 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 597 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 598 | int32 opener_id, |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 599 | const content::RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 600 | const WebPreferences& webkit_prefs, |
| 601 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 602 | int32 routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 603 | int32 surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 604 | int64 session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 605 | const string16& frame_name, |
| 606 | int32 next_page_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 607 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 608 | return new RenderViewImpl( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 609 | parent_hwnd, |
| 610 | opener_id, |
| 611 | renderer_prefs, |
| 612 | webkit_prefs, |
| 613 | counter, |
| 614 | routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 615 | surface_id, |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 616 | session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 617 | frame_name, |
| 618 | next_page_id); // adds reference |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 619 | } |
| 620 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 621 | WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler( |
| 622 | WebKit::WebPeerConnectionHandlerClient* client) { |
| 623 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 624 | if (!cmd_line->HasSwitch(switches::kEnableMediaStream)) |
| 625 | return NULL; |
| 626 | EnsureMediaStreamImpl(); |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 627 | if (!media_stream_impl_.get()) |
| 628 | return NULL; |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 629 | return media_stream_impl_->CreatePeerConnectionHandler(client); |
| 630 | } |
| 631 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 632 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 633 | observers_.AddObserver(observer); |
| 634 | } |
| 635 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 636 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 637 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 638 | observers_.RemoveObserver(observer); |
| 639 | } |
| 640 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 641 | WebKit::WebView* RenderViewImpl::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 642 | return static_cast<WebKit::WebView*>(webwidget()); |
| 643 | } |
| 644 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 645 | void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) { |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 646 | if (!enabled) { |
| 647 | load_progress_tracker_.reset(NULL); |
| 648 | return; |
| 649 | } |
| 650 | if (load_progress_tracker_ == NULL) |
| 651 | load_progress_tracker_.reset(new LoadProgressTracker(this)); |
| 652 | } |
| 653 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 654 | void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) { |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 655 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 656 | } |
| 657 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 658 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 659 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 660 | // If the renderer is visible, set initial visibility and focus state. |
| 661 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 662 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 663 | delegate->SetContainerVisibility(true); |
| 664 | if (webview() && webview()->isActive()) |
| 665 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 666 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 667 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 668 | // Plugins start assuming the content has focus (so that they work in |
| 669 | // environments where RenderView isn't hosting them), so we always have to |
| 670 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 671 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 672 | } |
| 673 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 674 | void RenderViewImpl::UnregisterPluginDelegate( |
| 675 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 676 | plugin_delegates_.erase(delegate); |
| 677 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 678 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 679 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 680 | const GURL& page_url, |
| 681 | const std::string& mime_type, |
| 682 | webkit::WebPluginInfo* plugin_info, |
| 683 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 684 | bool found = false; |
| 685 | Send(new ViewHostMsg_GetPluginInfo( |
| 686 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 687 | actual_mime_type)); |
| 688 | return found; |
| 689 | } |
| 690 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 691 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 692 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 693 | if (main_frame) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 694 | content::GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 695 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 696 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 697 | RenderViewObserver* observer; |
| 698 | while ((observer = it.GetNext()) != NULL) |
| 699 | if (observer->OnMessageReceived(message)) |
| 700 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 701 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 702 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 703 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 704 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 705 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 706 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 707 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 708 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 709 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 710 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 711 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 712 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 713 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 714 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 715 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 716 | IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 717 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
| 718 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 719 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 720 | IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 721 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 722 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 723 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 724 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 725 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 726 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 727 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 728 | IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 729 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 730 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 731 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 732 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 733 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 735 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 736 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 737 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 738 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 739 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 740 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 741 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 742 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 743 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
[email protected] | d098079 | 2011-02-13 19:41:40 | [diff] [blame] | 744 | IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 745 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 746 | IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect, |
| 747 | OnScrollFocusedEditableNodeIntoRect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 748 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 749 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 750 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 751 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 752 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 753 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 754 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 755 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 756 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 757 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 758 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 759 | OnDisassociateFromPopupCount) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 760 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 761 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 762 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 763 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 764 | OnEnablePreferredSizeChangedMode) |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 765 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 766 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 767 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 768 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 769 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 770 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 771 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 772 | #if defined(OS_MACOSX) |
| 773 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 774 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 775 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 776 | OnPluginImeCompositionCompleted) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 777 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 778 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 779 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 780 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 781 | OnCustomContextMenuAction) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 782 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 783 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, |
| 784 | OnPpapiBrokerChannelCreated) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 785 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 786 | OnGetAllSavableResourceLinksForCurrentPage) |
| 787 | IPC_MESSAGE_HANDLER( |
| 788 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 789 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 790 | #if defined(OS_MACOSX) |
| 791 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 792 | #endif |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 793 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 794 | // TODO(viettrungluu): Move to a separate message filter. |
| 795 | #if defined(ENABLE_FLAPPER_HACKS) |
| 796 | IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) |
| 797 | #endif |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 798 | #if defined(OS_MACOSX) |
| 799 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 800 | #endif |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 801 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 802 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 803 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 804 | IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 805 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 806 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 807 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 808 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 809 | |
| 810 | if (!msg_is_ok) { |
| 811 | // The message had a handler, but its deserialization failed. |
| 812 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 813 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 814 | } |
| 815 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 816 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 817 | } |
| 818 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 819 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 820 | MaybeHandleDebugURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 821 | if (!webview()) |
| 822 | return; |
| 823 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 824 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 825 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 826 | bool is_reload = IsReload(params); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 827 | |
| 828 | // If this is a stale back/forward (due to a recent navigation the browser |
| 829 | // didn't know about), ignore it. |
| 830 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 831 | return; |
| 832 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 833 | // Swap this renderer back in if necessary. |
| 834 | if (is_swapped_out_) |
| 835 | SetSwappedOut(false); |
| 836 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 837 | history_list_offset_ = params.current_history_list_offset; |
| 838 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 839 | if (history_list_length_ >= 0) |
| 840 | history_page_ids_.resize(history_list_length_, -1); |
| 841 | if (params.pending_history_list_offset >= 0 && |
| 842 | params.pending_history_list_offset < history_list_length_) |
| 843 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 844 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 845 | content::GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 846 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 847 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 848 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 849 | // We cannot reload if we do not have any history state. This happens, for |
| 850 | // example, when recovering from a crash. Our workaround here is a bit of |
| 851 | // a hack since it means that reload after a crashed tab does not cause an |
| 852 | // end-to-end cache validation. |
| 853 | is_reload = false; |
| 854 | } |
| 855 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 856 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 857 | *pending_navigation_params_.get() = params; |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 858 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 859 | // If we are reloading, then WebKit will use the history state of the current |
| 860 | // page, so we should just ignore any given history state. Otherwise, if we |
| 861 | // have history state, then we need to navigate to it, which corresponds to a |
| 862 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 863 | if (is_reload) { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 864 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 865 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 866 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 867 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 868 | // 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] | 869 | DCHECK_NE(params.page_id, -1); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 870 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 871 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 872 | } else { |
| 873 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 874 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 875 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 876 | // A session history navigation should have been accompanied by state. |
[email protected] | cbc0cb7 | 2011-12-06 18:58:23 | [diff] [blame] | 877 | CHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 878 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 879 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 880 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 881 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 882 | if (params.referrer.url.is_valid()) { |
| 883 | WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 884 | params.referrer.policy, |
| 885 | params.url, |
| 886 | WebString::fromUTF8(params.referrer.url.spec())); |
| 887 | if (!referrer.isEmpty()) |
| 888 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 889 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 890 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 891 | if (!params.extra_headers.empty()) { |
| 892 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 893 | params.extra_headers.end(), "\n"); |
| 894 | i.GetNext(); ) { |
| 895 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 896 | WebString::fromUTF8(i.values())); |
| 897 | } |
| 898 | } |
| 899 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 900 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 901 | } |
| 902 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 903 | // In case LoadRequest failed before DidCreateDataSource was called. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 904 | pending_navigation_params_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 905 | } |
| 906 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 907 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 908 | const ViewMsg_Navigate_Params& params, |
| 909 | bool is_reload) { |
| 910 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 911 | // or replaced from our history, before the browser knew about it. If so, |
| 912 | // a new navigation has committed in the mean time, and we can ignore this. |
| 913 | bool is_back_forward = !is_reload && !params.state.empty(); |
| 914 | |
| 915 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 916 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 917 | if (!is_back_forward || history_list_length_ <= 0) |
| 918 | return false; |
| 919 | |
| 920 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 921 | |
| 922 | // Check for whether the forward history has been cropped due to a recent |
| 923 | // navigation the browser didn't know about. |
| 924 | if (params.pending_history_list_offset >= history_list_length_) |
| 925 | return true; |
| 926 | |
| 927 | // Check for whether this entry has been replaced with a new one. |
| 928 | int expected_page_id = |
| 929 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 930 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 931 | if (params.page_id < expected_page_id) |
| 932 | return true; |
| 933 | |
| 934 | // Otherwise we've removed an earlier entry and should have shifted all |
| 935 | // entries left. For now, it's ok to lazily update the list. |
| 936 | // TODO(creis): Notify all live renderers when we remove entries from |
| 937 | // the front of the list, so that we don't hit this case. |
| 938 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 939 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 940 | |
| 941 | return false; |
| 942 | } |
| 943 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 944 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 945 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 946 | if (webview()) { |
| 947 | WebFrame* main_frame = webview()->mainFrame(); |
| 948 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 949 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 950 | // it may no longer be active. |
| 951 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 952 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 953 | main_frame->stopLoading(); |
| 954 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 955 | } |
| 956 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 957 | // Reload current focused frame. |
| 958 | // 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] | 959 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 960 | if (webview() && webview()->focusedFrame()) { |
| 961 | // We always obey the cache (ignore_cache=false) here. |
| 962 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 963 | // a cache-ignoring reload of the frame. |
| 964 | webview()->focusedFrame()->reload(false); |
| 965 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 966 | } |
| 967 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 968 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 969 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 970 | } |
| 971 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 972 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 973 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 974 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 975 | return; |
| 976 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 977 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 978 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 979 | } |
| 980 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 981 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 982 | // Check if there is a targeturl waiting to be sent. |
| 983 | if (target_url_status_ == TARGET_PENDING) { |
| 984 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 985 | pending_target_url_)); |
| 986 | } |
| 987 | |
| 988 | target_url_status_ = TARGET_NONE; |
| 989 | } |
| 990 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 991 | void RenderViewImpl::OnUndo() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 992 | if (!webview()) |
| 993 | return; |
| 994 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 995 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 996 | } |
| 997 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 998 | void RenderViewImpl::OnRedo() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 999 | if (!webview()) |
| 1000 | return; |
| 1001 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1002 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1003 | } |
| 1004 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1005 | void RenderViewImpl::OnCut() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1006 | if (!webview()) |
| 1007 | return; |
| 1008 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1009 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1010 | } |
| 1011 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1012 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1013 | if (!webview()) |
| 1014 | return; |
| 1015 | |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 1016 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
| 1017 | context_menu_node_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1020 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1021 | void RenderViewImpl::OnCopyToFindPboard() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1022 | if (!webview()) |
| 1023 | return; |
| 1024 | |
| 1025 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1026 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1027 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1028 | if (frame->hasSelection()) { |
| 1029 | string16 selection = frame->selectionAsText(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1030 | RenderThread::Get()->Send( |
[email protected] | 7e358974 | 2011-03-10 18:49:17 | [diff] [blame] | 1031 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1032 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1033 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1034 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1035 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1036 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1037 | if (!webview()) |
| 1038 | return; |
| 1039 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1040 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1041 | } |
| 1042 | |
[email protected] | 44bf700 | 2011-10-16 02:46:15 | [diff] [blame] | 1043 | void RenderViewImpl::OnPasteAndMatchStyle() { |
| 1044 | if (!webview()) |
| 1045 | return; |
| 1046 | |
| 1047 | webview()->focusedFrame()->executeCommand( |
| 1048 | WebString::fromUTF8("PasteAndMatchStyle")); |
| 1049 | } |
| 1050 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1051 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1052 | if (!webview()) |
| 1053 | return; |
| 1054 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1055 | WebFrame* frame = webview()->focusedFrame(); |
| 1056 | if (!frame->hasSelection()) |
| 1057 | frame->selectWordAroundCaret(); |
| 1058 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1059 | } |
| 1060 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1061 | void RenderViewImpl::OnDelete() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1062 | if (!webview()) |
| 1063 | return; |
| 1064 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1065 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1066 | } |
| 1067 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1068 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1069 | if (!webview()) |
| 1070 | return; |
| 1071 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1072 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1073 | WebString::fromUTF8("SelectAll")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1074 | } |
| 1075 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1076 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 1077 | const gfx::Point& end) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1078 | if (!webview()) |
| 1079 | return; |
| 1080 | |
| 1081 | handling_select_range_ = true; |
| 1082 | webview()->focusedFrame()->selectRange(start, end); |
| 1083 | handling_select_range_ = false; |
| 1084 | } |
| 1085 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1086 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 1087 | int32 minimum_page_id) { |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1088 | DCHECK(history_length >= 0); |
| 1089 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
| 1090 | DCHECK(minimum_page_id >= -1); |
| 1091 | |
| 1092 | // Generate the new list. |
| 1093 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 1094 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 1095 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 1096 | continue; |
| 1097 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 1098 | } |
| 1099 | new_history_page_ids.swap(history_page_ids_); |
| 1100 | |
| 1101 | // Update indexes. |
| 1102 | history_list_length_ = history_page_ids_.size(); |
| 1103 | history_list_offset_ = history_list_length_ - 1; |
| 1104 | } |
| 1105 | |
| 1106 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1107 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1108 | if (!webview()) |
| 1109 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1110 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1111 | } |
| 1112 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1113 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1114 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1115 | if (!webview()) |
| 1116 | return; |
| 1117 | if (in_live_resize) |
| 1118 | webview()->willStartLiveResize(); |
| 1119 | else |
| 1120 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1121 | } |
| 1122 | #endif |
| 1123 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1124 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1125 | const gfx::Rect& rect) { |
[email protected] | 13a1e4c3c | 2011-02-03 21:07:09 | [diff] [blame] | 1126 | WebKit::WebNode node = GetFocusedNode(); |
| 1127 | if (!node.isNull()) { |
| 1128 | if (IsEditableNode(node)) |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 1129 | webview()->scrollFocusedNodeIntoRect(rect); |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1133 | /////////////////////////////////////////////////////////////////////////////// |
| 1134 | |
| 1135 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1136 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1137 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1138 | DCHECK(ds); |
| 1139 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1140 | const WebURLRequest& request = ds->request(); |
| 1141 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1142 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1143 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1144 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 1145 | NavigationState* navigation_state = document_state->navigation_state(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1146 | |
| 1147 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1148 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1149 | params.is_post = false; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1150 | params.post_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1151 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1152 | params.frame_id = frame->identifier(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1153 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1154 | params.socket_address.set_port(response.remotePort()); |
[email protected] | b9a7c6d4 | 2011-02-25 02:13:03 | [diff] [blame] | 1155 | params.was_fetched_via_proxy = response.wasFetchedViaProxy(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1156 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1157 | if (!document_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1158 | // SSL state specified in the request takes precedence over the one in the |
| 1159 | // response. |
| 1160 | // So far this is only intended for error pages that are not expected to be |
| 1161 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1162 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1163 | params.security_info = document_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1164 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1165 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame^] | 1169 | params.url = GetLoadingUrl(frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1170 | |
[email protected] | 5f9b871 | 2011-11-23 08:55:57 | [diff] [blame] | 1171 | if (frame->document().baseURL() != params.url) |
| 1172 | params.base_url = frame->document().baseURL(); |
| 1173 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1174 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1175 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 1176 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1177 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1178 | params.searchable_form_url = document_state->searchable_form_url(); |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1179 | params.searchable_form_encoding = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1180 | document_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1181 | |
| 1182 | const PasswordForm* password_form_data = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 1183 | document_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1184 | if (password_form_data) |
| 1185 | params.password_form = *password_form_data; |
| 1186 | |
| 1187 | params.gesture = navigation_gesture_; |
| 1188 | navigation_gesture_ = NavigationGestureUnknown; |
| 1189 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1190 | // Make navigation state a part of the FrameNavigate message so that commited |
| 1191 | // entry had it at all times. |
| 1192 | const WebHistoryItem& item = frame->currentHistoryItem(); |
| 1193 | if (!item.isNull()) { |
| 1194 | params.content_state = webkit_glue::HistoryItemToString(item); |
| 1195 | } else { |
| 1196 | params.content_state = |
| 1197 | webkit_glue::CreateHistoryStateForURL(GURL(request.url())); |
| 1198 | } |
| 1199 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1200 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1201 | // Top-level navigation. |
| 1202 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1203 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1204 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1205 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1206 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1207 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1208 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1209 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1210 | } else { |
| 1211 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1212 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1213 | } |
| 1214 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1215 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1216 | // This zoom level was merely recorded transiently for this load. We can |
| 1217 | // erase it now. If at some point we reload this page, the browser will |
| 1218 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1219 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1220 | } |
| 1221 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1222 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1223 | // will also call us back which will cause us to send a message to |
| 1224 | // update TabContents. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1225 | webview()->zoomLimitsChanged( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1226 | WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor), |
| 1227 | WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1228 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1229 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1230 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1231 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1232 | params.transition = navigation_state->transition_type(); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1233 | if (!content::PageTransitionIsMainFrame(params.transition)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1234 | // If the main frame does a load, it should not be reported as a subframe |
| 1235 | // navigation. This can occur in the following case: |
| 1236 | // 1. You're on a site with frames. |
| 1237 | // 2. You do a subframe navigation. This is stored with transition type |
| 1238 | // MANUAL_SUBFRAME. |
| 1239 | // 3. You navigate to some non-frame site, say, google.com. |
| 1240 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1241 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1242 | // We don't want that, because any navigation that changes the toplevel |
| 1243 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1244 | // update the URL bar, etc). |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1245 | params.transition = content::PAGE_TRANSITION_LINK; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1246 | } |
| 1247 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1248 | // If we have a valid consumed client redirect source, |
| 1249 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1250 | // so we set the referrer and transition to match. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1251 | if (completed_client_redirect_src_.url.is_valid()) { |
| 1252 | DCHECK(completed_client_redirect_src_.url == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1253 | params.referrer = completed_client_redirect_src_; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1254 | params.transition = static_cast<content::PageTransition>( |
| 1255 | params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1256 | } else { |
| 1257 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1258 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1259 | params.referrer = Referrer(GURL( |
| 1260 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 1261 | getReferrerPolicyFromRequest(original_request)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1262 | } |
| 1263 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1264 | string16 method = request.httpMethod(); |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1265 | if (EqualsASCII(method, "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1266 | params.is_post = true; |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1267 | params.post_id = ExtractPostId(item); |
| 1268 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1269 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1270 | // Save some histogram data so we can compute the average memory used per |
| 1271 | // page load of the glyphs. |
| 1272 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1273 | webkit_glue::GetGlyphPageCount()); |
| 1274 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1275 | // This message needs to be sent before any of allowScripts(), |
| 1276 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1277 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1278 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1279 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1280 | } else { |
| 1281 | // Subframe navigation: the type depends on whether this navigation |
| 1282 | // generated a new session history entry. When they do generate a session |
| 1283 | // history entry, it means the user initiated the navigation and we should |
| 1284 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1285 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1286 | if (page_id_ > last_page_id_sent_to_browser_) |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1287 | params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1288 | else |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1289 | params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1290 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1291 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1292 | } |
| 1293 | |
| 1294 | last_page_id_sent_to_browser_ = |
| 1295 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1296 | |
| 1297 | // 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] | 1298 | // we don't want the transition type to persist. Just clear it. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1299 | navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1303 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 1304 | const string16& title, |
| 1305 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1306 | // Ignore all but top level navigations. |
| 1307 | if (frame->parent()) |
| 1308 | return; |
| 1309 | |
| 1310 | string16 shortened_title = title.substr(0, content::kMaxTitleChars); |
| 1311 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 1312 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1313 | } |
| 1314 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1315 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 1316 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1317 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1318 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1319 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1320 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1321 | last_encoding_name_ = encoding_name; |
| 1322 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1323 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 1327 | // Sends the last committed session history state to the browser so it will be |
| 1328 | // saved before we navigate to a new page. This must be called *before* the |
| 1329 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1330 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1331 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1332 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1333 | // there is no past session history to record. |
| 1334 | if (page_id_ == -1) |
| 1335 | return; |
| 1336 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1337 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1338 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1339 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1340 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1341 | |
| 1342 | Send(new ViewHostMsg_UpdateState( |
| 1343 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1344 | } |
| 1345 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1346 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 1347 | const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1348 | const Referrer& referrer, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1349 | WebNavigationPolicy policy) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1350 | Send(new ViewHostMsg_OpenURL( |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1351 | routing_id_, |
| 1352 | url, |
| 1353 | referrer, |
| 1354 | NavigationPolicyToDisposition(policy), |
| 1355 | frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1356 | } |
| 1357 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1358 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1359 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1360 | void RenderViewImpl::LoadNavigationErrorPage( |
| 1361 | WebFrame* frame, |
| 1362 | const WebURLRequest& failed_request, |
| 1363 | const WebURLError& error, |
| 1364 | const std::string& html, |
| 1365 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1366 | std::string alt_html; |
| 1367 | const std::string* error_html; |
| 1368 | |
| 1369 | if (!html.empty()) { |
| 1370 | error_html = &html; |
| 1371 | } else { |
| 1372 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 1373 | failed_request, error, &alt_html, NULL); |
| 1374 | error_html = &alt_html; |
| 1375 | } |
| 1376 | |
| 1377 | frame->loadHTMLString(*error_html, |
[email protected] | 144143c | 2010-10-28 08:17:36 | [diff] [blame] | 1378 | GURL(chrome::kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 1379 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1380 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1381 | } |
| 1382 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 1383 | bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1384 | const string16& message, |
| 1385 | const string16& default_value, |
| 1386 | const GURL& frame_url, |
| 1387 | string16* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1388 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1389 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1390 | if (!result) |
| 1391 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1392 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1393 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1394 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1395 | return success; |
| 1396 | } |
| 1397 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1398 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1399 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1400 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1401 | // it is particularly important that we do not call willEnterModalLoop as |
| 1402 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1403 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1404 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1405 | |
| 1406 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1407 | return Send(message); |
| 1408 | } |
| 1409 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1410 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1411 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1412 | WebView* RenderViewImpl::createView( |
[email protected] | 844acf37 | 2011-01-14 10:49:27 | [diff] [blame] | 1413 | WebFrame* creator, |
| 1414 | const WebURLRequest& request, |
| 1415 | const WebWindowFeatures& features, |
| 1416 | const WebString& frame_name) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1417 | // Check to make sure we aren't overloading on popups. |
| 1418 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1419 | return NULL; |
| 1420 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1421 | ViewHostMsg_CreateWindow_Params params; |
| 1422 | params.opener_id = routing_id_; |
| 1423 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1424 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1425 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1426 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1427 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1428 | params.opener_url = creator->document().url(); |
| 1429 | params.opener_security_origin = |
| 1430 | creator->document().securityOrigin().toString().utf8(); |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1431 | if (!request.isNull()) |
| 1432 | params.target_url = request.url(); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1433 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1434 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1435 | int32 surface_id = 0; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1436 | int64 cloned_session_storage_namespace_id; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1437 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1438 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1439 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1440 | new ViewHostMsg_CreateWindow(params, |
| 1441 | &routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1442 | &surface_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1443 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1444 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1445 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1446 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1447 | RenderViewImpl* view = RenderViewImpl::Create( |
| 1448 | 0, |
| 1449 | routing_id_, |
| 1450 | renderer_preferences_, |
| 1451 | webkit_preferences_, |
| 1452 | shared_popup_counter_, |
| 1453 | routing_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1454 | surface_id, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1455 | cloned_session_storage_namespace_id, |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1456 | frame_name, |
| 1457 | 1); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1458 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1459 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1460 | // Record whether the creator frame is trying to suppress the opener field. |
| 1461 | view->opener_suppressed_ = opener_suppressed; |
| 1462 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1463 | // Record the security origin of the creator. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1464 | GURL creator_url(creator->document().securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1465 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1466 | creator_url = GURL(); |
| 1467 | view->creator_url_ = creator_url; |
| 1468 | |
| 1469 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1470 | // the new render view (we don't need the browser to send the URL back down). |
| 1471 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1472 | |
| 1473 | return view->webview(); |
| 1474 | } |
| 1475 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1476 | WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1477 | RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1478 | return widget->webwidget(); |
| 1479 | } |
| 1480 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1481 | WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) { |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1482 | // TODO(jcivelli): Remove this deprecated method when its been removed from |
| 1483 | // the WebViewClient interface. It's been replaced by |
| 1484 | // createExternalPopupMenu. |
| 1485 | NOTREACHED(); |
| 1486 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1487 | } |
| 1488 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1489 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1490 | const WebPopupMenuInfo& popup_menu_info, |
| 1491 | WebExternalPopupMenuClient* popup_menu_client) { |
| 1492 | DCHECK(!external_popup_menu_.get()); |
| 1493 | external_popup_menu_.reset( |
| 1494 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 1495 | return external_popup_menu_.get(); |
| 1496 | } |
| 1497 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1498 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 1499 | webkit::ppapi::PluginInstance* plugin) { |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1500 | GURL active_url; |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 1501 | if (webview() && webview()->mainFrame()) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1502 | active_url = GURL(webview()->mainFrame()->document().url()); |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1503 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1504 | routing_id_, plugin, active_url); |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1505 | widget->show(WebKit::WebNavigationPolicyIgnore); |
[email protected] | 92abcb83 | 2011-01-06 20:39:56 | [diff] [blame] | 1506 | return widget; |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1507 | } |
| 1508 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1509 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace( |
| 1510 | unsigned quota) { |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1511 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1512 | return WebStorageNamespace::createSessionStorageNamespace(quota); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1513 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1514 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1515 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1516 | } |
| 1517 | |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1518 | WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D( |
[email protected] | 01e6903 | 2012-01-31 05:39:06 | [diff] [blame] | 1519 | const WebGraphicsContext3D::Attributes& attributes, |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1520 | bool direct) { |
| 1521 | if (!webview()) |
| 1522 | return NULL; |
| 1523 | // The WebGraphicsContext3DInProcessImpl code path is used for |
| 1524 | // layout tests (though not through this code) as well as for |
| 1525 | // debugging and bringing up new ports. |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1526 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) { |
[email protected] | 56200f01 | 2012-02-03 23:13:57 | [diff] [blame] | 1527 | return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( |
| 1528 | attributes, webview(), direct); |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1529 | } else { |
[email protected] | b3e83de | 2012-02-07 03:33:28 | [diff] [blame] | 1530 | int surface = direct ? surface_id() : 0; |
| 1531 | |
| 1532 | GURL url; |
| 1533 | if (webview()->mainFrame()) |
| 1534 | url = GURL(webview()->mainFrame()->document().url()); |
| 1535 | |
| 1536 | base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; |
| 1537 | if (direct) |
| 1538 | swap_client = AsWeakPtr(); |
| 1539 | |
| 1540 | scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 1541 | new WebGraphicsContext3DCommandBufferImpl( |
| 1542 | surface, url, swap_client)); |
| 1543 | |
| 1544 | if (!context->Initialize(attributes)) |
[email protected] | 56200f01 | 2012-02-03 23:13:57 | [diff] [blame] | 1545 | return NULL; |
| 1546 | return context.release(); |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1547 | } |
[email protected] | 7e8b4d1 | 2012-01-20 23:39:51 | [diff] [blame] | 1548 | } |
| 1549 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1550 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1551 | const WebConsoleMessage& message, const WebString& source_name, |
| 1552 | unsigned source_line) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1553 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 1554 | switch (message.level) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1555 | case WebConsoleMessage::LevelTip: |
| 1556 | log_severity = logging::LOG_VERBOSE; |
| 1557 | break; |
| 1558 | case WebConsoleMessage::LevelLog: |
| 1559 | log_severity = logging::LOG_INFO; |
| 1560 | break; |
| 1561 | case WebConsoleMessage::LevelWarning: |
| 1562 | log_severity = logging::LOG_WARNING; |
| 1563 | break; |
| 1564 | case WebConsoleMessage::LevelError: |
| 1565 | log_severity = logging::LOG_ERROR; |
| 1566 | break; |
| 1567 | default: |
| 1568 | NOTREACHED(); |
| 1569 | } |
| 1570 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1571 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1572 | static_cast<int32>(log_severity), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1573 | message.text, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1574 | static_cast<int32>(source_line), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1575 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1576 | } |
| 1577 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1578 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 1579 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1580 | } |
| 1581 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1582 | WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1583 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1584 | } |
| 1585 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1586 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1587 | const WebString& path, |
| 1588 | WebFileChooserCompletion* chooser_completion) { |
| 1589 | int id = enumeration_completion_id_++; |
| 1590 | enumeration_completions_[id] = chooser_completion; |
| 1591 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 1592 | routing_id_, |
| 1593 | id, |
| 1594 | webkit_glue::WebStringToFilePath(path))); |
| 1595 | } |
| 1596 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1597 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1598 | if (is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 1599 | DVLOG(1) << "didStartLoading called while loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1600 | return; |
| 1601 | } |
| 1602 | |
| 1603 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1604 | |
| 1605 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 1606 | |
| 1607 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1608 | } |
| 1609 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1610 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1611 | if (!is_loading_) { |
[email protected] | 511754da | 2012-01-24 20:48:14 | [diff] [blame] | 1612 | DVLOG(1) << "DidStopLoading called while not loading"; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | is_loading_ = false; |
| 1617 | |
| 1618 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1619 | // when done loading. This currently isn't an issue as the favicon is only |
| 1620 | // displayed when done loading. Ideally we would send notification when |
| 1621 | // finished parsing the head, but webkit doesn't support that yet. |
| 1622 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1623 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1624 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 1625 | if (load_progress_tracker_ != NULL) |
| 1626 | load_progress_tracker_->DidStopLoading(); |
| 1627 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 1628 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1629 | } |
| 1630 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1631 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 1632 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 1633 | if (load_progress_tracker_ != NULL) |
| 1634 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 1635 | } |
| 1636 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1637 | bool RenderViewImpl::isSmartInsertDeleteEnabled() { |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1638 | #if defined(OS_MACOSX) |
| 1639 | return true; |
| 1640 | #else |
| 1641 | return false; |
| 1642 | #endif |
| 1643 | } |
| 1644 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1645 | bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() { |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1646 | #if defined(OS_WIN) |
| 1647 | return true; |
| 1648 | #else |
| 1649 | return false; |
| 1650 | #endif |
| 1651 | } |
| 1652 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1653 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1654 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1655 | return; |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1656 | handling_select_range_ = false; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1657 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 1658 | SyncSelectionIfRequired(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1659 | } |
| 1660 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1661 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1662 | const std::string& name = UTF16ToUTF8(command_name); |
| 1663 | if (StartsWithASCII(name, "Move", true) || |
| 1664 | StartsWithASCII(name, "Insert", true) || |
| 1665 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1666 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1667 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1668 | } |
| 1669 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1670 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1671 | if (edit_commands_.empty()) |
| 1672 | return false; |
| 1673 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1674 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1675 | if (!frame) |
| 1676 | return false; |
| 1677 | |
| 1678 | EditCommands::iterator it = edit_commands_.begin(); |
| 1679 | EditCommands::iterator end = edit_commands_.end(); |
| 1680 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1681 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1682 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1683 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1684 | // key (but it's the exception). Once one edit command is not executed, it |
| 1685 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1686 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 1687 | WebString::fromUTF8(it->value))) |
| 1688 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1689 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1690 | } |
| 1691 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1692 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1693 | } |
| 1694 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1695 | bool RenderViewImpl::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 1696 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1697 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 1698 | // Do not open the file dialog in a hidden RenderView. |
| 1699 | if (is_hidden()) |
| 1700 | return false; |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1701 | content::FileChooserParams ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1702 | if (params.directory) |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1703 | ipc_params.mode = content::FileChooserParams::OpenFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1704 | else if (params.multiSelect) |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1705 | ipc_params.mode = content::FileChooserParams::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame] | 1706 | else if (params.saveAs) |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1707 | ipc_params.mode = content::FileChooserParams::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1708 | else |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1709 | ipc_params.mode = content::FileChooserParams::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1710 | ipc_params.title = params.title; |
| 1711 | ipc_params.default_file_name = |
| 1712 | webkit_glue::WebStringToFilePath(params.initialValue); |
[email protected] | 3314c2b1 | 2011-11-02 08:05:46 | [diff] [blame] | 1713 | ipc_params.accept_types.reserve(params.acceptMIMETypes.size()); |
| 1714 | for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i) |
| 1715 | ipc_params.accept_types.push_back(params.acceptMIMETypes[i]); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1716 | |
| 1717 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1718 | } |
| 1719 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 1720 | void RenderViewImpl::runModalAlertDialog(WebFrame* frame, |
| 1721 | const WebString& message) { |
| 1722 | RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1723 | message, |
| 1724 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1725 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1726 | NULL); |
| 1727 | } |
| 1728 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 1729 | bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame, |
| 1730 | const WebString& message) { |
| 1731 | return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1732 | message, |
| 1733 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1734 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1735 | NULL); |
| 1736 | } |
| 1737 | |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 1738 | bool RenderViewImpl::runModalPromptDialog(WebFrame* frame, |
| 1739 | const WebString& message, |
| 1740 | const WebString& default_value, |
| 1741 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1742 | string16 result; |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 1743 | bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1744 | message, |
| 1745 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1746 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1747 | &result); |
| 1748 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1749 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1750 | return ok; |
| 1751 | } |
| 1752 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1753 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1754 | WebFrame* frame, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1755 | // If we are swapping out, we have already run the beforeunload handler. |
| 1756 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 1757 | // at all, to avoid running it twice. |
| 1758 | if (is_swapped_out_) |
| 1759 | return true; |
| 1760 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1761 | bool success = false; |
| 1762 | // This is an ignored return value, but is included so we can accept the same |
| 1763 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1764 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1765 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1766 | routing_id_, frame->document().url(), message, |
| 1767 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1768 | return success; |
| 1769 | } |
| 1770 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1771 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1772 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 1773 | content::ContextMenuParams params(data); |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 1774 | |
| 1775 | // frame is NULL if invoked by BlockedPlugin. |
| 1776 | if (frame) |
| 1777 | params.frame_id = frame->identifier(); |
| 1778 | |
[email protected] | db803aae | 2011-03-05 02:00:42 | [diff] [blame] | 1779 | // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 1780 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 1781 | // in the context menu. |
| 1782 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 1783 | // data encoded images. We should have a way to save them. |
[email protected] | db803aae | 2011-03-05 02:00:42 | [diff] [blame] | 1784 | if (params.src_url.spec().size() > content::kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 1785 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 1786 | context_menu_node_ = data.node; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1787 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1788 | } |
| 1789 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1790 | void RenderViewImpl::enterFullscreen() { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1791 | // TODO(darin): Remove once WebKit roll is complete. |
| 1792 | enterFullScreen(); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1793 | } |
| 1794 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1795 | void RenderViewImpl::exitFullscreen() { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1796 | // TODO(darin): Remove once WebKit roll is complete. |
| 1797 | exitFullScreen(); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1798 | } |
| 1799 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1800 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1801 | } |
| 1802 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1803 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 1804 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1805 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1806 | if (latest_url == target_url_) |
| 1807 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1808 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1809 | // Tell the browser to display a destination link. |
| 1810 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1811 | target_url_status_ == TARGET_PENDING) { |
| 1812 | // If we have a request in-flight, save the URL to be sent when we |
| 1813 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1814 | // any existing pending sends. |
| 1815 | pending_target_url_ = latest_url; |
| 1816 | target_url_status_ = TARGET_PENDING; |
| 1817 | } else { |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1818 | // URLs larger than |content::kMaxURLChars| cannot be sent through IPC - |
| 1819 | // see |ParamTraits<GURL>|. |
| 1820 | if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars) |
| 1821 | latest_url = GURL(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1822 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 1823 | target_url_ = latest_url; |
| 1824 | target_url_status_ = TARGET_INFLIGHT; |
| 1825 | } |
| 1826 | } |
| 1827 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1828 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1829 | int delay; |
| 1830 | if (send_content_state_immediately_) |
| 1831 | delay = 0; |
| 1832 | else if (is_hidden()) |
| 1833 | delay = kDelaySecondsForContentStateSyncHidden; |
| 1834 | else |
| 1835 | delay = kDelaySecondsForContentStateSync; |
| 1836 | |
| 1837 | if (nav_state_sync_timer_.IsRunning()) { |
| 1838 | // The timer is already running. If the delay of the timer maches the amount |
| 1839 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1840 | // gets started with the right delay. |
| 1841 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 1842 | return; |
| 1843 | nav_state_sync_timer_.Stop(); |
| 1844 | } |
| 1845 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 1846 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1847 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1848 | } |
| 1849 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1850 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1851 | mouse_over_url_ = GURL(url); |
| 1852 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1853 | } |
| 1854 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1855 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1856 | focus_url_ = GURL(url); |
| 1857 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1858 | } |
| 1859 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1860 | void RenderViewImpl::startDragging(const WebDragData& data, |
| 1861 | WebDragOperationsMask mask, |
| 1862 | const WebImage& image, |
| 1863 | const WebPoint& imageOffset) { |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1864 | #if WEBKIT_USING_SKIA |
| 1865 | SkBitmap bitmap(image.getSkBitmap()); |
| 1866 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 1867 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1868 | #endif |
| 1869 | |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1870 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1871 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1872 | mask, |
| 1873 | bitmap, |
| 1874 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1875 | } |
| 1876 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1877 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1878 | return renderer_preferences_.can_accept_load_drops; |
| 1879 | } |
| 1880 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1881 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1882 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 1883 | } |
| 1884 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1885 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1886 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 1887 | } |
| 1888 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1889 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1890 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 1891 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 1892 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 1893 | } |
| 1894 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 1895 | void RenderViewImpl::didUpdateLayout() { |
| 1896 | // We don't always want to set up a timer, only if we've been put in that |
| 1897 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 1898 | // message. |
| 1899 | if (!send_preferred_size_changes_ || !webview()) |
| 1900 | return; |
| 1901 | |
| 1902 | if (check_preferred_size_timer_.IsRunning()) |
| 1903 | return; |
| 1904 | check_preferred_size_timer_.Start(FROM_HERE, |
| 1905 | TimeDelta::FromMilliseconds(0), this, |
| 1906 | &RenderViewImpl::CheckPreferredSize); |
| 1907 | } |
| 1908 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1909 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1910 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 1911 | } |
| 1912 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1913 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1914 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1915 | } |
| 1916 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1917 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1918 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1919 | } |
| 1920 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1921 | void RenderViewImpl::postAccessibilityNotification( |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 1922 | const WebAccessibilityObject& obj, |
| 1923 | WebAccessibilityNotification notification) { |
| 1924 | renderer_accessibility_->PostAccessibilityNotification(obj, notification); |
| 1925 | } |
| 1926 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1927 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 1928 | const WebString& value) { |
| 1929 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 1930 | key.utf8(), |
| 1931 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1932 | } |
| 1933 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1934 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 1935 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1936 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1937 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 1938 | // we won't have to test for user gesture anymore and we can |
| 1939 | // move that code back to render_widget.cc |
| 1940 | if (webview() && webview()->mainFrame() && |
| 1941 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 1942 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 1943 | } |
| 1944 | } |
| 1945 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1946 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1947 | // TODO(jcivelli): see TODO above in didFocus(). |
| 1948 | if (webview() && webview()->mainFrame() && |
| 1949 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 1950 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 1951 | } |
| 1952 | } |
| 1953 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1954 | // 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] | 1955 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1956 | // point to dispatch the ShowView message. |
| 1957 | // |
| 1958 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1959 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1960 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1961 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1962 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 1963 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 1964 | |
| 1965 | if (did_show_) |
| 1966 | return; |
| 1967 | did_show_ = true; |
| 1968 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 1969 | if (content::GetContentClient()->renderer()->AllowPopup(creator_url_)) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 1970 | opened_by_user_gesture_ = true; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 1971 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 1972 | // Force new windows to a popup if they were not opened with a user gesture. |
| 1973 | if (!opened_by_user_gesture_) { |
| 1974 | // We exempt background tabs for compat with older versions of Chrome. |
| 1975 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 1976 | // we probably don't need this check. |
| 1977 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 1978 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 1979 | } |
| 1980 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1981 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 1982 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 1983 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1984 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 1985 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1986 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1987 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1988 | } |
| 1989 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1990 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1991 | DCHECK(did_show_) << "should already have shown the view"; |
| 1992 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1993 | // We must keep WebKit's shared timer running in this case in order to allow |
| 1994 | // showModalDialog to function properly. |
| 1995 | // |
| 1996 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 1997 | // timers so that we do not need to manage the shared timer in such a heavy |
| 1998 | // handed manner. |
| 1999 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2000 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 2001 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2002 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2003 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2004 | } |
| 2005 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2006 | bool RenderViewImpl::enterFullScreen() { |
| 2007 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 2008 | return true; |
| 2009 | } |
| 2010 | |
| 2011 | void RenderViewImpl::exitFullScreen() { |
| 2012 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 2013 | } |
| 2014 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 2015 | bool RenderViewImpl::requestPointerLock() { |
| 2016 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2017 | } |
| 2018 | |
| 2019 | void RenderViewImpl::requestPointerUnlock() { |
| 2020 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2021 | } |
| 2022 | |
| 2023 | bool RenderViewImpl::isPointerLocked() { |
| 2024 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2025 | webwidget_mouse_lock_target_.get()); |
| 2026 | } |
| 2027 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2028 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2029 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2030 | WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 2031 | const WebPluginParams& params) { |
[email protected] | eaacd1f | 2011-09-23 02:32:55 | [diff] [blame] | 2032 | WebPlugin* plugin = NULL; |
| 2033 | if (content::GetContentClient()->renderer()->OverrideCreatePlugin( |
| 2034 | this, frame, params, &plugin)) { |
| 2035 | return plugin; |
| 2036 | } |
| 2037 | |
[email protected] | a813c8e | 2011-10-08 01:34:11 | [diff] [blame] | 2038 | webkit::WebPluginInfo info; |
| 2039 | std::string mime_type; |
| 2040 | bool found = GetPluginInfo(params.url, frame->top()->document().url(), |
| 2041 | params.mimeType.utf8(), &info, &mime_type); |
| 2042 | if (!found) |
| 2043 | return NULL; |
| 2044 | |
| 2045 | WebPluginParams params_to_use = params; |
| 2046 | params_to_use.mimeType = WebString::fromUTF8(mime_type); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2047 | return CreatePlugin(frame, info, params_to_use); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2048 | } |
| 2049 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2050 | WebSharedWorker* RenderViewImpl::createSharedWorker( |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2051 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2052 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2053 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2054 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2055 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2056 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2057 | ViewHostMsg_CreateWorker_Params params; |
| 2058 | params.url = url; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2059 | params.name = name; |
| 2060 | params.document_id = document_id; |
| 2061 | params.render_view_route_id = routing_id_; |
| 2062 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2063 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2064 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2065 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2066 | if (url_mismatch) { |
| 2067 | return NULL; |
| 2068 | } else { |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2069 | return new WebSharedWorkerProxy(RenderThreadImpl::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2070 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2071 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2072 | route_id, |
| 2073 | routing_id_); |
| 2074 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2075 | } |
| 2076 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2077 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2078 | WebFrame* frame, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2079 | FOR_EACH_OBSERVER( |
| 2080 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 2081 | |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2082 | media::MessageLoopFactory* message_loop_factory = |
| 2083 | new media::MessageLoopFactoryImpl(); |
| 2084 | media::FilterCollection* collection = new media::FilterCollection(); |
| 2085 | RenderMediaLog* render_media_log = new RenderMediaLog(); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2086 | |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2087 | RenderAudioSourceProvider* audio_source_provider = NULL; |
| 2088 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2089 | // Add in any custom filter factories first. |
| 2090 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 2091 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2092 | // audio_source_provider is a "provider" to WebKit, and a sink |
| 2093 | // from the perspective of the audio renderer. |
| 2094 | audio_source_provider = new RenderAudioSourceProvider(); |
| 2095 | |
| 2096 | // Add the chrome specific audio renderer, using audio_source_provider |
| 2097 | // as the sink. |
| 2098 | AudioRendererImpl* audio_renderer = |
| 2099 | new AudioRendererImpl(audio_source_provider); |
| 2100 | collection->AddAudioRenderer(audio_renderer); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2101 | } |
| 2102 | |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2103 | #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 2104 | // Currently only cros/arm has any HW video decode support in |
| 2105 | // GpuVideoDecodeAccelerator so we don't even try to use it on other |
| 2106 | // platforms. This is a startup-time optimization. When new VDA |
| 2107 | // implementations are added, relax the #if above. |
[email protected] | 4356730 | 2012-02-16 23:21:39 | [diff] [blame] | 2108 | WebGraphicsContext3DCommandBufferImpl* context3d = |
| 2109 | static_cast<WebGraphicsContext3DCommandBufferImpl*>( |
| 2110 | webview()->graphicsContext3D()); |
| 2111 | if (context3d && context3d->makeContextCurrent()) { |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2112 | GpuChannelHost* gpu_channel_host = |
| 2113 | RenderThreadImpl::current()->EstablishGpuChannelSync( |
| 2114 | content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
| 2115 | collection->AddVideoDecoder(new media::GpuVideoDecoder( |
[email protected] | 8d435928 | 2012-01-14 00:53:31 | [diff] [blame] | 2116 | message_loop_factory->GetMessageLoop("GpuVideoDecoder"), |
| 2117 | new RendererGpuVideoDecoderFactories( |
| 2118 | gpu_channel_host, context3d->context()->AsWeakPtr()))); |
[email protected] | e1d69d76 | 2011-12-13 05:12:18 | [diff] [blame] | 2119 | } |
| 2120 | #endif |
| 2121 | |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2122 | webkit_media::WebMediaPlayerImpl* media_player = |
| 2123 | content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer( |
| 2124 | this, frame, client, AsWeakPtr(), collection, audio_source_provider, |
| 2125 | message_loop_factory, media_stream_impl_.get(), render_media_log); |
[email protected] | c4dabe45 | 2012-02-08 23:58:12 | [diff] [blame] | 2126 | #if defined(OS_ANDROID) |
| 2127 | // TODO(qinmin): Implement for android. |
| 2128 | // http://crbug.com/113218 |
| 2129 | #else |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2130 | if (!media_player) { |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2131 | media_player = new webkit_media::WebMediaPlayerImpl( |
[email protected] | da952fd | 2012-01-13 03:49:25 | [diff] [blame] | 2132 | frame, client, AsWeakPtr(), collection, audio_source_provider, |
[email protected] | 9e2269d | 2012-01-07 00:06:21 | [diff] [blame] | 2133 | message_loop_factory, media_stream_impl_.get(), render_media_log); |
[email protected] | bb6fd40 | 2011-12-09 02:45:44 | [diff] [blame] | 2134 | } |
[email protected] | c4dabe45 | 2012-02-08 23:58:12 | [diff] [blame] | 2135 | #endif |
[email protected] | cec4eb8 | 2012-01-12 17:51:56 | [diff] [blame] | 2136 | return media_player; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2137 | } |
| 2138 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2139 | WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost( |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2140 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
[email protected] | cdeeeb2 | 2012-01-11 07:44:23 | [diff] [blame] | 2141 | if (!frame || !frame->view()) |
| 2142 | return NULL; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2143 | return new RendererWebApplicationCacheHostImpl( |
| 2144 | FromWebView(frame->view()), client, |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 2145 | RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy()); |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2146 | } |
| 2147 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2148 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 2149 | return &cookie_jar_; |
| 2150 | } |
| 2151 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2152 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2153 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2154 | } |
| 2155 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2156 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2157 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2158 | } |
| 2159 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2160 | void RenderViewImpl::loadURLExternally( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2161 | WebFrame* frame, const WebURLRequest& request, |
| 2162 | WebNavigationPolicy policy) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2163 | loadURLExternally(frame, request, policy, WebString()); |
| 2164 | } |
| 2165 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2166 | void RenderViewImpl::loadURLExternally( |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2167 | WebFrame* frame, const WebURLRequest& request, |
| 2168 | WebNavigationPolicy policy, |
| 2169 | const WebString& suggested_name) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2170 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2171 | if (policy == WebKit::WebNavigationPolicyDownload) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 2172 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer, |
| 2173 | suggested_name)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2174 | } else { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2175 | OpenURL(frame, request.url(), |
| 2176 | Referrer(referrer, getReferrerPolicyFromRequest(request)), policy); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2177 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2178 | } |
| 2179 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2180 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2181 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2182 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2183 | // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation. |
| 2184 | if (is_swapped_out_) { |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2185 | // It is possible for in-progress navigations to arrive here just after we |
| 2186 | // are swapped out, including iframes. We should cancel them. |
| 2187 | if (request.url() != GURL("about:swappedout")) |
| 2188 | return WebKit::WebNavigationPolicyIgnore; |
| 2189 | |
| 2190 | // Allow about:swappedout to complete. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2191 | return default_policy; |
| 2192 | } |
| 2193 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2194 | // Webkit is asking whether to navigate to a new URL. |
| 2195 | // This is fine normally, except if we're showing UI from one security |
| 2196 | // context and they're trying to navigate to a different context. |
| 2197 | const GURL& url = request.url(); |
| 2198 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2199 | // A content initiated navigation may have originated from a link-click, |
| 2200 | // script, drag-n-drop operation, etc. |
| 2201 | bool is_content_initiated = |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2202 | DocumentState::FromDataSource(frame->provisionalDataSource())-> |
| 2203 | navigation_state()->is_content_initiated(); |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2204 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 2205 | // Experimental: |
| 2206 | // If --enable-strict-site-isolation is enabled, send all top-level |
| 2207 | // navigations to the browser to let it swap processes when crossing site |
| 2208 | // boundaries. This is currently expected to break some script calls and |
| 2209 | // navigations, such as form submissions. |
| 2210 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2211 | if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) && |
| 2212 | !frame->parent() && (is_content_initiated || is_redirect)) { |
| 2213 | WebString origin_str = frame->document().securityOrigin().toString(); |
| 2214 | GURL frame_url(origin_str.utf8().data()); |
| 2215 | // TODO(cevans): revisit whether this origin check is still necessary once |
| 2216 | // crbug.com/101395 is fixed. |
| 2217 | if (frame_url.GetOrigin() != url.GetOrigin()) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2218 | Referrer referrer( |
| 2219 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 2220 | getReferrerPolicyFromRequest(request)); |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 2221 | OpenURL(frame, url, referrer, default_policy); |
| 2222 | return WebKit::WebNavigationPolicyIgnore; |
| 2223 | } |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 2224 | } |
| 2225 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2226 | // If the browser is interested, then give it a chance to look at top level |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 2227 | // navigations. |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 2228 | if (is_content_initiated) { |
| 2229 | bool browser_handles_top_level_requests = |
| 2230 | renderer_preferences_.browser_handles_top_level_requests && |
| 2231 | IsNonLocalTopLevelNavigation(url, frame, type); |
| 2232 | if (browser_handles_top_level_requests || |
| 2233 | renderer_preferences_.browser_handles_all_requests) { |
| 2234 | Referrer referrer( |
| 2235 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 2236 | getReferrerPolicyFromRequest(request)); |
| 2237 | // Reset these counters as the RenderView could be reused for the next |
| 2238 | // navigation. |
| 2239 | page_id_ = -1; |
| 2240 | last_page_id_sent_to_browser_ = -1; |
| 2241 | OpenURL(frame, url, referrer, default_policy); |
| 2242 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2243 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2244 | } |
| 2245 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2246 | // 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] | 2247 | // an extension or app origin, leaving a WebUI page, etc). We only care about |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 2248 | // top-level navigations within the current tab (as opposed to, for example, |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2249 | // opening a new window). But we sometimes navigate to about:blank to clear a |
| 2250 | // tab, and we want to still allow that. |
| 2251 | // |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 2252 | // Note: we do this only for GET requests because our mechanism for switching |
| 2253 | // processes only issues GET requests. In particular, POST requests don't |
| 2254 | // work, because this mechanism does not preserve form POST data. If it |
| 2255 | // becomes necessary to support process switching for POST requests, we will |
| 2256 | // need to send the request's httpBody data up to the browser process, and |
| 2257 | // issue a special POST navigation in WebKit (via |
| 2258 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 2259 | // for examples of how to send the httpBody data. |
[email protected] | 2762a1b | 2011-12-09 15:25:22 | [diff] [blame] | 2260 | if (!frame->parent() && is_content_initiated && |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2261 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2262 | request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) { |
| 2263 | bool send_referrer = false; |
| 2264 | bool should_fork = |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 2265 | (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2266 | frame->isViewSourceModeEnabled() || |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2267 | url.SchemeIs(chrome::kViewSourceScheme); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2268 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2269 | if (!should_fork) { |
| 2270 | // Give the embedder a chance. |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 2271 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2272 | should_fork = content::GetContentClient()->renderer()->ShouldFork( |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 2273 | frame, url, is_content_initiated, is_initial_navigation, |
| 2274 | &send_referrer); |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | if (should_fork) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2278 | Referrer referrer( |
| 2279 | GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), |
| 2280 | getReferrerPolicyFromRequest(request)); |
| 2281 | OpenURL( |
| 2282 | frame, url, send_referrer ? referrer : Referrer(), default_policy); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2283 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2284 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2285 | } |
| 2286 | |
[email protected] | 43763f98 | 2011-08-26 18:33:40 | [diff] [blame] | 2287 | // Use the frame's original request's URL rather than the document's URL for |
| 2288 | // this check. For a popup, the document's URL may become the opener window's |
| 2289 | // URL if the opener has called document.write. See http://crbug.com/93517. |
| 2290 | GURL old_url(frame->dataSource()->request().url()); |
| 2291 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2292 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2293 | // its own process. This is done by sites like Gmail that try to open links |
| 2294 | // in new windows without script connections back to the original page. We |
| 2295 | // treat such cases as browser navigations (in which we will create a new |
| 2296 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2297 | // |
| 2298 | // We use the following heuristic to decide whether to fork a new page in its |
| 2299 | // own process: |
| 2300 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2301 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2302 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2303 | // |
| 2304 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2305 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2306 | bool is_fork = |
| 2307 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2308 | old_url == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2309 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2310 | historyBackListCount() < 1 && |
| 2311 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2312 | // The parent page must have set the child's window.opener to null before |
| 2313 | // redirecting to the desired URL. |
| 2314 | frame->opener() == NULL && |
| 2315 | // Must be a top-level frame. |
| 2316 | frame->parent() == NULL && |
| 2317 | // Must not have issued the request from this page. |
| 2318 | is_content_initiated && |
| 2319 | // Must be targeted at the current tab. |
| 2320 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2321 | // Must be a JavaScript navigation, which appears as "other". |
| 2322 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2323 | |
| 2324 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2325 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2326 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2327 | // should let the browser handle it. |
| 2328 | bool is_noreferrer_and_blank_target = |
| 2329 | // Frame should be top level and not yet navigated. |
| 2330 | frame->parent() == NULL && |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2331 | frame->document().url().isEmpty() && |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2332 | historyBackListCount() < 1 && |
| 2333 | historyForwardListCount() < 1 && |
| 2334 | // Links with rel=noreferrer will have no Referer field, and their |
| 2335 | // resulting frame will have its window.opener suppressed. |
| 2336 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2337 | // typos on the unusual spelling of Referer. |
| 2338 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2339 | opener_suppressed_ && |
| 2340 | frame->opener() == NULL && |
| 2341 | // Links with target=_blank will have no name. |
| 2342 | frame->name().isNull() && |
| 2343 | // Another frame (with a non-empty creator) should have initiated the |
| 2344 | // request, targeted at this frame. |
| 2345 | !creator_url_.is_empty() && |
| 2346 | is_content_initiated && |
| 2347 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2348 | type == WebKit::WebNavigationTypeOther; |
| 2349 | |
| 2350 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2351 | // Open the URL via the browser, not via WebKit. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2352 | OpenURL(frame, url, Referrer(), default_policy); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2353 | return WebKit::WebNavigationPolicyIgnore; |
| 2354 | } |
| 2355 | |
| 2356 | return default_policy; |
| 2357 | } |
| 2358 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2359 | bool RenderViewImpl::canHandleRequest( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2360 | WebFrame* frame, const WebURLRequest& request) { |
| 2361 | // We allow WebKit to think that everything can be handled even though |
| 2362 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2363 | return true; |
| 2364 | } |
| 2365 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2366 | WebURLError RenderViewImpl::cannotHandleRequestError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2367 | WebFrame* frame, const WebURLRequest& request) { |
| 2368 | NOTREACHED(); // Since we said we can handle all requests. |
| 2369 | return WebURLError(); |
| 2370 | } |
| 2371 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2372 | WebURLError RenderViewImpl::cancelledError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2373 | WebFrame* frame, const WebURLRequest& request) { |
| 2374 | WebURLError error; |
| 2375 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2376 | error.reason = net::ERR_ABORTED; |
| 2377 | error.unreachableURL = request.url(); |
| 2378 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2379 | } |
| 2380 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2381 | void RenderViewImpl::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2382 | WebFrame*, const WebURLError&) { |
| 2383 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2384 | } |
| 2385 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2386 | void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame, |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2387 | const WebKit::WebFormElement& form) { |
| 2388 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2389 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2390 | // This method gets called before any of those handlers run, so save away |
| 2391 | // a copy of the password in case it gets lost. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2392 | DocumentState* document_state = |
| 2393 | DocumentState::FromDataSource(frame->dataSource()); |
| 2394 | document_state->set_password_form_data( |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2395 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2396 | } |
| 2397 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2398 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 2399 | const WebFormElement& form) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2400 | DocumentState* document_state = |
| 2401 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
| 2402 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2403 | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2404 | if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK) |
| 2405 | navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2406 | |
| 2407 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2408 | WebSearchableFormData web_searchable_form_data(form); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2409 | document_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2410 | document_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2411 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2412 | PasswordForm* password_form_data = |
| 2413 | PasswordFormDomManager::CreatePasswordForm(form); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2414 | document_state->set_password_form_data(password_form_data); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2415 | |
[email protected] | 098c95cb | 2011-04-28 16:49:01 | [diff] [blame] | 2416 | // In order to save the password that the user actually typed and not one |
| 2417 | // that may have gotten transformed by the site prior to submit, recover it |
| 2418 | // from the form contents already stored by |willSendSubmitEvent| into the |
| 2419 | // dataSource's NavigationState (as opposed to the provisionalDataSource's, |
| 2420 | // which is what we're storing into now.) |
| 2421 | if (password_form_data) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2422 | DocumentState* old_document_state = |
| 2423 | DocumentState::FromDataSource(frame->dataSource()); |
| 2424 | if (old_document_state) { |
| 2425 | PasswordForm* old_form_data = old_document_state->password_form_data(); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2426 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2427 | password_form_data->password_value = old_form_data->password_value; |
| 2428 | } |
| 2429 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2430 | |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 2431 | FOR_EACH_OBSERVER( |
| 2432 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2433 | } |
| 2434 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2435 | void RenderViewImpl::willPerformClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2436 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2437 | double fire_time) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2438 | FOR_EACH_OBSERVER( |
| 2439 | RenderViewObserver, observers_, |
| 2440 | WillPerformClientRedirect(frame, from, to, interval, fire_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2441 | } |
| 2442 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2443 | void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2444 | FOR_EACH_OBSERVER( |
| 2445 | RenderViewObserver, observers_, DidCancelClientRedirect(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2446 | } |
| 2447 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2448 | void RenderViewImpl::didCompleteClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2449 | WebFrame* frame, const WebURL& from) { |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2450 | if (!frame->parent()) { |
| 2451 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2452 | // If there's no provisional data source, it's a reference fragment |
| 2453 | // navigation. |
| 2454 | completed_client_redirect_src_ = Referrer( |
| 2455 | from, ds ? getReferrerPolicyFromRequest(ds->request()) : |
| 2456 | frame->referrerPolicy()); |
| 2457 | } |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2458 | FOR_EACH_OBSERVER( |
| 2459 | RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2460 | } |
| 2461 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2462 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2463 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2464 | if (!document_state) { |
| 2465 | document_state = new DocumentState; |
| 2466 | ds->setExtraData(document_state); |
| 2467 | } |
| 2468 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2469 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2470 | // non-null NavigationState. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2471 | bool content_initiated = !pending_navigation_params_.get(); |
| 2472 | if (content_initiated) |
| 2473 | document_state->set_navigation_state( |
| 2474 | NavigationState::CreateContentInitiated()); |
| 2475 | else |
| 2476 | PopulateStateFromPendingNavigationParams(document_state); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2477 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2478 | // DocumentState::referred_by_prefetcher_ is true if we are |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2479 | // navigating from a page that used prefetching using a link on that |
| 2480 | // page. We are early enough in the request process here that we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2481 | // can still see the DocumentState of the previous page and set |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2482 | // this value appropriately. |
| 2483 | // TODO(gavinp): catch the important case of navigation in a new |
| 2484 | // renderer process. |
| 2485 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2486 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2487 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2488 | const GURL referrer( |
| 2489 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2490 | if (!referrer.is_empty() && |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2491 | DocumentState::FromDataSource( |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2492 | old_frame->dataSource())->was_prefetcher()) { |
| 2493 | for (;old_frame;old_frame = old_frame->traverseNext(false)) { |
| 2494 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 2495 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2496 | document_state->set_was_referred_by_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2497 | break; |
| 2498 | } |
| 2499 | } |
| 2500 | } |
| 2501 | } |
| 2502 | } |
| 2503 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2504 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2505 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2506 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2507 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2508 | document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2509 | break; |
| 2510 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2511 | document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2512 | break; |
| 2513 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2514 | document_state->set_load_type( |
| 2515 | DocumentState::LINK_LOAD_CACHE_STALE_OK); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2516 | break; |
| 2517 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2518 | document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2519 | break; |
| 2520 | } |
| 2521 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2522 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 2523 | FOR_EACH_OBSERVER( |
| 2524 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2525 | } |
| 2526 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2527 | void RenderViewImpl::PopulateStateFromPendingNavigationParams( |
| 2528 | DocumentState* document_state) { |
| 2529 | const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get(); |
| 2530 | |
| 2531 | if (document_state->request_time().is_null()) |
| 2532 | document_state->set_request_time(params.request_time); |
| 2533 | |
| 2534 | // A navigation resulting from loading a javascript URL should not be treated |
| 2535 | // as a browser initiated event. Instead, we want it to look as if the page |
| 2536 | // initiated any load resulting from JS execution. |
| 2537 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 2538 | NavigationState* navigation_state = NavigationState::CreateBrowserInitiated( |
| 2539 | params.page_id, |
| 2540 | params.pending_history_list_offset, |
| 2541 | params.transition); |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2542 | navigation_state->set_transferred_request_child_id( |
| 2543 | params.transferred_request_child_id); |
| 2544 | navigation_state->set_transferred_request_request_id( |
| 2545 | params.transferred_request_request_id); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2546 | if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
| 2547 | // We're doing a load of a page that was restored from the last session. |
| 2548 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 2549 | // which can result in stale data for pages that are set to expire. We |
| 2550 | // explicitly override that by setting the policy here so that as |
| 2551 | // necessary we load from the network. |
| 2552 | document_state->set_cache_policy_override( |
| 2553 | WebURLRequest::UseProtocolCachePolicy); |
| 2554 | } |
| 2555 | document_state->set_navigation_state(navigation_state); |
| 2556 | } else { |
| 2557 | document_state->set_navigation_state( |
| 2558 | NavigationState::CreateContentInitiated()); |
| 2559 | } |
| 2560 | |
| 2561 | if (IsReload(params)) |
| 2562 | document_state->set_load_type(DocumentState::RELOAD); |
| 2563 | else if (!params.state.empty()) |
| 2564 | document_state->set_load_type(DocumentState::HISTORY_LOAD); |
| 2565 | else |
| 2566 | document_state->set_load_type(DocumentState::NORMAL_LOAD); |
| 2567 | |
| 2568 | pending_navigation_params_.reset(); |
| 2569 | } |
| 2570 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2571 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2572 | WebDataSource* ds = frame->provisionalDataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2573 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2574 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2575 | // Update the request time if WebKit has better knowledge of it. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2576 | if (document_state->request_time().is_null()) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2577 | double event_time = ds->triggeringEventTime(); |
| 2578 | if (event_time != 0.0) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2579 | document_state->set_request_time(Time::FromDoubleT(event_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2580 | } |
| 2581 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2582 | // Start time is only set after request time. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2583 | document_state->set_start_load_time(Time::Now()); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2584 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2585 | bool is_top_most = !frame->parent(); |
| 2586 | if (is_top_most) { |
| 2587 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 2588 | NavigationGestureUser : NavigationGestureAuto; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2589 | |
| 2590 | // Make sure redirect tracking state is clear for the new load. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2591 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2592 | } else if (frame->parent()->isLoading()) { |
| 2593 | // 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] | 2594 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2595 | document_state->navigation_state()->set_transition_type( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2596 | content::PAGE_TRANSITION_AUTO_SUBFRAME); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2597 | } |
| 2598 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2599 | FOR_EACH_OBSERVER( |
| 2600 | RenderViewObserver, observers_, DidStartProvisionalLoad(frame)); |
| 2601 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2602 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 2603 | routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(), |
[email protected] | eacb080b | 2011-05-22 19:40:26 | [diff] [blame] | 2604 | ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2605 | } |
| 2606 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2607 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 2608 | WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2609 | if (frame->parent()) |
| 2610 | return; |
| 2611 | // Received a redirect on the main frame. |
| 2612 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 2613 | if (!data_source) { |
| 2614 | // Should only be invoked when we have a data source. |
| 2615 | NOTREACHED(); |
| 2616 | return; |
| 2617 | } |
| 2618 | std::vector<GURL> redirects; |
| 2619 | GetRedirectChain(data_source, &redirects); |
| 2620 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2621 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 2622 | GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2623 | } |
| 2624 | } |
| 2625 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2626 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 2627 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2628 | // Notify the browser that we failed a provisional load with an error. |
| 2629 | // |
| 2630 | // Note: It is important this notification occur before DidStopLoading so the |
| 2631 | // SSL manager can react to the provisional load failure before being |
| 2632 | // notified the load stopped. |
| 2633 | // |
| 2634 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2635 | DCHECK(ds); |
| 2636 | |
| 2637 | const WebURLRequest& failed_request = ds->request(); |
| 2638 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2639 | FOR_EACH_OBSERVER( |
| 2640 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 2641 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2642 | bool show_repost_interstitial = |
| 2643 | (error.reason == net::ERR_CACHE_MISS && |
| 2644 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2645 | |
| 2646 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 2647 | params.frame_id = frame->identifier(); |
| 2648 | params.is_main_frame = !frame->parent(); |
| 2649 | params.error_code = error.reason; |
| 2650 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 2651 | failed_request, |
| 2652 | error, |
| 2653 | NULL, |
| 2654 | ¶ms.error_description); |
| 2655 | params.url = error.unreachableURL; |
| 2656 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2657 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2658 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2659 | |
| 2660 | // Don't display an error page if this is simply a cancelled load. Aside |
| 2661 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 2662 | if (error.reason == net::ERR_ABORTED) |
| 2663 | return; |
[email protected] | b553edd5 | 2012-01-10 12:15:23 | [diff] [blame] | 2664 | // Don't display an error message if the request was handled by an |
| 2665 | // external protocol handler. |
| 2666 | if (error.reason == net::ERR_UNKNOWN_URL_SCHEME) |
| 2667 | return; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2668 | |
| 2669 | // Make sure we never show errors in view source mode. |
| 2670 | frame->enableViewSourceMode(false); |
| 2671 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2672 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2673 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2674 | |
| 2675 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 2676 | // 'replace' load. This is necessary to avoid messing up session history. |
| 2677 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 2678 | // as session history is concerned. |
| 2679 | // |
| 2680 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 2681 | // the page id. |
| 2682 | // |
| 2683 | bool replace = |
| 2684 | navigation_state->pending_page_id() != -1 || |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2685 | navigation_state->transition_type() == |
| 2686 | content::PAGE_TRANSITION_AUTO_SUBFRAME; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2687 | |
| 2688 | // If we failed on a browser initiated request, then make sure that our error |
| 2689 | // page load is regarded as the same browser initiated request. |
| 2690 | if (!navigation_state->is_content_initiated()) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2691 | pending_navigation_params_.reset(new ViewMsg_Navigate_Params); |
| 2692 | pending_navigation_params_->page_id = |
| 2693 | navigation_state->pending_page_id(); |
| 2694 | pending_navigation_params_->pending_history_list_offset = |
| 2695 | navigation_state->pending_history_list_offset(); |
| 2696 | pending_navigation_params_->transition = |
| 2697 | navigation_state->transition_type(); |
| 2698 | pending_navigation_params_->request_time = |
| 2699 | document_state->request_time(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | // Provide the user with a more helpful error page? |
| 2703 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 2704 | return; |
| 2705 | |
| 2706 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 2707 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2708 | } |
| 2709 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2710 | void RenderViewImpl::didReceiveDocumentData( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2711 | WebFrame* frame, const char* data, size_t data_len, |
| 2712 | bool& prevent_default) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2713 | DocumentState* document_state = |
| 2714 | DocumentState::FromDataSource(frame->dataSource()); |
| 2715 | document_state->set_use_error_page(false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2716 | } |
| 2717 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2718 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 2719 | bool is_new_navigation) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2720 | DocumentState* document_state = |
| 2721 | DocumentState::FromDataSource(frame->dataSource()); |
| 2722 | NavigationState* navigation_state = document_state->navigation_state(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2723 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2724 | if (document_state->commit_load_time().is_null()) |
| 2725 | document_state->set_commit_load_time(Time::Now()); |
| 2726 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2727 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 2728 | // When we perform a new navigation, we need to update the last committed |
| 2729 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2730 | UpdateSessionHistory(frame); |
| 2731 | |
| 2732 | // We bump our Page ID to correspond with the new session history entry. |
| 2733 | page_id_ = next_page_id_++; |
| 2734 | |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame^] | 2735 | // Don't update history_page_ids_ (etc) for about:swappedout, since we |
| 2736 | // don't want to forget the entry that was there, and since we will |
| 2737 | // never come back to about:swappedout. Note that we have to call |
| 2738 | // UpdateSessionHistory and update page_id_ even in this case, so that |
| 2739 | // the current entry gets a state update and so that we don't send a |
| 2740 | // state update to the wrong entry when we swap back in. |
| 2741 | if (GetLoadingUrl(frame) != GURL("about:swappedout")) { |
| 2742 | // Advance our offset in session history, applying the length limit. |
| 2743 | // There is now no forward history. |
| 2744 | history_list_offset_++; |
| 2745 | if (history_list_offset_ >= content::kMaxSessionHistoryEntries) |
| 2746 | history_list_offset_ = content::kMaxSessionHistoryEntries - 1; |
| 2747 | history_list_length_ = history_list_offset_ + 1; |
| 2748 | history_page_ids_.resize(history_list_length_, -1); |
| 2749 | history_page_ids_[history_list_offset_] = page_id_; |
| 2750 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2751 | } else { |
| 2752 | // Inspect the navigation_state on this frame to see if the navigation |
| 2753 | // corresponds to a session history navigation... Note: |frame| may or |
| 2754 | // may not be the toplevel frame, but for the case of capturing session |
| 2755 | // history, the first committed frame suffices. We keep track of whether |
| 2756 | // we've seen this commit before so that only capture session history once |
| 2757 | // per navigation. |
| 2758 | // |
| 2759 | // Note that we need to check if the page ID changed. In the case of a |
| 2760 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 2761 | // previous URL and the current page ID, which would be wrong. |
| 2762 | if (navigation_state->pending_page_id() != -1 && |
| 2763 | navigation_state->pending_page_id() != page_id_ && |
| 2764 | !navigation_state->request_committed()) { |
| 2765 | // This is a successful session history navigation! |
| 2766 | UpdateSessionHistory(frame); |
| 2767 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2768 | |
| 2769 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 2770 | |
| 2771 | // If the history list is valid, our list of page IDs should be correct. |
| 2772 | DCHECK(history_list_length_ <= 0 || |
| 2773 | history_list_offset_ < 0 || |
| 2774 | history_list_offset_ >= history_list_length_ || |
| 2775 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2776 | } |
| 2777 | } |
| 2778 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2779 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2780 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 2781 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2782 | // Remember that we've already processed this request, so we don't update |
| 2783 | // the session history again. We do this regardless of whether this is |
| 2784 | // a session history navigation, because if we attempted a session history |
| 2785 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 2786 | // new navigation. |
| 2787 | navigation_state->set_request_committed(true); |
| 2788 | |
| 2789 | UpdateURL(frame); |
| 2790 | |
| 2791 | // If this committed load was initiated by a client redirect, we're |
| 2792 | // at the last stop now, so clear it. |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 2793 | completed_client_redirect_src_ = Referrer(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2794 | |
| 2795 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2796 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2797 | } |
| 2798 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2799 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 2800 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2801 | DidClearWindowObject(frame)); |
| 2802 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2803 | GURL frame_url = frame->document().url(); |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 2804 | if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) && |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 2805 | (frame_url.SchemeIs(chrome::kChromeUIScheme) || |
| 2806 | frame_url.SchemeIs(chrome::kDataScheme))) { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 2807 | GetWebUIBindings()->BindToJavascript(frame, "chrome"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2808 | } |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 2809 | |
| 2810 | if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) { |
| 2811 | if (!dom_automation_controller_.get()) |
| 2812 | dom_automation_controller_.reset(new DomAutomationController()); |
| 2813 | dom_automation_controller_->set_message_sender( |
| 2814 | static_cast<content::RenderView*>(this)); |
| 2815 | dom_automation_controller_->set_routing_id(routing_id()); |
| 2816 | dom_automation_controller_->BindToJavascript(frame, |
| 2817 | "domAutomationController"); |
| 2818 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2819 | } |
| 2820 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2821 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2822 | // Notify the browser about non-blank documents loading in the top frame. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2823 | GURL url = frame->document().url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 2824 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2825 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2826 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 2827 | } |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2828 | |
| 2829 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2830 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2831 | } |
| 2832 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2833 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 2834 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2835 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2836 | |
| 2837 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2838 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2839 | } |
| 2840 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2841 | void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) { |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 2842 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2843 | DidChangeIcon(frame, type)); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 2844 | } |
| 2845 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2846 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2847 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2848 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2849 | document_state->set_finish_document_load_time(Time::Now()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2850 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 2851 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2852 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2853 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2854 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2855 | |
| 2856 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2857 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2858 | } |
| 2859 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2860 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2861 | if (webview()->mainFrame() == frame) { |
| 2862 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 2863 | page_id_)); |
| 2864 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2865 | } |
| 2866 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2867 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 2868 | WebDataSource* ds = frame->dataSource(); |
| 2869 | DCHECK(ds); |
| 2870 | |
| 2871 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2872 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 2873 | |
| 2874 | const WebURLRequest& failed_request = ds->request(); |
| 2875 | string16 error_description; |
| 2876 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 2877 | failed_request, |
| 2878 | error, |
| 2879 | NULL, |
| 2880 | &error_description); |
| 2881 | Send(new ViewHostMsg_DidFailLoadWithError(routing_id_, |
| 2882 | frame->identifier(), |
| 2883 | failed_request.url(), |
| 2884 | !frame->parent(), |
| 2885 | error.reason, |
| 2886 | error_description)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2887 | } |
| 2888 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2889 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2890 | WebDataSource* ds = frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2891 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
| 2892 | if (document_state->finish_load_time().is_null()) |
| 2893 | document_state->set_finish_load_time(Time::Now()); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2894 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2895 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 2896 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 2897 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, |
| 2898 | frame->identifier(), |
| 2899 | ds->request().url(), |
| 2900 | !frame->parent())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2901 | } |
| 2902 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2903 | void RenderViewImpl::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2904 | WebFrame* frame, bool is_new_navigation) { |
| 2905 | // If this was a reference fragment navigation that we initiated, then we |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2906 | // 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] | 2907 | // update the ExtraData on the datasource so that others who read the |
| 2908 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 2909 | // initiate this navigation, then we need to take care to reset any pre- |
| 2910 | // existing navigation state to a content-initiated navigation state. |
| 2911 | // DidCreateDataSource conveniently takes care of this for us. |
| 2912 | didCreateDataSource(frame, frame->dataSource()); |
| 2913 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2914 | DocumentState* document_state = |
| 2915 | DocumentState::FromDataSource(frame->dataSource()); |
| 2916 | NavigationState* new_state = document_state->navigation_state(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 2917 | new_state->set_was_within_same_page(true); |
| 2918 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2919 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 2920 | |
[email protected] | 750fcf87 | 2011-08-03 23:10:47 | [diff] [blame] | 2921 | WebDataSource* datasource = frame->view()->mainFrame()->dataSource(); |
| 2922 | UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2923 | } |
| 2924 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2925 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2926 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2927 | } |
| 2928 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2929 | void RenderViewImpl::assignIdentifierToRequest( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2930 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 2931 | // Ignore |
| 2932 | } |
| 2933 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2934 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 2935 | unsigned identifier, |
| 2936 | WebURLRequest& request, |
| 2937 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 2938 | WebFrame* top_frame = frame->top(); |
| 2939 | if (!top_frame) |
| 2940 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2941 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 2942 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 2943 | WebDataSource* data_source = |
| 2944 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 2945 | |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 2946 | GURL request_url(request.url()); |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2947 | GURL new_url; |
| 2948 | if (content::GetContentClient()->renderer()->WillSendRequest( |
| 2949 | frame, request_url, &new_url)) { |
| 2950 | request.setURL(WebURL(new_url)); |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 2951 | } |
| 2952 | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2953 | content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2954 | DocumentState* document_state = DocumentState::FromDataSource(data_source); |
| 2955 | NavigationState* navigation_state = document_state->navigation_state(); |
| 2956 | if (document_state) { |
| 2957 | if (document_state->is_cache_policy_override_set()) |
| 2958 | request.setCachePolicy(document_state->cache_policy_override()); |
| 2959 | transition_type = navigation_state->transition_type(); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 2960 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2961 | |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 2962 | request.setExtraData( |
[email protected] | 537fbe0 | 2011-11-24 00:58:06 | [diff] [blame] | 2963 | new RequestExtraData(frame->referrerPolicy(), |
| 2964 | (frame == top_frame), |
[email protected] | 91043a823 | 2011-11-04 16:41:19 | [diff] [blame] | 2965 | frame->identifier(), |
| 2966 | frame->parent() == top_frame, |
| 2967 | frame->parent() ? frame->parent()->identifier() : -1, |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2968 | transition_type, |
| 2969 | navigation_state->transferred_request_child_id(), |
| 2970 | navigation_state->transferred_request_request_id())); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 2971 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2972 | DocumentState* top_document_state = |
| 2973 | DocumentState::FromDataSource(top_data_source); |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 2974 | // TODO(gavinp): separate out prefetching and prerender field trials |
| 2975 | // if the rel=prerender rel type is sticking around. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2976 | if (top_document_state && |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 2977 | (request.targetType() == WebURLRequest::TargetIsPrefetch || |
| 2978 | request.targetType() == WebURLRequest::TargetIsPrerender)) |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 2979 | top_document_state->set_was_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2980 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2981 | request.setRequestorID(routing_id_); |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 2982 | request.setHasUserGesture(frame->isProcessingUserGesture()); |
| 2983 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 2984 | if (!renderer_preferences_.enable_referrers) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 2985 | request.clearHTTPHeaderField("Referer"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2986 | } |
| 2987 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2988 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2989 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2990 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2991 | // Only do this for responses that correspond to a provisional data source |
| 2992 | // of the top-most frame. If we have a provisional data source, then we |
| 2993 | // can't have any sub-resources yet, so we know that this response must |
| 2994 | // correspond to a frame load. |
| 2995 | if (!frame->provisionalDataSource() || frame->parent()) |
| 2996 | return; |
| 2997 | |
| 2998 | // 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] | 2999 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3000 | if (frame->isViewSourceModeEnabled()) |
| 3001 | return; |
| 3002 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3003 | DocumentState* document_state = |
| 3004 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3005 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3006 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3007 | // Record page load flags. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3008 | document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 3009 | document_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
| 3010 | document_state->set_was_alternate_protocol_available( |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 3011 | response.wasAlternateProtocolAvailable()); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3012 | document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
| 3013 | document_state->set_http_status_code(http_status_code); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3014 | // Whether or not the http status code actually corresponds to an error is |
| 3015 | // only checked when the page is done loading, if |use_error_page| is |
| 3016 | // still true. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3017 | document_state->set_use_error_page(true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3018 | } |
| 3019 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3020 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3021 | WebFrame* frame, unsigned identifier) { |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3022 | DocumentState* document_state = |
| 3023 | DocumentState::FromDataSource(frame->dataSource()); |
| 3024 | if (!document_state->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3025 | return; |
| 3026 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 3027 | // Do not show error page when DevTools is attached. |
| 3028 | if (devtools_agent_->IsAttached()) |
| 3029 | return; |
| 3030 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3031 | // Display error page, if appropriate. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3032 | int http_status_code = document_state->http_status_code(); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3033 | if (http_status_code == 404) { |
| 3034 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3035 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3036 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3037 | const GURL& error_page_url = |
| 3038 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3039 | if (error_page_url.is_valid()) { |
| 3040 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 3041 | original_error.domain = "http"; |
| 3042 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3043 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3044 | |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 3045 | document_state->set_alt_error_page_fetcher( |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3046 | new AltErrorPageResourceFetcher( |
| 3047 | error_page_url, frame, original_error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 3048 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 3049 | base::Unretained(this)))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3050 | return; |
| 3051 | } |
| 3052 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3053 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 3054 | std::string error_domain; |
| 3055 | if (content::GetContentClient()->renderer()->HasErrorPage( |
| 3056 | http_status_code, &error_domain)) { |
| 3057 | WebURLError error; |
| 3058 | error.unreachableURL = frame->document().url(); |
| 3059 | error.domain = WebString::fromUTF8(error_domain); |
| 3060 | error.reason = http_status_code; |
| 3061 | |
| 3062 | LoadNavigationErrorPage( |
| 3063 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 3064 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3065 | } |
| 3066 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3067 | void RenderViewImpl::didFailResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3068 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3069 | // Ignore |
| 3070 | } |
| 3071 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3072 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3073 | WebFrame* frame, const WebURLRequest& request, |
| 3074 | const WebURLResponse& response) { |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 3075 | // The recipients of this message have no use for data: URLs: they don't |
| 3076 | // affect the page's insecure content list and are not in the disk cache. To |
| 3077 | // prevent large (1M+) data: URLs from crashing in the IPC system, we simply |
| 3078 | // filter them out here. |
| 3079 | GURL url(request.url()); |
| 3080 | if (url.SchemeIs("data")) |
| 3081 | return; |
| 3082 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3083 | // Let the browser know we loaded a resource from the memory cache. This |
| 3084 | // message is needed to display the correct SSL indicators. |
| 3085 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 3086 | routing_id_, |
[email protected] | 8470329 | 2011-10-28 20:44:00 | [diff] [blame] | 3087 | url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3088 | response.securityInfo(), |
| 3089 | request.httpMethod().utf8(), |
| 3090 | ResourceType::FromTargetType(request.targetType()))); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3091 | } |
| 3092 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3093 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3094 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 3095 | } |
| 3096 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3097 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3098 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3099 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 3100 | routing_id_, |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 3101 | origin.toString().utf8(), |
| 3102 | target)); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3103 | } |
| 3104 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3105 | void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) { |
[email protected] | b00ba70 | 2011-08-17 01:41:03 | [diff] [blame] | 3106 | webkit_glue::WebURLLoaderImpl* loader_impl = |
| 3107 | static_cast<webkit_glue::WebURLLoaderImpl*>(loader); |
| 3108 | loader_impl->UpdateRoutingId(routing_id_); |
| 3109 | } |
| 3110 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3111 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3112 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3113 | } |
| 3114 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3115 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 3116 | v8::Handle<v8::Context> context, |
| 3117 | int world_id) { |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 3118 | content::GetContentClient()->renderer()->DidCreateScriptContext( |
| 3119 | frame, context, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3120 | } |
| 3121 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3122 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 3123 | v8::Handle<v8::Context> context, |
| 3124 | int world_id) { |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 3125 | content::GetContentClient()->renderer()->WillReleaseScriptContext( |
| 3126 | frame, context, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3127 | } |
| 3128 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3129 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3130 | // We don't always want to send the change messages over IPC, only if we've |
| 3131 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 3132 | // message. |
| 3133 | if (!send_preferred_size_changes_ || !webview()) |
| 3134 | return; |
| 3135 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3136 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3137 | webview()->mainFrame()->documentElementScrollHeight()); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 3138 | |
| 3139 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 3140 | // so we need to adjust. |
| 3141 | double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel()); |
| 3142 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 3143 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 3144 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3145 | if (size == preferred_size_) |
| 3146 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3147 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3148 | preferred_size_ = size; |
| 3149 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3150 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3151 | } |
| 3152 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3153 | void RenderViewImpl::EnsureMediaStreamImpl() { |
| 3154 | #if defined(ENABLE_P2P_APIS) |
| 3155 | if (!p2p_socket_dispatcher_) |
| 3156 | p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); |
| 3157 | #endif |
| 3158 | |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 3159 | #if defined(ENABLE_WEBRTC) |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3160 | if (!media_stream_dispatcher_) |
| 3161 | media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 3162 | |
| 3163 | if (!media_stream_impl_.get()) { |
| 3164 | MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory(); |
| 3165 | media_stream_impl_ = new MediaStreamImpl( |
| 3166 | media_stream_dispatcher_, |
| 3167 | p2p_socket_dispatcher_, |
| 3168 | RenderThreadImpl::current()->video_capture_impl_manager(), |
| 3169 | factory); |
| 3170 | } |
[email protected] | 5b87e78 | 2012-02-09 18:19:32 | [diff] [blame] | 3171 | #endif |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 3172 | } |
| 3173 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3174 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 3175 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3176 | if (webview()->mainFrame() != frame) |
| 3177 | return; |
| 3178 | WebView* frameView = frame->view(); |
| 3179 | if (!frameView) |
| 3180 | return; |
| 3181 | |
| 3182 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 3183 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 3184 | |
| 3185 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 3186 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 3187 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 3188 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 3189 | |
| 3190 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 3191 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 3192 | } |
| 3193 | } |
| 3194 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3195 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3196 | WebSize offset = frame->scrollOffset(); |
| 3197 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 3198 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 3199 | |
| 3200 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 3201 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 3202 | |
| 3203 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 3204 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 3205 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 3206 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 3207 | |
| 3208 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 3209 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 3210 | } |
| 3211 | } |
| 3212 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3213 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3214 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3215 | |
| 3216 | if (webview()->mainFrame() == frame) |
| 3217 | UpdateScrollState(frame); |
| 3218 | } |
| 3219 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3220 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3221 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3222 | } |
| 3223 | |
[email protected] | ea93125 | 2012-02-15 22:01:03 | [diff] [blame] | 3224 | void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) { |
| 3225 | Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers)); |
| 3226 | } |
| 3227 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3228 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count, |
| 3229 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3230 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 3231 | if (!count) |
| 3232 | active_match_ordinal = 0; |
| 3233 | |
| 3234 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 3235 | routing_id_, |
| 3236 | request_id, |
| 3237 | count, |
| 3238 | gfx::Rect(), |
| 3239 | active_match_ordinal, |
| 3240 | final_update); |
| 3241 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3242 | // If we have a message that has been queued up, then we should just replace |
| 3243 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 3244 | // wants it. |
| 3245 | if (queued_find_reply_message_.get()) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3246 | queued_find_reply_message_.reset(msg); |
| 3247 | } else { |
| 3248 | // Send the search result over to the browser process. |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3249 | Send(msg); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3250 | } |
| 3251 | } |
| 3252 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3253 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 3254 | int active_match_ordinal, |
| 3255 | const WebRect& selection_rect) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3256 | // Send the search result over to the browser process. |
| 3257 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3258 | request_id, |
| 3259 | -1, |
| 3260 | selection_rect, |
| 3261 | active_match_ordinal, |
| 3262 | false)); |
| 3263 | } |
| 3264 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3265 | void RenderViewImpl::openFileSystem( |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3266 | WebFrame* frame, |
| 3267 | WebFileSystem::Type type, |
| 3268 | long long size, |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 3269 | bool create, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3270 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3271 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3272 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3273 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 3274 | if (origin.isUnique()) { |
| 3275 | // Unique origins cannot store persistent state. |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3276 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 3277 | return; |
| 3278 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3279 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3280 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 3281 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 3282 | size, create, new WebFileSystemCallbackDispatcher(callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3283 | } |
| 3284 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3285 | void RenderViewImpl::queryStorageUsageAndQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 3286 | WebFrame* frame, |
| 3287 | WebStorageQuotaType type, |
| 3288 | WebStorageQuotaCallbacks* callbacks) { |
| 3289 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3290 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 3291 | if (origin.isUnique()) { |
| 3292 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 3293 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 3294 | return; |
| 3295 | } |
| 3296 | ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 3297 | GURL(origin.toString()), |
| 3298 | static_cast<quota::StorageType>(type), |
| 3299 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 3300 | } |
| 3301 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3302 | void RenderViewImpl::requestStorageQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 3303 | WebFrame* frame, |
| 3304 | WebStorageQuotaType type, |
| 3305 | unsigned long long requested_size, |
| 3306 | WebStorageQuotaCallbacks* callbacks) { |
| 3307 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3308 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 753ab8c8 | 2011-11-21 20:25:56 | [diff] [blame] | 3309 | if (origin.isUnique()) { |
| 3310 | // Unique origins cannot store persistent state. |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 3311 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 3312 | return; |
| 3313 | } |
| 3314 | ChildThread::current()->quota_dispatcher()->RequestStorageQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 3315 | routing_id(), GURL(origin.toString()), |
| 3316 | static_cast<quota::StorageType>(type), requested_size, |
| 3317 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 3318 | } |
| 3319 | |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 3320 | void RenderViewImpl::registerIntentService( |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 3321 | WebFrame* frame, const WebIntentServiceInfo& service) { |
[email protected] | e6e35cd | 2011-12-22 19:37:06 | [diff] [blame] | 3322 | string16 title = service.title(); |
| 3323 | if (title.empty()) |
| 3324 | title = webview()->mainFrame()->document().title(); |
| 3325 | |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 3326 | Send(new IntentsHostMsg_RegisterIntentService(routing_id_, |
| 3327 | service.action(), |
| 3328 | service.type(), |
| 3329 | service.url().spec().utf16(), |
[email protected] | e6e35cd | 2011-12-22 19:37:06 | [diff] [blame] | 3330 | title, |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 3331 | service.disposition())); |
| 3332 | } |
| 3333 | |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 3334 | void RenderViewImpl::dispatchIntent( |
| 3335 | WebFrame* frame, const WebIntentRequest& intentRequest) { |
| 3336 | webkit_glue::WebIntentData intent_data(intentRequest.intent()); |
| 3337 | int id = intents_host_->RegisterWebIntent(intentRequest); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 3338 | Send(new IntentsHostMsg_WebIntentDispatch( |
[email protected] | ffc8bed | 2012-01-21 01:23:15 | [diff] [blame] | 3339 | routing_id_, intent_data, id)); |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 3340 | } |
| 3341 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3342 | // WebKit::WebPageSerializerClient implementation ------------------------------ |
| 3343 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3344 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3345 | const WebURL& frame_url, |
| 3346 | const WebCString& data, |
| 3347 | WebPageSerializerClient::PageSerializationStatus status) { |
| 3348 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 3349 | routing_id(), |
| 3350 | frame_url, |
| 3351 | data.data(), |
| 3352 | static_cast<int32>(status))); |
| 3353 | } |
| 3354 | |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3355 | // content::RenderView implementation ------------------------------------------ |
| 3356 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3357 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3358 | return RenderWidget::Send(message); |
| 3359 | } |
| 3360 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3361 | int RenderViewImpl::GetRoutingId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3362 | return routing_id_; |
| 3363 | } |
| 3364 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3365 | int RenderViewImpl::GetPageId() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3366 | return page_id_; |
| 3367 | } |
| 3368 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3369 | gfx::Size RenderViewImpl::GetSize() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3370 | return size(); |
| 3371 | } |
| 3372 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3373 | gfx::NativeViewId RenderViewImpl::GetHostWindow() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3374 | return host_window(); |
| 3375 | } |
| 3376 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3377 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3378 | return webkit_preferences_; |
| 3379 | } |
| 3380 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3381 | WebKit::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3382 | return webview(); |
| 3383 | } |
| 3384 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3385 | WebKit::WebNode RenderViewImpl::GetFocusedNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3386 | if (!webview()) |
| 3387 | return WebNode(); |
| 3388 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 3389 | if (focused_frame) { |
| 3390 | WebDocument doc = focused_frame->document(); |
| 3391 | if (!doc.isNull()) |
| 3392 | return doc.focusedNode(); |
| 3393 | } |
| 3394 | |
| 3395 | return WebNode(); |
| 3396 | } |
| 3397 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3398 | WebKit::WebNode RenderViewImpl::GetContextMenuNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3399 | return context_menu_node_; |
| 3400 | } |
| 3401 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3402 | bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3403 | bool is_editable_node = false; |
| 3404 | if (!node.isNull()) { |
| 3405 | if (node.isContentEditable()) { |
| 3406 | is_editable_node = true; |
| 3407 | } else if (node.isElementNode()) { |
| 3408 | is_editable_node = |
| 3409 | node.toConst<WebElement>().isTextFormControlElement(); |
| 3410 | } |
| 3411 | } |
| 3412 | return is_editable_node; |
| 3413 | } |
| 3414 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3415 | WebKit::WebPlugin* RenderViewImpl::CreatePlugin( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3416 | WebKit::WebFrame* frame, |
| 3417 | const webkit::WebPluginInfo& info, |
| 3418 | const WebKit::WebPluginParams& params) { |
| 3419 | bool pepper_plugin_was_registered = false; |
| 3420 | scoped_refptr<webkit::ppapi::PluginModule> pepper_module( |
| 3421 | pepper_delegate_.CreatePepperPluginModule(info, |
| 3422 | &pepper_plugin_was_registered)); |
| 3423 | if (pepper_plugin_was_registered) { |
| 3424 | if (!pepper_module) |
| 3425 | return NULL; |
| 3426 | return new webkit::ppapi::WebPluginImpl( |
| 3427 | pepper_module.get(), params, pepper_delegate_.AsWeakPtr()); |
| 3428 | } |
| 3429 | |
[email protected] | 34b27e44 | 2012-01-20 20:07:41 | [diff] [blame] | 3430 | #if defined(USE_AURA) |
| 3431 | return NULL; |
| 3432 | #else |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3433 | return new webkit::npapi::WebPluginImpl( |
| 3434 | frame, params, info.path, AsWeakPtr()); |
[email protected] | 34b27e44 | 2012-01-20 20:07:41 | [diff] [blame] | 3435 | #endif |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3436 | } |
| 3437 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3438 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 3439 | const string16& jscript, |
| 3440 | int id, |
| 3441 | bool notify_result) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3442 | v8::Handle<v8::Value> result; |
| 3443 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 3444 | if (web_frame) |
| 3445 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 3446 | if (notify_result) { |
| 3447 | ListValue list; |
| 3448 | if (!result.IsEmpty() && web_frame) { |
| 3449 | v8::HandleScope handle_scope; |
| 3450 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 3451 | v8::Context::Scope context_scope(context); |
| 3452 | V8ValueConverterImpl converter; |
| 3453 | converter.set_allow_date(true); |
| 3454 | converter.set_allow_regexp(true); |
| 3455 | list.Set(0, converter.FromV8Value(result, context)); |
| 3456 | } else { |
| 3457 | list.Set(0, Value::CreateNullValue()); |
| 3458 | } |
| 3459 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 3460 | } |
| 3461 | } |
| 3462 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3463 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3464 | return (!send_preferred_size_changes_ || |
| 3465 | (disable_scrollbars_size_limit_.width() <= width || |
| 3466 | disable_scrollbars_size_limit_.height() <= height)); |
| 3467 | } |
| 3468 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3469 | int RenderViewImpl::GetEnabledBindings() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3470 | return enabled_bindings_; |
| 3471 | } |
| 3472 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3473 | bool RenderViewImpl::GetContentStateImmediately() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3474 | return send_content_state_immediately_; |
| 3475 | } |
| 3476 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3477 | float RenderViewImpl::GetFilteredTimePerFrame() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3478 | return filtered_time_per_frame(); |
| 3479 | } |
| 3480 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3481 | void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame, |
| 3482 | const WebKit::WebContextMenuData& data) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3483 | showContextMenu(frame, data); |
| 3484 | } |
| 3485 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3486 | WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3487 | return visibilityState(); |
| 3488 | } |
| 3489 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3490 | void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame, |
| 3491 | const WebKit::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3492 | return runModalAlertDialog(frame, message); |
| 3493 | } |
| 3494 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3495 | void RenderViewImpl::LoadURLExternally( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3496 | WebKit::WebFrame* frame, |
| 3497 | const WebKit::WebURLRequest& request, |
| 3498 | WebKit::WebNavigationPolicy policy) { |
| 3499 | loadURLExternally(frame, request, policy); |
| 3500 | } |
| 3501 | |
| 3502 | // webkit_glue::WebPluginPageDelegate ------------------------------------------ |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3503 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3504 | webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3505 | const FilePath& file_path, |
| 3506 | const std::string& mime_type) { |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 3507 | if (!PluginChannelHost::IsListening()) { |
| 3508 | LOG(ERROR) << "PluginChannelHost isn't listening"; |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3509 | return NULL; |
[email protected] | 94752ee | 2012-02-10 10:38:20 | [diff] [blame] | 3510 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3511 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3512 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3513 | if (in_process_plugin) { |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 3514 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 3515 | return webkit::npapi::WebPluginDelegateImpl::Create( |
| 3516 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3517 | #else |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 3518 | // In-proc plugins aren't supported on non-Windows. |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 3519 | NOTIMPLEMENTED(); |
| 3520 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3521 | #endif |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3522 | } |
| 3523 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3524 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3525 | } |
| 3526 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3527 | void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3528 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 3529 | Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3530 | #endif |
| 3531 | } |
| 3532 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3533 | void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3534 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 3535 | Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3536 | #endif |
| 3537 | CleanupWindowInPluginMoves(window); |
| 3538 | } |
| 3539 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3540 | void RenderViewImpl::DidMovePlugin( |
| 3541 | const webkit::npapi::WebPluginGeometry& move) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3542 | SchedulePluginMove(move); |
| 3543 | } |
| 3544 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3545 | void RenderViewImpl::DidStartLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3546 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3547 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3548 | } |
| 3549 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3550 | void RenderViewImpl::DidStopLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3551 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3552 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3553 | } |
| 3554 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3555 | WebCookieJar* RenderViewImpl::GetCookieJar() { |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3556 | return &cookie_jar_; |
| 3557 | } |
| 3558 | |
[email protected] | a9288f5 | 2011-11-17 05:18:16 | [diff] [blame] | 3559 | void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 3560 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 3561 | reinterpret_cast<int64>(player), |
| 3562 | player->hasVideo(), |
| 3563 | player->hasAudio(), |
| 3564 | true)); |
| 3565 | } |
| 3566 | |
[email protected] | a9288f5 | 2011-11-17 05:18:16 | [diff] [blame] | 3567 | void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 3568 | Send(new ViewHostMsg_MediaNotification(routing_id_, |
| 3569 | reinterpret_cast<int64>(player), |
| 3570 | player->hasVideo(), |
| 3571 | player->hasAudio(), |
| 3572 | false)); |
| 3573 | } |
| 3574 | |
[email protected] | a9288f5 | 2011-11-17 05:18:16 | [diff] [blame] | 3575 | void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) { |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 3576 | DidPause(player); |
| 3577 | } |
| 3578 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3579 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3580 | if (!webview()) |
| 3581 | return; |
| 3582 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3583 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3584 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3585 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3586 | |
| 3587 | Send(new ViewHostMsg_UpdateState( |
| 3588 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3589 | } |
| 3590 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3591 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3592 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 3593 | if (!frame) |
| 3594 | return; |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3595 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3596 | size_t location, length; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 3597 | if (!webview()->caretOrSelectionRange(&location, &length)) |
| 3598 | return; |
| 3599 | |
| 3600 | string16 text; |
| 3601 | size_t offset; |
| 3602 | ui::Range range(location, location + length); |
| 3603 | |
| 3604 | if (webview()->textInputType() != WebKit::WebTextInputTypeNone) { |
| 3605 | // If current focused element is editable, we will send 100 more chars |
| 3606 | // before and after selection. It is for input method surrounding text |
| 3607 | // feature. |
| 3608 | if (location > kExtraCharsBeforeAndAfterSelection) |
| 3609 | offset = location - kExtraCharsBeforeAndAfterSelection; |
| 3610 | else |
| 3611 | offset = 0; |
| 3612 | length = location + length - offset + kExtraCharsBeforeAndAfterSelection; |
| 3613 | WebRange webrange = WebRange::fromDocumentRange(frame, offset, length); |
| 3614 | if (!webrange.isNull()) |
| 3615 | text = WebRange::fromDocumentRange(frame, offset, length).toPlainText(); |
| 3616 | } else { |
| 3617 | offset = location; |
| 3618 | text = frame->selectionAsText(); |
[email protected] | e8cdf353 | 2011-10-29 00:50:52 | [diff] [blame] | 3619 | // http://crbug.com/101435 |
| 3620 | // In some case, frame->selectionAsText() returned text's length is not |
| 3621 | // equal to the length returned from webview()->caretOrSelectionRange(). |
| 3622 | // So we have to set the range according to text.length(). |
| 3623 | range.set_end(range.start() + text.length()); |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3624 | } |
| 3625 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3626 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 3627 | // the selection hasn't actually changed. We don't want to report these |
| 3628 | // because it will cause us to continually claim the X clipboard. |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 3629 | if (selection_text_offset_ != offset || |
| 3630 | selection_range_ != range || |
| 3631 | selection_text_ != text) { |
| 3632 | selection_text_ = text; |
| 3633 | selection_text_offset_ = offset; |
| 3634 | selection_range_ = range; |
| 3635 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range)); |
| 3636 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3637 | } |
| 3638 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3639 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 3640 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3641 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3642 | // If the URL that failed was secure, then the embedding web page was not |
| 3643 | // expecting a network attacker to be able to manipulate its contents. As |
| 3644 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3645 | // attacker to manipulate the contents of the response if we tried to use |
| 3646 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3647 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | // Grab the base URL from the browser process. |
| 3651 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3652 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3653 | |
| 3654 | // Strip query params from the failed URL. |
| 3655 | GURL::Replacements remove_params; |
| 3656 | remove_params.ClearUsername(); |
| 3657 | remove_params.ClearPassword(); |
| 3658 | remove_params.ClearQuery(); |
| 3659 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3660 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3661 | std::string spec_to_send = url_to_send.spec(); |
| 3662 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3663 | if (failed_url.has_query()) |
| 3664 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3665 | |
| 3666 | // Construct the query params to send to link doctor. |
| 3667 | std::string params(alternate_error_page_url_.query()); |
| 3668 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 3669 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3670 | params.append("&sourceid=chrome"); |
| 3671 | params.append("&error="); |
| 3672 | switch (error_type) { |
| 3673 | case DNS_ERROR: |
| 3674 | params.append("dnserror"); |
| 3675 | break; |
| 3676 | |
| 3677 | case HTTP_404: |
| 3678 | params.append("http404"); |
| 3679 | break; |
| 3680 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3681 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3682 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3683 | break; |
| 3684 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3685 | default: |
| 3686 | NOTREACHED() << "unknown ErrorPageType"; |
| 3687 | } |
| 3688 | |
| 3689 | // OK, build the final url to return. |
| 3690 | GURL::Replacements link_doctor_params; |
| 3691 | link_doctor_params.SetQueryStr(params); |
| 3692 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3693 | return url; |
| 3694 | } |
| 3695 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3696 | GURL RenderViewImpl::GetOpenerUrl() const { |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 3697 | if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_) |
| 3698 | return GURL(); |
| 3699 | else |
| 3700 | return creator_url_; |
| 3701 | } |
| 3702 | |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame^] | 3703 | GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const { |
| 3704 | WebDataSource* ds = frame->dataSource(); |
| 3705 | if (ds->hasUnreachableURL()) |
| 3706 | return ds->unreachableURL(); |
| 3707 | |
| 3708 | const WebURLRequest& request = ds->request(); |
| 3709 | return request.url(); |
| 3710 | } |
| 3711 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3712 | WebUIBindings* RenderViewImpl::GetWebUIBindings() { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 3713 | if (!web_ui_bindings_.get()) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3714 | web_ui_bindings_.reset(new WebUIBindings( |
| 3715 | static_cast<content::RenderView*>(this), routing_id_)); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3716 | } |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 3717 | return web_ui_bindings_.get(); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3718 | } |
| 3719 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3720 | WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3721 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3722 | } |
| 3723 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3724 | void RenderViewImpl::OnFind(int request_id, const string16& search_text, |
| 3725 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3726 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3727 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 3728 | // Check if the plugin still exists in the document. |
| 3729 | if (main_frame->document().isPluginDocument() && |
| 3730 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3731 | if (options.findNext) { |
| 3732 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3733 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3734 | } else { |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 3735 | if (GetWebPluginFromPluginDocument()->startFind( |
| 3736 | search_text, options.matchCase, request_id)) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3737 | } else { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3738 | // Send "no results". |
| 3739 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3740 | request_id, |
| 3741 | 0, |
| 3742 | gfx::Rect(), |
| 3743 | 0, |
| 3744 | true)); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3745 | } |
| 3746 | } |
| 3747 | return; |
| 3748 | } |
| 3749 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3750 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3751 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3752 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 3753 | |
| 3754 | bool multi_frame = (frame_after_main != main_frame); |
| 3755 | |
| 3756 | // If we have multiple frames, we don't want to wrap the search within the |
| 3757 | // frame, so we check here if we only have main_frame in the chain. |
| 3758 | bool wrap_within_frame = !multi_frame; |
| 3759 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 3760 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3761 | bool result = false; |
| 3762 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3763 | // If something is selected when we start searching it means we cannot just |
| 3764 | // increment the current match ordinal; we need to re-generate it. |
| 3765 | WebRange current_selection = focused_frame->selectionRange(); |
| 3766 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3767 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3768 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3769 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3770 | |
| 3771 | if (!result) { |
| 3772 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3773 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3774 | |
| 3775 | // Find the next frame, but skip the invisible ones. |
| 3776 | do { |
| 3777 | // What is the next frame to search? (we might be going backwards). Note |
| 3778 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3779 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3780 | search_frame->traverseNext(true) : |
| 3781 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3782 | } while (!search_frame->hasVisibleContent() && |
| 3783 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3784 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 3785 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3786 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3787 | |
| 3788 | // If we have multiple frames and we have wrapped back around to the |
| 3789 | // focused frame, we need to search it once more allowing wrap within |
| 3790 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 3791 | // reported matches, but no frames after the focused_frame contain a |
| 3792 | // match for the search word(s). |
| 3793 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3794 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3795 | request_id, search_text, options, true, // Force wrapping. |
| 3796 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3797 | } |
| 3798 | } |
| 3799 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3800 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3801 | } while (!result && search_frame != focused_frame); |
| 3802 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3803 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3804 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3805 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3806 | } else { |
| 3807 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 3808 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 3809 | // yet what is active. |
| 3810 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 3811 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3812 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3813 | // If we find no matches then this will be our last status update. |
| 3814 | // Otherwise the scoping effort will send more results. |
| 3815 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3816 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3817 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 3818 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3819 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3820 | match_count, |
| 3821 | selection_rect, |
| 3822 | ordinal, |
| 3823 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3824 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3825 | // Scoping effort begins, starting with the mainframe. |
| 3826 | search_frame = main_frame; |
| 3827 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3828 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3829 | |
| 3830 | do { |
| 3831 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3832 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3833 | |
| 3834 | // We don't start another scoping effort unless at least one match has |
| 3835 | // been found. |
| 3836 | if (result) { |
| 3837 | // Start new scoping request. If the scoping function determines that it |
| 3838 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3839 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3840 | search_text, |
| 3841 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3842 | true); // reset the tickmarks |
| 3843 | } |
| 3844 | |
| 3845 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 3846 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3847 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3848 | } while (search_frame != main_frame); |
| 3849 | } |
| 3850 | } |
| 3851 | |
[email protected] | 815dd987 | 2011-11-23 18:40:30 | [diff] [blame] | 3852 | void RenderViewImpl::OnStopFinding(content::StopFindAction action) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3853 | WebView* view = webview(); |
| 3854 | if (!view) |
| 3855 | return; |
| 3856 | |
| 3857 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 3858 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3859 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3860 | return; |
| 3861 | } |
| 3862 | |
[email protected] | 815dd987 | 2011-11-23 18:40:30 | [diff] [blame] | 3863 | bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3864 | if (clear_selection) |
| 3865 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 3866 | |
| 3867 | WebFrame* frame = view->mainFrame(); |
| 3868 | while (frame) { |
| 3869 | frame->stopFinding(clear_selection); |
| 3870 | frame = frame->traverseNext(false); |
| 3871 | } |
| 3872 | |
[email protected] | 815dd987 | 2011-11-23 18:40:30 | [diff] [blame] | 3873 | if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3874 | WebFrame* focused_frame = view->focusedFrame(); |
| 3875 | if (focused_frame) { |
| 3876 | WebDocument doc = focused_frame->document(); |
| 3877 | if (!doc.isNull()) { |
| 3878 | WebNode node = doc.focusedNode(); |
| 3879 | if (!node.isNull()) |
| 3880 | node.simulateClick(); |
| 3881 | } |
| 3882 | } |
| 3883 | } |
| 3884 | } |
| 3885 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3886 | void RenderViewImpl::OnFindReplyAck() { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3887 | // Check if there is any queued up request waiting to be sent. |
| 3888 | if (queued_find_reply_message_.get()) { |
| 3889 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 3890 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3894 | void RenderViewImpl::OnZoom(content::PageZoom zoom) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3895 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 3896 | return; |
| 3897 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 3898 | webview()->hidePopups(); |
[email protected] | 854ab546 | 2011-11-22 20:48:10 | [diff] [blame] | 3899 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3900 | double old_zoom_level = webview()->zoomLevel(); |
| 3901 | double zoom_level; |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3902 | if (zoom == content::PAGE_ZOOM_RESET) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3903 | zoom_level = 0; |
| 3904 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 3905 | // Previous zoom level is a whole number, so just increment/decrement. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3906 | zoom_level = old_zoom_level + zoom; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3907 | } else { |
| 3908 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 3909 | // not a whole number, or a plugin changed it to a custom value. We want |
| 3910 | // to go to the next whole number so that the user can always get back to |
| 3911 | // 100% with the keyboard/menu. |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3912 | if ((old_zoom_level > 1 && zoom > 0) || |
| 3913 | (old_zoom_level < 1 && zoom < 0)) { |
| 3914 | zoom_level = static_cast<int>(old_zoom_level + zoom); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3915 | } else { |
| 3916 | // We're going towards 100%, so first go to the next whole number. |
| 3917 | zoom_level = static_cast<int>(old_zoom_level); |
| 3918 | } |
| 3919 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3920 | webview()->setZoomLevel(false, zoom_level); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 3921 | zoomLevelChanged(); |
| 3922 | } |
| 3923 | |
| 3924 | void RenderViewImpl::OnZoomFactor(content::PageZoom zoom, |
| 3925 | int zoom_center_x, int zoom_center_y) { |
| 3926 | ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y, |
| 3927 | kScalingIncrementForGesture); |
| 3928 | } |
| 3929 | |
| 3930 | void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom, |
| 3931 | int zoom_center_x, |
| 3932 | int zoom_center_y, |
| 3933 | float scaling_increment) { |
| 3934 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 3935 | return; |
| 3936 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 3937 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 3938 | double page_scale_factor; |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 3939 | if (zoom == content::PAGE_ZOOM_RESET) { |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 3940 | page_scale_factor = 1.0; |
| 3941 | } else { |
| 3942 | page_scale_factor = old_page_scale_factor + |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 3943 | (zoom > 0 ? scaling_increment : -scaling_increment); |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 3944 | } |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 3945 | if (page_scale_factor > 0) { |
[email protected] | 8519136 | 2011-11-08 18:53:09 | [diff] [blame] | 3946 | webview()->setPageScaleFactor(page_scale_factor, |
| 3947 | WebPoint(zoom_center_x, zoom_center_y)); |
[email protected] | 47578fa0 | 2011-11-02 19:34:41 | [diff] [blame] | 3948 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3949 | } |
| 3950 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3951 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 3952 | webview()->hidePopups(); |
| 3953 | webview()->setZoomLevel(false, zoom_level); |
| 3954 | zoomLevelChanged(); |
| 3955 | } |
| 3956 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3957 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 3958 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3959 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3960 | } |
| 3961 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3962 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3963 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3964 | } |
| 3965 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3966 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3967 | WebString no_encoding; |
| 3968 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3969 | } |
| 3970 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3971 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3972 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3973 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3974 | |
| 3975 | // xpath string can represent a frame deep down the tree (across multiple |
| 3976 | // frame DOMs). |
| 3977 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 3978 | // should break into 2 xpaths |
| 3979 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 3980 | std::vector<string16> xpaths; |
| 3981 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3982 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3983 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 3984 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 3985 | frame && i != xpaths.end(); ++i) { |
| 3986 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3987 | } |
| 3988 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3989 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3990 | } |
| 3991 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3992 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 3993 | const string16& jscript, |
| 3994 | int id, |
| 3995 | bool notify_result) { |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 3996 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3997 | } |
| 3998 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3999 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 4000 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4001 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 4002 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 4003 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4004 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 4005 | frame->document().insertUserStyleSheet( |
| 4006 | WebString::fromUTF8(css), |
| 4007 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4008 | } |
| 4009 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4010 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4011 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4012 | } |
| 4013 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4014 | void RenderViewImpl::OnSetWebUIProperty(const std::string& name, |
| 4015 | const std::string& value) { |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 4016 | DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI); |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 4017 | GetWebUIBindings()->SetProperty(name, value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4018 | } |
| 4019 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4020 | void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data, |
| 4021 | const gfx::Point& client_point, |
| 4022 | const gfx::Point& screen_point, |
| 4023 | WebDragOperationsMask ops) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4024 | WebDragOperation operation = webview()->dragTargetDragEnter( |
| 4025 | drop_data.ToDragData(), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4026 | client_point, |
| 4027 | screen_point, |
| 4028 | ops); |
| 4029 | |
| 4030 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 4031 | } |
| 4032 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4033 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 4034 | const gfx::Point& screen_point, |
| 4035 | WebDragOperationsMask ops) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4036 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 4037 | client_point, |
| 4038 | screen_point, |
| 4039 | ops); |
| 4040 | |
| 4041 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 4042 | } |
| 4043 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4044 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4045 | webview()->dragTargetDragLeave(); |
| 4046 | } |
| 4047 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4048 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
| 4049 | const gfx::Point& screen_point) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4050 | webview()->dragTargetDrop(client_point, screen_point); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 4051 | |
| 4052 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 4053 | } |
| 4054 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4055 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 4056 | const gfx::Point& screen_point, |
| 4057 | bool ended, |
| 4058 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4059 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4060 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 4061 | } else { |
| 4062 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4063 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4064 | } |
| 4065 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4066 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4067 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4068 | } |
| 4069 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4070 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 4071 | webkit_preferences_ = prefs; |
| 4072 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4073 | } |
| 4074 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4075 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4076 | alternate_error_page_url_ = url; |
| 4077 | } |
| 4078 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4079 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 4080 | const content::CustomContextMenuContext& custom_context, |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 4081 | unsigned action) { |
| 4082 | if (custom_context.is_pepper_menu) |
| 4083 | pepper_delegate_.OnCustomContextMenuAction(custom_context, action); |
| 4084 | else |
| 4085 | webview()->performCustomContextMenuAction(action); |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 4086 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 4087 | ContextMenuAction(action)); |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 4088 | } |
| 4089 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4090 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 4091 | int id, |
| 4092 | const std::vector<FilePath>& paths) { |
| 4093 | if (!enumeration_completions_[id]) |
| 4094 | return; |
| 4095 | |
| 4096 | WebVector<WebString> ws_file_names(paths.size()); |
| 4097 | for (size_t i = 0; i < paths.size(); ++i) |
| 4098 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
| 4099 | |
| 4100 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 4101 | enumeration_completions_.erase(id); |
| 4102 | } |
| 4103 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4104 | void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4105 | // This could happen if we navigated to a different page before the user |
| 4106 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4107 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4108 | return; |
| 4109 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4110 | WebVector<WebString> ws_file_names(paths.size()); |
| 4111 | for (size_t i = 0; i < paths.size(); ++i) |
| 4112 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 4113 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4114 | if (file_chooser_completions_.front()->completion) |
| 4115 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 4116 | file_chooser_completions_.pop_front(); |
| 4117 | |
| 4118 | // If there are more pending file chooser requests, schedule one now. |
| 4119 | if (!file_chooser_completions_.empty()) { |
| 4120 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 4121 | file_chooser_completions_.front()->params)); |
| 4122 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4123 | } |
| 4124 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 4125 | void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size, |
| 4126 | const gfx::Size& max_size) { |
| 4127 | DCHECK(disable_scrollbars_size_limit_.IsEmpty()); |
| 4128 | if (!webview()) |
| 4129 | return; |
| 4130 | webview()->enableAutoResizeMode(true, min_size, max_size); |
| 4131 | } |
| 4132 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 4133 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4134 | if (send_preferred_size_changes_) |
| 4135 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4136 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4137 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 4138 | // Start off with an initial preferred size notification (in case |
| 4139 | // |didUpdateLayout| was already called). |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 4140 | didUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 4141 | } |
| 4142 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4143 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4144 | const gfx::Size& disable_scrollbar_size_limit) { |
| 4145 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 4146 | } |
| 4147 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4148 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 4149 | const content::RendererPreferences& renderer_prefs) { |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 4150 | double old_zoom_level = renderer_preferences_.default_zoom_level; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4151 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 4152 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 0dd6f9b5 | 2010-10-14 16:39:13 | [diff] [blame] | 4153 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 4154 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 4155 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 4156 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 42e5c86 | 2011-04-07 22:13:51 | [diff] [blame] | 4157 | gfx::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 4158 | renderer_prefs.thumb_inactive_color, |
| 4159 | renderer_prefs.thumb_active_color, |
| 4160 | renderer_prefs.track_color); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4161 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4162 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4163 | webview()->setScrollbarColors( |
| 4164 | renderer_prefs.thumb_inactive_color, |
| 4165 | renderer_prefs.thumb_active_color, |
| 4166 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4167 | webview()->setSelectionColors( |
| 4168 | renderer_prefs.active_selection_bg_color, |
| 4169 | renderer_prefs.active_selection_fg_color, |
| 4170 | renderer_prefs.inactive_selection_bg_color, |
| 4171 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4172 | webview()->themeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4173 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 4174 | #endif |
[email protected] | d051d9a | 2011-12-10 02:02:50 | [diff] [blame] | 4175 | // If the zoom level for this page matches the old zoom default, and this |
| 4176 | // is not a plugin, update the zoom level to match the new default. |
| 4177 | if (webview() && !webview()->mainFrame()->document().isPluginDocument() && |
| 4178 | content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) { |
| 4179 | webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level); |
| 4180 | zoomLevelChanged(); |
| 4181 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4182 | } |
| 4183 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4184 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 4185 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 4186 | if (webview()) |
| 4187 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 4188 | } |
| 4189 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 4190 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 4191 | const WebPluginAction& action) { |
| 4192 | if (webview()) |
| 4193 | webview()->performPluginAction(action, location); |
| 4194 | } |
| 4195 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4196 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4197 | const GURL& page_url) { |
| 4198 | // Prepare list to storage all savable resource links. |
| 4199 | std::vector<GURL> resources_list; |
| 4200 | std::vector<GURL> referrers_list; |
| 4201 | std::vector<GURL> frames_list; |
| 4202 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 4203 | &referrers_list, |
| 4204 | &frames_list); |
| 4205 | |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 4206 | // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to |
| 4207 | // return referrers, it should also return the referrer policies. |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4208 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 4209 | webview(), |
| 4210 | page_url, |
| 4211 | &result, |
[email protected] | 2a80aee | 2011-10-07 16:06:03 | [diff] [blame] | 4212 | chrome::GetSavableSchemes())) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4213 | // If something is wrong when collecting all savable resource links, |
| 4214 | // send empty list to embedder(browser) to tell it failed. |
| 4215 | referrers_list.clear(); |
| 4216 | resources_list.clear(); |
| 4217 | frames_list.clear(); |
| 4218 | } |
| 4219 | |
| 4220 | // Send result of all savable resource links to embedder. |
| 4221 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 4222 | resources_list, |
| 4223 | referrers_list, |
| 4224 | frames_list)); |
| 4225 | } |
| 4226 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4227 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 4228 | const std::vector<GURL>& links, |
| 4229 | const std::vector<FilePath>& local_paths, |
| 4230 | const FilePath& local_directory_name) { |
| 4231 | |
| 4232 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 4233 | WebVector<WebURL> weburl_links(links); |
| 4234 | |
| 4235 | // Convert std::vector of std::strings to WebVector<WebString> |
| 4236 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 4237 | for (size_t i = 0; i < local_paths.size(); i++) |
| 4238 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 4239 | |
| 4240 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 4241 | webstring_paths, |
| 4242 | webkit_glue::FilePathToWebString( |
| 4243 | local_directory_name)); |
| 4244 | } |
| 4245 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4246 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4247 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4248 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4249 | } |
| 4250 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4251 | void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame^] | 4252 | // Ensure that no other in-progress navigation continues. |
| 4253 | OnStop(); |
| 4254 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4255 | // Only run unload if we're not swapped out yet, but send the ack either way. |
| 4256 | if (!is_swapped_out_) { |
| 4257 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 4258 | // different process. This involves running the unload handler and clearing |
| 4259 | // the page. Once WasSwappedOut is called, we also allow this process to |
| 4260 | // exit if there are no other active RenderViews in it. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4261 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4262 | // Send an UpdateState message before we get swapped out. |
| 4263 | SyncNavigationState(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4264 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4265 | // Synchronously run the unload handler before sending the ACK. |
| 4266 | webview()->dispatchUnloadEvent(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4267 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4268 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 4269 | SetSwappedOut(true); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4270 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4271 | // Replace the page with a blank dummy URL. The unload handler will not be |
| 4272 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame^] | 4273 | // We use loadRequest instead of loadHTMLString because the former commits |
| 4274 | // synchronously. Otherwise a new navigation can interrupt the navigation |
| 4275 | // to about:swappedout. If that happens to be to the page we had been |
| 4276 | // showing, then WebKit will never send a commit and we'll be left spinning. |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4277 | // TODO(creis): Need to add a better way to do this that avoids running the |
| 4278 | // beforeunload handler. For now, we just run it a second time silently. |
[email protected] | 69ddf85 | 2012-02-21 23:21:31 | [diff] [blame^] | 4279 | WebURLRequest request(GURL("about:swappedout")); |
| 4280 | webview()->mainFrame()->loadRequest(request); |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4281 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4282 | |
| 4283 | // Just echo back the params in the ACK. |
| 4284 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 4285 | } |
| 4286 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4287 | void RenderViewImpl::OnClosePage() { |
[email protected] | 77fc9b9 | 2011-10-15 16:20:37 | [diff] [blame] | 4288 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4289 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4290 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4291 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 4292 | // calling the FrameLoader's CloseURL method directly. This should be |
| 4293 | // revisited to avoid having two ways to close a page. Having a single way |
| 4294 | // to close that can run onunload is also useful for fixing |
| 4295 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4296 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4297 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4298 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4299 | } |
| 4300 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4301 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 4302 | #if defined(USE_AURA) |
| 4303 | // Aura doesn't care if we switch themes. |
| 4304 | #elif defined(OS_WIN) |
[email protected] | c6d94221 | 2011-03-30 19:02:16 | [diff] [blame] | 4305 | gfx::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4306 | if (webview()) |
| 4307 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4308 | #else // defined(OS_WIN) |
| 4309 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 4310 | NOTIMPLEMENTED(); |
| 4311 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4312 | } |
| 4313 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4314 | void RenderViewImpl::OnDisassociateFromPopupCount() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 4315 | if (decrement_shared_popup_at_destruction_) |
| 4316 | shared_popup_counter_->data--; |
| 4317 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 4318 | decrement_shared_popup_at_destruction_ = false; |
| 4319 | } |
| 4320 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4321 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 4322 | const WebURLError& error, |
| 4323 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4324 | // We only show alternate error pages in the main frame. They are |
| 4325 | // intended to assist the user when navigating, so there is not much |
| 4326 | // value in showing them for failed subframes. Ideally, we would be |
| 4327 | // able to use the TYPED transition type for this, but that flag is |
| 4328 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4329 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4330 | return false; |
| 4331 | |
| 4332 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4333 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4334 | int ec = error.reason; |
| 4335 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 4336 | ec != net::ERR_CONNECTION_FAILED && |
| 4337 | ec != net::ERR_CONNECTION_REFUSED && |
| 4338 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4339 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4340 | return false; |
| 4341 | |
| 4342 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4343 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4344 | if (!error_page_url.is_valid()) |
| 4345 | return false; |
| 4346 | |
| 4347 | // Load an empty page first so there is an immediate response to the error, |
| 4348 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4349 | frame->loadHTMLString(std::string(), |
[email protected] | 144143c | 2010-10-28 08:17:36 | [diff] [blame] | 4350 | GURL(chrome::kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4351 | error.unreachableURL, |
| 4352 | replace); |
| 4353 | |
| 4354 | // Now, create a fetcher for the error page and associate it with the data |
| 4355 | // source we just created via the LoadHTMLString call. That way if another |
| 4356 | // navigation occurs, the fetcher will get destroyed. |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 4357 | DocumentState* document_state = |
| 4358 | DocumentState::FromDataSource(frame->provisionalDataSource()); |
| 4359 | document_state->set_alt_error_page_fetcher( |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4360 | new AltErrorPageResourceFetcher( |
| 4361 | error_page_url, frame, error, |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 4362 | base::Bind(&RenderViewImpl::AltErrorPageFinished, |
| 4363 | base::Unretained(this)))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4364 | return true; |
| 4365 | } |
| 4366 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4367 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
| 4368 | const WebURLError& original_error, |
| 4369 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4370 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4371 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4372 | // will simply display a default error page. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 4373 | LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4374 | } |
| 4375 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4376 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4377 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4378 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4379 | } |
| 4380 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4381 | void RenderViewImpl::OnResize(const gfx::Size& new_size, |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 4382 | const gfx::Rect& resizer_rect, |
| 4383 | bool is_fullscreen) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4384 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4385 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4386 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 4387 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 4388 | ShouldDisplayScrollbars(new_size.width(), new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4389 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 4390 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4391 | } |
| 4392 | |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 4393 | RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4394 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 4395 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 4396 | void RenderViewImpl::WillInitiatePaint() { |
| 4397 | // Notify the pepper plugins that we're about to paint. |
| 4398 | pepper_delegate_.ViewWillInitiatePaint(); |
| 4399 | } |
| 4400 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4401 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 4402 | // Notify the pepper plugins that we've painted, and are waiting to flush. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4403 | pepper_delegate_.ViewInitiatedPaint(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4404 | } |
| 4405 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4406 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4407 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 4408 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 4409 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 4410 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4411 | pepper_delegate_.ViewFlushedPaint(); |
| 4412 | |
[email protected] | 5b1dec8c | 2012-02-07 04:35:38 | [diff] [blame] | 4413 | // If the RenderWidget is closing down then early-exit, otherwise we'll crash. |
| 4414 | // See crbug.com/112921. |
| 4415 | if (!webview()) |
| 4416 | return; |
| 4417 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4418 | WebFrame* main_frame = webview()->mainFrame(); |
| 4419 | |
| 4420 | // If we have a provisional frame we are between the start and commit stages |
| 4421 | // of loading and we don't want to save stats. |
| 4422 | if (!main_frame->provisionalDataSource()) { |
| 4423 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 4424 | DocumentState* document_state = DocumentState::FromDataSource(ds); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4425 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4426 | // TODO(jar): The following code should all be inside a method, probably in |
| 4427 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4428 | Time now = Time::Now(); |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 4429 | if (document_state->first_paint_time().is_null()) { |
| 4430 | document_state->set_first_paint_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4431 | } |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 4432 | if (document_state->first_paint_after_load_time().is_null() && |
| 4433 | !document_state->finish_load_time().is_null()) { |
| 4434 | document_state->set_first_paint_after_load_time(now); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4435 | } |
| 4436 | } |
| 4437 | } |
| 4438 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4439 | void RenderViewImpl::OnViewContextSwapBuffersPosted() { |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 4440 | RenderWidget::OnSwapBuffersPosted(); |
| 4441 | } |
| 4442 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4443 | void RenderViewImpl::OnViewContextSwapBuffersComplete() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 4444 | RenderWidget::OnSwapBuffersComplete(); |
| 4445 | } |
| 4446 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4447 | void RenderViewImpl::OnViewContextSwapBuffersAborted() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 4448 | RenderWidget::OnSwapBuffersAborted(); |
| 4449 | } |
| 4450 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4451 | webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 4452 | const gfx::Rect& paint_bounds, |
| 4453 | TransportDIB** dib, |
| 4454 | gfx::Rect* location, |
| 4455 | gfx::Rect* clip) { |
| 4456 | return pepper_delegate_.GetBitmapForOptimizedPluginPaint( |
| 4457 | paint_bounds, dib, location, clip); |
| 4458 | } |
| 4459 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4460 | gfx::Point RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 4461 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | bcaf227 | 2011-02-15 15:29:43 | [diff] [blame] | 4462 | return gfx::Point(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 4463 | } |
| 4464 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4465 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4466 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4467 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4468 | } |
| 4469 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4470 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4471 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4472 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4473 | |
| 4474 | SetBackground(background); |
| 4475 | } |
| 4476 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4477 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4478 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4479 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4480 | |
| 4481 | #if defined(OS_MACOSX) |
| 4482 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4483 | for (plugin_it = plugin_delegates_.begin(); |
| 4484 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4485 | (*plugin_it)->SetWindowFocus(active); |
| 4486 | } |
| 4487 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4488 | } |
| 4489 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4490 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4491 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4492 | // Inform plugins that their container has changed visibility. |
| 4493 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4494 | for (plugin_it = plugin_delegates_.begin(); |
| 4495 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4496 | (*plugin_it)->SetContainerVisibility(visible); |
| 4497 | } |
| 4498 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4499 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4500 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 4501 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4502 | // Inform plugins that their window's frame has changed. |
| 4503 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4504 | for (plugin_it = plugin_delegates_.begin(); |
| 4505 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4506 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 4507 | } |
| 4508 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4509 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4510 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 4511 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4512 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4513 | // applies to it or not, so inform all the delegates. |
| 4514 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4515 | for (plugin_it = plugin_delegates_.begin(); |
| 4516 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4517 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4518 | } |
| 4519 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4520 | #endif // OS_MACOSX |
| 4521 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4522 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4523 | const EditCommands& edit_commands) { |
| 4524 | edit_commands_ = edit_commands; |
| 4525 | } |
| 4526 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4527 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 4528 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 4529 | WebView* doomed = webview(); |
| 4530 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 4531 | g_view_map.Get().erase(doomed); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 4532 | } |
| 4533 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4534 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4535 | edit_commands_.clear(); |
| 4536 | } |
| 4537 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4538 | bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 4539 | pepper_delegate_.WillHandleMouseEvent(); |
| 4540 | |
| 4541 | // If the mouse is locked, only the current owner of the mouse lock can |
| 4542 | // process mouse events. |
| 4543 | return mouse_lock_dispatcher_->WillHandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 4544 | } |
| 4545 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4546 | void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4547 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 4548 | } |
| 4549 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4550 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 4551 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 4552 | } |
| 4553 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4554 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4555 | RenderWidget::OnWasHidden(); |
| 4556 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4557 | if (webview()) { |
| 4558 | webview()->settings()->setMinimumTimerInterval( |
| 4559 | webkit_glue::kBackgroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 4560 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4561 | } |
| 4562 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 4563 | // Inform PPAPI plugins that their page is no longer visible. |
| 4564 | pepper_delegate_.PageVisibilityChanged(false); |
| 4565 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4566 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 4567 | // Inform NPAPI plugins that their container is no longer visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4568 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4569 | for (plugin_it = plugin_delegates_.begin(); |
| 4570 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4571 | (*plugin_it)->SetContainerVisibility(false); |
| 4572 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4573 | #endif // OS_MACOSX |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4574 | } |
| 4575 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4576 | void RenderViewImpl::OnWasRestored(bool needs_repainting) { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4577 | RenderWidget::OnWasRestored(needs_repainting); |
| 4578 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4579 | if (webview()) { |
| 4580 | webview()->settings()->setMinimumTimerInterval( |
| 4581 | webkit_glue::kForegroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 4582 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4583 | } |
| 4584 | |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 4585 | // Inform PPAPI plugins that their page is visible. |
| 4586 | pepper_delegate_.PageVisibilityChanged(true); |
| 4587 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4588 | #if defined(OS_MACOSX) |
[email protected] | 204f1df | 2012-01-04 20:21:13 | [diff] [blame] | 4589 | // Inform NPAPI plugins that their container is now visible. |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4590 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4591 | for (plugin_it = plugin_delegates_.begin(); |
| 4592 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4593 | (*plugin_it)->SetContainerVisibility(true); |
| 4594 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 4595 | #endif // OS_MACOSX |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4596 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4597 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4598 | bool RenderViewImpl::SupportsAsynchronousSwapBuffers() { |
[email protected] | 555e75d | 2011-10-08 01:23:38 | [diff] [blame] | 4599 | if (WebWidgetHandlesCompositorScheduling()) |
| 4600 | return false; |
| 4601 | |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 4602 | if (queried_for_swapbuffers_complete_callback_) |
| 4603 | return context_has_swapbuffers_complete_callback_; |
| 4604 | |
| 4605 | queried_for_swapbuffers_complete_callback_ = true; |
| 4606 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 4607 | WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D(); |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 4608 | if (context && context->makeContextCurrent()) { |
| 4609 | std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8()); |
| 4610 | context_has_swapbuffers_complete_callback_ = |
| 4611 | extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") |
| 4612 | != std::string::npos; |
| 4613 | } |
| 4614 | |
| 4615 | return context_has_swapbuffers_complete_callback_; |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 4616 | } |
| 4617 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4618 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4619 | RenderWidget::OnSetFocus(enable); |
| 4620 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4621 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 4622 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4623 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4624 | for (plugin_it = plugin_delegates_.begin(); |
| 4625 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 4626 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4627 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 4628 | // activation state to change just like a call to setIsActive. |
| 4629 | if (enable) |
| 4630 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 4631 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4632 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4633 | } |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 4634 | |
| 4635 | // Notify all Pepper plugins. |
| 4636 | pepper_delegate_.OnSetFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4637 | } |
| 4638 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4639 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4640 | void RenderViewImpl::PpapiPluginFocusChanged() { |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4641 | UpdateTextInputState(); |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 4642 | UpdateSelectionBounds(); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4643 | } |
| 4644 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4645 | void RenderViewImpl::PpapiPluginTextInputTypeChanged() { |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 4646 | UpdateTextInputState(); |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4647 | } |
| 4648 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 4649 | void RenderViewImpl::PpapiPluginCaretPositionChanged() { |
| 4650 | UpdateSelectionBounds(); |
| 4651 | } |
| 4652 | |
[email protected] | b25b3ee | 2012-01-13 05:19:54 | [diff] [blame] | 4653 | bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) { |
| 4654 | if (!pepper_delegate_.IsPluginFocused()) |
| 4655 | return false; |
| 4656 | *rect = pepper_delegate_.GetCaretBounds(); |
| 4657 | return true; |
| 4658 | } |
| 4659 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4660 | void RenderViewImpl::PpapiPluginCancelComposition() { |
| 4661 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 4662 | ui::Range range(ui::Range::InvalidRange()); |
| 4663 | Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
| 4664 | } |
| 4665 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4666 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4667 | const string16& text, |
| 4668 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 4669 | int selection_start, |
| 4670 | int selection_end) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4671 | if (pepper_delegate_.IsPluginFocused()) { |
| 4672 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 4673 | pepper_delegate_.OnImeSetComposition(text, |
| 4674 | underlines, |
| 4675 | selection_start, |
| 4676 | selection_end); |
| 4677 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4678 | #if defined(OS_WIN) |
| 4679 | // When a plug-in has focus, we create platform-specific IME data used by |
| 4680 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 4681 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 4682 | // instance ID is the same one as the specified ID.) |
| 4683 | if (focused_plugin_id_ >= 0) { |
| 4684 | std::vector<int> clauses; |
| 4685 | std::vector<int> target; |
| 4686 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 4687 | clauses.push_back(underlines[i].startOffset); |
| 4688 | clauses.push_back(underlines[i].endOffset); |
| 4689 | if (underlines[i].thick) { |
| 4690 | target.clear(); |
| 4691 | target.push_back(underlines[i].startOffset); |
| 4692 | target.push_back(underlines[i].endOffset); |
| 4693 | } |
| 4694 | } |
| 4695 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 4696 | for (it = plugin_delegates_.begin(); |
| 4697 | it != plugin_delegates_.end(); ++it) { |
| 4698 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 4699 | focused_plugin_id_); |
| 4700 | } |
| 4701 | return; |
| 4702 | } |
| 4703 | #endif |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4704 | RenderWidget::OnImeSetComposition(text, |
| 4705 | underlines, |
| 4706 | selection_start, |
| 4707 | selection_end); |
| 4708 | } |
| 4709 | } |
| 4710 | |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 4711 | void RenderViewImpl::OnImeConfirmComposition( |
| 4712 | const string16& text, const ui::Range& replacement_range) { |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4713 | if (pepper_delegate_.IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4714 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 4715 | pepper_delegate_.OnImeConfirmComposition(text); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4716 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4717 | #if defined(OS_WIN) |
| 4718 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 4719 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 4720 | // it to WebKit to prevent WebKit from controlling IMEs. |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 4721 | // TODO(thakis): Honor |replacement_range| for plugins? |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4722 | if (focused_plugin_id_ >= 0) { |
| 4723 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 4724 | for (it = plugin_delegates_.begin(); |
| 4725 | it != plugin_delegates_.end(); ++it) { |
| 4726 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 4727 | } |
| 4728 | return; |
| 4729 | } |
| 4730 | #endif |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 4731 | if (replacement_range.IsValid() && webview()) { |
| 4732 | // Select the text in |replacement_range|, it will then be replaced by |
| 4733 | // text added by the call to RenderWidget::OnImeConfirmComposition(). |
| 4734 | if (WebFrame* frame = webview()->focusedFrame()) { |
[email protected] | 4bacb82 | 2011-11-02 15:10:16 | [diff] [blame] | 4735 | WebRange webrange = WebRange::fromDocumentRange( |
| 4736 | frame, replacement_range.start(), replacement_range.length()); |
| 4737 | if (!webrange.isNull()) |
| 4738 | frame->setSelectionToRange(webrange); |
[email protected] | ebd28ac | 2011-10-13 18:49:05 | [diff] [blame] | 4739 | } |
| 4740 | } |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 4741 | RenderWidget::OnImeConfirmComposition(text, replacement_range); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4742 | } |
| 4743 | } |
| 4744 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4745 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4746 | return pepper_delegate_.IsPluginFocused() ? |
| 4747 | pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType(); |
| 4748 | } |
| 4749 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 4750 | void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
| 4751 | if (pepper_delegate_.IsPluginFocused()) { |
| 4752 | // TODO(kinaba) http://crbug.com/101101 |
| 4753 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 4754 | // use the caret position as an empty range for now. It will be updated |
| 4755 | // after Pepper API equips features related to surrounding text retrieval. |
| 4756 | gfx::Rect caret = pepper_delegate_.GetCaretBounds(); |
| 4757 | *start = caret; |
| 4758 | *end = caret; |
| 4759 | return; |
| 4760 | } |
| 4761 | RenderWidget::GetSelectionBounds(start, end); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 4762 | } |
| 4763 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4764 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4765 | return pepper_delegate_.IsPluginFocused() ? |
| 4766 | pepper_delegate_.CanComposeInline() : true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4767 | } |
| 4768 | |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4769 | #if defined(OS_WIN) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4770 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4771 | if (focused) |
| 4772 | focused_plugin_id_ = plugin_id; |
| 4773 | else |
| 4774 | focused_plugin_id_ = -1; |
| 4775 | } |
| 4776 | #endif |
| 4777 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4778 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4779 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4780 | IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(), |
| 4781 | focused, plugin_id); |
| 4782 | Send(msg); |
| 4783 | } |
| 4784 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4785 | void RenderViewImpl::StartPluginIme() { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4786 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4787 | // This message can be sent during event-handling, and needs to be delivered |
| 4788 | // within that context. |
| 4789 | msg->set_unblock(true); |
| 4790 | Send(msg); |
| 4791 | } |
| 4792 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4793 | gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 4794 | bool opaque, bool root) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4795 | gfx::PluginWindowHandle window = NULL; |
| 4796 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 4797 | routing_id(), opaque, root, &window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 4798 | if (window) { |
| 4799 | fake_plugin_window_handles_.insert(window); |
| 4800 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4801 | return window; |
| 4802 | } |
| 4803 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4804 | void RenderViewImpl::DestroyFakePluginWindowHandle( |
| 4805 | gfx::PluginWindowHandle window) { |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 4806 | if (window && fake_plugin_window_handles_.find(window) != |
| 4807 | fake_plugin_window_handles_.end()) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4808 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 4809 | fake_plugin_window_handles_.erase(window); |
| 4810 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4811 | } |
| 4812 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4813 | void RenderViewImpl::AcceleratedSurfaceSetIOSurface( |
| 4814 | gfx::PluginWindowHandle window, |
| 4815 | int32 width, |
| 4816 | int32 height, |
| 4817 | uint64 io_surface_identifier) { |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4818 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4819 | routing_id(), window, width, height, io_surface_identifier)); |
| 4820 | } |
| 4821 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4822 | void RenderViewImpl::AcceleratedSurfaceSetTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4823 | gfx::PluginWindowHandle window, |
| 4824 | int32 width, |
| 4825 | int32 height, |
| 4826 | TransportDIB::Handle transport_dib) { |
| 4827 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4828 | routing_id(), window, width, height, transport_dib)); |
| 4829 | } |
| 4830 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4831 | TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4832 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4833 | TransportDIB::Handle dib_handle; |
| 4834 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 4835 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4836 | return dib_handle; |
| 4837 | // Return an invalid handle if Send() fails. |
| 4838 | return TransportDIB::DefaultHandleValue(); |
| 4839 | } |
| 4840 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4841 | void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB( |
| 4842 | TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4843 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 4844 | } |
| 4845 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4846 | void RenderViewImpl::AcceleratedSurfaceBuffersSwapped( |
[email protected] | f35d667 | 2010-10-28 21:39:14 | [diff] [blame] | 4847 | gfx::PluginWindowHandle window, uint64 surface_id) { |
| 4848 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped( |
| 4849 | routing_id(), window, surface_id)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4850 | } |
| 4851 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 4852 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4853 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 4854 | const content::FileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4855 | WebFileChooserCompletion* completion) { |
| 4856 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 4857 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 4858 | // This sanity check prevents too many file choose requests from getting |
| 4859 | // queued which could DoS the user. Getting these is most likely a |
| 4860 | // programming error (there are many ways to DoS the user so it's not |
| 4861 | // considered a "real" security check), either in JS requesting many file |
| 4862 | // choosers to pop up, or in a plugin. |
| 4863 | // |
| 4864 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 4865 | // a file picker, which will address this issue in a better way. |
| 4866 | return false; |
| 4867 | } |
| 4868 | |
| 4869 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 4870 | new PendingFileChooser(params, completion))); |
| 4871 | if (file_chooser_completions_.size() == 1) { |
| 4872 | // Actually show the browse dialog when this is the first request. |
| 4873 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 4874 | } |
| 4875 | return true; |
| 4876 | } |
| 4877 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4878 | WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4879 | if (!geolocation_dispatcher_) |
| 4880 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 4881 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 4882 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4883 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4884 | WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 4885 | WebKit::WebSpeechInputListener* listener) { |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 4886 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4887 | if (!speech_input_dispatcher_) |
| 4888 | speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener); |
[email protected] | 9eb100e | 2011-10-14 05:08:22 | [diff] [blame] | 4889 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4890 | return speech_input_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 4891 | } |
| 4892 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4893 | WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4894 | if (!device_orientation_dispatcher_) |
| 4895 | device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this); |
| 4896 | return device_orientation_dispatcher_; |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 4897 | } |
| 4898 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4899 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 4900 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4901 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 4902 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 4903 | // different). |
| 4904 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 4905 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4906 | int minimum_percent = static_cast<int>( |
| 4907 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 4908 | int maximum_percent = static_cast<int>( |
| 4909 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4910 | |
| 4911 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 4912 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 4913 | } |
| 4914 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4915 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4916 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 4917 | float zoom_level = webview()->zoomLevel(); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4918 | // Tell the browser which url got zoomed so it can update the menu and the |
| 4919 | // saved values if necessary |
| 4920 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 4921 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4922 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4923 | } |
| 4924 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4925 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 4926 | const WebString& base_url, |
| 4927 | const WebString& url, |
| 4928 | const WebString& title) { |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 4929 | GURL base(base_url); |
| 4930 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 4931 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 4932 | return; |
| 4933 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 4934 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 4935 | UTF16ToUTF8(scheme), |
| 4936 | absolute_url, |
| 4937 | title)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 4938 | } |
| 4939 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4940 | WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 4941 | WebKit::WebPageVisibilityState current_state = is_hidden() ? |
| 4942 | WebKit::WebPageVisibilityStateHidden : |
| 4943 | WebKit::WebPageVisibilityStateVisible; |
| 4944 | WebKit::WebPageVisibilityState override_state = current_state; |
| 4945 | if (content::GetContentClient()->renderer()-> |
| 4946 | ShouldOverridePageVisibilityState(this, |
| 4947 | &override_state)) |
| 4948 | return override_state; |
| 4949 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 4950 | } |
| 4951 | |
[email protected] | 273558fb | 2012-01-12 15:03:51 | [diff] [blame] | 4952 | WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() { |
| 4953 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 4954 | if (!cmd_line->HasSwitch(switches::kEnableMediaStream)) |
| 4955 | return NULL; |
| 4956 | EnsureMediaStreamImpl(); |
| 4957 | return media_stream_impl_; |
| 4958 | } |
| 4959 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4960 | bool RenderViewImpl::IsNonLocalTopLevelNavigation( |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4961 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 4962 | // Must be a top level frame. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4963 | if (frame->parent() != NULL) |
| 4964 | return false; |
| 4965 | |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 4966 | // Navigations initiated within Webkit are not sent out to the external host |
| 4967 | // in the following cases. |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 4968 | // 1. The url scheme is not http/https |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 4969 | // 2. The origin of the url and the opener is the same in which case the |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 4970 | // opener relationship is maintained. |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 4971 | // 3. Reloads/form submits/back forward navigations |
[email protected] | abbfaec | 2011-05-23 23:57:33 | [diff] [blame] | 4972 | if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 4973 | return false; |
| 4974 | |
[email protected] | 2fc22d1 | 2010-12-02 23:08:16 | [diff] [blame] | 4975 | // Not interested in reloads/form submits/resubmits/back forward navigations. |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 4976 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 4977 | type != WebKit::WebNavigationTypeFormSubmitted && |
[email protected] | 2fc22d1 | 2010-12-02 23:08:16 | [diff] [blame] | 4978 | type != WebKit::WebNavigationTypeFormResubmitted && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 4979 | type != WebKit::WebNavigationTypeBackForward) { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 4980 | // The opener relationship between the new window and the parent allows the |
| 4981 | // new window to script the parent and vice versa. This is not allowed if |
| 4982 | // the origins of the two domains are different. This can be treated as a |
| 4983 | // top level navigation and routed back to the host. |
| 4984 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 4985 | if (!opener) { |
[email protected] | 8696536 | 2011-04-21 18:42:51 | [diff] [blame] | 4986 | return true; |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 4987 | } else { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4988 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 4989 | return true; |
| 4990 | } |
| 4991 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4992 | return false; |
| 4993 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4994 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4995 | void RenderViewImpl::OnAsyncFileOpened( |
| 4996 | base::PlatformFileError error_code, |
| 4997 | IPC::PlatformFileForTransit file_for_transit, |
| 4998 | int message_id) { |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 4999 | pepper_delegate_.OnAsyncFileOpened( |
| 5000 | error_code, |
| 5001 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 5002 | message_id); |
| 5003 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 5004 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5005 | void RenderViewImpl::OnPpapiBrokerChannelCreated( |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 5006 | int request_id, |
| 5007 | base::ProcessHandle broker_process_handle, |
[email protected] | d5430507 | 2011-06-22 20:58:43 | [diff] [blame] | 5008 | const IPC::ChannelHandle& handle) { |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 5009 | pepper_delegate_.OnPpapiBrokerChannelCreated(request_id, |
| 5010 | broker_process_handle, |
| 5011 | handle); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 5012 | } |
| 5013 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 5014 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5015 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 5016 | if (external_popup_menu_ == NULL) { |
| 5017 | // Crash reports from the field indicate that we can be notified with a |
| 5018 | // NULL external popup menu (we probably get notified twice). |
| 5019 | // If you hit this please file a bug against jcivelli and include the page |
| 5020 | // and steps to repro. |
| 5021 | NOTREACHED(); |
| 5022 | return; |
| 5023 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 5024 | external_popup_menu_->DidSelectItem(selected_index); |
| 5025 | external_popup_menu_.reset(); |
| 5026 | } |
| 5027 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 5028 | |
[email protected] | 1b4209f | 2011-01-07 00:25:40 | [diff] [blame] | 5029 | #if defined(ENABLE_FLAPPER_HACKS) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5030 | void RenderViewImpl::OnConnectTcpACK( |
[email protected] | 1b4209f | 2011-01-07 00:25:40 | [diff] [blame] | 5031 | int request_id, |
| 5032 | IPC::PlatformFileForTransit socket_for_transit, |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 5033 | const PP_NetAddress_Private& local_addr, |
| 5034 | const PP_NetAddress_Private& remote_addr) { |
[email protected] | 1b4209f | 2011-01-07 00:25:40 | [diff] [blame] | 5035 | pepper_delegate_.OnConnectTcpACK( |
| 5036 | request_id, |
| 5037 | IPC::PlatformFileForTransitToPlatformFile(socket_for_transit), |
| 5038 | local_addr, |
| 5039 | remote_addr); |
| 5040 | } |
| 5041 | #endif |
[email protected] | a6097f4 | 2011-01-10 08:50:51 | [diff] [blame] | 5042 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5043 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 5044 | const content::CustomContextMenuContext& custom_context) { |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 5045 | if (custom_context.is_pepper_menu) |
| 5046 | pepper_delegate_.OnContextMenuClosed(custom_context); |
| 5047 | else |
| 5048 | context_menu_node_.reset(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 5049 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 5050 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5051 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 5052 | if (!webview()) |
| 5053 | return; |
| 5054 | WebFrame* main_frame = webview()->mainFrame(); |
| 5055 | if (!main_frame) |
| 5056 | return; |
| 5057 | main_frame->enableViewSourceMode(true); |
| 5058 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 5059 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5060 | bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
[email protected] | ab21f2c | 2011-11-19 00:50:08 | [diff] [blame] | 5061 | return !!RenderThreadImpl::current()->compositor_thread(); |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 5062 | } |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 5063 | |
[email protected] | 64d0e19 | 2011-12-09 14:44:20 | [diff] [blame] | 5064 | void RenderViewImpl::OnJavaBridgeInit() { |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 5065 | DCHECK(!java_bridge_dispatcher_.get()); |
[email protected] | 464750f | 2011-10-24 23:16:18 | [diff] [blame] | 5066 | #if defined(ENABLE_JAVA_BRIDGE) |
[email protected] | 64d0e19 | 2011-12-09 14:44:20 | [diff] [blame] | 5067 | java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this)); |
[email protected] | 464750f | 2011-10-24 23:16:18 | [diff] [blame] | 5068 | #endif |
[email protected] | 7f3c7af | 2011-10-20 22:52:51 | [diff] [blame] | 5069 | } |