[email protected] | 1b4209f | 2011-01-07 00:25:40 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 12 | #include "base/callback.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 14 | #include "base/compiler_specific.h" |
[email protected] | 005bab0 | 2011-10-07 18:36:00 | [diff] [blame] | 15 | #include "base/json/json_value_serializer.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 16 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 17 | #include "base/lazy_instance.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 18 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 19 | #include "base/path_service.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 20 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "base/string_piece.h" |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 22 | #include "base/string_split.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | #include "base/string_util.h" |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 24 | #include "base/sys_string_conversions.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 25 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 26 | #include "base/utf_string_conversions.h" |
[email protected] | e93e04e | 2011-03-14 00:27:10 | [diff] [blame] | 27 | #include "content/common/appcache/appcache_dispatcher.h" |
[email protected] | 127dd58 | 2011-03-16 21:32:10 | [diff] [blame] | 28 | #include "content/common/clipboard_messages.h" |
[email protected] | db803aae | 2011-03-05 02:00:42 | [diff] [blame] | 29 | #include "content/common/content_constants.h" |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 30 | #include "content/common/content_switches.h" |
[email protected] | 37666cf | 2011-03-13 21:51:42 | [diff] [blame] | 31 | #include "content/common/database_messages.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 32 | #include "content/common/drag_messages.h" |
[email protected] | 7ef40ffe1 | 2011-03-08 05:05:28 | [diff] [blame] | 33 | #include "content/common/file_system/file_system_dispatcher.h" |
| 34 | #include "content/common/file_system/webfilesystem_callback_dispatcher.h" |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 35 | #include "content/common/intents_messages.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 36 | #include "content/common/notification_service.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] | 6091604 | 2011-03-19 00:43:36 | [diff] [blame] | 40 | #include "content/common/renderer_preferences.h" |
[email protected] | 940895b | 2011-08-20 00:50:05 | [diff] [blame] | 41 | #include "content/common/request_extra_data.h" |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 42 | #include "content/common/url_constants.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 43 | #include "content/common/view_messages.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 44 | #include "content/public/common/bindings_policy.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 45 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 46 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 47 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 48 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 49 | #include "content/renderer/device_orientation_dispatcher.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 50 | #include "content/renderer/devtools_agent.h" |
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 51 | #include "content/renderer/external_popup_menu.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 52 | #include "content/renderer/geolocation_dispatcher.h" |
[email protected] | a03a222 | 2011-05-25 21:26:40 | [diff] [blame] | 53 | #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | 1ef9313 | 2011-09-16 18:33:47 | [diff] [blame] | 54 | #include "content/renderer/intents_dispatcher.h" |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 55 | #include "content/renderer/load_progress_tracker.h" |
[email protected] | 25803d15 | 2011-06-14 01:18:08 | [diff] [blame] | 56 | #include "content/renderer/media/audio_message_filter.h" |
[email protected] | ccc70d8e | 2011-03-16 20:40:37 | [diff] [blame] | 57 | #include "content/renderer/media/audio_renderer_impl.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 58 | #include "content/renderer/media/media_stream_impl.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 59 | #include "content/renderer/media/render_media_log.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 60 | #include "content/renderer/mhtml_generator.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 61 | #include "content/renderer/notification_provider.h" |
[email protected] | ccc70d8e | 2011-03-16 20:40:37 | [diff] [blame] | 62 | #include "content/renderer/p2p/socket_dispatcher.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 63 | #include "content/renderer/plugin_channel_host.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 64 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 65 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 66 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 67 | #include "content/renderer/renderer_accessibility.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 68 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
| 69 | #include "content/renderer/renderer_webstoragenamespace_impl.h" |
[email protected] | 230b7ef | 2011-03-16 22:30:19 | [diff] [blame] | 70 | #include "content/renderer/speech_input_dispatcher.h" |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 71 | #include "content/renderer/text_input_client_observer.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 72 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 73 | #include "content/renderer/web_ui_bindings.h" |
[email protected] | 6f51608 | 2011-03-17 19:15:35 | [diff] [blame] | 74 | #include "content/renderer/webplugin_delegate_proxy.h" |
| 75 | #include "content/renderer/websharedworker_proxy.h" |
| 76 | #include "content/renderer/webworker_proxy.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 77 | #include "media/base/filter_collection.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 78 | #include "media/base/media_switches.h" |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 79 | #include "media/base/message_loop_factory_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | #include "net/base/escape.h" |
| 81 | #include "net/base/net_errors.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 82 | #include "net/http/http_util.h" |
[email protected] | 9d9f1bb | 2011-02-23 22:10:57 | [diff] [blame] | 83 | #include "ppapi/c/private/ppb_flash_net_connector.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 84 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" |
| 85 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
| 86 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 87 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 88 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" |
| 89 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 90 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 91 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 92 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" |
| 93 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" |
| 94 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 95 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 96 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h" |
| 97 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
| 98 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h" |
| 99 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 100 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
[email protected] | 69f110d6 | 2011-03-17 19:01:14 | [diff] [blame] | 101 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 102 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 103 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 104 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
| 105 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 106 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h" |
| 107 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
| 108 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h" |
| 109 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
| 110 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
| 111 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 112 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h" |
| 113 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 114 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 115 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" |
| 116 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
| 117 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 118 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 119 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 120 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 121 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
| 122 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 123 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 124 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
| 125 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 126 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 127 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 128 | #include "ui/base/message_box_flags.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 129 | #include "ui/gfx/native_widget_types.h" |
| 130 | #include "ui/gfx/point.h" |
| 131 | #include "ui/gfx/rect.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 132 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 133 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | 25e18f8 | 2010-10-27 16:38:43 | [diff] [blame] | 134 | #include "webkit/glue/alt_error_page_resource_fetcher.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 135 | #include "webkit/glue/context_menu.h" |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 136 | #include "webkit/glue/dom_operations.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 137 | #include "webkit/glue/form_data.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 138 | #include "webkit/glue/form_field.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 139 | #include "webkit/glue/glue_serialize.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 140 | #include "webkit/glue/media/video_renderer_impl.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 141 | #include "webkit/glue/password_form_dom_manager.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 142 | #include "webkit/glue/webdropdata.h" |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 143 | #include "webkit/glue/webkit_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 144 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 145 | #include "webkit/glue/webmediaplayer_impl.h" |
[email protected] | b00ba70 | 2011-08-17 01:41:03 | [diff] [blame] | 146 | #include "webkit/glue/weburlloader_impl.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 147 | #include "webkit/plugins/npapi/default_plugin_shared.h" |
| 148 | #include "webkit/plugins/npapi/plugin_list.h" |
| 149 | #include "webkit/plugins/npapi/webplugin_delegate.h" |
| 150 | #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
| 151 | #include "webkit/plugins/npapi/webplugin_impl.h" |
| 152 | #include "webkit/plugins/npapi/webview_plugin.h" |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 153 | #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 155 | #if defined(OS_WIN) |
| 156 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 157 | // * theming |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 158 | #include "ui/gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 159 | #elif defined(USE_X11) |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 160 | #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 42e5c86 | 2011-04-07 22:13:51 | [diff] [blame] | 161 | #include "ui/gfx/native_theme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 162 | #elif defined(OS_MACOSX) |
| 163 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 164 | #endif |
| 165 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 166 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 167 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 168 | using WebKit::WebApplicationCacheHost; |
| 169 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 170 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 171 | using WebKit::WebColor; |
| 172 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 173 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 174 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 175 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 176 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 177 | using WebKit::WebDataSource; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 178 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 179 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 180 | using WebKit::WebDragOperation; |
| 181 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 182 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 183 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 184 | using WebKit::WebExternalPopupMenu; |
| 185 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 186 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 187 | using WebKit::WebFileSystem; |
| 188 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 189 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 190 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 191 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 192 | using WebKit::WebFrame; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 193 | using WebKit::WebHistoryItem; |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 194 | using WebKit::WebIconURL; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 195 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 196 | using WebKit::WebInputElement; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 197 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 198 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 199 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 200 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 201 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 202 | using WebKit::WebNode; |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 203 | using WebKit::WebPageSerializer; |
| 204 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 205 | using WebKit::WebPlugin; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 206 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 207 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 208 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 209 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 210 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 211 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 212 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 213 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 214 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 215 | using WebKit::WebSecurityOrigin; |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 216 | using WebKit::WebSecurityPolicy; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 217 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 218 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 219 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 220 | using WebKit::WebStorageNamespace; |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 221 | using WebKit::WebStorageQuotaCallbacks; |
| 222 | using WebKit::WebStorageQuotaError; |
| 223 | using WebKit::WebStorageQuotaType; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 224 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 225 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 226 | using WebKit::WebTextDirection; |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 227 | using WebKit::WebTouchEvent; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 228 | using WebKit::WebURL; |
| 229 | using WebKit::WebURLError; |
| 230 | using WebKit::WebURLRequest; |
| 231 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 232 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 233 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 234 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 235 | using WebKit::WebWindowFeatures; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 236 | using WebKit::WebWorker; |
| 237 | using WebKit::WebWorkerClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 238 | using appcache::WebApplicationCacheHostImpl; |
| 239 | using base::Time; |
| 240 | using base::TimeDelta; |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 241 | using content::NavigationState; |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 242 | using content::RenderThread; |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 243 | using content::RenderViewObserver; |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 244 | using content::RenderViewVisitor; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 245 | using content::V8ValueConverter; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 246 | using webkit_glue::AltErrorPageResourceFetcher; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 247 | using webkit_glue::FormField; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 248 | using webkit_glue::PasswordForm; |
| 249 | using webkit_glue::PasswordFormDomManager; |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 250 | using webkit_glue::ResourceFetcher; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 251 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 252 | //----------------------------------------------------------------------------- |
| 253 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 254 | typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 255 | static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED); |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 256 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 257 | // Time, in seconds, we delay before sending content state changes (such as form |
| 258 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 259 | // spamming the browser. |
| 260 | // To avoid having tab/session restore require sending a message to get the |
| 261 | // current content state during tab closing we use a shorter timeout for the |
| 262 | // foreground renderer. This means there is a small window of time from which |
| 263 | // content state is modified and not sent to session restore, but this is |
| 264 | // better than having to wake up all renderers during shutdown. |
| 265 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 266 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 267 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 268 | // The maximum number of popups that can be spawned from one page. |
| 269 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 270 | |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 271 | static const float kScalingIncrement = 0.1f; |
| 272 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 273 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 274 | WebVector<WebURL> urls; |
| 275 | ds->redirectChain(urls); |
| 276 | result->reserve(urls.size()); |
| 277 | for (size_t i = 0; i < urls.size(); ++i) |
| 278 | result->push_back(urls[i]); |
| 279 | } |
| 280 | |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 281 | // If |data_source| is non-null and has a NavigationState associated with it, |
| 282 | // the AltErrorPageResourceFetcher is reset. |
| 283 | static void StopAltErrorPageFetcher(WebDataSource* data_source) { |
| 284 | if (data_source) { |
| 285 | NavigationState* state = NavigationState::FromDataSource(data_source); |
| 286 | if (state) |
| 287 | state->set_alt_error_page_fetcher(NULL); |
| 288 | } |
| 289 | } |
| 290 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | /////////////////////////////////////////////////////////////////////////////// |
| 292 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 293 | int32 RenderViewImpl::next_page_id_ = 1; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 294 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 295 | struct RenderViewImpl::PendingFileChooser { |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 296 | PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
| 297 | WebFileChooserCompletion* c) |
| 298 | : params(p), |
| 299 | completion(c) { |
| 300 | } |
| 301 | ViewHostMsg_RunFileChooser_Params params; |
| 302 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 303 | }; |
| 304 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 305 | RenderViewImpl::RenderViewImpl(gfx::NativeViewId parent_hwnd, |
| 306 | int32 opener_id, |
| 307 | const RendererPreferences& renderer_prefs, |
| 308 | const WebPreferences& webkit_prefs, |
| 309 | SharedRenderViewCounter* counter, |
| 310 | int32 routing_id, |
| 311 | int64 session_storage_namespace_id, |
| 312 | const string16& frame_name) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 313 | : RenderWidget(WebKit::WebPopupTypeNone), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 314 | webkit_preferences_(webkit_prefs), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 315 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 316 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 317 | send_preferred_size_changes_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 318 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 319 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 320 | opened_by_user_gesture_(true), |
| 321 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 322 | page_id_(-1), |
| 323 | last_page_id_sent_to_browser_(-1), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 324 | history_list_offset_(-1), |
| 325 | history_list_length_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 326 | target_url_status_(TARGET_NONE), |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 327 | cached_is_main_frame_pinned_to_left_(false), |
| 328 | cached_is_main_frame_pinned_to_right_(false), |
| 329 | cached_has_main_frame_horizontal_scrollbar_(false), |
| 330 | cached_has_main_frame_vertical_scrollbar_(false), |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 331 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 332 | #if defined(OS_WIN) |
| 333 | focused_plugin_id_(-1), |
| 334 | #endif |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 335 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 336 | geolocation_dispatcher_(NULL), |
| 337 | speech_input_dispatcher_(NULL), |
| 338 | device_orientation_dispatcher_(NULL), |
[email protected] | cae8c849 | 2011-03-03 11:12:18 | [diff] [blame] | 339 | p2p_socket_dispatcher_(NULL), |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 340 | devtools_agent_(NULL), |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 341 | renderer_accessibility_(NULL), |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 342 | session_storage_namespace_id_(session_storage_namespace_id), |
| 343 | handling_select_range_(false) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 344 | routing_id_ = routing_id; |
| 345 | if (opener_id != MSG_ROUTING_NONE) |
| 346 | opener_id_ = opener_id; |
| 347 | |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 348 | webwidget_ = WebView::create(this); |
| 349 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 350 | if (counter) { |
| 351 | shared_popup_counter_ = counter; |
| 352 | shared_popup_counter_->data++; |
| 353 | decrement_shared_popup_at_destruction_ = true; |
| 354 | } else { |
| 355 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 356 | decrement_shared_popup_at_destruction_ = false; |
| 357 | } |
| 358 | |
[email protected] | 1ef9313 | 2011-09-16 18:33:47 | [diff] [blame] | 359 | intents_dispatcher_ = new IntentsDispatcher(this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 360 | notification_provider_ = new NotificationProvider(this); |
| 361 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 362 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 363 | // Take a reference on behalf of the RenderThread. This will be balanced |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 364 | // when we receive ViewMsg_ClosePage. |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 365 | AddRef(); |
| 366 | |
| 367 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 368 | // completing initialization. Otherwise, we can finish it now. |
| 369 | if (opener_id == MSG_ROUTING_NONE) { |
| 370 | did_show_ = true; |
[email protected] | 2d7c855 | 2011-06-27 19:21:55 | [diff] [blame] | 371 | CompleteInit(parent_hwnd); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 374 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
| 375 | webkit_preferences_.Apply(webview()); |
| 376 | webview()->initializeMainFrame(this); |
[email protected] | 2024c92 | 2011-09-02 23:34:35 | [diff] [blame] | 377 | if (!frame_name.empty()) |
| 378 | webview()->mainFrame()->setName(frame_name); |
[email protected] | 34c61bd5 | 2011-05-02 19:38:33 | [diff] [blame] | 379 | webview()->settings()->setMinimumTimerInterval( |
| 380 | is_hidden() ? webkit_glue::kBackgroundTabTimerInterval : |
| 381 | webkit_glue::kForegroundTabTimerInterval); |
| 382 | |
| 383 | OnSetRendererPrefs(renderer_prefs); |
| 384 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 385 | host_window_ = parent_hwnd; |
| 386 | |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 387 | #if defined(ENABLE_P2P_APIS) |
[email protected] | b3f8f972 | 2011-08-25 20:56:07 | [diff] [blame] | 388 | p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this); |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 389 | #endif |
[email protected] | cae8c849 | 2011-03-03 11:12:18 | [diff] [blame] | 390 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 391 | new MHTMLGenerator(this); |
[email protected] | 86a7d3c | 2011-09-12 16:45:32 | [diff] [blame] | 392 | #if defined(OS_MACOSX) |
| 393 | new TextInputClientObserver(this); |
| 394 | #endif // defined(OS_MACOSX) |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 395 | |
[email protected] | c5c1d6d | 2011-07-28 18:42:41 | [diff] [blame] | 396 | devtools_agent_ = new DevToolsAgent(this); |
[email protected] | 8262245 | 2011-07-22 09:57:20 | [diff] [blame] | 397 | |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 398 | renderer_accessibility_ = new RendererAccessibility(this); |
| 399 | |
| 400 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 401 | if (command_line.HasSwitch(switches::kEnableMediaStream)) { |
| 402 | media_stream_impl_ = new MediaStreamImpl( |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 403 | RenderThreadImpl::current()->video_capture_impl_manager()); |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 406 | content::GetContentClient()->renderer()->RenderViewCreated(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 407 | } |
| 408 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 409 | RenderViewImpl::~RenderViewImpl() { |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 410 | history_page_ids_.clear(); |
| 411 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 412 | if (decrement_shared_popup_at_destruction_) |
| 413 | shared_popup_counter_->data--; |
| 414 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 415 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 416 | while (!file_chooser_completions_.empty()) { |
| 417 | if (file_chooser_completions_.front()->completion) { |
| 418 | file_chooser_completions_.front()->completion->didChooseFile( |
| 419 | WebVector<WebString>()); |
| 420 | } |
| 421 | file_chooser_completions_.pop_front(); |
| 422 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 423 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 424 | #if defined(OS_MACOSX) |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 425 | // Destroy all fake plugin window handles on the browser side. |
| 426 | while (!fake_plugin_window_handles_.empty()) { |
| 427 | // Make sure no NULL plugin window handles were inserted into this list. |
| 428 | DCHECK(*fake_plugin_window_handles_.begin()); |
| 429 | // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
| 430 | DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
| 431 | } |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 432 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 433 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 434 | #ifndef NDEBUG |
| 435 | // Make sure we are no longer referenced by the ViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 436 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 437 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 438 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 439 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 440 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 441 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone()); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 442 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 446 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 447 | ViewMap* views = g_view_map.Pointer(); |
| 448 | ViewMap::iterator it = views->find(webview); |
| 449 | return it == views->end() ? NULL : it->second; |
| 450 | } |
| 451 | |
| 452 | /*static*/ |
| 453 | content::RenderView* |
| 454 | content::RenderView::FromWebView(WebKit::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 455 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /*static*/ |
| 459 | void content::RenderView::ForEach(content::RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 460 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 461 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 462 | if (!visitor->Visit(it->second)) |
| 463 | return; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 468 | RenderViewImpl* RenderViewImpl::Create( |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 469 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 470 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 471 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 472 | const WebPreferences& webkit_prefs, |
| 473 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 474 | int32 routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 475 | int64 session_storage_namespace_id, |
| 476 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 478 | return new RenderViewImpl( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 479 | parent_hwnd, |
| 480 | opener_id, |
| 481 | renderer_prefs, |
| 482 | webkit_prefs, |
| 483 | counter, |
| 484 | routing_id, |
| 485 | session_storage_namespace_id, |
| 486 | frame_name); // adds reference |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 487 | } |
| 488 | |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 489 | // static |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 490 | void RenderViewImpl::SetNextPageID(int32 next_page_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 491 | // This method should only be called during process startup, and the given |
| 492 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 493 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 494 | DCHECK(next_page_id >= next_page_id_); |
| 495 | next_page_id_ = next_page_id; |
| 496 | } |
| 497 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 498 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 499 | observers_.AddObserver(observer); |
| 500 | } |
| 501 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 502 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 503 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 504 | observers_.RemoveObserver(observer); |
| 505 | } |
| 506 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 507 | WebKit::WebView* RenderViewImpl::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 508 | return static_cast<WebKit::WebView*>(webwidget()); |
| 509 | } |
| 510 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 511 | void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) { |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 512 | if (!enabled) { |
| 513 | load_progress_tracker_.reset(NULL); |
| 514 | return; |
| 515 | } |
| 516 | if (load_progress_tracker_ == NULL) |
| 517 | load_progress_tracker_.reset(new LoadProgressTracker(this)); |
| 518 | } |
| 519 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 520 | void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) { |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 521 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 522 | } |
| 523 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 524 | void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 525 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 526 | // If the renderer is visible, set initial visibility and focus state. |
| 527 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 528 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 529 | delegate->SetContainerVisibility(true); |
| 530 | if (webview() && webview()->isActive()) |
| 531 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 532 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 533 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 534 | // Plugins start assuming the content has focus (so that they work in |
| 535 | // environments where RenderView isn't hosting them), so we always have to |
| 536 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 537 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 540 | void RenderViewImpl::UnregisterPluginDelegate( |
| 541 | WebPluginDelegateProxy* delegate) { |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 542 | plugin_delegates_.erase(delegate); |
| 543 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 544 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 545 | bool RenderViewImpl::GetPluginInfo(const GURL& url, |
| 546 | const GURL& page_url, |
| 547 | const std::string& mime_type, |
| 548 | webkit::WebPluginInfo* plugin_info, |
| 549 | std::string* actual_mime_type) { |
[email protected] | 4a7d639 | 2011-09-19 20:55:08 | [diff] [blame] | 550 | bool found = false; |
| 551 | Send(new ViewHostMsg_GetPluginInfo( |
| 552 | routing_id_, url, page_url, mime_type, &found, plugin_info, |
| 553 | actual_mime_type)); |
| 554 | return found; |
| 555 | } |
| 556 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 557 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 558 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 559 | if (main_frame) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 560 | content::GetContentClient()->SetActiveURL(main_frame->document().url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 561 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 562 | ObserverListBase<RenderViewObserver>::Iterator it(observers_); |
| 563 | RenderViewObserver* observer; |
| 564 | while ((observer = it.GetNext()) != NULL) |
| 565 | if (observer->OnMessageReceived(message)) |
| 566 | return true; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 567 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 568 | bool handled = true; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 569 | bool msg_is_ok = true; |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 570 | IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 571 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 572 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 573 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 574 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 575 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 576 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 577 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 578 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 579 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 580 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 581 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 582 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
| 583 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 584 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 585 | IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 586 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 587 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 588 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 589 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 590 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 591 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 592 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 593 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 594 | OnSetZoomLevelForLoadingURL) |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 595 | IPC_MESSAGE_HANDLER(ViewMsg_ExitFullscreen, OnExitFullscreen) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 596 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 597 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 598 | OnResetPageEncodingToDefault) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 599 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 600 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 601 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 602 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 603 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 604 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 605 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| 606 | IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved) |
| 607 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 608 | OnDragSourceSystemDragEnded) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 609 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
[email protected] | d098079 | 2011-02-13 19:41:40 | [diff] [blame] | 610 | IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 611 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 612 | IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect, |
| 613 | OnScrollFocusedEditableNodeIntoRect) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 614 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 615 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 616 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 617 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 618 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 619 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 620 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 621 | IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 622 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 623 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 624 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 625 | OnDisassociateFromPopupCount) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 626 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 627 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 628 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 629 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 630 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 631 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 632 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 633 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 634 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 635 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 636 | #if defined(OS_MACOSX) |
| 637 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 638 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 639 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted, |
| 640 | OnPluginImeCompositionCompleted) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 641 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 642 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 643 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 644 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 645 | OnCustomContextMenuAction) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 646 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 647 | IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated, |
| 648 | OnPpapiBrokerChannelCreated) |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 649 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 650 | OnGetAllSavableResourceLinksForCurrentPage) |
| 651 | IPC_MESSAGE_HANDLER( |
| 652 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 653 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 654 | #if defined(OS_MACOSX) |
| 655 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 656 | #endif |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 657 | IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) |
[email protected] | f055793 | 2011-01-25 20:20:51 | [diff] [blame] | 658 | // TODO(viettrungluu): Move to a separate message filter. |
| 659 | #if defined(ENABLE_FLAPPER_HACKS) |
| 660 | IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) |
| 661 | #endif |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 662 | #if defined(OS_MACOSX) |
| 663 | IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 664 | #endif |
[email protected] | 08bb1e72 | 2011-07-30 19:13:04 | [diff] [blame] | 665 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateRemoteAccessClientFirewallTraversal, |
| 666 | OnUpdateRemoteAccessClientFirewallTraversal) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 667 | IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune, |
| 668 | OnSetHistoryLengthAndPrune) |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 669 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 670 | IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK) |
| 671 | IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost) |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 672 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 673 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 674 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 675 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 676 | |
| 677 | if (!msg_is_ok) { |
| 678 | // The message had a handler, but its deserialization failed. |
| 679 | // Kill the renderer to avoid potential spoofing attacks. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 680 | CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 681 | } |
| 682 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 683 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 684 | } |
| 685 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 686 | void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 687 | if (!webview()) |
| 688 | return; |
| 689 | |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 690 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url)); |
| 691 | |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 692 | bool is_reload = |
| 693 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
| 694 | params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; |
| 695 | |
| 696 | // If this is a stale back/forward (due to a recent navigation the browser |
| 697 | // didn't know about), ignore it. |
| 698 | if (IsBackForwardToStaleEntry(params, is_reload)) |
| 699 | return; |
| 700 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 701 | // Swap this renderer back in if necessary. |
| 702 | if (is_swapped_out_) |
| 703 | SetSwappedOut(false); |
| 704 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 705 | history_list_offset_ = params.current_history_list_offset; |
| 706 | history_list_length_ = params.current_history_list_length; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 707 | if (history_list_length_ >= 0) |
| 708 | history_page_ids_.resize(history_list_length_, -1); |
| 709 | if (params.pending_history_list_offset >= 0 && |
| 710 | params.pending_history_list_offset < history_list_length_) |
| 711 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 712 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 713 | content::GetContentClient()->SetActiveURL(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 714 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 715 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 716 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 717 | // We cannot reload if we do not have any history state. This happens, for |
| 718 | // example, when recovering from a crash. Our workaround here is a bit of |
| 719 | // a hack since it means that reload after a crashed tab does not cause an |
| 720 | // end-to-end cache validation. |
| 721 | is_reload = false; |
| 722 | } |
| 723 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 724 | // A navigation resulting from loading a javascript URL should not be treated |
| 725 | // as a browser initiated event. Instead, we want it to look as if the page |
| 726 | // initiated any load resulting from JS execution. |
| 727 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 728 | NavigationState* state = NavigationState::CreateBrowserInitiated( |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 729 | params.page_id, |
| 730 | params.pending_history_list_offset, |
| 731 | params.transition, |
| 732 | params.request_time); |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 733 | if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 734 | // We're doing a load of a page that was restored from the last session. |
| 735 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 736 | // which can result in stale data for pages that are set to expire. We |
| 737 | // explicitly override that by setting the policy here so that as |
| 738 | // necessary we load from the network. |
| 739 | state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy); |
| 740 | } |
| 741 | pending_navigation_state_.reset(state); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 742 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 743 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 744 | NavigationState* navigation_state = pending_navigation_state_.get(); |
| 745 | |
[email protected] | 48a5c77 | 2011-04-18 23:50:50 | [diff] [blame] | 746 | if (navigation_state) { |
| 747 | // New loads need to reset the error page fetcher. Otherwise if there is an |
| 748 | // outstanding error page fetcher it may complete and clobber the current |
| 749 | // page load. |
| 750 | navigation_state->set_alt_error_page_fetcher(NULL); |
| 751 | } |
| 752 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 753 | // If we are reloading, then WebKit will use the history state of the current |
| 754 | // page, so we should just ignore any given history state. Otherwise, if we |
| 755 | // have history state, then we need to navigate to it, which corresponds to a |
| 756 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 757 | if (is_reload) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 758 | if (navigation_state) |
| 759 | navigation_state->set_load_type(NavigationState::RELOAD); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 760 | bool ignore_cache = (params.navigation_type == |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 761 | ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 762 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 763 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 764 | // 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] | 765 | DCHECK_NE(params.page_id, -1); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 766 | if (navigation_state) |
| 767 | navigation_state->set_load_type(NavigationState::HISTORY_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 768 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 769 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 770 | } else { |
| 771 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 772 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 773 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 774 | // A session history navigation should have been accompanied by state. |
| 775 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 776 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 777 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 778 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 779 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 780 | if (params.referrer.is_valid()) { |
[email protected] | 20dc3cad | 2011-04-20 17:27:17 | [diff] [blame] | 781 | if (!WebSecurityPolicy::shouldHideReferrer( |
| 782 | params.url, |
| 783 | WebString::fromUTF8(params.referrer.spec()))) { |
| 784 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 785 | WebString::fromUTF8(params.referrer.spec())); |
| 786 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 787 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 788 | |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 789 | if (!params.extra_headers.empty()) { |
| 790 | for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), |
| 791 | params.extra_headers.end(), "\n"); |
| 792 | i.GetNext(); ) { |
| 793 | request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 794 | WebString::fromUTF8(i.values())); |
| 795 | } |
| 796 | } |
| 797 | |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 798 | if (navigation_state) |
| 799 | navigation_state->set_load_type(NavigationState::NORMAL_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 800 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 801 | } |
| 802 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 803 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 804 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 805 | } |
| 806 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 807 | bool RenderViewImpl::IsBackForwardToStaleEntry( |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 808 | const ViewMsg_Navigate_Params& params, |
| 809 | bool is_reload) { |
| 810 | // Make sure this isn't a back/forward to an entry we have already cropped |
| 811 | // or replaced from our history, before the browser knew about it. If so, |
| 812 | // a new navigation has committed in the mean time, and we can ignore this. |
| 813 | bool is_back_forward = !is_reload && !params.state.empty(); |
| 814 | |
| 815 | // Note: if the history_list_length_ is 0 for a back/forward, we must be |
| 816 | // restoring from a previous session. We'll update our state in OnNavigate. |
| 817 | if (!is_back_forward || history_list_length_ <= 0) |
| 818 | return false; |
| 819 | |
| 820 | DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_); |
| 821 | |
| 822 | // Check for whether the forward history has been cropped due to a recent |
| 823 | // navigation the browser didn't know about. |
| 824 | if (params.pending_history_list_offset >= history_list_length_) |
| 825 | return true; |
| 826 | |
| 827 | // Check for whether this entry has been replaced with a new one. |
| 828 | int expected_page_id = |
| 829 | history_page_ids_[params.pending_history_list_offset]; |
[email protected] | 9978b8f0 | 2011-08-13 16:17:44 | [diff] [blame] | 830 | if (expected_page_id > 0 && params.page_id != expected_page_id) { |
| 831 | if (params.page_id < expected_page_id) |
| 832 | return true; |
| 833 | |
| 834 | // Otherwise we've removed an earlier entry and should have shifted all |
| 835 | // entries left. For now, it's ok to lazily update the list. |
| 836 | // TODO(creis): Notify all live renderers when we remove entries from |
| 837 | // the front of the list, so that we don't hit this case. |
| 838 | history_page_ids_[params.pending_history_list_offset] = params.page_id; |
| 839 | } |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 840 | |
| 841 | return false; |
| 842 | } |
| 843 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 844 | // Stop loading the current page |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 845 | void RenderViewImpl::OnStop() { |
[email protected] | 6a8f511 | 2011-05-13 16:38:44 | [diff] [blame] | 846 | if (webview()) { |
| 847 | WebFrame* main_frame = webview()->mainFrame(); |
| 848 | // Stop the alt error page fetcher. If we let it continue it may complete |
| 849 | // and cause RenderViewHostManager to swap to this RenderView, even though |
| 850 | // it may no longer be active. |
| 851 | StopAltErrorPageFetcher(main_frame->provisionalDataSource()); |
| 852 | StopAltErrorPageFetcher(main_frame->dataSource()); |
| 853 | main_frame->stopLoading(); |
| 854 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 855 | } |
| 856 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 857 | // Reload current focused frame. |
| 858 | // 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] | 859 | void RenderViewImpl::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 860 | if (webview() && webview()->focusedFrame()) { |
| 861 | // We always obey the cache (ignore_cache=false) here. |
| 862 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 863 | // a cache-ignoring reload of the frame. |
| 864 | webview()->focusedFrame()->reload(false); |
| 865 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 866 | } |
| 867 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 868 | void RenderViewImpl::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 869 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 870 | } |
| 871 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 872 | void RenderViewImpl::OnExecuteEditCommand(const std::string& name, |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 873 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 874 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 875 | return; |
| 876 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 877 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 878 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 879 | } |
| 880 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 881 | void RenderViewImpl::OnUpdateTargetURLAck() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 882 | // Check if there is a targeturl waiting to be sent. |
| 883 | if (target_url_status_ == TARGET_PENDING) { |
| 884 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 885 | pending_target_url_)); |
| 886 | } |
| 887 | |
| 888 | target_url_status_ = TARGET_NONE; |
| 889 | } |
| 890 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 891 | void RenderViewImpl::OnUndo() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 892 | if (!webview()) |
| 893 | return; |
| 894 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 895 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 896 | } |
| 897 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 898 | void RenderViewImpl::OnRedo() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 899 | if (!webview()) |
| 900 | return; |
| 901 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 902 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 903 | } |
| 904 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 905 | void RenderViewImpl::OnCut() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 906 | if (!webview()) |
| 907 | return; |
| 908 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 909 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 910 | } |
| 911 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 912 | void RenderViewImpl::OnCopy() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 913 | if (!webview()) |
| 914 | return; |
| 915 | |
[email protected] | f6b1856b | 2011-06-29 22:02:53 | [diff] [blame] | 916 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), |
| 917 | context_menu_node_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 918 | } |
| 919 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 920 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 921 | void RenderViewImpl::OnCopyToFindPboard() { |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 922 | if (!webview()) |
| 923 | return; |
| 924 | |
| 925 | // Since the find pasteboard supports only plain text, this can be simpler |
| 926 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 927 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 928 | if (frame->hasSelection()) { |
| 929 | string16 selection = frame->selectionAsText(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 930 | RenderThread::Get()->Send( |
[email protected] | 7e358974 | 2011-03-10 18:49:17 | [diff] [blame] | 931 | new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 932 | } |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 933 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 934 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 935 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 936 | void RenderViewImpl::OnPaste() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 937 | if (!webview()) |
| 938 | return; |
| 939 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 940 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 941 | } |
| 942 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 943 | void RenderViewImpl::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 944 | if (!webview()) |
| 945 | return; |
| 946 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 947 | WebFrame* frame = webview()->focusedFrame(); |
| 948 | if (!frame->hasSelection()) |
| 949 | frame->selectWordAroundCaret(); |
| 950 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 951 | } |
| 952 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 953 | void RenderViewImpl::OnDelete() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 954 | if (!webview()) |
| 955 | return; |
| 956 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 957 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 958 | } |
| 959 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 960 | void RenderViewImpl::OnSelectAll() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 961 | if (!webview()) |
| 962 | return; |
| 963 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 964 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 965 | WebString::fromUTF8("SelectAll")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 966 | } |
| 967 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 968 | void RenderViewImpl::OnSelectRange(const gfx::Point& start, |
| 969 | const gfx::Point& end) { |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 970 | if (!webview()) |
| 971 | return; |
| 972 | |
| 973 | handling_select_range_ = true; |
| 974 | webview()->focusedFrame()->selectRange(start, end); |
| 975 | handling_select_range_ = false; |
| 976 | } |
| 977 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 978 | void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length, |
| 979 | int32 minimum_page_id) { |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 980 | DCHECK(history_length >= 0); |
| 981 | DCHECK(history_list_offset_ == history_list_length_ - 1); |
| 982 | DCHECK(minimum_page_id >= -1); |
| 983 | |
| 984 | // Generate the new list. |
| 985 | std::vector<int32> new_history_page_ids(history_length, -1); |
| 986 | for (size_t i = 0; i < history_page_ids_.size(); ++i) { |
| 987 | if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id) |
| 988 | continue; |
| 989 | new_history_page_ids.push_back(history_page_ids_[i]); |
| 990 | } |
| 991 | new_history_page_ids.swap(history_page_ids_); |
| 992 | |
| 993 | // Update indexes. |
| 994 | history_list_length_ = history_page_ids_.size(); |
| 995 | history_list_offset_ = history_list_length_ - 1; |
| 996 | } |
| 997 | |
| 998 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 999 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1000 | if (!webview()) |
| 1001 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1002 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1003 | } |
| 1004 | |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1005 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1006 | void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) { |
[email protected] | 4274b3e | 2011-08-09 19:09:33 | [diff] [blame] | 1007 | if (!webview()) |
| 1008 | return; |
| 1009 | if (in_live_resize) |
| 1010 | webview()->willStartLiveResize(); |
| 1011 | else |
| 1012 | webview()->willEndLiveResize(); |
[email protected] | 54ca3ca89 | 2011-06-07 21:14:54 | [diff] [blame] | 1013 | } |
| 1014 | #endif |
| 1015 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1016 | void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( |
| 1017 | const gfx::Rect& rect) { |
[email protected] | 13a1e4c3c | 2011-02-03 21:07:09 | [diff] [blame] | 1018 | WebKit::WebNode node = GetFocusedNode(); |
| 1019 | if (!node.isNull()) { |
| 1020 | if (IsEditableNode(node)) |
[email protected] | 333ec8d0 | 2011-09-16 18:59:19 | [diff] [blame] | 1021 | webview()->scrollFocusedNodeIntoRect(rect); |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1025 | /////////////////////////////////////////////////////////////////////////////// |
| 1026 | |
| 1027 | // Tell the embedding application that the URL of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1028 | void RenderViewImpl::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1029 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1030 | DCHECK(ds); |
| 1031 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1032 | const WebURLRequest& request = ds->request(); |
| 1033 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1034 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1035 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1036 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1037 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1038 | |
| 1039 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1040 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1041 | params.is_post = false; |
| 1042 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1043 | params.frame_id = frame->identifier(); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1044 | params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1045 | params.socket_address.set_port(response.remotePort()); |
[email protected] | b9a7c6d4 | 2011-02-25 02:13:03 | [diff] [blame] | 1046 | params.was_fetched_via_proxy = response.wasFetchedViaProxy(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1047 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1048 | if (!navigation_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1049 | // SSL state specified in the request takes precedence over the one in the |
| 1050 | // response. |
| 1051 | // So far this is only intended for error pages that are not expected to be |
| 1052 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1053 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1054 | params.security_info = navigation_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1055 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1056 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1060 | if (ds->hasUnreachableURL()) { |
| 1061 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1062 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1063 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1064 | } |
| 1065 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1066 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1067 | params.should_update_history = !ds->hasUnreachableURL() && |
[email protected] | b7df1b7 | 2011-02-10 00:08:04 | [diff] [blame] | 1068 | !response.isMultipartPayload() && (response.httpStatusCode() != 404); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1069 | |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1070 | params.searchable_form_url = navigation_state->searchable_form_url(); |
| 1071 | params.searchable_form_encoding = |
| 1072 | navigation_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1073 | |
| 1074 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1075 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1076 | if (password_form_data) |
| 1077 | params.password_form = *password_form_data; |
| 1078 | |
| 1079 | params.gesture = navigation_gesture_; |
| 1080 | navigation_gesture_ = NavigationGestureUnknown; |
| 1081 | |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1082 | // Make navigation state a part of the FrameNavigate message so that commited |
| 1083 | // entry had it at all times. |
| 1084 | const WebHistoryItem& item = frame->currentHistoryItem(); |
| 1085 | if (!item.isNull()) { |
| 1086 | params.content_state = webkit_glue::HistoryItemToString(item); |
| 1087 | } else { |
| 1088 | params.content_state = |
| 1089 | webkit_glue::CreateHistoryStateForURL(GURL(request.url())); |
| 1090 | } |
| 1091 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1092 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1093 | // Top-level navigation. |
| 1094 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1095 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1096 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1097 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1098 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1099 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1100 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1101 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1102 | } else { |
| 1103 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1104 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1105 | } |
| 1106 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1107 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1108 | // This zoom level was merely recorded transiently for this load. We can |
| 1109 | // erase it now. If at some point we reload this page, the browser will |
| 1110 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1111 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1112 | } |
| 1113 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1114 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1115 | // will also call us back which will cause us to send a message to |
| 1116 | // update TabContents. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1117 | webview()->zoomLimitsChanged( |
| 1118 | WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier), |
| 1119 | WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1120 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1121 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1122 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1123 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1124 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1125 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 1126 | // If the main frame does a load, it should not be reported as a subframe |
| 1127 | // navigation. This can occur in the following case: |
| 1128 | // 1. You're on a site with frames. |
| 1129 | // 2. You do a subframe navigation. This is stored with transition type |
| 1130 | // MANUAL_SUBFRAME. |
| 1131 | // 3. You navigate to some non-frame site, say, google.com. |
| 1132 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1133 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1134 | // We don't want that, because any navigation that changes the toplevel |
| 1135 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1136 | // update the URL bar, etc). |
| 1137 | params.transition = PageTransition::LINK; |
| 1138 | } |
| 1139 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1140 | // If we have a valid consumed client redirect source, |
| 1141 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1142 | // so we set the referrer and transition to match. |
| 1143 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1144 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1145 | params.referrer = completed_client_redirect_src_; |
| 1146 | params.transition = static_cast<PageTransition::Type>( |
| 1147 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 1148 | } else { |
| 1149 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1150 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1151 | params.referrer = GURL( |
| 1152 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1153 | } |
| 1154 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1155 | string16 method = request.httpMethod(); |
| 1156 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1157 | params.is_post = true; |
| 1158 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1159 | // Save some histogram data so we can compute the average memory used per |
| 1160 | // page load of the glyphs. |
| 1161 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1162 | webkit_glue::GetGlyphPageCount()); |
| 1163 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1164 | // This message needs to be sent before any of allowScripts(), |
| 1165 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1166 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1167 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1168 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1169 | } else { |
| 1170 | // Subframe navigation: the type depends on whether this navigation |
| 1171 | // generated a new session history entry. When they do generate a session |
| 1172 | // history entry, it means the user initiated the navigation and we should |
| 1173 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1174 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1175 | if (page_id_ > last_page_id_sent_to_browser_) |
| 1176 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 1177 | else |
| 1178 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 1179 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1180 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1181 | } |
| 1182 | |
| 1183 | last_page_id_sent_to_browser_ = |
| 1184 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1185 | |
| 1186 | // 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] | 1187 | // we don't want the transition type to persist. Just clear it. |
| 1188 | navigation_state->set_transition_type(PageTransition::LINK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1192 | void RenderViewImpl::UpdateTitle(WebFrame* frame, |
| 1193 | const string16& title, |
| 1194 | WebTextDirection title_direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1195 | // Ignore all but top level navigations. |
| 1196 | if (frame->parent()) |
| 1197 | return; |
| 1198 | |
| 1199 | string16 shortened_title = title.substr(0, content::kMaxTitleChars); |
| 1200 | Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title, |
| 1201 | title_direction)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1202 | } |
| 1203 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1204 | void RenderViewImpl::UpdateEncoding(WebFrame* frame, |
| 1205 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1206 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1207 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1208 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1209 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1210 | last_encoding_name_ = encoding_name; |
| 1211 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1212 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 1216 | // Sends the last committed session history state to the browser so it will be |
| 1217 | // saved before we navigate to a new page. This must be called *before* the |
| 1218 | // page ID has been updated so we know what it was. |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1219 | void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1220 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1221 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1222 | // there is no past session history to record. |
| 1223 | if (page_id_ == -1) |
| 1224 | return; |
| 1225 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1226 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1227 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1228 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1229 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1230 | |
| 1231 | Send(new ViewHostMsg_UpdateState( |
| 1232 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1233 | } |
| 1234 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1235 | void RenderViewImpl::OpenURL(WebFrame* frame, |
| 1236 | const GURL& url, |
| 1237 | const GURL& referrer, |
| 1238 | WebNavigationPolicy policy) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1239 | Send(new ViewHostMsg_OpenURL( |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1240 | routing_id_, |
| 1241 | url, |
| 1242 | referrer, |
| 1243 | NavigationPolicyToDisposition(policy), |
| 1244 | frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1245 | } |
| 1246 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1247 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1248 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1249 | void RenderViewImpl::LoadNavigationErrorPage( |
| 1250 | WebFrame* frame, |
| 1251 | const WebURLRequest& failed_request, |
| 1252 | const WebURLError& error, |
| 1253 | const std::string& html, |
| 1254 | bool replace) { |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1255 | std::string alt_html; |
| 1256 | const std::string* error_html; |
| 1257 | |
| 1258 | if (!html.empty()) { |
| 1259 | error_html = &html; |
| 1260 | } else { |
| 1261 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 1262 | failed_request, error, &alt_html, NULL); |
| 1263 | error_html = &alt_html; |
| 1264 | } |
| 1265 | |
| 1266 | frame->loadHTMLString(*error_html, |
[email protected] | 144143c | 2010-10-28 08:17:36 | [diff] [blame] | 1267 | GURL(chrome::kUnreachableWebDataURL), |
[email protected] | 21d61e5 | 2011-03-18 19:08:25 | [diff] [blame] | 1268 | error.unreachableURL, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1269 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1270 | } |
| 1271 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1272 | bool RenderViewImpl::RunJavaScriptMessage(int type, |
| 1273 | const string16& message, |
| 1274 | const string16& default_value, |
| 1275 | const GURL& frame_url, |
| 1276 | string16* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1277 | bool success = false; |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1278 | string16 result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1279 | if (!result) |
| 1280 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1281 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1282 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1283 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1284 | return success; |
| 1285 | } |
| 1286 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1287 | bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1288 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1289 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1290 | // it is particularly important that we do not call willEnterModalLoop as |
| 1291 | // that would defer resource loads for the dialog itself. |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1292 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1293 | RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1294 | |
| 1295 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1296 | return Send(message); |
| 1297 | } |
| 1298 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1299 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1300 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1301 | WebView* RenderViewImpl::createView( |
[email protected] | 844acf37 | 2011-01-14 10:49:27 | [diff] [blame] | 1302 | WebFrame* creator, |
| 1303 | const WebURLRequest& request, |
| 1304 | const WebWindowFeatures& features, |
| 1305 | const WebString& frame_name) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1306 | // Check to make sure we aren't overloading on popups. |
| 1307 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1308 | return NULL; |
| 1309 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1310 | ViewHostMsg_CreateWindow_Params params; |
| 1311 | params.opener_id = routing_id_; |
| 1312 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1313 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1314 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1315 | params.frame_name = frame_name; |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1316 | params.opener_frame_id = creator->identifier(); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1317 | params.opener_url = creator->document().url(); |
| 1318 | params.opener_security_origin = |
| 1319 | creator->document().securityOrigin().toString().utf8(); |
[email protected] | 41e6550 | 2011-01-21 09:29:11 | [diff] [blame] | 1320 | if (!request.isNull()) |
| 1321 | params.target_url = request.url(); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1322 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1323 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1324 | int64 cloned_session_storage_namespace_id; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1325 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1326 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1327 | RenderThread::Get()->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1328 | new ViewHostMsg_CreateWindow(params, |
| 1329 | &routing_id, |
| 1330 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1331 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1332 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1333 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1334 | RenderViewImpl* view = RenderViewImpl::Create( |
| 1335 | 0, |
| 1336 | routing_id_, |
| 1337 | renderer_preferences_, |
| 1338 | webkit_preferences_, |
| 1339 | shared_popup_counter_, |
| 1340 | routing_id, |
| 1341 | cloned_session_storage_namespace_id, |
| 1342 | frame_name); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1343 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1344 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1345 | // Record whether the creator frame is trying to suppress the opener field. |
| 1346 | view->opener_suppressed_ = opener_suppressed; |
| 1347 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1348 | // Record the security origin of the creator. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1349 | GURL creator_url(creator->document().securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1350 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1351 | creator_url = GURL(); |
| 1352 | view->creator_url_ = creator_url; |
| 1353 | |
| 1354 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1355 | // the new render view (we don't need the browser to send the URL back down). |
| 1356 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1357 | |
| 1358 | return view->webview(); |
| 1359 | } |
| 1360 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1361 | WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1362 | RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1363 | return widget->webwidget(); |
| 1364 | } |
| 1365 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1366 | WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) { |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1367 | // TODO(jcivelli): Remove this deprecated method when its been removed from |
| 1368 | // the WebViewClient interface. It's been replaced by |
| 1369 | // createExternalPopupMenu. |
| 1370 | NOTREACHED(); |
| 1371 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1372 | } |
| 1373 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1374 | WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu( |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1375 | const WebPopupMenuInfo& popup_menu_info, |
| 1376 | WebExternalPopupMenuClient* popup_menu_client) { |
| 1377 | DCHECK(!external_popup_menu_.get()); |
| 1378 | external_popup_menu_.reset( |
| 1379 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 1380 | return external_popup_menu_.get(); |
| 1381 | } |
| 1382 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1383 | RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer( |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 1384 | webkit::ppapi::PluginInstance* plugin) { |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1385 | GURL active_url; |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 1386 | if (webview() && webview()->mainFrame()) |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1387 | active_url = GURL(webview()->mainFrame()->document().url()); |
[email protected] | d91233b7e | 2011-03-29 20:33:53 | [diff] [blame] | 1388 | RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create( |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1389 | routing_id_, plugin, active_url); |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1390 | widget->show(WebKit::WebNavigationPolicyIgnore); |
[email protected] | 92abcb83 | 2011-01-06 20:39:56 | [diff] [blame] | 1391 | return widget; |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1392 | } |
| 1393 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1394 | WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace( |
| 1395 | unsigned quota) { |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1396 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1397 | return WebStorageNamespace::createSessionStorageNamespace(quota); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1398 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1399 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1400 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1401 | } |
| 1402 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1403 | void RenderViewImpl::didAddMessageToConsole( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1404 | const WebConsoleMessage& message, const WebString& source_name, |
| 1405 | unsigned source_line) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1406 | logging::LogSeverity log_severity = logging::LOG_VERBOSE; |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 1407 | switch (message.level) { |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1408 | case WebConsoleMessage::LevelTip: |
| 1409 | log_severity = logging::LOG_VERBOSE; |
| 1410 | break; |
| 1411 | case WebConsoleMessage::LevelLog: |
| 1412 | log_severity = logging::LOG_INFO; |
| 1413 | break; |
| 1414 | case WebConsoleMessage::LevelWarning: |
| 1415 | log_severity = logging::LOG_WARNING; |
| 1416 | break; |
| 1417 | case WebConsoleMessage::LevelError: |
| 1418 | log_severity = logging::LOG_ERROR; |
| 1419 | break; |
| 1420 | default: |
| 1421 | NOTREACHED(); |
| 1422 | } |
| 1423 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1424 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
[email protected] | d09df4b | 2011-04-11 19:01:08 | [diff] [blame] | 1425 | static_cast<int32>(log_severity), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1426 | message.text, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1427 | static_cast<int32>(source_line), |
[email protected] | aa21d2a | 2011-08-08 23:56:31 | [diff] [blame] | 1428 | source_name)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1429 | } |
| 1430 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1431 | void RenderViewImpl::printPage(WebFrame* frame) { |
[email protected] | d91ddfc | 2011-04-07 18:33:42 | [diff] [blame] | 1432 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1433 | } |
| 1434 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1435 | WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1436 | return notification_provider_; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1437 | } |
| 1438 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1439 | bool RenderViewImpl::enumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1440 | const WebString& path, |
| 1441 | WebFileChooserCompletion* chooser_completion) { |
| 1442 | int id = enumeration_completion_id_++; |
| 1443 | enumeration_completions_[id] = chooser_completion; |
| 1444 | return Send(new ViewHostMsg_EnumerateDirectory( |
| 1445 | routing_id_, |
| 1446 | id, |
| 1447 | webkit_glue::WebStringToFilePath(path))); |
| 1448 | } |
| 1449 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1450 | void RenderViewImpl::didStartLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1451 | if (is_loading_) { |
| 1452 | DLOG(WARNING) << "didStartLoading called while loading"; |
| 1453 | return; |
| 1454 | } |
| 1455 | |
| 1456 | is_loading_ = true; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1457 | |
| 1458 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 1459 | |
| 1460 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1461 | } |
| 1462 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1463 | void RenderViewImpl::didStopLoading() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1464 | if (!is_loading_) { |
| 1465 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1466 | return; |
| 1467 | } |
| 1468 | |
| 1469 | is_loading_ = false; |
| 1470 | |
| 1471 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1472 | // when done loading. This currently isn't an issue as the favicon is only |
| 1473 | // displayed when done loading. Ideally we would send notification when |
| 1474 | // finished parsing the head, but webkit doesn't support that yet. |
| 1475 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1476 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1477 | |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 1478 | if (load_progress_tracker_ != NULL) |
| 1479 | load_progress_tracker_->DidStopLoading(); |
| 1480 | |
[email protected] | 93b9d69 | 2011-04-13 00:44:31 | [diff] [blame] | 1481 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1482 | } |
| 1483 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1484 | void RenderViewImpl::didChangeLoadProgress(WebFrame* frame, |
| 1485 | double load_progress) { |
[email protected] | 9010941 | 2010-12-15 17:14:24 | [diff] [blame] | 1486 | if (load_progress_tracker_ != NULL) |
| 1487 | load_progress_tracker_->DidChangeLoadProgress(frame, load_progress); |
| 1488 | } |
| 1489 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1490 | bool RenderViewImpl::isSmartInsertDeleteEnabled() { |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1491 | #if defined(OS_MACOSX) |
| 1492 | return true; |
| 1493 | #else |
| 1494 | return false; |
| 1495 | #endif |
| 1496 | } |
| 1497 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1498 | bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() { |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1499 | #if defined(OS_WIN) |
| 1500 | return true; |
| 1501 | #else |
| 1502 | return false; |
| 1503 | #endif |
| 1504 | } |
| 1505 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1506 | void RenderViewImpl::didChangeSelection(bool is_empty_selection) { |
[email protected] | 0ff0ff3 | 2010-12-21 19:34:42 | [diff] [blame] | 1507 | #if defined(OS_POSIX) |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1508 | if (!handling_input_event_ && !handling_select_range_) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1509 | return; |
[email protected] | 4fb6014 | 2011-08-09 02:22:08 | [diff] [blame] | 1510 | handling_select_range_ = false; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1511 | |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 1512 | SyncSelectionIfRequired(); |
[email protected] | 0ff0ff3 | 2010-12-21 19:34:42 | [diff] [blame] | 1513 | #endif // defined(OS_POSIX) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1514 | } |
| 1515 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1516 | void RenderViewImpl::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1517 | const std::string& name = UTF16ToUTF8(command_name); |
| 1518 | if (StartsWithASCII(name, "Move", true) || |
| 1519 | StartsWithASCII(name, "Insert", true) || |
| 1520 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1521 | return; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1522 | RenderThreadImpl::current()->RecordUserMetrics(name); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1523 | } |
| 1524 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1525 | bool RenderViewImpl::handleCurrentKeyboardEvent() { |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1526 | if (edit_commands_.empty()) |
| 1527 | return false; |
| 1528 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1529 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1530 | if (!frame) |
| 1531 | return false; |
| 1532 | |
| 1533 | EditCommands::iterator it = edit_commands_.begin(); |
| 1534 | EditCommands::iterator end = edit_commands_.end(); |
| 1535 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1536 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1537 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1538 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1539 | // key (but it's the exception). Once one edit command is not executed, it |
| 1540 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1541 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 1542 | WebString::fromUTF8(it->value))) |
| 1543 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1544 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1545 | } |
| 1546 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1547 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1548 | } |
| 1549 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1550 | bool RenderViewImpl::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 1551 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1552 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 1553 | // Do not open the file dialog in a hidden RenderView. |
| 1554 | if (is_hidden()) |
| 1555 | return false; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1556 | ViewHostMsg_RunFileChooser_Params ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1557 | if (params.directory) |
[email protected] | 0aed2f5 | 2011-03-23 18:06:36 | [diff] [blame] | 1558 | ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1559 | else if (params.multiSelect) |
[email protected] | 0aed2f5 | 2011-03-23 18:06:36 | [diff] [blame] | 1560 | ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple; |
[email protected] | 459fba8 | 2011-10-13 02:48:50 | [diff] [blame^] | 1561 | else if (params.saveAs) |
| 1562 | ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Save; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1563 | else |
[email protected] | 0aed2f5 | 2011-03-23 18:06:36 | [diff] [blame] | 1564 | ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1565 | ipc_params.title = params.title; |
| 1566 | ipc_params.default_file_name = |
| 1567 | webkit_glue::WebStringToFilePath(params.initialValue); |
[email protected] | 09994913 | 2010-09-08 20:24:59 | [diff] [blame] | 1568 | ipc_params.accept_types = params.acceptTypes; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1569 | |
| 1570 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1571 | } |
| 1572 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1573 | void RenderViewImpl::runModalAlertDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1574 | WebFrame* frame, const WebString& message) { |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 1575 | RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1576 | message, |
| 1577 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1578 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1579 | NULL); |
| 1580 | } |
| 1581 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1582 | bool RenderViewImpl::runModalConfirmDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1583 | WebFrame* frame, const WebString& message) { |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 1584 | return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1585 | message, |
| 1586 | string16(), |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1587 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1588 | NULL); |
| 1589 | } |
| 1590 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1591 | bool RenderViewImpl::runModalPromptDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1592 | WebFrame* frame, const WebString& message, const WebString& default_value, |
| 1593 | WebString* actual_value) { |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1594 | string16 result; |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 1595 | bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1596 | message, |
| 1597 | default_value, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1598 | frame->document().url(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1599 | &result); |
| 1600 | if (ok) |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1601 | actual_value->assign(result); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1602 | return ok; |
| 1603 | } |
| 1604 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1605 | bool RenderViewImpl::runModalBeforeUnloadDialog( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1606 | WebFrame* frame, const WebString& message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1607 | // If we are swapping out, we have already run the beforeunload handler. |
| 1608 | // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 1609 | // at all, to avoid running it twice. |
| 1610 | if (is_swapped_out_) |
| 1611 | return true; |
| 1612 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1613 | bool success = false; |
| 1614 | // This is an ignored return value, but is included so we can accept the same |
| 1615 | // response as RunJavaScriptMessage. |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 1616 | string16 ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1617 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 1618 | routing_id_, frame->document().url(), message, |
| 1619 | &success, &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1620 | return success; |
| 1621 | } |
| 1622 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1623 | void RenderViewImpl::showContextMenu( |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1624 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1625 | ContextMenuParams params = ContextMenuParams(data); |
[email protected] | 7fcd9b7 | 2011-07-27 16:52:37 | [diff] [blame] | 1626 | |
| 1627 | // frame is NULL if invoked by BlockedPlugin. |
| 1628 | if (frame) |
| 1629 | params.frame_id = frame->identifier(); |
| 1630 | |
[email protected] | db803aae | 2011-03-05 02:00:42 | [diff] [blame] | 1631 | // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 1632 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 1633 | // in the context menu. |
| 1634 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 1635 | // data encoded images. We should have a way to save them. |
[email protected] | db803aae | 2011-03-05 02:00:42 | [diff] [blame] | 1636 | if (params.src_url.spec().size() > content::kMaxURLChars) |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 1637 | params.src_url = GURL(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 1638 | context_menu_node_ = data.node; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1639 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1640 | } |
| 1641 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1642 | bool RenderViewImpl::supportsFullscreen() { |
[email protected] | 52f139e2c | 2010-06-11 16:56:09 | [diff] [blame] | 1643 | return CommandLine::ForCurrentProcess()->HasSwitch( |
| 1644 | switches::kEnableVideoFullscreen); |
| 1645 | } |
| 1646 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1647 | void RenderViewImpl::enterFullscreenForNode(const WebKit::WebNode& node) { |
[email protected] | 52f139e2c | 2010-06-11 16:56:09 | [diff] [blame] | 1648 | NOTIMPLEMENTED(); |
| 1649 | } |
| 1650 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1651 | void RenderViewImpl::exitFullscreenForNode(const WebKit::WebNode& node) { |
[email protected] | 52f139e2c | 2010-06-11 16:56:09 | [diff] [blame] | 1652 | NOTIMPLEMENTED(); |
| 1653 | } |
| 1654 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1655 | void RenderViewImpl::enterFullscreen() { |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1656 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true)); |
| 1657 | } |
| 1658 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1659 | void RenderViewImpl::exitFullscreen() { |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1660 | Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| 1661 | } |
| 1662 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1663 | void RenderViewImpl::setStatusText(const WebString& text) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1664 | } |
| 1665 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1666 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 1667 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1668 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1669 | if (latest_url == target_url_) |
| 1670 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1671 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1672 | // Tell the browser to display a destination link. |
| 1673 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1674 | target_url_status_ == TARGET_PENDING) { |
| 1675 | // If we have a request in-flight, save the URL to be sent when we |
| 1676 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1677 | // any existing pending sends. |
| 1678 | pending_target_url_ = latest_url; |
| 1679 | target_url_status_ = TARGET_PENDING; |
| 1680 | } else { |
| 1681 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 1682 | target_url_ = latest_url; |
| 1683 | target_url_status_ = TARGET_INFLIGHT; |
| 1684 | } |
| 1685 | } |
| 1686 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1687 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary() { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1688 | int delay; |
| 1689 | if (send_content_state_immediately_) |
| 1690 | delay = 0; |
| 1691 | else if (is_hidden()) |
| 1692 | delay = kDelaySecondsForContentStateSyncHidden; |
| 1693 | else |
| 1694 | delay = kDelaySecondsForContentStateSync; |
| 1695 | |
| 1696 | if (nav_state_sync_timer_.IsRunning()) { |
| 1697 | // The timer is already running. If the delay of the timer maches the amount |
| 1698 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1699 | // gets started with the right delay. |
| 1700 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 1701 | return; |
| 1702 | nav_state_sync_timer_.Stop(); |
| 1703 | } |
| 1704 | |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 1705 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1706 | &RenderViewImpl::SyncNavigationState); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1707 | } |
| 1708 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1709 | void RenderViewImpl::setMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1710 | mouse_over_url_ = GURL(url); |
| 1711 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1712 | } |
| 1713 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1714 | void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1715 | focus_url_ = GURL(url); |
| 1716 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1717 | } |
| 1718 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1719 | void RenderViewImpl::startDragging(const WebDragData& data, |
| 1720 | WebDragOperationsMask mask, |
| 1721 | const WebImage& image, |
| 1722 | const WebPoint& imageOffset) { |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1723 | #if WEBKIT_USING_SKIA |
| 1724 | SkBitmap bitmap(image.getSkBitmap()); |
| 1725 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 1726 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1727 | #endif |
| 1728 | |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 1729 | Send(new DragHostMsg_StartDragging(routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1730 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1731 | mask, |
| 1732 | bitmap, |
| 1733 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1734 | } |
| 1735 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1736 | bool RenderViewImpl::acceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1737 | return renderer_preferences_.can_accept_load_drops; |
| 1738 | } |
| 1739 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1740 | void RenderViewImpl::focusNext() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1741 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 1742 | } |
| 1743 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1744 | void RenderViewImpl::focusPrevious() { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1745 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 1746 | } |
| 1747 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1748 | void RenderViewImpl::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1749 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 1750 | |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 1751 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node)); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 1752 | } |
| 1753 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1754 | void RenderViewImpl::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1755 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 1756 | } |
| 1757 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1758 | int RenderViewImpl::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1759 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1760 | } |
| 1761 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1762 | int RenderViewImpl::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1763 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1764 | } |
| 1765 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1766 | void RenderViewImpl::postAccessibilityNotification( |
[email protected] | 063afcb | 2011-09-29 07:54:32 | [diff] [blame] | 1767 | const WebAccessibilityObject& obj, |
| 1768 | WebAccessibilityNotification notification) { |
| 1769 | renderer_accessibility_->PostAccessibilityNotification(obj, notification); |
| 1770 | } |
| 1771 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1772 | void RenderViewImpl::didUpdateInspectorSetting(const WebString& key, |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 1773 | const WebString& value) { |
| 1774 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 1775 | key.utf8(), |
| 1776 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1777 | } |
| 1778 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1779 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 1780 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1781 | void RenderViewImpl::didFocus() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1782 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 1783 | // we won't have to test for user gesture anymore and we can |
| 1784 | // move that code back to render_widget.cc |
| 1785 | if (webview() && webview()->mainFrame() && |
| 1786 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 1787 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 1788 | } |
| 1789 | } |
| 1790 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1791 | void RenderViewImpl::didBlur() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1792 | // TODO(jcivelli): see TODO above in didFocus(). |
| 1793 | if (webview() && webview()->mainFrame() && |
| 1794 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 1795 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 1796 | } |
| 1797 | } |
| 1798 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1799 | // 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] | 1800 | // that was created via RenderViewImpl::CreateWebView. So, we wait until this |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1801 | // point to dispatch the ShowView message. |
| 1802 | // |
| 1803 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1804 | // created RenderView (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1805 | // |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1806 | void RenderViewImpl::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1807 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 1808 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 1809 | |
| 1810 | if (did_show_) |
| 1811 | return; |
| 1812 | did_show_ = true; |
| 1813 | |
[email protected] | 6779aa1 | 2011-03-29 17:32:24 | [diff] [blame] | 1814 | if (content::GetContentClient()->renderer()->AllowPopup(creator_url_)) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 1815 | opened_by_user_gesture_ = true; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 1816 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 1817 | // Force new windows to a popup if they were not opened with a user gesture. |
| 1818 | if (!opened_by_user_gesture_) { |
| 1819 | // We exempt background tabs for compat with older versions of Chrome. |
| 1820 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 1821 | // we probably don't need this check. |
| 1822 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 1823 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 1824 | } |
| 1825 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1826 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 1827 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 1828 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1829 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 1830 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1831 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1832 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1833 | } |
| 1834 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1835 | void RenderViewImpl::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1836 | DCHECK(did_show_) << "should already have shown the view"; |
| 1837 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1838 | // We must keep WebKit's shared timer running in this case in order to allow |
| 1839 | // showModalDialog to function properly. |
| 1840 | // |
| 1841 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 1842 | // timers so that we do not need to manage the shared timer in such a heavy |
| 1843 | // handed manner. |
| 1844 | // |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1845 | if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 1846 | RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1847 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1848 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1849 | } |
| 1850 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1851 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 1852 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1853 | WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| 1854 | const WebPluginParams& params) { |
[email protected] | eaacd1f | 2011-09-23 02:32:55 | [diff] [blame] | 1855 | WebPlugin* plugin = NULL; |
| 1856 | if (content::GetContentClient()->renderer()->OverrideCreatePlugin( |
| 1857 | this, frame, params, &plugin)) { |
| 1858 | return plugin; |
| 1859 | } |
| 1860 | |
[email protected] | a813c8e | 2011-10-08 01:34:11 | [diff] [blame] | 1861 | webkit::WebPluginInfo info; |
| 1862 | std::string mime_type; |
| 1863 | bool found = GetPluginInfo(params.url, frame->top()->document().url(), |
| 1864 | params.mimeType.utf8(), &info, &mime_type); |
| 1865 | if (!found) |
| 1866 | return NULL; |
| 1867 | |
| 1868 | WebPluginParams params_to_use = params; |
| 1869 | params_to_use.mimeType = WebString::fromUTF8(mime_type); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1870 | return CreatePlugin(frame, info, params_to_use); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1871 | } |
| 1872 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1873 | WebWorker* RenderViewImpl::createWorker(WebFrame* frame, |
| 1874 | WebWorkerClient* client) { |
[email protected] | 14396e9 | 2010-05-06 20:40:56 | [diff] [blame] | 1875 | WebApplicationCacheHostImpl* appcache_host = |
| 1876 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 1877 | int appcache_host_id = appcache_host ? appcache_host->host_id() : 0; |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1878 | return new WebWorkerProxy(client, RenderThreadImpl::current(), routing_id_, |
[email protected] | 14396e9 | 2010-05-06 20:40:56 | [diff] [blame] | 1879 | appcache_host_id); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1880 | } |
| 1881 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1882 | WebSharedWorker* RenderViewImpl::createSharedWorker( |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 1883 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 1884 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 1885 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 1886 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 1887 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 1888 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 1889 | ViewHostMsg_CreateWorker_Params params; |
| 1890 | params.url = url; |
| 1891 | params.is_shared = true; |
| 1892 | params.name = name; |
| 1893 | params.document_id = document_id; |
| 1894 | params.render_view_route_id = routing_id_; |
| 1895 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 1896 | params.parent_appcache_host_id = 0; |
| 1897 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 1898 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 1899 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 1900 | if (url_mismatch) { |
| 1901 | return NULL; |
| 1902 | } else { |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1903 | return new WebSharedWorkerProxy(RenderThreadImpl::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 1904 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 1905 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 1906 | route_id, |
| 1907 | routing_id_); |
| 1908 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 1909 | } |
| 1910 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1911 | WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1912 | WebFrame* frame, WebMediaPlayerClient* client) { |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 1913 | FOR_EACH_OBSERVER( |
| 1914 | RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client)); |
[email protected] | 7198402c | 2011-04-11 12:15:17 | [diff] [blame] | 1915 | |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 1916 | scoped_ptr<media::MessageLoopFactory> message_loop_factory( |
| 1917 | new media::MessageLoopFactoryImpl()); |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 1918 | scoped_ptr<media::FilterCollection> collection( |
| 1919 | new media::FilterCollection()); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 1920 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1921 | // Add in any custom filter factories first. |
| 1922 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 1923 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 1924 | // Add the chrome specific audio renderer. |
[email protected] | f7eb0a39 | 2011-07-12 10:19:51 | [diff] [blame] | 1925 | collection->AddAudioRenderer(new AudioRendererImpl()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1926 | } |
| 1927 | |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 1928 | scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer; |
[email protected] | 77128dec | 2010-11-08 17:05:31 | [diff] [blame] | 1929 | bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); |
| 1930 | scoped_refptr<webkit_glue::VideoRendererImpl> renderer( |
| 1931 | new webkit_glue::VideoRendererImpl(pts_logging)); |
[email protected] | b7ba5b5 | 2010-11-15 22:04:49 | [diff] [blame] | 1932 | collection->AddVideoRenderer(renderer); |
[email protected] | 77128dec | 2010-11-08 17:05:31 | [diff] [blame] | 1933 | video_renderer = renderer; |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 1934 | |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 1935 | scoped_ptr<webkit_glue::WebMediaPlayerImpl> result( |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 1936 | new webkit_glue::WebMediaPlayerImpl(client, |
| 1937 | collection.release(), |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 1938 | message_loop_factory.release(), |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 1939 | media_stream_impl_.get(), |
| 1940 | new RenderMediaLog())); |
[email protected] | 7968428 | 2010-12-06 21:15:46 | [diff] [blame] | 1941 | if (!result->Initialize(frame, |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 1942 | cmd_line->HasSwitch(switches::kSimpleDataSource), |
| 1943 | video_renderer)) { |
| 1944 | return NULL; |
| 1945 | } |
| 1946 | return result.release(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1947 | } |
| 1948 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1949 | WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost( |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 1950 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
| 1951 | return new RendererWebApplicationCacheHostImpl( |
| 1952 | FromWebView(frame->view()), client, |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 1953 | RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy()); |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 1954 | } |
| 1955 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1956 | WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) { |
[email protected] | 8ff18107 | 2010-11-29 17:09:38 | [diff] [blame] | 1957 | return &cookie_jar_; |
| 1958 | } |
| 1959 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1960 | void RenderViewImpl::frameDetached(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1961 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame)); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 1962 | } |
| 1963 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1964 | void RenderViewImpl::willClose(WebFrame* frame) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1965 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1966 | } |
| 1967 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1968 | void RenderViewImpl::loadURLExternally( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1969 | WebFrame* frame, const WebURLRequest& request, |
| 1970 | WebNavigationPolicy policy) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 1971 | loadURLExternally(frame, request, policy, WebString()); |
| 1972 | } |
| 1973 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1974 | void RenderViewImpl::loadURLExternally( |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 1975 | WebFrame* frame, const WebURLRequest& request, |
| 1976 | WebNavigationPolicy policy, |
| 1977 | const WebString& suggested_name) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 1978 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 1979 | if (policy == WebKit::WebNavigationPolicyDownload) { |
[email protected] | 0622875ab | 2011-07-27 12:10:34 | [diff] [blame] | 1980 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer, |
| 1981 | suggested_name)); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 1982 | } else { |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1983 | OpenURL(frame, request.url(), referrer, policy); |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 1984 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1985 | } |
| 1986 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1987 | WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1988 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 1989 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1990 | // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation. |
| 1991 | if (is_swapped_out_) { |
| 1992 | DCHECK(request.url() == GURL("about:swappedout")); |
| 1993 | return default_policy; |
| 1994 | } |
| 1995 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1996 | // Webkit is asking whether to navigate to a new URL. |
| 1997 | // This is fine normally, except if we're showing UI from one security |
| 1998 | // context and they're trying to navigate to a different context. |
| 1999 | const GURL& url = request.url(); |
| 2000 | |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2001 | // A content initiated navigation may have originated from a link-click, |
| 2002 | // script, drag-n-drop operation, etc. |
| 2003 | bool is_content_initiated = |
| 2004 | NavigationState::FromDataSource(frame->provisionalDataSource())-> |
| 2005 | is_content_initiated(); |
| 2006 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2007 | // 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] | 2008 | // navigations. |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 2009 | if (is_content_initiated && |
| 2010 | renderer_preferences_.browser_handles_top_level_requests && |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2011 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2012 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2013 | // Reset these counters as the RenderView could be reused for the next |
| 2014 | // navigation. |
| 2015 | page_id_ = -1; |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2016 | last_page_id_sent_to_browser_ = -1; |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2017 | OpenURL(frame, url, referrer, default_policy); |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2018 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2019 | } |
| 2020 | |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2021 | // 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] | 2022 | // 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] | 2023 | // top-level navigations within the current tab (as opposed to, for example, |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2024 | // opening a new window). But we sometimes navigate to about:blank to clear a |
| 2025 | // tab, and we want to still allow that. |
| 2026 | // |
[email protected] | 8f4da8c | 2011-02-09 19:49:57 | [diff] [blame] | 2027 | // Note: we do this only for GET requests because our mechanism for switching |
| 2028 | // processes only issues GET requests. In particular, POST requests don't |
| 2029 | // work, because this mechanism does not preserve form POST data. If it |
| 2030 | // becomes necessary to support process switching for POST requests, we will |
| 2031 | // need to send the request's httpBody data up to the browser process, and |
| 2032 | // issue a special POST navigation in WebKit (via |
| 2033 | // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl |
| 2034 | // for examples of how to send the httpBody data. |
| 2035 | // Note2: We normally don't do this for browser-initiated navigations, since |
| 2036 | // it's pointless to tell the browser about navigations it gave us. But |
| 2037 | // we do potentially ask the browser to handle a redirect that was originally |
| 2038 | // initiated by the browser. See http://crbug.com/70943 |
| 2039 | // |
| 2040 | // TODO(creis): Move this redirect check to the browser process to avoid |
| 2041 | // ping-ponging. See http://crbug.com/72380. |
| 2042 | if (!frame->parent() && (is_content_initiated || is_redirect) && |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2043 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2044 | request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) { |
| 2045 | bool send_referrer = false; |
| 2046 | bool should_fork = |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 2047 | (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2048 | frame->isViewSourceModeEnabled() || |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2049 | url.SchemeIs(chrome::kViewSourceScheme); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2050 | |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2051 | if (!should_fork) { |
| 2052 | // Give the embedder a chance. |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 2053 | bool is_initial_navigation = page_id_ == -1; |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2054 | should_fork = content::GetContentClient()->renderer()->ShouldFork( |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 2055 | frame, url, is_content_initiated, is_initial_navigation, |
| 2056 | &send_referrer); |
[email protected] | 6101c34 | 2010-12-16 22:44:37 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | if (should_fork) { |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2060 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2061 | OpenURL(frame, url, send_referrer ? referrer : GURL(), default_policy); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2062 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2063 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2064 | } |
| 2065 | |
[email protected] | 43763f98 | 2011-08-26 18:33:40 | [diff] [blame] | 2066 | // Use the frame's original request's URL rather than the document's URL for |
| 2067 | // this check. For a popup, the document's URL may become the opener window's |
| 2068 | // URL if the opener has called document.write. See http://crbug.com/93517. |
| 2069 | GURL old_url(frame->dataSource()->request().url()); |
| 2070 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2071 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2072 | // its own process. This is done by sites like Gmail that try to open links |
| 2073 | // in new windows without script connections back to the original page. We |
| 2074 | // treat such cases as browser navigations (in which we will create a new |
| 2075 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2076 | // |
| 2077 | // We use the following heuristic to decide whether to fork a new page in its |
| 2078 | // own process: |
| 2079 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2080 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2081 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2082 | // |
| 2083 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2084 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2085 | bool is_fork = |
| 2086 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2087 | old_url == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2088 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2089 | historyBackListCount() < 1 && |
| 2090 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2091 | // The parent page must have set the child's window.opener to null before |
| 2092 | // redirecting to the desired URL. |
| 2093 | frame->opener() == NULL && |
| 2094 | // Must be a top-level frame. |
| 2095 | frame->parent() == NULL && |
| 2096 | // Must not have issued the request from this page. |
| 2097 | is_content_initiated && |
| 2098 | // Must be targeted at the current tab. |
| 2099 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2100 | // Must be a JavaScript navigation, which appears as "other". |
| 2101 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2102 | |
| 2103 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2104 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2105 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2106 | // should let the browser handle it. |
| 2107 | bool is_noreferrer_and_blank_target = |
| 2108 | // Frame should be top level and not yet navigated. |
| 2109 | frame->parent() == NULL && |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2110 | frame->document().url().isEmpty() && |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2111 | historyBackListCount() < 1 && |
| 2112 | historyForwardListCount() < 1 && |
| 2113 | // Links with rel=noreferrer will have no Referer field, and their |
| 2114 | // resulting frame will have its window.opener suppressed. |
| 2115 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2116 | // typos on the unusual spelling of Referer. |
| 2117 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2118 | opener_suppressed_ && |
| 2119 | frame->opener() == NULL && |
| 2120 | // Links with target=_blank will have no name. |
| 2121 | frame->name().isNull() && |
| 2122 | // Another frame (with a non-empty creator) should have initiated the |
| 2123 | // request, targeted at this frame. |
| 2124 | !creator_url_.is_empty() && |
| 2125 | is_content_initiated && |
| 2126 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2127 | type == WebKit::WebNavigationTypeOther; |
| 2128 | |
| 2129 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2130 | // Open the URL via the browser, not via WebKit. |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2131 | OpenURL(frame, url, GURL(), default_policy); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2132 | return WebKit::WebNavigationPolicyIgnore; |
| 2133 | } |
| 2134 | |
| 2135 | return default_policy; |
| 2136 | } |
| 2137 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2138 | bool RenderViewImpl::canHandleRequest( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2139 | WebFrame* frame, const WebURLRequest& request) { |
| 2140 | // We allow WebKit to think that everything can be handled even though |
| 2141 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2142 | return true; |
| 2143 | } |
| 2144 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2145 | WebURLError RenderViewImpl::cannotHandleRequestError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2146 | WebFrame* frame, const WebURLRequest& request) { |
| 2147 | NOTREACHED(); // Since we said we can handle all requests. |
| 2148 | return WebURLError(); |
| 2149 | } |
| 2150 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2151 | WebURLError RenderViewImpl::cancelledError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2152 | WebFrame* frame, const WebURLRequest& request) { |
| 2153 | WebURLError error; |
| 2154 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2155 | error.reason = net::ERR_ABORTED; |
| 2156 | error.unreachableURL = request.url(); |
| 2157 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2158 | } |
| 2159 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2160 | void RenderViewImpl::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2161 | WebFrame*, const WebURLError&) { |
| 2162 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2163 | } |
| 2164 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2165 | void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame, |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2166 | const WebKit::WebFormElement& form) { |
| 2167 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2168 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2169 | // This method gets called before any of those handlers run, so save away |
| 2170 | // a copy of the password in case it gets lost. |
| 2171 | NavigationState* navigation_state = |
| 2172 | NavigationState::FromDataSource(frame->dataSource()); |
| 2173 | navigation_state->set_password_form_data( |
| 2174 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2175 | } |
| 2176 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2177 | void RenderViewImpl::willSubmitForm(WebFrame* frame, |
| 2178 | const WebFormElement& form) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2179 | NavigationState* navigation_state = |
| 2180 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2181 | |
| 2182 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 2183 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 2184 | |
| 2185 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2186 | WebSearchableFormData web_searchable_form_data(form); |
| 2187 | navigation_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2188 | navigation_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2189 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2190 | PasswordForm* password_form_data = |
| 2191 | PasswordFormDomManager::CreatePasswordForm(form); |
| 2192 | navigation_state->set_password_form_data(password_form_data); |
| 2193 | |
[email protected] | 098c95cb | 2011-04-28 16:49:01 | [diff] [blame] | 2194 | // In order to save the password that the user actually typed and not one |
| 2195 | // that may have gotten transformed by the site prior to submit, recover it |
| 2196 | // from the form contents already stored by |willSendSubmitEvent| into the |
| 2197 | // dataSource's NavigationState (as opposed to the provisionalDataSource's, |
| 2198 | // which is what we're storing into now.) |
| 2199 | if (password_form_data) { |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2200 | NavigationState* old_navigation_state = |
| 2201 | NavigationState::FromDataSource(frame->dataSource()); |
| 2202 | if (old_navigation_state) { |
| 2203 | PasswordForm* old_form_data = old_navigation_state->password_form_data(); |
| 2204 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2205 | password_form_data->password_value = old_form_data->password_value; |
| 2206 | } |
| 2207 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2208 | |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 2209 | FOR_EACH_OBSERVER( |
| 2210 | RenderViewObserver, observers_, WillSubmitForm(frame, form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2211 | } |
| 2212 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2213 | void RenderViewImpl::willPerformClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2214 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2215 | double fire_time) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2216 | FOR_EACH_OBSERVER( |
| 2217 | RenderViewObserver, observers_, |
| 2218 | WillPerformClientRedirect(frame, from, to, interval, fire_time)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2219 | } |
| 2220 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2221 | void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) { |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2222 | FOR_EACH_OBSERVER( |
| 2223 | RenderViewObserver, observers_, DidCancelClientRedirect(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2224 | } |
| 2225 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2226 | void RenderViewImpl::didCompleteClientRedirect( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2227 | WebFrame* frame, const WebURL& from) { |
| 2228 | if (!frame->parent()) |
| 2229 | completed_client_redirect_src_ = from; |
[email protected] | eb0bff94 | 2011-04-07 22:08:38 | [diff] [blame] | 2230 | FOR_EACH_OBSERVER( |
| 2231 | RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2232 | } |
| 2233 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2234 | void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2235 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2236 | // non-null NavigationState. |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 2237 | bool content_initiated = !pending_navigation_state_.get(); |
| 2238 | NavigationState* state = content_initiated ? |
| 2239 | NavigationState::CreateContentInitiated() : |
| 2240 | pending_navigation_state_.release(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2241 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2242 | // NavigationState::referred_by_prefetcher_ is true if we are |
| 2243 | // navigating from a page that used prefetching using a link on that |
| 2244 | // page. We are early enough in the request process here that we |
| 2245 | // can still see the NavigationState of the previous page and set |
| 2246 | // this value appropriately. |
| 2247 | // TODO(gavinp): catch the important case of navigation in a new |
| 2248 | // renderer process. |
| 2249 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2250 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2251 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2252 | const GURL referrer( |
| 2253 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2254 | if (!referrer.is_empty() && |
| 2255 | NavigationState::FromDataSource( |
| 2256 | old_frame->dataSource())->was_prefetcher()) { |
| 2257 | for (;old_frame;old_frame = old_frame->traverseNext(false)) { |
| 2258 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 2259 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
| 2260 | state->set_was_referred_by_prefetcher(true); |
| 2261 | break; |
| 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | } |
| 2266 | } |
| 2267 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2268 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2269 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2270 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2271 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
| 2272 | state->set_load_type(NavigationState::LINK_LOAD_NORMAL); |
| 2273 | break; |
| 2274 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
| 2275 | state->set_load_type(NavigationState::LINK_LOAD_RELOAD); |
| 2276 | break; |
| 2277 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
| 2278 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); |
| 2279 | break; |
| 2280 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
| 2281 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); |
| 2282 | break; |
| 2283 | } |
| 2284 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2285 | |
[email protected] | 16e923d | 2011-04-30 00:41:44 | [diff] [blame] | 2286 | ds->setExtraData(state); |
[email protected] | 11f595b2 | 2011-04-11 14:48:50 | [diff] [blame] | 2287 | |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 2288 | FOR_EACH_OBSERVER( |
| 2289 | RenderViewObserver, observers_, DidCreateDataSource(frame, ds)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2290 | } |
| 2291 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2292 | void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2293 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2294 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2295 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2296 | // Update the request time if WebKit has better knowledge of it. |
| 2297 | if (navigation_state->request_time().is_null()) { |
| 2298 | double event_time = ds->triggeringEventTime(); |
| 2299 | if (event_time != 0.0) |
| 2300 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 2301 | } |
| 2302 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2303 | // Start time is only set after request time. |
| 2304 | navigation_state->set_start_load_time(Time::Now()); |
| 2305 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2306 | bool is_top_most = !frame->parent(); |
| 2307 | if (is_top_most) { |
| 2308 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 2309 | NavigationGestureUser : NavigationGestureAuto; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2310 | |
| 2311 | // Make sure redirect tracking state is clear for the new load. |
| 2312 | completed_client_redirect_src_ = GURL(); |
| 2313 | } else if (frame->parent()->isLoading()) { |
| 2314 | // 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] | 2315 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2316 | navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); |
| 2317 | } |
| 2318 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2319 | FOR_EACH_OBSERVER( |
| 2320 | RenderViewObserver, observers_, DidStartProvisionalLoad(frame)); |
| 2321 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2322 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 2323 | routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(), |
[email protected] | eacb080b | 2011-05-22 19:40:26 | [diff] [blame] | 2324 | ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2325 | } |
| 2326 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2327 | void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad( |
| 2328 | WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2329 | if (frame->parent()) |
| 2330 | return; |
| 2331 | // Received a redirect on the main frame. |
| 2332 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 2333 | if (!data_source) { |
| 2334 | // Should only be invoked when we have a data source. |
| 2335 | NOTREACHED(); |
| 2336 | return; |
| 2337 | } |
| 2338 | std::vector<GURL> redirects; |
| 2339 | GetRedirectChain(data_source, &redirects); |
| 2340 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2341 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 2342 | GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2346 | void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame, |
| 2347 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2348 | // Notify the browser that we failed a provisional load with an error. |
| 2349 | // |
| 2350 | // Note: It is important this notification occur before DidStopLoading so the |
| 2351 | // SSL manager can react to the provisional load failure before being |
| 2352 | // notified the load stopped. |
| 2353 | // |
| 2354 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2355 | DCHECK(ds); |
| 2356 | |
| 2357 | const WebURLRequest& failed_request = ds->request(); |
| 2358 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2359 | FOR_EACH_OBSERVER( |
| 2360 | RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error)); |
| 2361 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2362 | bool show_repost_interstitial = |
| 2363 | (error.reason == net::ERR_CACHE_MISS && |
| 2364 | EqualsASCII(failed_request.httpMethod(), "POST")); |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2365 | |
| 2366 | ViewHostMsg_DidFailProvisionalLoadWithError_Params params; |
| 2367 | params.frame_id = frame->identifier(); |
| 2368 | params.is_main_frame = !frame->parent(); |
| 2369 | params.error_code = error.reason; |
| 2370 | content::GetContentClient()->renderer()->GetNavigationErrorStrings( |
| 2371 | failed_request, |
| 2372 | error, |
| 2373 | NULL, |
| 2374 | ¶ms.error_description); |
| 2375 | params.url = error.unreachableURL; |
| 2376 | params.showing_repost_interstitial = show_repost_interstitial; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2377 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 2378 | routing_id_, params)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2379 | |
| 2380 | // Don't display an error page if this is simply a cancelled load. Aside |
| 2381 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 2382 | if (error.reason == net::ERR_ABORTED) |
| 2383 | return; |
| 2384 | |
| 2385 | // Make sure we never show errors in view source mode. |
| 2386 | frame->enableViewSourceMode(false); |
| 2387 | |
| 2388 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2389 | |
| 2390 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 2391 | // 'replace' load. This is necessary to avoid messing up session history. |
| 2392 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 2393 | // as session history is concerned. |
| 2394 | // |
| 2395 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 2396 | // the page id. |
| 2397 | // |
| 2398 | bool replace = |
| 2399 | navigation_state->pending_page_id() != -1 || |
| 2400 | navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME; |
| 2401 | |
| 2402 | // If we failed on a browser initiated request, then make sure that our error |
| 2403 | // page load is regarded as the same browser initiated request. |
| 2404 | if (!navigation_state->is_content_initiated()) { |
| 2405 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
| 2406 | navigation_state->pending_page_id(), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2407 | navigation_state->pending_history_list_offset(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2408 | navigation_state->transition_type(), |
| 2409 | navigation_state->request_time())); |
| 2410 | } |
| 2411 | |
| 2412 | // Provide the user with a more helpful error page? |
| 2413 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 2414 | return; |
| 2415 | |
| 2416 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 2417 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2418 | } |
| 2419 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2420 | void RenderViewImpl::didReceiveDocumentData( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2421 | WebFrame* frame, const char* data, size_t data_len, |
| 2422 | bool& prevent_default) { |
| 2423 | NavigationState* navigation_state = |
| 2424 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2425 | navigation_state->set_use_error_page(false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2426 | } |
| 2427 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2428 | void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame, |
| 2429 | bool is_new_navigation) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2430 | NavigationState* navigation_state = |
| 2431 | NavigationState::FromDataSource(frame->dataSource()); |
| 2432 | |
| 2433 | navigation_state->set_commit_load_time(Time::Now()); |
| 2434 | if (is_new_navigation) { |
[email protected] | e15f68073 | 2010-11-23 22:30:20 | [diff] [blame] | 2435 | // When we perform a new navigation, we need to update the last committed |
| 2436 | // session history entry with state for the page we are leaving. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2437 | UpdateSessionHistory(frame); |
| 2438 | |
| 2439 | // We bump our Page ID to correspond with the new session history entry. |
| 2440 | page_id_ = next_page_id_++; |
| 2441 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2442 | // Advance our offset in session history, applying the length limit. There |
| 2443 | // is now no forward history. |
| 2444 | history_list_offset_++; |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 2445 | if (history_list_offset_ >= content::kMaxSessionHistoryEntries) |
| 2446 | history_list_offset_ = content::kMaxSessionHistoryEntries - 1; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2447 | history_list_length_ = history_list_offset_ + 1; |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 2448 | history_page_ids_.resize(history_list_length_, -1); |
| 2449 | history_page_ids_[history_list_offset_] = page_id_; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2450 | } else { |
| 2451 | // Inspect the navigation_state on this frame to see if the navigation |
| 2452 | // corresponds to a session history navigation... Note: |frame| may or |
| 2453 | // may not be the toplevel frame, but for the case of capturing session |
| 2454 | // history, the first committed frame suffices. We keep track of whether |
| 2455 | // we've seen this commit before so that only capture session history once |
| 2456 | // per navigation. |
| 2457 | // |
| 2458 | // Note that we need to check if the page ID changed. In the case of a |
| 2459 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 2460 | // previous URL and the current page ID, which would be wrong. |
| 2461 | if (navigation_state->pending_page_id() != -1 && |
| 2462 | navigation_state->pending_page_id() != page_id_ && |
| 2463 | !navigation_state->request_committed()) { |
| 2464 | // This is a successful session history navigation! |
| 2465 | UpdateSessionHistory(frame); |
| 2466 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2467 | |
| 2468 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | d466b8a | 2011-07-15 21:48:03 | [diff] [blame] | 2469 | |
| 2470 | // If the history list is valid, our list of page IDs should be correct. |
| 2471 | DCHECK(history_list_length_ <= 0 || |
| 2472 | history_list_offset_ < 0 || |
| 2473 | history_list_offset_ >= history_list_length_ || |
| 2474 | history_page_ids_[history_list_offset_] == page_id_); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2478 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2479 | DidCommitProvisionalLoad(frame, is_new_navigation)); |
| 2480 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2481 | // Remember that we've already processed this request, so we don't update |
| 2482 | // the session history again. We do this regardless of whether this is |
| 2483 | // a session history navigation, because if we attempted a session history |
| 2484 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 2485 | // new navigation. |
| 2486 | navigation_state->set_request_committed(true); |
| 2487 | |
| 2488 | UpdateURL(frame); |
| 2489 | |
| 2490 | // If this committed load was initiated by a client redirect, we're |
| 2491 | // at the last stop now, so clear it. |
| 2492 | completed_client_redirect_src_ = GURL(); |
| 2493 | |
| 2494 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2495 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2496 | } |
| 2497 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2498 | void RenderViewImpl::didClearWindowObject(WebFrame* frame) { |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 2499 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2500 | DidClearWindowObject(frame)); |
| 2501 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2502 | GURL frame_url = frame->document().url(); |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 2503 | if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) && |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 2504 | (frame_url.SchemeIs(chrome::kChromeUIScheme) || |
| 2505 | frame_url.SchemeIs(chrome::kDataScheme))) { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 2506 | GetWebUIBindings()->BindToJavascript(frame, "chrome"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2507 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2508 | } |
| 2509 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2510 | void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2511 | // Notify the browser about non-blank documents loading in the top frame. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2512 | GURL url = frame->document().url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 2513 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2514 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2515 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 2516 | } |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2517 | |
| 2518 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2519 | DidCreateDocumentElement(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2520 | } |
| 2521 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2522 | void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title, |
| 2523 | WebTextDirection direction) { |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2524 | UpdateTitle(frame, title, direction); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2525 | |
| 2526 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2527 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2528 | } |
| 2529 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2530 | void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) { |
[email protected] | 42054a25 | 2011-05-17 18:02:13 | [diff] [blame] | 2531 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2532 | DidChangeIcon(frame, type)); |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 2533 | } |
| 2534 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2535 | void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2536 | WebDataSource* ds = frame->dataSource(); |
| 2537 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2538 | DCHECK(navigation_state); |
| 2539 | navigation_state->set_finish_document_load_time(Time::Now()); |
| 2540 | |
[email protected] | 622474d | 2010-11-04 09:21:08 | [diff] [blame] | 2541 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2542 | |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2543 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 2544 | DidFinishDocumentLoad(frame)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2545 | |
| 2546 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2547 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2548 | } |
| 2549 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2550 | void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2551 | if (webview()->mainFrame() == frame) { |
| 2552 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 2553 | page_id_)); |
| 2554 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2555 | } |
| 2556 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2557 | void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) { |
[email protected] | 28685da9 | 2011-02-07 21:49:17 | [diff] [blame] | 2558 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2559 | } |
| 2560 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2561 | void RenderViewImpl::didFinishLoad(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2562 | WebDataSource* ds = frame->dataSource(); |
| 2563 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2564 | DCHECK(navigation_state); |
| 2565 | navigation_state->set_finish_load_time(Time::Now()); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2566 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 2567 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame)); |
[email protected] | fdd94a0 | 2010-11-05 08:07:17 | [diff] [blame] | 2568 | |
| 2569 | Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2570 | } |
| 2571 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2572 | void RenderViewImpl::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2573 | WebFrame* frame, bool is_new_navigation) { |
| 2574 | // If this was a reference fragment navigation that we initiated, then we |
| 2575 | // could end up having a non-null pending navigation state. We just need to |
| 2576 | // update the ExtraData on the datasource so that others who read the |
| 2577 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 2578 | // initiate this navigation, then we need to take care to reset any pre- |
| 2579 | // existing navigation state to a content-initiated navigation state. |
| 2580 | // DidCreateDataSource conveniently takes care of this for us. |
| 2581 | didCreateDataSource(frame, frame->dataSource()); |
| 2582 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 2583 | NavigationState* new_state = |
| 2584 | NavigationState::FromDataSource(frame->dataSource()); |
| 2585 | new_state->set_was_within_same_page(true); |
| 2586 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2587 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 2588 | |
[email protected] | 750fcf87 | 2011-08-03 23:10:47 | [diff] [blame] | 2589 | WebDataSource* datasource = frame->view()->mainFrame()->dataSource(); |
| 2590 | UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2591 | } |
| 2592 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2593 | void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2594 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2595 | } |
| 2596 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2597 | void RenderViewImpl::assignIdentifierToRequest( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2598 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 2599 | // Ignore |
| 2600 | } |
| 2601 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2602 | void RenderViewImpl::willSendRequest(WebFrame* frame, |
| 2603 | unsigned identifier, |
| 2604 | WebURLRequest& request, |
| 2605 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 2606 | WebFrame* top_frame = frame->top(); |
| 2607 | if (!top_frame) |
| 2608 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2609 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 2610 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 2611 | WebDataSource* data_source = |
| 2612 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 2613 | |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 2614 | GURL request_url(request.url()); |
[email protected] | e48869a | 2011-04-01 19:56:03 | [diff] [blame] | 2615 | GURL new_url; |
| 2616 | if (content::GetContentClient()->renderer()->WillSendRequest( |
| 2617 | frame, request_url, &new_url)) { |
| 2618 | request.setURL(WebURL(new_url)); |
[email protected] | 78d5cfe | 2011-02-04 08:43:22 | [diff] [blame] | 2619 | } |
| 2620 | |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 2621 | PageTransition::Type transition_type = PageTransition::LINK; |
| 2622 | NavigationState* data_state = NavigationState::FromDataSource(data_source); |
| 2623 | if (data_state) { |
| 2624 | if (data_state->is_cache_policy_override_set()) |
| 2625 | request.setCachePolicy(data_state->cache_policy_override()); |
| 2626 | transition_type = data_state->transition_type(); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 2627 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2628 | |
[email protected] | d88bf0a | 2011-08-30 23:55:57 | [diff] [blame] | 2629 | request.setExtraData(new RequestExtraData((frame == top_frame), |
| 2630 | frame->identifier(), transition_type)); |
| 2631 | |
| 2632 | NavigationState* top_data_state = |
| 2633 | NavigationState::FromDataSource(top_data_source); |
| 2634 | // TODO(gavinp): separate out prefetching and prerender field trials |
| 2635 | // if the rel=prerender rel type is sticking around. |
| 2636 | if (top_data_state && |
| 2637 | (request.targetType() == WebURLRequest::TargetIsPrefetch || |
| 2638 | request.targetType() == WebURLRequest::TargetIsPrerender)) |
| 2639 | top_data_state->set_was_prefetcher(true); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2640 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2641 | request.setRequestorID(routing_id_); |
[email protected] | cd44809 | 2010-12-06 23:49:13 | [diff] [blame] | 2642 | request.setHasUserGesture(frame->isProcessingUserGesture()); |
| 2643 | |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 2644 | if (!renderer_preferences_.enable_referrers) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 2645 | request.clearHTTPHeaderField("Referer"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2646 | } |
| 2647 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2648 | void RenderViewImpl::didReceiveResponse( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2649 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2650 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2651 | // Only do this for responses that correspond to a provisional data source |
| 2652 | // of the top-most frame. If we have a provisional data source, then we |
| 2653 | // can't have any sub-resources yet, so we know that this response must |
| 2654 | // correspond to a frame load. |
| 2655 | if (!frame->provisionalDataSource() || frame->parent()) |
| 2656 | return; |
| 2657 | |
| 2658 | // 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] | 2659 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2660 | if (frame->isViewSourceModeEnabled()) |
| 2661 | return; |
| 2662 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 2663 | NavigationState* navigation_state = |
| 2664 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2665 | CHECK(navigation_state); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 2666 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 2667 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 2668 | // Record page load flags. |
| 2669 | navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 2670 | navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 2671 | navigation_state->set_was_alternate_protocol_available( |
| 2672 | response.wasAlternateProtocolAvailable()); |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 2673 | navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 2674 | navigation_state->set_http_status_code(http_status_code); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2675 | // Whether or not the http status code actually corresponds to an error is |
| 2676 | // only checked when the page is done loading, if |use_error_page| is |
| 2677 | // still true. |
| 2678 | navigation_state->set_use_error_page(true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2679 | } |
| 2680 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2681 | void RenderViewImpl::didFinishResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2682 | WebFrame* frame, unsigned identifier) { |
| 2683 | NavigationState* navigation_state = |
| 2684 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2685 | if (!navigation_state->use_error_page()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2686 | return; |
| 2687 | |
[email protected] | 7bfc153f | 2011-09-23 22:00:20 | [diff] [blame] | 2688 | // Do not show error page when DevTools is attached. |
| 2689 | if (devtools_agent_->IsAttached()) |
| 2690 | return; |
| 2691 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2692 | // Display error page, if appropriate. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 2693 | int http_status_code = navigation_state->http_status_code(); |
| 2694 | if (http_status_code == 404) { |
| 2695 | // On 404s, try a remote search page as a fallback. |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2696 | const GURL& document_url = frame->document().url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2697 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2698 | const GURL& error_page_url = |
| 2699 | GetAlternateErrorPageURL(document_url, HTTP_404); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2700 | if (error_page_url.is_valid()) { |
| 2701 | WebURLError original_error; |
[email protected] | 2e9706c | 2011-06-09 16:49:47 | [diff] [blame] | 2702 | original_error.domain = "http"; |
| 2703 | original_error.reason = 404; |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2704 | original_error.unreachableURL = document_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2705 | |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2706 | navigation_state->set_alt_error_page_fetcher( |
| 2707 | new AltErrorPageResourceFetcher( |
| 2708 | error_page_url, frame, original_error, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2709 | NewCallback(this, &RenderViewImpl::AltErrorPageFinished))); |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 2710 | return; |
| 2711 | } |
| 2712 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2713 | |
[email protected] | e6a2ce5 | 2011-10-08 01:40:13 | [diff] [blame] | 2714 | std::string error_domain; |
| 2715 | if (content::GetContentClient()->renderer()->HasErrorPage( |
| 2716 | http_status_code, &error_domain)) { |
| 2717 | WebURLError error; |
| 2718 | error.unreachableURL = frame->document().url(); |
| 2719 | error.domain = WebString::fromUTF8(error_domain); |
| 2720 | error.reason = http_status_code; |
| 2721 | |
| 2722 | LoadNavigationErrorPage( |
| 2723 | frame, frame->dataSource()->request(), error, std::string(), true); |
| 2724 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2725 | } |
| 2726 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2727 | void RenderViewImpl::didFailResourceLoad( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2728 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 2729 | // Ignore |
| 2730 | } |
| 2731 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2732 | void RenderViewImpl::didLoadResourceFromMemoryCache( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2733 | WebFrame* frame, const WebURLRequest& request, |
| 2734 | const WebURLResponse& response) { |
| 2735 | // Let the browser know we loaded a resource from the memory cache. This |
| 2736 | // message is needed to display the correct SSL indicators. |
| 2737 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 2738 | routing_id_, |
| 2739 | request.url(), |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 2740 | response.securityInfo(), |
| 2741 | request.httpMethod().utf8(), |
| 2742 | ResourceType::FromTargetType(request.targetType()))); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2743 | } |
| 2744 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2745 | void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2746 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 2747 | } |
| 2748 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2749 | void RenderViewImpl::didRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 2750 | WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2751 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 2752 | routing_id_, |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 2753 | origin.toString().utf8(), |
| 2754 | target)); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2755 | } |
| 2756 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2757 | void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) { |
[email protected] | b00ba70 | 2011-08-17 01:41:03 | [diff] [blame] | 2758 | webkit_glue::WebURLLoaderImpl* loader_impl = |
| 2759 | static_cast<webkit_glue::WebURLLoaderImpl*>(loader); |
| 2760 | loader_impl->UpdateRoutingId(routing_id_); |
| 2761 | } |
| 2762 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2763 | void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2764 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 2765 | } |
| 2766 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2767 | void RenderViewImpl::didCreateScriptContext(WebFrame* frame, |
| 2768 | v8::Handle<v8::Context> context, |
| 2769 | int world_id) { |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 2770 | content::GetContentClient()->renderer()->DidCreateScriptContext( |
| 2771 | frame, context, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 2772 | } |
| 2773 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2774 | void RenderViewImpl::willReleaseScriptContext(WebFrame* frame, |
| 2775 | v8::Handle<v8::Context> context, |
| 2776 | int world_id) { |
[email protected] | 5bc1093 | 2011-09-21 21:03:30 | [diff] [blame] | 2777 | content::GetContentClient()->renderer()->WillReleaseScriptContext( |
| 2778 | frame, context, world_id); |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 2779 | } |
| 2780 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2781 | void RenderViewImpl::didUpdateLayout(WebFrame* frame) { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 2782 | // We don't always want to set up a timer, only if we've been put in that |
| 2783 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2784 | // message. |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2785 | if (!send_preferred_size_changes_ || !webview()) |
| 2786 | return; |
[email protected] | dfca5acf | 2010-03-22 03:28:43 | [diff] [blame] | 2787 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 2788 | if (check_preferred_size_timer_.IsRunning()) |
| 2789 | return; |
[email protected] | d323a17 | 2011-09-02 18:23:02 | [diff] [blame] | 2790 | check_preferred_size_timer_.Start(FROM_HERE, |
| 2791 | TimeDelta::FromMilliseconds(0), this, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2792 | &RenderViewImpl::CheckPreferredSize); |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 2793 | } |
| 2794 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2795 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 2796 | // We don't always want to send the change messages over IPC, only if we've |
| 2797 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 2798 | // message. |
| 2799 | if (!send_preferred_size_changes_ || !webview()) |
| 2800 | return; |
| 2801 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2802 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 2803 | webview()->mainFrame()->documentElementScrollHeight()); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 2804 | |
| 2805 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 2806 | // so we need to adjust. |
| 2807 | double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel()); |
| 2808 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 2809 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 2810 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2811 | if (size == preferred_size_) |
| 2812 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2813 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 2814 | preferred_size_ = size; |
| 2815 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 2816 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2817 | } |
| 2818 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2819 | void RenderViewImpl::didChangeContentsSize(WebFrame* frame, |
| 2820 | const WebSize& size) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2821 | if (webview()->mainFrame() != frame) |
| 2822 | return; |
| 2823 | WebView* frameView = frame->view(); |
| 2824 | if (!frameView) |
| 2825 | return; |
| 2826 | |
| 2827 | bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); |
| 2828 | bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); |
| 2829 | |
| 2830 | if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || |
| 2831 | has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { |
| 2832 | Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( |
| 2833 | routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); |
| 2834 | |
| 2835 | cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; |
| 2836 | cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; |
| 2837 | } |
| 2838 | } |
| 2839 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2840 | void RenderViewImpl::UpdateScrollState(WebFrame* frame) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2841 | WebSize offset = frame->scrollOffset(); |
| 2842 | WebSize minimum_offset = frame->minimumScrollOffset(); |
| 2843 | WebSize maximum_offset = frame->maximumScrollOffset(); |
| 2844 | |
| 2845 | bool is_pinned_to_left = offset.width <= minimum_offset.width; |
| 2846 | bool is_pinned_to_right = offset.width >= maximum_offset.width; |
| 2847 | |
| 2848 | if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || |
| 2849 | is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { |
| 2850 | Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( |
| 2851 | routing_id_, is_pinned_to_left, is_pinned_to_right)); |
| 2852 | |
| 2853 | cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; |
| 2854 | cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; |
| 2855 | } |
| 2856 | } |
| 2857 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2858 | void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 2859 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2860 | |
| 2861 | if (webview()->mainFrame() == frame) |
| 2862 | UpdateScrollState(frame); |
| 2863 | } |
| 2864 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2865 | void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) { |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 2866 | Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 2867 | } |
| 2868 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2869 | void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count, |
| 2870 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 2871 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 2872 | if (!count) |
| 2873 | active_match_ordinal = 0; |
| 2874 | |
| 2875 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 2876 | routing_id_, |
| 2877 | request_id, |
| 2878 | count, |
| 2879 | gfx::Rect(), |
| 2880 | active_match_ordinal, |
| 2881 | final_update); |
| 2882 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2883 | // If we have a message that has been queued up, then we should just replace |
| 2884 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 2885 | // wants it. |
| 2886 | if (queued_find_reply_message_.get()) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2887 | queued_find_reply_message_.reset(msg); |
| 2888 | } else { |
| 2889 | // Send the search result over to the browser process. |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 2890 | Send(msg); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2891 | } |
| 2892 | } |
| 2893 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2894 | void RenderViewImpl::reportFindInPageSelection(int request_id, |
| 2895 | int active_match_ordinal, |
| 2896 | const WebRect& selection_rect) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2897 | // Send the search result over to the browser process. |
| 2898 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 2899 | request_id, |
| 2900 | -1, |
| 2901 | selection_rect, |
| 2902 | active_match_ordinal, |
| 2903 | false)); |
| 2904 | } |
| 2905 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2906 | void RenderViewImpl::openFileSystem( |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 2907 | WebFrame* frame, |
| 2908 | WebFileSystem::Type type, |
| 2909 | long long size, |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 2910 | bool create, |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 2911 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 2912 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 2913 | |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2914 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 2915 | if (origin.isEmpty()) { |
| 2916 | // Uninitialized document? |
| 2917 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 2918 | return; |
| 2919 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 2920 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 2921 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 2922 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
[email protected] | d275d7a | 2010-11-03 01:34:49 | [diff] [blame] | 2923 | size, create, new WebFileSystemCallbackDispatcher(callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 2924 | } |
| 2925 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2926 | void RenderViewImpl::queryStorageUsageAndQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 2927 | WebFrame* frame, |
| 2928 | WebStorageQuotaType type, |
| 2929 | WebStorageQuotaCallbacks* callbacks) { |
| 2930 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2931 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 2932 | if (origin.isEmpty()) { |
| 2933 | // Uninitialized document? |
| 2934 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 2935 | return; |
| 2936 | } |
| 2937 | ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 2938 | GURL(origin.toString()), |
| 2939 | static_cast<quota::StorageType>(type), |
| 2940 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 2941 | } |
| 2942 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2943 | void RenderViewImpl::requestStorageQuota( |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 2944 | WebFrame* frame, |
| 2945 | WebStorageQuotaType type, |
| 2946 | unsigned long long requested_size, |
| 2947 | WebStorageQuotaCallbacks* callbacks) { |
| 2948 | DCHECK(frame); |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 2949 | WebSecurityOrigin origin = frame->document().securityOrigin(); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 2950 | if (origin.isEmpty()) { |
| 2951 | // Uninitialized document? |
| 2952 | callbacks->didFail(WebKit::WebStorageQuotaErrorAbort); |
| 2953 | return; |
| 2954 | } |
| 2955 | ChildThread::current()->quota_dispatcher()->RequestStorageQuota( |
[email protected] | 666bcc5c | 2011-07-29 06:25:53 | [diff] [blame] | 2956 | routing_id(), GURL(origin.toString()), |
| 2957 | static_cast<quota::StorageType>(type), requested_size, |
| 2958 | QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
[email protected] | 10e5cf1 | 2011-04-13 04:10:40 | [diff] [blame] | 2959 | } |
| 2960 | |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 2961 | // WebKit::WebPageSerializerClient implementation ------------------------------ |
| 2962 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2963 | void RenderViewImpl::didSerializeDataForFrame( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 2964 | const WebURL& frame_url, |
| 2965 | const WebCString& data, |
| 2966 | WebPageSerializerClient::PageSerializationStatus status) { |
| 2967 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 2968 | routing_id(), |
| 2969 | frame_url, |
| 2970 | data.data(), |
| 2971 | static_cast<int32>(status))); |
| 2972 | } |
| 2973 | |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2974 | // content::RenderView implementation ------------------------------------------ |
| 2975 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2976 | bool RenderViewImpl::Send(IPC::Message* message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2977 | return RenderWidget::Send(message); |
| 2978 | } |
| 2979 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2980 | int RenderViewImpl::GetRoutingId() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2981 | return routing_id_; |
| 2982 | } |
| 2983 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2984 | int RenderViewImpl::GetPageId() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2985 | return page_id_; |
| 2986 | } |
| 2987 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2988 | gfx::Size RenderViewImpl::GetSize() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2989 | return size(); |
| 2990 | } |
| 2991 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2992 | gfx::NativeViewId RenderViewImpl::GetHostWindow() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2993 | return host_window(); |
| 2994 | } |
| 2995 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 2996 | WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 2997 | return webkit_preferences_; |
| 2998 | } |
| 2999 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3000 | WebKit::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3001 | return webview(); |
| 3002 | } |
| 3003 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3004 | WebKit::WebNode RenderViewImpl::GetFocusedNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3005 | if (!webview()) |
| 3006 | return WebNode(); |
| 3007 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 3008 | if (focused_frame) { |
| 3009 | WebDocument doc = focused_frame->document(); |
| 3010 | if (!doc.isNull()) |
| 3011 | return doc.focusedNode(); |
| 3012 | } |
| 3013 | |
| 3014 | return WebNode(); |
| 3015 | } |
| 3016 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3017 | WebKit::WebNode RenderViewImpl::GetContextMenuNode() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3018 | return context_menu_node_; |
| 3019 | } |
| 3020 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3021 | bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3022 | bool is_editable_node = false; |
| 3023 | if (!node.isNull()) { |
| 3024 | if (node.isContentEditable()) { |
| 3025 | is_editable_node = true; |
| 3026 | } else if (node.isElementNode()) { |
| 3027 | is_editable_node = |
| 3028 | node.toConst<WebElement>().isTextFormControlElement(); |
| 3029 | } |
| 3030 | } |
| 3031 | return is_editable_node; |
| 3032 | } |
| 3033 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3034 | WebKit::WebPlugin* RenderViewImpl::CreatePlugin( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3035 | WebKit::WebFrame* frame, |
| 3036 | const webkit::WebPluginInfo& info, |
| 3037 | const WebKit::WebPluginParams& params) { |
| 3038 | bool pepper_plugin_was_registered = false; |
| 3039 | scoped_refptr<webkit::ppapi::PluginModule> pepper_module( |
| 3040 | pepper_delegate_.CreatePepperPluginModule(info, |
| 3041 | &pepper_plugin_was_registered)); |
| 3042 | if (pepper_plugin_was_registered) { |
| 3043 | if (!pepper_module) |
| 3044 | return NULL; |
| 3045 | return new webkit::ppapi::WebPluginImpl( |
| 3046 | pepper_module.get(), params, pepper_delegate_.AsWeakPtr()); |
| 3047 | } |
| 3048 | |
| 3049 | return new webkit::npapi::WebPluginImpl( |
| 3050 | frame, params, info.path, AsWeakPtr()); |
| 3051 | } |
| 3052 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3053 | void RenderViewImpl::EvaluateScript(const string16& frame_xpath, |
| 3054 | const string16& jscript, |
| 3055 | int id, |
| 3056 | bool notify_result) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3057 | v8::Handle<v8::Value> result; |
| 3058 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 3059 | if (web_frame) |
| 3060 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript)); |
| 3061 | if (notify_result) { |
| 3062 | ListValue list; |
| 3063 | if (!result.IsEmpty() && web_frame) { |
| 3064 | v8::HandleScope handle_scope; |
| 3065 | v8::Local<v8::Context> context = web_frame->mainWorldScriptContext(); |
| 3066 | v8::Context::Scope context_scope(context); |
| 3067 | V8ValueConverterImpl converter; |
| 3068 | converter.set_allow_date(true); |
| 3069 | converter.set_allow_regexp(true); |
| 3070 | list.Set(0, converter.FromV8Value(result, context)); |
| 3071 | } else { |
| 3072 | list.Set(0, Value::CreateNullValue()); |
| 3073 | } |
| 3074 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list)); |
| 3075 | } |
| 3076 | } |
| 3077 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3078 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3079 | return (!send_preferred_size_changes_ || |
| 3080 | (disable_scrollbars_size_limit_.width() <= width || |
| 3081 | disable_scrollbars_size_limit_.height() <= height)); |
| 3082 | } |
| 3083 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3084 | int RenderViewImpl::GetEnabledBindings() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3085 | return enabled_bindings_; |
| 3086 | } |
| 3087 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3088 | void RenderViewImpl::SetEnabledBindings(int enabled_bindings) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3089 | enabled_bindings_ = enabled_bindings; |
| 3090 | } |
| 3091 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3092 | bool RenderViewImpl::GetContentStateImmediately() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3093 | return send_content_state_immediately_; |
| 3094 | } |
| 3095 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3096 | float RenderViewImpl::GetFilteredTimePerFrame() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3097 | return filtered_time_per_frame(); |
| 3098 | } |
| 3099 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3100 | void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame, |
| 3101 | const WebKit::WebContextMenuData& data) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3102 | showContextMenu(frame, data); |
| 3103 | } |
| 3104 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3105 | WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3106 | return visibilityState(); |
| 3107 | } |
| 3108 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3109 | void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame, |
| 3110 | const WebKit::WebString& message) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3111 | return runModalAlertDialog(frame, message); |
| 3112 | } |
| 3113 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3114 | void RenderViewImpl::LoadURLExternally( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3115 | WebKit::WebFrame* frame, |
| 3116 | const WebKit::WebURLRequest& request, |
| 3117 | WebKit::WebNavigationPolicy policy) { |
| 3118 | loadURLExternally(frame, request, policy); |
| 3119 | } |
| 3120 | |
| 3121 | // webkit_glue::WebPluginPageDelegate ------------------------------------------ |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3122 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3123 | webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3124 | const FilePath& file_path, |
| 3125 | const std::string& mime_type) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3126 | if (!PluginChannelHost::IsListening()) |
| 3127 | return NULL; |
| 3128 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3129 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3130 | if (in_process_plugin) { |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 3131 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 3132 | return webkit::npapi::WebPluginDelegateImpl::Create( |
| 3133 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3134 | #else |
[email protected] | 7398dcc | 2011-09-06 21:40:32 | [diff] [blame] | 3135 | // In-proc plugins aren't supported on non-Windows. |
[email protected] | e8f7a18 | 2011-03-10 00:50:22 | [diff] [blame] | 3136 | NOTIMPLEMENTED(); |
| 3137 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3138 | #endif |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3139 | } |
| 3140 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3141 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3142 | } |
| 3143 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3144 | void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3145 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 3146 | Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3147 | #endif |
| 3148 | } |
| 3149 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3150 | void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3151 | #if defined(USE_X11) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 3152 | Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3153 | #endif |
| 3154 | CleanupWindowInPluginMoves(window); |
| 3155 | } |
| 3156 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3157 | void RenderViewImpl::DidMovePlugin( |
| 3158 | const webkit::npapi::WebPluginGeometry& move) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3159 | SchedulePluginMove(move); |
| 3160 | } |
| 3161 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3162 | void RenderViewImpl::DidStartLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3163 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3164 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3165 | } |
| 3166 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3167 | void RenderViewImpl::DidStopLoadingForPlugin() { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3168 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3169 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3170 | } |
| 3171 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3172 | WebCookieJar* RenderViewImpl::GetCookieJar() { |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3173 | return &cookie_jar_; |
| 3174 | } |
| 3175 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3176 | void RenderViewImpl::SyncNavigationState() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3177 | if (!webview()) |
| 3178 | return; |
| 3179 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3180 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3181 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3182 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3183 | |
| 3184 | Send(new ViewHostMsg_UpdateState( |
| 3185 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3186 | } |
| 3187 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3188 | void RenderViewImpl::SyncSelectionIfRequired() { |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3189 | WebFrame* frame = webview()->focusedFrame(); |
| 3190 | const std::string& text = frame->selectionAsText().utf8(); |
| 3191 | |
| 3192 | ui::Range range(ui::Range::InvalidRange()); |
| 3193 | size_t location, length; |
| 3194 | if (webview()->caretOrSelectionRange(&location, &length)) { |
| 3195 | range.set_start(location); |
| 3196 | range.set_end(location + length); |
| 3197 | } |
| 3198 | |
| 3199 | WebPoint start, end; |
| 3200 | webview()->selectionRange(start, end); |
| 3201 | |
| 3202 | RenderViewSelection this_selection(text, range, start, end); |
| 3203 | |
| 3204 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 3205 | // the selection hasn't actually changed. We don't want to report these |
| 3206 | // because it will cause us to continually claim the X clipboard. |
| 3207 | if (this_selection.Equals(last_selection_)) |
| 3208 | return; |
| 3209 | last_selection_ = this_selection; |
| 3210 | |
| 3211 | Send(new ViewHostMsg_SelectionChanged(routing_id_, text, range, |
| 3212 | start, end)); |
| 3213 | } |
| 3214 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3215 | GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url, |
| 3216 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3217 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3218 | // If the URL that failed was secure, then the embedding web page was not |
| 3219 | // expecting a network attacker to be able to manipulate its contents. As |
| 3220 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3221 | // attacker to manipulate the contents of the response if we tried to use |
| 3222 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3223 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | // Grab the base URL from the browser process. |
| 3227 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3228 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3229 | |
| 3230 | // Strip query params from the failed URL. |
| 3231 | GURL::Replacements remove_params; |
| 3232 | remove_params.ClearUsername(); |
| 3233 | remove_params.ClearPassword(); |
| 3234 | remove_params.ClearQuery(); |
| 3235 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3236 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3237 | std::string spec_to_send = url_to_send.spec(); |
| 3238 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3239 | if (failed_url.has_query()) |
| 3240 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3241 | |
| 3242 | // Construct the query params to send to link doctor. |
| 3243 | std::string params(alternate_error_page_url_.query()); |
| 3244 | params.append("&url="); |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 3245 | params.append(net::EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3246 | params.append("&sourceid=chrome"); |
| 3247 | params.append("&error="); |
| 3248 | switch (error_type) { |
| 3249 | case DNS_ERROR: |
| 3250 | params.append("dnserror"); |
| 3251 | break; |
| 3252 | |
| 3253 | case HTTP_404: |
| 3254 | params.append("http404"); |
| 3255 | break; |
| 3256 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3257 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3258 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3259 | break; |
| 3260 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3261 | default: |
| 3262 | NOTREACHED() << "unknown ErrorPageType"; |
| 3263 | } |
| 3264 | |
| 3265 | // OK, build the final url to return. |
| 3266 | GURL::Replacements link_doctor_params; |
| 3267 | link_doctor_params.SetQueryStr(params); |
| 3268 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3269 | return url; |
| 3270 | } |
| 3271 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3272 | GURL RenderViewImpl::GetOpenerUrl() const { |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 3273 | if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_) |
| 3274 | return GURL(); |
| 3275 | else |
| 3276 | return creator_url_; |
| 3277 | } |
| 3278 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3279 | WebUIBindings* RenderViewImpl::GetWebUIBindings() { |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 3280 | if (!web_ui_bindings_.get()) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3281 | web_ui_bindings_.reset(new WebUIBindings( |
| 3282 | static_cast<content::RenderView*>(this), routing_id_)); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3283 | } |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 3284 | return web_ui_bindings_.get(); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3285 | } |
| 3286 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3287 | WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3288 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3289 | } |
| 3290 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3291 | void RenderViewImpl::OnFind(int request_id, const string16& search_text, |
| 3292 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3293 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3294 | |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 3295 | // Check if the plugin still exists in the document. |
| 3296 | if (main_frame->document().isPluginDocument() && |
| 3297 | GetWebPluginFromPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3298 | if (options.findNext) { |
| 3299 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3300 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3301 | } else { |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 3302 | if (GetWebPluginFromPluginDocument()->startFind( |
| 3303 | search_text, options.matchCase, request_id)) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3304 | } else { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3305 | // Send "no results". |
| 3306 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3307 | request_id, |
| 3308 | 0, |
| 3309 | gfx::Rect(), |
| 3310 | 0, |
| 3311 | true)); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3312 | } |
| 3313 | } |
| 3314 | return; |
| 3315 | } |
| 3316 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3317 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3318 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3319 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 3320 | |
| 3321 | bool multi_frame = (frame_after_main != main_frame); |
| 3322 | |
| 3323 | // If we have multiple frames, we don't want to wrap the search within the |
| 3324 | // frame, so we check here if we only have main_frame in the chain. |
| 3325 | bool wrap_within_frame = !multi_frame; |
| 3326 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 3327 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3328 | bool result = false; |
| 3329 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3330 | // If something is selected when we start searching it means we cannot just |
| 3331 | // increment the current match ordinal; we need to re-generate it. |
| 3332 | WebRange current_selection = focused_frame->selectionRange(); |
| 3333 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3334 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3335 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3336 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3337 | |
| 3338 | if (!result) { |
| 3339 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3340 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3341 | |
| 3342 | // Find the next frame, but skip the invisible ones. |
| 3343 | do { |
| 3344 | // What is the next frame to search? (we might be going backwards). Note |
| 3345 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3346 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3347 | search_frame->traverseNext(true) : |
| 3348 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3349 | } while (!search_frame->hasVisibleContent() && |
| 3350 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3351 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 3352 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3353 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3354 | |
| 3355 | // If we have multiple frames and we have wrapped back around to the |
| 3356 | // focused frame, we need to search it once more allowing wrap within |
| 3357 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 3358 | // reported matches, but no frames after the focused_frame contain a |
| 3359 | // match for the search word(s). |
| 3360 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3361 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3362 | request_id, search_text, options, true, // Force wrapping. |
| 3363 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3364 | } |
| 3365 | } |
| 3366 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3367 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3368 | } while (!result && search_frame != focused_frame); |
| 3369 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3370 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3371 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3372 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3373 | } else { |
| 3374 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 3375 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 3376 | // yet what is active. |
| 3377 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 3378 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3379 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3380 | // If we find no matches then this will be our last status update. |
| 3381 | // Otherwise the scoping effort will send more results. |
| 3382 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3383 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3384 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 3385 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3386 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3387 | match_count, |
| 3388 | selection_rect, |
| 3389 | ordinal, |
| 3390 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3391 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3392 | // Scoping effort begins, starting with the mainframe. |
| 3393 | search_frame = main_frame; |
| 3394 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3395 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3396 | |
| 3397 | do { |
| 3398 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3399 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3400 | |
| 3401 | // We don't start another scoping effort unless at least one match has |
| 3402 | // been found. |
| 3403 | if (result) { |
| 3404 | // Start new scoping request. If the scoping function determines that it |
| 3405 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3406 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3407 | search_text, |
| 3408 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3409 | true); // reset the tickmarks |
| 3410 | } |
| 3411 | |
| 3412 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 3413 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3414 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3415 | } while (search_frame != main_frame); |
| 3416 | } |
| 3417 | } |
| 3418 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3419 | void RenderViewImpl::OnStopFinding(const ViewMsg_StopFinding_Params& params) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3420 | WebView* view = webview(); |
| 3421 | if (!view) |
| 3422 | return; |
| 3423 | |
| 3424 | WebDocument doc = view->mainFrame()->document(); |
[email protected] | 87254253 | 2011-06-23 00:43:16 | [diff] [blame] | 3425 | if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3426 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3427 | return; |
| 3428 | } |
| 3429 | |
| 3430 | bool clear_selection = |
| 3431 | params.action == ViewMsg_StopFinding_Params::kClearSelection; |
| 3432 | if (clear_selection) |
| 3433 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 3434 | |
| 3435 | WebFrame* frame = view->mainFrame(); |
| 3436 | while (frame) { |
| 3437 | frame->stopFinding(clear_selection); |
| 3438 | frame = frame->traverseNext(false); |
| 3439 | } |
| 3440 | |
| 3441 | if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) { |
| 3442 | WebFrame* focused_frame = view->focusedFrame(); |
| 3443 | if (focused_frame) { |
| 3444 | WebDocument doc = focused_frame->document(); |
| 3445 | if (!doc.isNull()) { |
| 3446 | WebNode node = doc.focusedNode(); |
| 3447 | if (!node.isNull()) |
| 3448 | node.simulateClick(); |
| 3449 | } |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3454 | void RenderViewImpl::OnFindReplyAck() { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3455 | // Check if there is any queued up request waiting to be sent. |
| 3456 | if (queued_find_reply_message_.get()) { |
| 3457 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 3458 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3459 | } |
| 3460 | } |
| 3461 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3462 | void RenderViewImpl::OnZoom(PageZoom::Function function) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3463 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 3464 | return; |
| 3465 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 3466 | webview()->hidePopups(); |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 3467 | #if !defined(TOUCH_UI) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3468 | double old_zoom_level = webview()->zoomLevel(); |
| 3469 | double zoom_level; |
| 3470 | if (function == PageZoom::RESET) { |
| 3471 | zoom_level = 0; |
| 3472 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 3473 | // Previous zoom level is a whole number, so just increment/decrement. |
| 3474 | zoom_level = old_zoom_level + function; |
| 3475 | } else { |
| 3476 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 3477 | // not a whole number, or a plugin changed it to a custom value. We want |
| 3478 | // to go to the next whole number so that the user can always get back to |
| 3479 | // 100% with the keyboard/menu. |
| 3480 | if ((old_zoom_level > 1 && function > 0) || |
| 3481 | (old_zoom_level < 1 && function < 0)) { |
[email protected] | 3209e711 | 2010-10-01 23:53:45 | [diff] [blame] | 3482 | zoom_level = static_cast<int>(old_zoom_level + function); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3483 | } else { |
| 3484 | // We're going towards 100%, so first go to the next whole number. |
| 3485 | zoom_level = static_cast<int>(old_zoom_level); |
| 3486 | } |
| 3487 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3488 | webview()->setZoomLevel(false, zoom_level); |
[email protected] | c514d637 | 2011-08-16 22:54:44 | [diff] [blame] | 3489 | #else |
| 3490 | double old_page_scale_factor = webview()->pageScaleFactor(); |
| 3491 | double page_scale_factor; |
| 3492 | if (function == PageZoom::RESET) { |
| 3493 | page_scale_factor = 1.0; |
| 3494 | } else { |
| 3495 | page_scale_factor = old_page_scale_factor + |
| 3496 | (function > 0 ? kScalingIncrement : -kScalingIncrement); |
| 3497 | } |
| 3498 | webview()->scalePage(page_scale_factor, WebPoint(0, 0)); |
| 3499 | #endif |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 3500 | zoomLevelChanged(); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3501 | } |
| 3502 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3503 | void RenderViewImpl::OnSetZoomLevel(double zoom_level) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 3504 | // Don't set zoom level for full-page plugin since they don't use the same |
| 3505 | // zoom settings. |
| 3506 | if (webview()->mainFrame()->document().isPluginDocument()) |
| 3507 | return; |
| 3508 | |
| 3509 | webview()->hidePopups(); |
| 3510 | webview()->setZoomLevel(false, zoom_level); |
| 3511 | zoomLevelChanged(); |
| 3512 | } |
| 3513 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3514 | void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 3515 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3516 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3517 | } |
| 3518 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3519 | void RenderViewImpl::OnExitFullscreen() { |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 3520 | webview()->exitFullscreen(); |
| 3521 | } |
| 3522 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3523 | void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3524 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3525 | } |
| 3526 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3527 | void RenderViewImpl::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3528 | WebString no_encoding; |
| 3529 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3530 | } |
| 3531 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3532 | WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3533 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3534 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3535 | |
| 3536 | // xpath string can represent a frame deep down the tree (across multiple |
| 3537 | // frame DOMs). |
| 3538 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 3539 | // should break into 2 xpaths |
| 3540 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 3541 | std::vector<string16> xpaths; |
| 3542 | base::SplitString(xpath, '\n', &xpaths); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3543 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3544 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | 318bf580 | 2011-08-08 17:12:41 | [diff] [blame] | 3545 | for (std::vector<string16>::const_iterator i = xpaths.begin(); |
| 3546 | frame && i != xpaths.end(); ++i) { |
| 3547 | frame = frame->findChildByExpression(*i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3548 | } |
| 3549 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3550 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3551 | } |
| 3552 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3553 | void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath, |
| 3554 | const string16& jscript, |
| 3555 | int id, |
| 3556 | bool notify_result) { |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 3557 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3558 | } |
| 3559 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3560 | void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath, |
| 3561 | const std::string& css) { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 3562 | WebFrame* frame = GetChildFrame(frame_xpath); |
| 3563 | if (!frame) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3564 | return; |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 3565 | |
[email protected] | 01cf589c | 2011-07-28 18:04:03 | [diff] [blame] | 3566 | frame->document().insertUserStyleSheet( |
| 3567 | WebString::fromUTF8(css), |
| 3568 | WebDocument::UserStyleAuthorLevel); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3569 | } |
| 3570 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3571 | void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 3572 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3573 | } |
| 3574 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3575 | void RenderViewImpl::OnSetWebUIProperty(const std::string& name, |
| 3576 | const std::string& value) { |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 3577 | DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI); |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 3578 | GetWebUIBindings()->SetProperty(name, value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3579 | } |
| 3580 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3581 | void RenderViewImpl::OnReservePageIDRange(int size_of_range) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3582 | next_page_id_ += size_of_range + 1; |
| 3583 | } |
| 3584 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3585 | void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data, |
| 3586 | const gfx::Point& client_point, |
| 3587 | const gfx::Point& screen_point, |
| 3588 | WebDragOperationsMask ops) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3589 | WebDragOperation operation = webview()->dragTargetDragEnter( |
| 3590 | drop_data.ToDragData(), |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3591 | client_point, |
| 3592 | screen_point, |
| 3593 | ops); |
| 3594 | |
| 3595 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 3596 | } |
| 3597 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3598 | void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
| 3599 | const gfx::Point& screen_point, |
| 3600 | WebDragOperationsMask ops) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3601 | WebDragOperation operation = webview()->dragTargetDragOver( |
| 3602 | client_point, |
| 3603 | screen_point, |
| 3604 | ops); |
| 3605 | |
| 3606 | Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation)); |
| 3607 | } |
| 3608 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3609 | void RenderViewImpl::OnDragTargetDragLeave() { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3610 | webview()->dragTargetDragLeave(); |
| 3611 | } |
| 3612 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3613 | void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, |
| 3614 | const gfx::Point& screen_point) { |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3615 | webview()->dragTargetDrop(client_point, screen_point); |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 3616 | |
| 3617 | Send(new DragHostMsg_TargetDrop_ACK(routing_id_)); |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 3618 | } |
| 3619 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3620 | void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 3621 | const gfx::Point& screen_point, |
| 3622 | bool ended, |
| 3623 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 3624 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3625 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 3626 | } else { |
| 3627 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 3628 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3629 | } |
| 3630 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3631 | void RenderViewImpl::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3632 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3633 | } |
| 3634 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3635 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 3636 | webkit_preferences_ = prefs; |
| 3637 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3638 | } |
| 3639 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3640 | void RenderViewImpl::OnUpdateRemoteAccessClientFirewallTraversal( |
[email protected] | 08bb1e72 | 2011-07-30 19:13:04 | [diff] [blame] | 3641 | const std::string& policy) { |
| 3642 | pepper_delegate_.PublishPolicy(policy); |
| 3643 | } |
| 3644 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3645 | void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3646 | alternate_error_page_url_ = url; |
| 3647 | } |
| 3648 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3649 | void RenderViewImpl::OnCustomContextMenuAction( |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 3650 | const webkit_glue::CustomContextMenuContext& custom_context, |
| 3651 | unsigned action) { |
| 3652 | if (custom_context.is_pepper_menu) |
| 3653 | pepper_delegate_.OnCustomContextMenuAction(custom_context, action); |
| 3654 | else |
| 3655 | webview()->performCustomContextMenuAction(action); |
[email protected] | 440a0e5 | 2011-09-13 17:38:58 | [diff] [blame] | 3656 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
| 3657 | ContextMenuAction(action)); |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 3658 | } |
| 3659 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3660 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 3661 | int id, |
| 3662 | const std::vector<FilePath>& paths) { |
| 3663 | if (!enumeration_completions_[id]) |
| 3664 | return; |
| 3665 | |
| 3666 | WebVector<WebString> ws_file_names(paths.size()); |
| 3667 | for (size_t i = 0; i < paths.size(); ++i) |
| 3668 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
| 3669 | |
| 3670 | enumeration_completions_[id]->didChooseFile(ws_file_names); |
| 3671 | enumeration_completions_.erase(id); |
| 3672 | } |
| 3673 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3674 | void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3675 | // This could happen if we navigated to a different page before the user |
| 3676 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3677 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3678 | return; |
| 3679 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3680 | WebVector<WebString> ws_file_names(paths.size()); |
| 3681 | for (size_t i = 0; i < paths.size(); ++i) |
| 3682 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 3683 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3684 | if (file_chooser_completions_.front()->completion) |
| 3685 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 3686 | file_chooser_completions_.pop_front(); |
| 3687 | |
| 3688 | // If there are more pending file chooser requests, schedule one now. |
| 3689 | if (!file_chooser_completions_.empty()) { |
| 3690 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 3691 | file_chooser_completions_.front()->params)); |
| 3692 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3693 | } |
| 3694 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3695 | void RenderViewImpl::OnEnablePreferredSizeChangedMode(int flags) { |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 3696 | DCHECK(flags != kPreferredSizeNothing); |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3697 | if (send_preferred_size_changes_) |
| 3698 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3699 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 3700 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3701 | // Start off with an initial preferred size notification (in case |
| 3702 | // |didUpdateLayout| was already called). |
| 3703 | if (webview()) |
| 3704 | didUpdateLayout(webview()->mainFrame()); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 3705 | } |
| 3706 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3707 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3708 | const gfx::Size& disable_scrollbar_size_limit) { |
| 3709 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 3710 | } |
| 3711 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3712 | void RenderViewImpl::OnSetRendererPrefs( |
| 3713 | const RendererPreferences& renderer_prefs) { |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3714 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 3715 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 0dd6f9b5 | 2010-10-14 16:39:13 | [diff] [blame] | 3716 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 3717 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 3718 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 3719 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 42e5c86 | 2011-04-07 22:13:51 | [diff] [blame] | 3720 | gfx::NativeTheme::instance()->SetScrollbarColors( |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 3721 | renderer_prefs.thumb_inactive_color, |
| 3722 | renderer_prefs.thumb_active_color, |
| 3723 | renderer_prefs.track_color); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 3724 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3725 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 3726 | webview()->setScrollbarColors( |
| 3727 | renderer_prefs.thumb_inactive_color, |
| 3728 | renderer_prefs.thumb_active_color, |
| 3729 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3730 | webview()->setSelectionColors( |
| 3731 | renderer_prefs.active_selection_bg_color, |
| 3732 | renderer_prefs.active_selection_fg_color, |
| 3733 | renderer_prefs.inactive_selection_bg_color, |
| 3734 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 3735 | webview()->themeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3736 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 3737 | #endif |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3738 | } |
| 3739 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3740 | void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location, |
| 3741 | const WebMediaPlayerAction& action) { |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 3742 | if (webview()) |
| 3743 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 3744 | } |
| 3745 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3746 | void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3747 | const GURL& page_url) { |
| 3748 | // Prepare list to storage all savable resource links. |
| 3749 | std::vector<GURL> resources_list; |
| 3750 | std::vector<GURL> referrers_list; |
| 3751 | std::vector<GURL> frames_list; |
| 3752 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 3753 | &referrers_list, |
| 3754 | &frames_list); |
| 3755 | |
| 3756 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 3757 | webview(), |
| 3758 | page_url, |
| 3759 | &result, |
[email protected] | 2a80aee | 2011-10-07 16:06:03 | [diff] [blame] | 3760 | chrome::GetSavableSchemes())) { |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3761 | // If something is wrong when collecting all savable resource links, |
| 3762 | // send empty list to embedder(browser) to tell it failed. |
| 3763 | referrers_list.clear(); |
| 3764 | resources_list.clear(); |
| 3765 | frames_list.clear(); |
| 3766 | } |
| 3767 | |
| 3768 | // Send result of all savable resource links to embedder. |
| 3769 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), |
| 3770 | resources_list, |
| 3771 | referrers_list, |
| 3772 | frames_list)); |
| 3773 | } |
| 3774 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3775 | void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | 18d5be9 | 2011-07-25 18:00:19 | [diff] [blame] | 3776 | const std::vector<GURL>& links, |
| 3777 | const std::vector<FilePath>& local_paths, |
| 3778 | const FilePath& local_directory_name) { |
| 3779 | |
| 3780 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 3781 | WebVector<WebURL> weburl_links(links); |
| 3782 | |
| 3783 | // Convert std::vector of std::strings to WebVector<WebString> |
| 3784 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 3785 | for (size_t i = 0; i < local_paths.size(); i++) |
| 3786 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 3787 | |
| 3788 | WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links, |
| 3789 | webstring_paths, |
| 3790 | webkit_glue::FilePathToWebString( |
| 3791 | local_directory_name)); |
| 3792 | } |
| 3793 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3794 | void RenderViewImpl::OnShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3795 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3796 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3797 | } |
| 3798 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3799 | void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3800 | if (is_swapped_out_) |
| 3801 | return; |
| 3802 | |
| 3803 | // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 3804 | // different process. This involves running the unload handler and clearing |
| 3805 | // the page. Once WasSwappedOut is called, we also allow this process to exit |
| 3806 | // if there are no other active RenderViews in it. |
| 3807 | |
| 3808 | // Send an UpdateState message before we get swapped out. |
| 3809 | SyncNavigationState(); |
| 3810 | |
| 3811 | // Synchronously run the unload handler before sending the ACK. |
| 3812 | webview()->dispatchUnloadEvent(); |
| 3813 | |
| 3814 | // Swap out and stop sending any IPC messages that are not ACKs. |
| 3815 | SetSwappedOut(true); |
| 3816 | |
| 3817 | // Replace the page with a blank dummy URL. The unload handler will not be |
| 3818 | // run a second time, thanks to a check in FrameLoader::stopLoading. |
| 3819 | // TODO(creis): Need to add a better way to do this that avoids running the |
| 3820 | // beforeunload handler. For now, we just run it a second time silently. |
| 3821 | webview()->mainFrame()->loadHTMLString(std::string(), |
| 3822 | GURL("about:swappedout"), |
| 3823 | GURL("about:swappedout"), |
| 3824 | false); |
| 3825 | |
| 3826 | // Just echo back the params in the ACK. |
| 3827 | Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 3828 | } |
| 3829 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3830 | void RenderViewImpl::OnClosePage() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3831 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 3832 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 3833 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 3834 | // calling the FrameLoader's CloseURL method directly. This should be |
| 3835 | // revisited to avoid having two ways to close a page. Having a single way |
| 3836 | // to close that can run onunload is also useful for fixing |
| 3837 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3838 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3839 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 3840 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3841 | } |
| 3842 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3843 | void RenderViewImpl::OnThemeChanged() { |
[email protected] | e8d6b9f | 2011-10-10 22:21:02 | [diff] [blame] | 3844 | #if defined(USE_AURA) |
| 3845 | // Aura doesn't care if we switch themes. |
| 3846 | #elif defined(OS_WIN) |
[email protected] | c6d94221 | 2011-03-30 19:02:16 | [diff] [blame] | 3847 | gfx::NativeThemeWin::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 3848 | if (webview()) |
| 3849 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 3850 | #else // defined(OS_WIN) |
| 3851 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 3852 | NOTIMPLEMENTED(); |
| 3853 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3854 | } |
| 3855 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3856 | void RenderViewImpl::OnDisassociateFromPopupCount() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 3857 | if (decrement_shared_popup_at_destruction_) |
| 3858 | shared_popup_counter_->data--; |
| 3859 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 3860 | decrement_shared_popup_at_destruction_ = false; |
| 3861 | } |
| 3862 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3863 | bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 3864 | const WebURLError& error, |
| 3865 | bool replace) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3866 | // We only show alternate error pages in the main frame. They are |
| 3867 | // intended to assist the user when navigating, so there is not much |
| 3868 | // value in showing them for failed subframes. Ideally, we would be |
| 3869 | // able to use the TYPED transition type for this, but that flag is |
| 3870 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3871 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3872 | return false; |
| 3873 | |
| 3874 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 3875 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3876 | int ec = error.reason; |
| 3877 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 3878 | ec != net::ERR_CONNECTION_FAILED && |
| 3879 | ec != net::ERR_CONNECTION_REFUSED && |
| 3880 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 3881 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3882 | return false; |
| 3883 | |
| 3884 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3885 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3886 | if (!error_page_url.is_valid()) |
| 3887 | return false; |
| 3888 | |
| 3889 | // Load an empty page first so there is an immediate response to the error, |
| 3890 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3891 | frame->loadHTMLString(std::string(), |
[email protected] | 144143c | 2010-10-28 08:17:36 | [diff] [blame] | 3892 | GURL(chrome::kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3893 | error.unreachableURL, |
| 3894 | replace); |
| 3895 | |
| 3896 | // Now, create a fetcher for the error page and associate it with the data |
| 3897 | // source we just created via the LoadHTMLString call. That way if another |
| 3898 | // navigation occurs, the fetcher will get destroyed. |
| 3899 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3900 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3901 | navigation_state->set_alt_error_page_fetcher( |
| 3902 | new AltErrorPageResourceFetcher( |
| 3903 | error_page_url, frame, error, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3904 | NewCallback(this, &RenderViewImpl::AltErrorPageFinished))); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3905 | return true; |
| 3906 | } |
| 3907 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3908 | void RenderViewImpl::AltErrorPageFinished(WebFrame* frame, |
| 3909 | const WebURLError& original_error, |
| 3910 | const std::string& html) { |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3911 | // Here, we replace the blank page we loaded previously. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3912 | // If we failed to download the alternate error page, LoadNavigationErrorPage |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3913 | // will simply display a default error page. |
[email protected] | 06333afe | 2011-02-24 14:55:09 | [diff] [blame] | 3914 | LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 3915 | } |
| 3916 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3917 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3918 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 3919 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3920 | } |
| 3921 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3922 | void RenderViewImpl::OnResize(const gfx::Size& new_size, |
| 3923 | const gfx::Rect& resizer_rect) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3924 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 3925 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3926 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 3927 | webview()->mainFrame()->setCanHaveScrollbars( |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 3928 | ShouldDisplayScrollbars(new_size.width(), new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3929 | } |
[email protected] | dd6afca | 2011-08-13 03:44:31 | [diff] [blame] | 3930 | UpdateScrollState(webview()->mainFrame()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3931 | } |
| 3932 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 3933 | RenderWidget::OnResize(new_size, resizer_rect); |
| 3934 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 3935 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3936 | void RenderViewImpl::DidInitiatePaint() { |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 3937 | // Notify the pepper plugins that we started painting. |
| 3938 | pepper_delegate_.ViewInitiatedPaint(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3939 | } |
| 3940 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3941 | void RenderViewImpl::DidFlushPaint() { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3942 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 3943 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 3944 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 3945 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 3946 | pepper_delegate_.ViewFlushedPaint(); |
| 3947 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3948 | WebFrame* main_frame = webview()->mainFrame(); |
| 3949 | |
| 3950 | // If we have a provisional frame we are between the start and commit stages |
| 3951 | // of loading and we don't want to save stats. |
| 3952 | if (!main_frame->provisionalDataSource()) { |
| 3953 | WebDataSource* ds = main_frame->dataSource(); |
| 3954 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3955 | DCHECK(navigation_state); |
| 3956 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3957 | // TODO(jar): The following code should all be inside a method, probably in |
| 3958 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3959 | Time now = Time::Now(); |
| 3960 | if (navigation_state->first_paint_time().is_null()) { |
| 3961 | navigation_state->set_first_paint_time(now); |
| 3962 | } |
| 3963 | if (navigation_state->first_paint_after_load_time().is_null() && |
| 3964 | !navigation_state->finish_load_time().is_null()) { |
| 3965 | navigation_state->set_first_paint_after_load_time(now); |
| 3966 | } |
| 3967 | } |
[email protected] | b781ff28 | 2011-08-20 06:19:36 | [diff] [blame] | 3968 | |
| 3969 | #if defined(TOUCH_UI) |
| 3970 | SyncSelectionIfRequired(); |
| 3971 | #endif |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3972 | } |
| 3973 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3974 | void RenderViewImpl::OnViewContextSwapBuffersPosted() { |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 3975 | RenderWidget::OnSwapBuffersPosted(); |
| 3976 | } |
| 3977 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3978 | void RenderViewImpl::OnViewContextSwapBuffersComplete() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 3979 | RenderWidget::OnSwapBuffersComplete(); |
| 3980 | } |
| 3981 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3982 | void RenderViewImpl::OnViewContextSwapBuffersAborted() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 3983 | RenderWidget::OnSwapBuffersAborted(); |
| 3984 | } |
| 3985 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3986 | webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 3987 | const gfx::Rect& paint_bounds, |
| 3988 | TransportDIB** dib, |
| 3989 | gfx::Rect* location, |
| 3990 | gfx::Rect* clip) { |
| 3991 | return pepper_delegate_.GetBitmapForOptimizedPluginPaint( |
| 3992 | paint_bounds, dib, location, clip); |
| 3993 | } |
| 3994 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 3995 | gfx::Point RenderViewImpl::GetScrollOffset() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 3996 | WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
[email protected] | bcaf227 | 2011-02-15 15:29:43 | [diff] [blame] | 3997 | return gfx::Point(scroll_offset.width, scroll_offset.height); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 3998 | } |
| 3999 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4000 | void RenderViewImpl::OnClearFocusedNode() { |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4001 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4002 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4003 | } |
| 4004 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4005 | void RenderViewImpl::OnSetBackground(const SkBitmap& background) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4006 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4007 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4008 | |
| 4009 | SetBackground(background); |
| 4010 | } |
| 4011 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4012 | void RenderViewImpl::OnSetActive(bool active) { |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4013 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4014 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4015 | |
| 4016 | #if defined(OS_MACOSX) |
| 4017 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4018 | for (plugin_it = plugin_delegates_.begin(); |
| 4019 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4020 | (*plugin_it)->SetWindowFocus(active); |
| 4021 | } |
| 4022 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4023 | } |
| 4024 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4025 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4026 | void RenderViewImpl::OnSetWindowVisibility(bool visible) { |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4027 | // Inform plugins that their container has changed visibility. |
| 4028 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4029 | for (plugin_it = plugin_delegates_.begin(); |
| 4030 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4031 | (*plugin_it)->SetContainerVisibility(visible); |
| 4032 | } |
| 4033 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4034 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4035 | void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 4036 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4037 | // Inform plugins that their window's frame has changed. |
| 4038 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4039 | for (plugin_it = plugin_delegates_.begin(); |
| 4040 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4041 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 4042 | } |
| 4043 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4044 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4045 | void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text, |
| 4046 | int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4047 | // WebPluginDelegateProxy is responsible for figuring out if this event |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4048 | // applies to it or not, so inform all the delegates. |
| 4049 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4050 | for (plugin_it = plugin_delegates_.begin(); |
| 4051 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4052 | (*plugin_it)->ImeCompositionCompleted(text, plugin_id); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4053 | } |
| 4054 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4055 | #endif // OS_MACOSX |
| 4056 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4057 | void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4058 | const EditCommands& edit_commands) { |
| 4059 | edit_commands_ = edit_commands; |
| 4060 | } |
| 4061 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4062 | void RenderViewImpl::Close() { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 4063 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 4064 | WebView* doomed = webview(); |
| 4065 | RenderWidget::Close(); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 4066 | g_view_map.Get().erase(doomed); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 4067 | } |
| 4068 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4069 | void RenderViewImpl::DidHandleKeyEvent() { |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4070 | edit_commands_.clear(); |
| 4071 | } |
| 4072 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4073 | bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | b993705a | 2011-10-09 23:00:24 | [diff] [blame] | 4074 | return pepper_delegate_.HandleMouseEvent(event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 4075 | } |
| 4076 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4077 | void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4078 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event)); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 4079 | } |
| 4080 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4081 | void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) { |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 4082 | FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event)); |
| 4083 | } |
| 4084 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4085 | void RenderViewImpl::OnWasHidden() { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4086 | RenderWidget::OnWasHidden(); |
| 4087 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4088 | if (webview()) { |
| 4089 | webview()->settings()->setMinimumTimerInterval( |
| 4090 | webkit_glue::kBackgroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 4091 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | #if defined(OS_MACOSX) |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4095 | // Inform plugins that their container is no longer visible. |
| 4096 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4097 | for (plugin_it = plugin_delegates_.begin(); |
| 4098 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4099 | (*plugin_it)->SetContainerVisibility(false); |
| 4100 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4101 | #endif // OS_MACOSX |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4102 | } |
| 4103 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4104 | void RenderViewImpl::OnWasRestored(bool needs_repainting) { |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4105 | RenderWidget::OnWasRestored(needs_repainting); |
| 4106 | |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4107 | if (webview()) { |
| 4108 | webview()->settings()->setMinimumTimerInterval( |
| 4109 | webkit_glue::kForegroundTabTimerInterval); |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 4110 | webview()->setVisibilityState(visibilityState(), false); |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | #if defined(OS_MACOSX) |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4114 | // Inform plugins that their container is now visible. |
| 4115 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4116 | for (plugin_it = plugin_delegates_.begin(); |
| 4117 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4118 | (*plugin_it)->SetContainerVisibility(true); |
| 4119 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 4120 | #endif // OS_MACOSX |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 4121 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4122 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4123 | bool RenderViewImpl::SupportsAsynchronousSwapBuffers() { |
[email protected] | 555e75d | 2011-10-08 01:23:38 | [diff] [blame] | 4124 | if (WebWidgetHandlesCompositorScheduling()) |
| 4125 | return false; |
| 4126 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 4127 | WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D(); |
| 4128 | if (!context) |
| 4129 | return false; |
| 4130 | std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8()); |
| 4131 | return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") != |
| 4132 | std::string::npos; |
| 4133 | } |
| 4134 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4135 | void RenderViewImpl::OnSetFocus(bool enable) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4136 | RenderWidget::OnSetFocus(enable); |
| 4137 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4138 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 4139 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4140 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4141 | for (plugin_it = plugin_delegates_.begin(); |
| 4142 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 4143 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4144 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 4145 | // activation state to change just like a call to setIsActive. |
| 4146 | if (enable) |
| 4147 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 4148 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4149 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4150 | } |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 4151 | |
| 4152 | // Notify all Pepper plugins. |
| 4153 | pepper_delegate_.OnSetFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4154 | } |
| 4155 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4156 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4157 | void RenderViewImpl::PpapiPluginFocusChanged() { |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4158 | UpdateInputMethod(); |
| 4159 | } |
| 4160 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4161 | void RenderViewImpl::PpapiPluginTextInputTypeChanged() { |
| 4162 | UpdateInputMethod(); |
| 4163 | } |
| 4164 | |
| 4165 | void RenderViewImpl::PpapiPluginCancelComposition() { |
| 4166 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 4167 | ui::Range range(ui::Range::InvalidRange()); |
| 4168 | Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
| 4169 | } |
| 4170 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4171 | void RenderViewImpl::RequestRemoteAccessClientFirewallTraversal() { |
[email protected] | 08bb1e72 | 2011-07-30 19:13:04 | [diff] [blame] | 4172 | Send(new ViewHostMsg_RequestRemoteAccessClientFirewallTraversal(routing_id_)); |
| 4173 | } |
| 4174 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4175 | void RenderViewImpl::OnImeSetComposition( |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4176 | const string16& text, |
| 4177 | const std::vector<WebKit::WebCompositionUnderline>& underlines, |
| 4178 | int selection_start, |
| 4179 | int selection_end) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4180 | if (pepper_delegate_.IsPluginFocused()) { |
| 4181 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 4182 | pepper_delegate_.OnImeSetComposition(text, |
| 4183 | underlines, |
| 4184 | selection_start, |
| 4185 | selection_end); |
| 4186 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4187 | #if defined(OS_WIN) |
| 4188 | // When a plug-in has focus, we create platform-specific IME data used by |
| 4189 | // our IME emulator and send it directly to the focused plug-in, i.e. we |
| 4190 | // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its |
| 4191 | // instance ID is the same one as the specified ID.) |
| 4192 | if (focused_plugin_id_ >= 0) { |
| 4193 | std::vector<int> clauses; |
| 4194 | std::vector<int> target; |
| 4195 | for (size_t i = 0; i < underlines.size(); ++i) { |
| 4196 | clauses.push_back(underlines[i].startOffset); |
| 4197 | clauses.push_back(underlines[i].endOffset); |
| 4198 | if (underlines[i].thick) { |
| 4199 | target.clear(); |
| 4200 | target.push_back(underlines[i].startOffset); |
| 4201 | target.push_back(underlines[i].endOffset); |
| 4202 | } |
| 4203 | } |
| 4204 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 4205 | for (it = plugin_delegates_.begin(); |
| 4206 | it != plugin_delegates_.end(); ++it) { |
| 4207 | (*it)->ImeCompositionUpdated(text, clauses, target, selection_end, |
| 4208 | focused_plugin_id_); |
| 4209 | } |
| 4210 | return; |
| 4211 | } |
| 4212 | #endif |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4213 | RenderWidget::OnImeSetComposition(text, |
| 4214 | underlines, |
| 4215 | selection_start, |
| 4216 | selection_end); |
| 4217 | } |
| 4218 | } |
| 4219 | |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 4220 | void RenderViewImpl::OnImeConfirmComposition( |
| 4221 | const string16& text, const ui::Range& replacement_range) { |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4222 | if (pepper_delegate_.IsPluginFocused()) { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4223 | // When a PPAPI plugin has focus, we bypass WebKit. |
| 4224 | pepper_delegate_.OnImeConfirmComposition(text); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4225 | } else { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4226 | #if defined(OS_WIN) |
| 4227 | // Same as OnImeSetComposition(), we send the text from IMEs directly to |
| 4228 | // plug-ins. When we send IME text directly to plug-ins, we should not send |
| 4229 | // it to WebKit to prevent WebKit from controlling IMEs. |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 4230 | // TODO(thakis): Honor |replacement_range| for plugins? |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4231 | if (focused_plugin_id_ >= 0) { |
| 4232 | std::set<WebPluginDelegateProxy*>::iterator it; |
| 4233 | for (it = plugin_delegates_.begin(); |
| 4234 | it != plugin_delegates_.end(); ++it) { |
| 4235 | (*it)->ImeCompositionCompleted(text, focused_plugin_id_); |
| 4236 | } |
| 4237 | return; |
| 4238 | } |
| 4239 | #endif |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 4240 | RenderWidget::OnImeConfirmComposition(text, replacement_range); |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4244 | ui::TextInputType RenderViewImpl::GetTextInputType() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4245 | return pepper_delegate_.IsPluginFocused() ? |
| 4246 | pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType(); |
| 4247 | } |
| 4248 | |
| 4249 | gfx::Rect RenderViewImpl::GetCaretBounds() { |
| 4250 | return pepper_delegate_.IsPluginFocused() ? |
| 4251 | pepper_delegate_.GetCaretBounds() : RenderWidget::GetCaretBounds(); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 4252 | } |
| 4253 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4254 | bool RenderViewImpl::CanComposeInline() { |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 4255 | return pepper_delegate_.IsPluginFocused() ? |
| 4256 | pepper_delegate_.CanComposeInline() : true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 4257 | } |
| 4258 | |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4259 | #if defined(OS_WIN) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4260 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | e6ae0f6c | 2011-10-04 10:39:23 | [diff] [blame] | 4261 | if (focused) |
| 4262 | focused_plugin_id_ = plugin_id; |
| 4263 | else |
| 4264 | focused_plugin_id_ = -1; |
| 4265 | } |
| 4266 | #endif |
| 4267 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4268 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4269 | void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4270 | IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(), |
| 4271 | focused, plugin_id); |
| 4272 | Send(msg); |
| 4273 | } |
| 4274 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4275 | void RenderViewImpl::StartPluginIme() { |
[email protected] | b7f7586 | 2011-01-21 21:15:13 | [diff] [blame] | 4276 | IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id()); |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4277 | // This message can be sent during event-handling, and needs to be delivered |
| 4278 | // within that context. |
| 4279 | msg->set_unblock(true); |
| 4280 | Send(msg); |
| 4281 | } |
| 4282 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4283 | gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 4284 | bool opaque, bool root) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4285 | gfx::PluginWindowHandle window = NULL; |
| 4286 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 4287 | routing_id(), opaque, root, &window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 4288 | if (window) { |
| 4289 | fake_plugin_window_handles_.insert(window); |
| 4290 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4291 | return window; |
| 4292 | } |
| 4293 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4294 | void RenderViewImpl::DestroyFakePluginWindowHandle( |
| 4295 | gfx::PluginWindowHandle window) { |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 4296 | if (window && fake_plugin_window_handles_.find(window) != |
| 4297 | fake_plugin_window_handles_.end()) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4298 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 4299 | fake_plugin_window_handles_.erase(window); |
| 4300 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4301 | } |
| 4302 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4303 | void RenderViewImpl::AcceleratedSurfaceSetIOSurface( |
| 4304 | gfx::PluginWindowHandle window, |
| 4305 | int32 width, |
| 4306 | int32 height, |
| 4307 | uint64 io_surface_identifier) { |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4308 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4309 | routing_id(), window, width, height, io_surface_identifier)); |
| 4310 | } |
| 4311 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4312 | void RenderViewImpl::AcceleratedSurfaceSetTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4313 | gfx::PluginWindowHandle window, |
| 4314 | int32 width, |
| 4315 | int32 height, |
| 4316 | TransportDIB::Handle transport_dib) { |
| 4317 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4318 | routing_id(), window, width, height, transport_dib)); |
| 4319 | } |
| 4320 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4321 | TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB( |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4322 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4323 | TransportDIB::Handle dib_handle; |
| 4324 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 4325 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4326 | return dib_handle; |
| 4327 | // Return an invalid handle if Send() fails. |
| 4328 | return TransportDIB::DefaultHandleValue(); |
| 4329 | } |
| 4330 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4331 | void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB( |
| 4332 | TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4333 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 4334 | } |
| 4335 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4336 | void RenderViewImpl::AcceleratedSurfaceBuffersSwapped( |
[email protected] | f35d667 | 2010-10-28 21:39:14 | [diff] [blame] | 4337 | gfx::PluginWindowHandle window, uint64 surface_id) { |
| 4338 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped( |
| 4339 | routing_id(), window, surface_id)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4340 | } |
| 4341 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 4342 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4343 | bool RenderViewImpl::ScheduleFileChooser( |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4344 | const ViewHostMsg_RunFileChooser_Params& params, |
| 4345 | WebFileChooserCompletion* completion) { |
| 4346 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 4347 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 4348 | // This sanity check prevents too many file choose requests from getting |
| 4349 | // queued which could DoS the user. Getting these is most likely a |
| 4350 | // programming error (there are many ways to DoS the user so it's not |
| 4351 | // considered a "real" security check), either in JS requesting many file |
| 4352 | // choosers to pop up, or in a plugin. |
| 4353 | // |
| 4354 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 4355 | // a file picker, which will address this issue in a better way. |
| 4356 | return false; |
| 4357 | } |
| 4358 | |
| 4359 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 4360 | new PendingFileChooser(params, completion))); |
| 4361 | if (file_chooser_completions_.size() == 1) { |
| 4362 | // Actually show the browse dialog when this is the first request. |
| 4363 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 4364 | } |
| 4365 | return true; |
| 4366 | } |
| 4367 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4368 | WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4369 | if (!geolocation_dispatcher_) |
| 4370 | geolocation_dispatcher_ = new GeolocationDispatcher(this); |
| 4371 | return geolocation_dispatcher_; |
[email protected] | 7e0c470 | 2010-12-31 14:06:25 | [diff] [blame] | 4372 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4373 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4374 | WebKit::WebSpeechInputController* RenderViewImpl::speechInputController( |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 4375 | WebKit::WebSpeechInputListener* listener) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4376 | if (!speech_input_dispatcher_) |
| 4377 | speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener); |
| 4378 | return speech_input_dispatcher_; |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 4379 | } |
| 4380 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4381 | WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 4382 | if (!device_orientation_dispatcher_) |
| 4383 | device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this); |
| 4384 | return device_orientation_dispatcher_; |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 4385 | } |
| 4386 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4387 | void RenderViewImpl::zoomLimitsChanged(double minimum_level, |
| 4388 | double maximum_level) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4389 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 4390 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 4391 | // different). |
| 4392 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 4393 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4394 | int minimum_percent = static_cast<int>( |
| 4395 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 4396 | int maximum_percent = static_cast<int>( |
| 4397 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4398 | |
| 4399 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 4400 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 4401 | } |
| 4402 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4403 | void RenderViewImpl::zoomLevelChanged() { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4404 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 4405 | #if defined(TOUCH_UI) |
| 4406 | float zoom_level = |
| 4407 | WebView::zoomFactorToZoomLevel(webview()->pageScaleFactor()); |
| 4408 | #else |
| 4409 | float zoom_level = webview()->zoomLevel(); |
| 4410 | #endif |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4411 | // Tell the browser which url got zoomed so it can update the menu and the |
| 4412 | // saved values if necessary |
| 4413 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | ba51d3b | 2011-08-24 19:53:08 | [diff] [blame] | 4414 | routing_id_, zoom_level, remember, |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4415 | GURL(webview()->mainFrame()->document().url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4416 | } |
| 4417 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4418 | void RenderViewImpl::registerProtocolHandler(const WebString& scheme, |
| 4419 | const WebString& base_url, |
| 4420 | const WebString& url, |
| 4421 | const WebString& title) { |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 4422 | GURL base(base_url); |
| 4423 | GURL absolute_url = base.Resolve(UTF16ToUTF8(url)); |
| 4424 | if (base.GetOrigin() != absolute_url.GetOrigin()) { |
| 4425 | return; |
| 4426 | } |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 4427 | Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_, |
| 4428 | UTF16ToUTF8(scheme), |
| 4429 | absolute_url, |
| 4430 | title)); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 4431 | } |
| 4432 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4433 | void RenderViewImpl::registerIntentHandler(const WebString& action, |
| 4434 | const WebString& type, |
| 4435 | const WebString& href, |
| 4436 | const WebString& title) { |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 4437 | Send(new ViewHostMsg_RegisterIntentHandler(routing_id_, |
| 4438 | action, |
| 4439 | type, |
| 4440 | href, |
| 4441 | title)); |
[email protected] | 62af76e | 2011-08-01 02:34:01 | [diff] [blame] | 4442 | } |
| 4443 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4444 | WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const { |
[email protected] | f59203a | 2011-06-07 10:01:44 | [diff] [blame] | 4445 | WebKit::WebPageVisibilityState current_state = is_hidden() ? |
| 4446 | WebKit::WebPageVisibilityStateHidden : |
| 4447 | WebKit::WebPageVisibilityStateVisible; |
| 4448 | WebKit::WebPageVisibilityState override_state = current_state; |
| 4449 | if (content::GetContentClient()->renderer()-> |
| 4450 | ShouldOverridePageVisibilityState(this, |
| 4451 | &override_state)) |
| 4452 | return override_state; |
| 4453 | return current_state; |
[email protected] | 94dec93 | 2011-05-26 20:04:21 | [diff] [blame] | 4454 | } |
| 4455 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4456 | void RenderViewImpl::startActivity(const WebKit::WebString& action, |
| 4457 | const WebKit::WebString& type, |
| 4458 | const WebKit::WebString& data, |
| 4459 | int intent_id) { |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 4460 | webkit_glue::WebIntentData intent_data; |
| 4461 | intent_data.action = action; |
| 4462 | intent_data.type = type; |
| 4463 | intent_data.data = data; |
| 4464 | Send(new IntentsHostMsg_WebIntentDispatch( |
| 4465 | routing_id_, intent_data, intent_id)); |
[email protected] | e235c7d0 | 2011-08-18 22:38:43 | [diff] [blame] | 4466 | } |
| 4467 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4468 | bool RenderViewImpl::IsNonLocalTopLevelNavigation( |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4469 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 4470 | // Must be a top level frame. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4471 | if (frame->parent() != NULL) |
| 4472 | return false; |
| 4473 | |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 4474 | // Navigations initiated within Webkit are not sent out to the external host |
| 4475 | // in the following cases. |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 4476 | // 1. The url scheme is not http/https |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 4477 | // 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] | 4478 | // opener relationship is maintained. |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 4479 | // 3. Reloads/form submits/back forward navigations |
[email protected] | abbfaec | 2011-05-23 23:57:33 | [diff] [blame] | 4480 | if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 4481 | return false; |
| 4482 | |
[email protected] | 2fc22d1 | 2010-12-02 23:08:16 | [diff] [blame] | 4483 | // Not interested in reloads/form submits/resubmits/back forward navigations. |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 4484 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 4485 | type != WebKit::WebNavigationTypeFormSubmitted && |
[email protected] | 2fc22d1 | 2010-12-02 23:08:16 | [diff] [blame] | 4486 | type != WebKit::WebNavigationTypeFormResubmitted && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 4487 | type != WebKit::WebNavigationTypeBackForward) { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 4488 | // The opener relationship between the new window and the parent allows the |
| 4489 | // new window to script the parent and vice versa. This is not allowed if |
| 4490 | // the origins of the two domains are different. This can be treated as a |
| 4491 | // top level navigation and routed back to the host. |
| 4492 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 4493 | if (!opener) { |
[email protected] | 8696536 | 2011-04-21 18:42:51 | [diff] [blame] | 4494 | return true; |
[email protected] | d19ea34 | 2011-04-20 20:31:13 | [diff] [blame] | 4495 | } else { |
[email protected] | b6cb3a84 | 2011-06-24 18:28:41 | [diff] [blame] | 4496 | if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 4497 | return true; |
| 4498 | } |
| 4499 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4500 | return false; |
| 4501 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 4502 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4503 | void RenderViewImpl::OnAsyncFileOpened( |
| 4504 | base::PlatformFileError error_code, |
| 4505 | IPC::PlatformFileForTransit file_for_transit, |
| 4506 | int message_id) { |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 4507 | pepper_delegate_.OnAsyncFileOpened( |
| 4508 | error_code, |
| 4509 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 4510 | message_id); |
| 4511 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 4512 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4513 | void RenderViewImpl::OnPpapiBrokerChannelCreated( |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 4514 | int request_id, |
| 4515 | base::ProcessHandle broker_process_handle, |
[email protected] | d5430507 | 2011-06-22 20:58:43 | [diff] [blame] | 4516 | const IPC::ChannelHandle& handle) { |
[email protected] | 2b657fd | 2011-04-18 16:00:47 | [diff] [blame] | 4517 | pepper_delegate_.OnPpapiBrokerChannelCreated(request_id, |
| 4518 | broker_process_handle, |
| 4519 | handle); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 4520 | } |
| 4521 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 4522 | #if defined(OS_MACOSX) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4523 | void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) { |
[email protected] | 68dc3ba | 2010-12-06 21:43:15 | [diff] [blame] | 4524 | if (external_popup_menu_ == NULL) { |
| 4525 | // Crash reports from the field indicate that we can be notified with a |
| 4526 | // NULL external popup menu (we probably get notified twice). |
| 4527 | // If you hit this please file a bug against jcivelli and include the page |
| 4528 | // and steps to repro. |
| 4529 | NOTREACHED(); |
| 4530 | return; |
| 4531 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 4532 | external_popup_menu_->DidSelectItem(selected_index); |
| 4533 | external_popup_menu_.reset(); |
| 4534 | } |
| 4535 | #endif |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 4536 | |
[email protected] | 1b4209f | 2011-01-07 00:25:40 | [diff] [blame] | 4537 | #if defined(ENABLE_FLAPPER_HACKS) |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4538 | void RenderViewImpl::OnConnectTcpACK( |
[email protected] | 1b4209f | 2011-01-07 00:25:40 | [diff] [blame] | 4539 | int request_id, |
| 4540 | IPC::PlatformFileForTransit socket_for_transit, |
| 4541 | const PP_Flash_NetAddress& local_addr, |
| 4542 | const PP_Flash_NetAddress& remote_addr) { |
| 4543 | pepper_delegate_.OnConnectTcpACK( |
| 4544 | request_id, |
| 4545 | IPC::PlatformFileForTransitToPlatformFile(socket_for_transit), |
| 4546 | local_addr, |
| 4547 | remote_addr); |
| 4548 | } |
| 4549 | #endif |
[email protected] | a6097f4 | 2011-01-10 08:50:51 | [diff] [blame] | 4550 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4551 | void RenderViewImpl::OnContextMenuClosed( |
[email protected] | b29aa74b | 2011-01-31 21:41:08 | [diff] [blame] | 4552 | const webkit_glue::CustomContextMenuContext& custom_context) { |
| 4553 | if (custom_context.is_pepper_menu) |
| 4554 | pepper_delegate_.OnContextMenuClosed(custom_context); |
| 4555 | else |
| 4556 | context_menu_node_.reset(); |
[email protected] | 521b248 | 2011-01-15 00:10:10 | [diff] [blame] | 4557 | } |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 4558 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4559 | void RenderViewImpl::OnEnableViewSourceMode() { |
[email protected] | 5a7b15a | 2011-08-22 22:48:18 | [diff] [blame] | 4560 | if (!webview()) |
| 4561 | return; |
| 4562 | WebFrame* main_frame = webview()->mainFrame(); |
| 4563 | if (!main_frame) |
| 4564 | return; |
| 4565 | main_frame->enableViewSourceMode(true); |
| 4566 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 4567 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4568 | void RenderViewImpl::OnLockMouseACK(bool succeeded) { |
[email protected] | 57e02be | 2011-10-11 19:00:53 | [diff] [blame] | 4569 | // Mouse Lock removes the system cursor and provides all mouse motion as |
| 4570 | // .movementX/Y values on events all sent to a fixed target. This requires |
| 4571 | // content to specifically request the mode to be entered. |
| 4572 | // Mouse Capture is implicitly given for the duration of a drag event, and |
| 4573 | // sends all mouse events to the initial target of the drag. |
| 4574 | // If Lock is entered it supercedes any in progress Capture. |
| 4575 | if (succeeded) |
| 4576 | OnMouseCaptureLost(); |
| 4577 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 4578 | pepper_delegate_.OnLockMouseACK(succeeded); |
| 4579 | } |
| 4580 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4581 | void RenderViewImpl::OnMouseLockLost() { |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 4582 | pepper_delegate_.OnMouseLockLost(); |
| 4583 | } |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 4584 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 4585 | bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 4586 | return webview()->settings()->useThreadedCompositor(); |
| 4587 | } |