[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | |
| 5 | #include "chrome/renderer/render_view.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | a92b864 | 2009-05-05 23:38:56 | [diff] [blame] | 11 | #include "app/l10n_util.h" |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 12 | #include "app/message_box_flags.h" |
[email protected] | 9929da9 | 2009-05-05 02:05:11 | [diff] [blame] | 13 | #include "app/resource_bundle.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 14 | #include "base/callback.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 17 | #include "base/field_trial.h" |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 18 | #include "base/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" |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 21 | #include "base/singleton.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | #include "base/string_piece.h" |
| 23 | #include "base/string_util.h" |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 24 | #include "base/time.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 25 | #include "build/build_config.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 26 | #include "chrome/common/appcache/appcache_dispatcher.h" |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 27 | #include "chrome/common/bindings_policy.h" |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 28 | #include "chrome/common/child_process_logging.h" |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 29 | #include "chrome/common/chrome_constants.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 30 | #include "chrome/common/chrome_paths.h" |
| 31 | #include "chrome/common/chrome_switches.h" |
[email protected] | d146b83 | 2009-12-23 02:45:48 | [diff] [blame] | 32 | #include "chrome/common/extensions/extension_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 33 | #include "chrome/common/jstemplate_builder.h" |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 34 | #include "chrome/common/page_zoom.h" |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 35 | #include "chrome/common/pepper_plugin_registry.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 36 | #include "chrome/common/render_messages.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 37 | #include "chrome/common/renderer_preferences.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | #include "chrome/common/thumbnail_score.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 39 | #include "chrome/common/url_constants.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 40 | #include "chrome/common/window_container_type.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | #include "chrome/renderer/about_handler.h" |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 42 | #include "chrome/renderer/audio_message_filter.h" |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 43 | #include "chrome/renderer/devtools_agent.h" |
| 44 | #include "chrome/renderer/devtools_client.h" |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 45 | #include "chrome/renderer/extension_groups.h" |
[email protected] | f816c01 | 2009-06-26 21:48:32 | [diff] [blame] | 46 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 47 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 48 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 49 | #include "chrome/renderer/geolocation_dispatcher.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | #include "chrome/renderer/localized_error.h" |
[email protected] | 6f56d48 | 2009-02-20 05:02:56 | [diff] [blame] | 51 | #include "chrome/renderer/media/audio_renderer_impl.h" |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 52 | #include "chrome/renderer/media/ipc_video_renderer.h" |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 53 | #include "chrome/renderer/navigation_state.h" |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 54 | #include "chrome/renderer/notification_provider.h" |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 55 | #include "chrome/renderer/plugin_channel_host.h" |
[email protected] | d81c1e5 | 2009-06-03 22:09:50 | [diff] [blame] | 56 | #include "chrome/renderer/print_web_view_helper.h" |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 57 | #include "chrome/renderer/render_process.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 58 | #include "chrome/renderer/render_thread.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 59 | #include "chrome/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 60 | #include "chrome/renderer/renderer_webstoragenamespace_impl.h" |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 61 | #include "chrome/renderer/spellchecker/spellcheck.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 62 | #include "chrome/renderer/user_script_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | #include "chrome/renderer/visitedlink_slave.h" |
[email protected] | d439ba07 | 2009-10-17 22:32:29 | [diff] [blame] | 64 | #include "chrome/renderer/webplugin_delegate_pepper.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 65 | #include "chrome/renderer/webplugin_delegate_proxy.h" |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 66 | #include "chrome/renderer/websharedworker_proxy.h" |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 67 | #include "chrome/renderer/webworker_proxy.h" |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 68 | #include "gfx/color_utils.h" |
| 69 | #include "gfx/favicon_size.h" |
[email protected] | 5c7293a | 2010-03-17 06:40:57 | [diff] [blame] | 70 | #include "gfx/native_widget_types.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 71 | #include "grit/generated_resources.h" |
| 72 | #include "grit/renderer_resources.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 73 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 74 | #include "net/base/escape.h" |
| 75 | #include "net/base/net_errors.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 76 | #include "skia/ext/bitmap_platform_device.h" |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 77 | #include "skia/ext/image_operations.h" |
[email protected] | 65127279 | 2010-02-04 23:16:30 | [diff] [blame] | 78 | #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 79 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 80 | #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 81 | #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 82 | #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 83 | #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 84 | #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 85 | #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 86 | #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 87 | #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
| 88 | #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 89 | #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 90 | #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 91 | #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 92 | #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 93 | #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 94 | #include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 95 | #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 96 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 97 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 98 | #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 99 | #include "third_party/WebKit/WebKit/chromium/public/WebRange.h" |
| 100 | #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 101 | #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 102 | #include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h" |
| 103 | #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 104 | #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 105 | #include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 106 | #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 107 | #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 108 | #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 109 | #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 110 | #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 111 | #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 112 | #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 113 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 114 | #include "webkit/default_plugin/default_plugin_shared.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | #include "webkit/glue/dom_operations.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 116 | #include "webkit/glue/form_data.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 117 | #include "webkit/glue/form_field.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 118 | #include "webkit/glue/glue_serialize.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 119 | #include "webkit/glue/image_decoder.h" |
[email protected] | 8e296bbd | 2009-07-22 21:37:17 | [diff] [blame] | 120 | #include "webkit/glue/media/buffered_data_source.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 121 | #include "webkit/glue/media/simple_data_source.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 122 | #include "webkit/glue/media/video_renderer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | #include "webkit/glue/password_form.h" |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 124 | #include "webkit/glue/plugins/pepper_webplugin_impl.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 125 | #include "webkit/glue/plugins/plugin_list.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 126 | #include "webkit/glue/plugins/webplugin_delegate.h" |
[email protected] | 8a3b796 | 2009-09-04 05:53:23 | [diff] [blame] | 127 | #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 128 | #include "webkit/glue/plugins/webplugin_impl.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 129 | #include "webkit/glue/site_isolation_metrics.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 130 | #include "webkit/glue/webdropdata.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 132 | #include "webkit/glue/webmediaplayer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 133 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 134 | #if defined(OS_WIN) |
| 135 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 136 | // * theming |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 137 | #include "gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 138 | #elif defined(USE_X11) |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 139 | #include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 140 | #elif defined(OS_MACOSX) |
| 141 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 142 | #endif |
| 143 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 144 | using appcache::WebApplicationCacheHostImpl; |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 145 | using base::Time; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 146 | using base::TimeDelta; |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 147 | using webkit_glue::AltErrorPageResourceFetcher; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 148 | using webkit_glue::FormData; |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 149 | using webkit_glue::FormField; |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 150 | using webkit_glue::ImageResourceFetcher; |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 151 | using webkit_glue::PasswordForm; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 152 | using webkit_glue::PasswordFormDomManager; |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 153 | using webkit_glue::SiteIsolationMetrics; |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 154 | using WebKit::WebAccessibilityCache; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 155 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 156 | using WebKit::WebApplicationCacheHost; |
| 157 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 158 | using WebKit::WebColor; |
| 159 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 160 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 161 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 162 | using WebKit::WebCookieJar; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 163 | using WebKit::WebCString; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 164 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 165 | using WebKit::WebDataSource; |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 166 | using WebKit::WebDevToolsAgent; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 167 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 168 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 169 | using WebKit::WebDragOperation; |
| 170 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 171 | using WebKit::WebEditingAction; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 172 | using WebKit::WebFileChooserCompletion; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 173 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 174 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 175 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 176 | using WebKit::WebFrame; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 177 | using WebKit::WebHistoryItem; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 178 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 179 | using WebKit::WebInputElement; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 180 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 181 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 182 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 183 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 184 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 185 | using WebKit::WebNode; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 186 | using WebKit::WebPageSerializer; |
| 187 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 188 | using WebKit::WebPlugin; |
| 189 | using WebKit::WebPluginParams; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 190 | using WebKit::WebPluginDocument; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 191 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 192 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 193 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 194 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 195 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 196 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 197 | using WebKit::WebSecurityOrigin; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 198 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 199 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 200 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 201 | using WebKit::WebStorageNamespace; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 202 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 203 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 204 | using WebKit::WebTextDirection; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 205 | using WebKit::WebURL; |
| 206 | using WebKit::WebURLError; |
| 207 | using WebKit::WebURLRequest; |
| 208 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 209 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 210 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 211 | using WebKit::WebWidget; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 212 | using WebKit::WebWorker; |
| 213 | using WebKit::WebWorkerClient; |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 214 | using WebKit::WebWindowFeatures; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 215 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 216 | //----------------------------------------------------------------------------- |
| 217 | |
| 218 | // define to write the time necessary for thumbnail/DOM text retrieval, |
| 219 | // respectively, into the system debug log |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 220 | // #define TIME_TEXT_RETRIEVAL |
| 221 | |
| 222 | // maximum number of characters in the document to index, any text beyond this |
| 223 | // point will be clipped |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 224 | static const size_t kMaxIndexChars = 65535; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | |
| 226 | // Size of the thumbnails that we'll generate |
[email protected] | 8b4f489 | 2009-09-04 21:52:37 | [diff] [blame] | 227 | static const int kThumbnailWidth = 212; |
| 228 | static const int kThumbnailHeight = 132; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 229 | |
| 230 | // Delay in milliseconds that we'll wait before capturing the page contents |
| 231 | // and thumbnail. |
| 232 | static const int kDelayForCaptureMs = 500; |
| 233 | |
| 234 | // Typically, we capture the page data once the page is loaded. |
| 235 | // Sometimes, the page never finishes to load, preventing the page capture |
| 236 | // To workaround this problem, we always perform a capture after the following |
| 237 | // delay. |
| 238 | static const int kDelayForForcedCaptureMs = 6000; |
| 239 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 240 | // Time, in seconds, we delay before sending content state changes (such as form |
| 241 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 242 | // spamming the browser. |
| 243 | // To avoid having tab/session restore require sending a message to get the |
| 244 | // current content state during tab closing we use a shorter timeout for the |
| 245 | // foreground renderer. This means there is a small window of time from which |
| 246 | // content state is modified and not sent to session restore, but this is |
| 247 | // better than having to wake up all renderers during shutdown. |
| 248 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 249 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 250 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 251 | // The maximum number of popups that can be spawned from one page. |
| 252 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 253 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 254 | static const char* const kUnreachableWebDataURL = |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 255 | "chrome://chromewebdata/"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 256 | |
[email protected] | 50b691c | 2008-10-31 19:08:35 | [diff] [blame] | 257 | static const char* const kBackForwardNavigationScheme = "history"; |
| 258 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 259 | // static |
| 260 | const char* const RenderView::kUnknownLanguageCode = "und"; |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 261 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 262 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 263 | WebVector<WebURL> urls; |
| 264 | ds->redirectChain(urls); |
| 265 | result->reserve(urls.size()); |
| 266 | for (size_t i = 0; i < urls.size(); ++i) |
| 267 | result->push_back(urls[i]); |
| 268 | } |
| 269 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 270 | static bool UrlMatchesPermissions( |
| 271 | const GURL& url, const std::vector<URLPattern>& host_permissions) { |
| 272 | for (size_t i = 0; i < host_permissions.size(); ++i) { |
| 273 | if (host_permissions[i].MatchesUrl(url)) |
| 274 | return true; |
| 275 | } |
| 276 | |
| 277 | return false; |
| 278 | } |
| 279 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 280 | static bool PaintViewIntoCanvas(WebView* view, |
| 281 | skia::PlatformCanvas& canvas) { |
| 282 | view->layout(); |
| 283 | const WebSize& size = view->size(); |
| 284 | |
| 285 | if (!canvas.initialize(size.width, size.height, true)) |
| 286 | return false; |
| 287 | |
| 288 | view->paint(webkit_glue::ToWebCanvas(&canvas), |
| 289 | WebRect(0, 0, size.width, size.height)); |
| 290 | // TODO: Add a way to snapshot the whole page, not just the currently |
| 291 | // visible part. |
| 292 | |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | // Calculates how "boring" a thumbnail is. The boring score is the |
| 297 | // 0,1 ranged percentage of pixels that are the most common |
| 298 | // luma. Higher boring scores indicate that a higher percentage of a |
| 299 | // bitmap are all the same brightness. |
| 300 | static double CalculateBoringScore(SkBitmap* bitmap) { |
| 301 | int histogram[256] = {0}; |
| 302 | color_utils::BuildLumaHistogram(bitmap, histogram); |
| 303 | |
| 304 | int color_count = *std::max_element(histogram, histogram + 256); |
| 305 | int pixel_count = bitmap->width() * bitmap->height(); |
| 306 | return static_cast<double>(color_count) / pixel_count; |
| 307 | } |
| 308 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 309 | // True if |frame| contains content that is white-listed for content settings. |
| 310 | static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
| 311 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 312 | if (origin.isEmpty()) |
| 313 | return false; // Uninitialized document? |
| 314 | |
| 315 | if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 316 | return true; // Browser UI elements should still work. |
| 317 | |
| 318 | // If the scheme is ftp: or file:, an empty file name indicates a directory |
| 319 | // listing, which requires JavaScript to function properly. |
| 320 | GURL frame_url = frame->url(); |
| 321 | const char* kDirProtocols[] = { "ftp", "file" }; |
| 322 | for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
| 323 | if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
| 324 | return frame_url.SchemeIs(kDirProtocols[i]) && |
| 325 | frame_url.ExtractFileName().empty(); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | return false; |
| 330 | } |
| 331 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 332 | // Returns true if the frame is navigating to an URL either into or out of an |
| 333 | // extension app's extent. |
| 334 | static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) { |
| 335 | if (!RenderThread::current()) |
| 336 | return false; |
| 337 | |
| 338 | // If the URL is still empty, this is a window.open navigation. Check the |
| 339 | // opener's URL. |
| 340 | GURL old_url(frame->url()); |
| 341 | if (old_url.is_empty() && frame->opener()) |
| 342 | old_url = frame->opener()->url(); |
| 343 | |
| 344 | std::string old_extension = |
| 345 | RenderThread::current()->GetExtensionIdForURL(old_url); |
| 346 | std::string new_extension = |
| 347 | RenderThread::current()->GetExtensionIdForURL(new_url); |
| 348 | return (old_extension != new_extension); |
| 349 | } |
| 350 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | /////////////////////////////////////////////////////////////////////////////// |
| 352 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 353 | int32 RenderView::next_page_id_ = 1; |
| 354 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 355 | struct RenderView::PendingFileChooser { |
| 356 | PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
| 357 | WebFileChooserCompletion* c) |
| 358 | : params(p), |
| 359 | completion(c) { |
| 360 | } |
| 361 | ViewHostMsg_RunFileChooser_Params params; |
| 362 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 363 | }; |
| 364 | |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 365 | RenderView::RenderView(RenderThreadBase* render_thread, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 366 | const WebPreferences& webkit_preferences, |
| 367 | int64 session_storage_namespace_id) |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 368 | : RenderWidget(render_thread, WebKit::WebPopupTypeNone), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 369 | enabled_bindings_(0), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 370 | target_url_status_(TARGET_NONE), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 371 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 372 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 373 | page_id_(-1), |
| 374 | last_page_id_sent_to_browser_(-1), |
| 375 | last_indexed_page_id_(-1), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 376 | opened_by_user_gesture_(true), |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 377 | opener_suppressed_(false), |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 378 | ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 379 | devtools_agent_(NULL), |
| 380 | devtools_client_(NULL), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 381 | history_list_offset_(-1), |
| 382 | history_list_length_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 383 | has_unload_listener_(false), |
| 384 | decrement_shared_popup_at_destruction_(false), |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 385 | autofill_query_id_(0), |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 386 | script_can_close_(true), |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 387 | spelling_panel_visible_(false), |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 388 | send_content_state_immediately_(false), |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 389 | send_preferred_size_changes_(false), |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 390 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 391 | notification_provider_(new NotificationProvider(this))), |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 392 | view_type_(ViewType::INVALID), |
| 393 | browser_window_id_(-1), |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 394 | last_top_level_navigation_page_id_(-1), |
| 395 | #if defined(OS_MACOSX) |
| 396 | has_document_tag_(false), |
| 397 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 398 | document_tag_(0), |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 399 | webkit_preferences_(webkit_preferences), |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 400 | session_storage_namespace_id_(session_storage_namespace_id), |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 401 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 402 | ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 403 | cross_origin_access_count_(0), |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 404 | same_origin_access_count_(0), |
| 405 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 406 | ClearBlockedContentSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | RenderView::~RenderView() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 410 | if (decrement_shared_popup_at_destruction_) |
| 411 | shared_popup_counter_->data--; |
| 412 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 413 | // Dispose of un-disposed image fetchers. |
| 414 | for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); |
| 415 | i != image_fetchers_.end(); ++i) { |
| 416 | delete *i; |
| 417 | } |
| 418 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 419 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 420 | while (!file_chooser_completions_.empty()) { |
| 421 | if (file_chooser_completions_.front()->completion) { |
| 422 | file_chooser_completions_.front()->completion->didChooseFile( |
| 423 | WebVector<WebString>()); |
| 424 | } |
| 425 | file_chooser_completions_.pop_front(); |
| 426 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 427 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 428 | #if defined(OS_MACOSX) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 429 | // Tell the spellchecker that the document is closed. |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 430 | if (has_document_tag_) |
| 431 | Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
| 432 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 433 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 434 | render_thread_->RemoveFilter(audio_message_filter_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 435 | |
| 436 | #ifndef NDEBUG |
| 437 | // Make sure we are no longer referenced by the ViewMap. |
| 438 | ViewMap* views = Singleton<ViewMap>::get(); |
| 439 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 440 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 441 | #endif |
| 442 | } |
| 443 | |
| 444 | /*static*/ |
| 445 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
| 446 | ViewMap* views = Singleton<ViewMap>::get(); |
| 447 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 448 | if (!visitor->Visit(it->second)) |
| 449 | return; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /*static*/ |
| 454 | RenderView* RenderView::FromWebView(WebView* webview) { |
| 455 | ViewMap* views = Singleton<ViewMap>::get(); |
| 456 | ViewMap::iterator it = views->find(webview); |
| 457 | return it == views->end() ? NULL : it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /*static*/ |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 461 | RenderView* RenderView::Create( |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 462 | RenderThreadBase* render_thread, |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 463 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 464 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 465 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 466 | const WebPreferences& webkit_prefs, |
| 467 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 468 | int32 routing_id, |
| 469 | int64 session_storage_namespace_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 470 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 471 | scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs, |
| 472 | session_storage_namespace_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 473 | view->Init(parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 474 | opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 475 | renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 476 | counter, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | routing_id); // adds reference |
| 478 | return view; |
| 479 | } |
| 480 | |
| 481 | /*static*/ |
| 482 | void RenderView::SetNextPageID(int32 next_page_id) { |
| 483 | // This method should only be called during process startup, and the given |
| 484 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 485 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 486 | DCHECK(next_page_id >= next_page_id_); |
| 487 | next_page_id_ = next_page_id; |
| 488 | } |
| 489 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 490 | void RenderView::UserMetricsRecordAction(const std::string& action) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 491 | Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
| 492 | } |
| 493 | |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 494 | void RenderView::PluginCrashed(const FilePath& plugin_path) { |
| 495 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 496 | } |
| 497 | |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 498 | #if defined(OS_MACOSX) |
| 499 | void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 500 | plugin_delegates_.insert(delegate); |
| 501 | } |
| 502 | |
| 503 | void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 504 | plugin_delegates_.erase(delegate); |
| 505 | } |
| 506 | #endif |
| 507 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 508 | void RenderView::Init(gfx::NativeViewId parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 509 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 510 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 511 | SharedRenderViewCounter* counter, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 512 | int32 routing_id) { |
| 513 | DCHECK(!webview()); |
| 514 | |
| 515 | if (opener_id != MSG_ROUTING_NONE) |
| 516 | opener_id_ = opener_id; |
| 517 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 518 | if (counter) { |
| 519 | shared_popup_counter_ = counter; |
| 520 | shared_popup_counter_->data++; |
| 521 | decrement_shared_popup_at_destruction_ = true; |
| 522 | } else { |
| 523 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 524 | decrement_shared_popup_at_destruction_ = false; |
| 525 | } |
| 526 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 527 | devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
[email protected] | 9b9d728 | 2009-04-08 14:13:04 | [diff] [blame] | 528 | |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 529 | webwidget_ = WebView::create(this); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 530 | Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 531 | webkit_preferences_.Apply(webview()); |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 532 | webview()->initializeMainFrame(this); |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 533 | webview()->setDevToolsAgent( |
| 534 | WebDevToolsAgent::create(webview(), devtools_agent_.get())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 535 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 536 | OnSetRendererPrefs(renderer_prefs); |
| 537 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 538 | routing_id_ = routing_id; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 539 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 540 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 541 | // when we receive ViewMsg_Close. |
| 542 | AddRef(); |
| 543 | |
| 544 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 545 | // completing initialization. Otherwise, we can finish it now. |
| 546 | if (opener_id == MSG_ROUTING_NONE) { |
| 547 | did_show_ = true; |
| 548 | CompleteInit(parent_hwnd); |
| 549 | } |
| 550 | |
| 551 | host_window_ = parent_hwnd; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 552 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 553 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 554 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 555 | enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 556 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 557 | audio_message_filter_ = new AudioMessageFilter(routing_id_); |
| 558 | render_thread_->AddFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | void RenderView::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 562 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 563 | if (main_frame) |
| 564 | child_process_logging::SetActiveURL(main_frame->url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 565 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 566 | // If this is developer tools renderer intercept tools messages first. |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 567 | if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 568 | return; |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 569 | if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) |
| 570 | return; |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 571 | if (notification_provider_->OnMessageReceived(message)) |
| 572 | return; |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 573 | if (geolocation_dispatcher_.get() && |
| 574 | geolocation_dispatcher_->OnMessageReceived(message)) { |
| 575 | return; |
| 576 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 577 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 578 | IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 579 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 580 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 581 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 582 | IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 583 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 584 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 585 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 586 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 587 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 588 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 589 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 590 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 591 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 592 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 593 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 594 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 595 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 596 | IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 597 | OnAdvanceToNextMisspelling) |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 598 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 599 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 600 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 601 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 602 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 603 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 604 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 605 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 606 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 607 | IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
| 608 | OnSetContentSettingsForLoadingURL) |
| 609 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 610 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 611 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 612 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 613 | OnResetPageEncodingToDefault) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 614 | IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 615 | IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 616 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 617 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 618 | IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 619 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 620 | IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) |
| 621 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
| 622 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
| 623 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
| 624 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 625 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 626 | IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 627 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, |
| 628 | OnDragSourceEndedOrMoved) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 629 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
| 630 | OnDragSourceSystemDragEnded) |
| 631 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 632 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 633 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 634 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
| 635 | IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
| 636 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 637 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 638 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 639 | OnGetAllSavableResourceLinksForCurrentPage) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 640 | IPC_MESSAGE_HANDLER( |
| 641 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 642 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 643 | IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
| 644 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose) |
| 645 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 646 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 647 | IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
| 648 | OnMessageFromExternalHost) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 649 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 650 | OnDisassociateFromPopupCount) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 651 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned, |
| 652 | OnAutoFillSuggestionsReturned) |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 653 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillForms, OnAutoFillForms) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 654 | IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned, |
| 655 | OnAutocompleteSuggestionsReturned) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 656 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled, |
| 657 | OnAutoFillFormDataFilled) |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 658 | IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, |
| 659 | OnAllowScriptToClose) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 660 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 661 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 662 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 663 | OnExtensionMessageInvoke) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 664 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 665 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 666 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 667 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 668 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 669 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 670 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 671 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, |
| 672 | OnUpdateBrowserWindowId) |
| 673 | IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, |
| 674 | OnNotifyRendererViewType) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 675 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 676 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 677 | #if defined(OS_MACOSX) |
| 678 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 679 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 680 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 681 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 682 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 683 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, |
| 684 | OnExecuteCode) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 685 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 686 | OnCustomContextMenuAction) |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 687 | IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage) |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 688 | IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation) |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 689 | IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree) |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 690 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) |
| 691 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, |
| 692 | OnAccessibilityDoDefaultAction) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 693 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 694 | // Have the super handle all other messages. |
| 695 | IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
| 696 | IPC_END_MESSAGE_MAP() |
| 697 | } |
| 698 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 699 | void RenderView::SendThumbnail() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 700 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | if (!main_frame) |
| 702 | return; |
| 703 | |
| 704 | // get the URL for this page |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 705 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 706 | if (url.is_empty()) |
| 707 | return; |
| 708 | |
| 709 | if (size_.IsEmpty()) |
| 710 | return; // Don't create an empty thumbnail! |
| 711 | |
| 712 | ThumbnailScore score; |
| 713 | SkBitmap thumbnail; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 714 | if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 715 | &thumbnail, &score)) |
| 716 | return; |
| 717 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 718 | // send the thumbnail message to the browser process |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 719 | Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 720 | } |
| 721 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 722 | void RenderView::SendSnapshot() { |
| 723 | SkBitmap snapshot; |
| 724 | bool error = false; |
| 725 | |
| 726 | WebFrame* main_frame = webview()->mainFrame(); |
| 727 | if (!main_frame) |
| 728 | error = true; |
| 729 | |
| 730 | if (!error && !CaptureSnapshot(webview(), &snapshot)) |
| 731 | error = true; |
| 732 | |
| 733 | DCHECK(error == snapshot.empty()) << |
| 734 | "Snapshot should be empty on error, non-empty otherwise."; |
| 735 | |
| 736 | // Send the snapshot to the browser process. |
| 737 | Send(new ViewHostMsg_Snapshot(routing_id_, snapshot)); |
| 738 | } |
| 739 | |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 740 | void RenderView::OnPrintPages() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 741 | DCHECK(webview()); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 742 | if (webview()) { |
| 743 | // If the user has selected text in the currently focused frame we print |
| 744 | // only that frame (this makes print selection work for multiple frames). |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 745 | if (webview()->focusedFrame()->hasSelection()) |
| 746 | Print(webview()->focusedFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 747 | else |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 748 | Print(webview()->mainFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 749 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 750 | } |
| 751 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 752 | void RenderView::OnPrintingDone(int document_cookie, bool success) { |
| 753 | // Ignoring document cookie here since only one print job can be outstanding |
| 754 | // per renderer and document_cookie is 0 when printing is successful. |
| 755 | DCHECK(print_helper_.get()); |
| 756 | if (print_helper_.get() != NULL) { |
| 757 | print_helper_->DidFinishPrinting(success); |
| 758 | } |
| 759 | } |
| 760 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 761 | void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| 762 | if (load_id != page_id_) |
| 763 | return; // this capture call is no longer relevant due to navigation |
| 764 | if (load_id == last_indexed_page_id_) |
| 765 | return; // we already indexed this page |
| 766 | |
| 767 | if (!webview()) |
| 768 | return; |
| 769 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 770 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 771 | if (!main_frame) |
| 772 | return; |
| 773 | |
| 774 | // Don't index/capture pages that are in view source mode. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 775 | if (main_frame->isViewSourceModeEnabled()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 776 | return; |
| 777 | |
| 778 | // Don't index/capture pages that failed to load. This only checks the top |
| 779 | // level frame so the thumbnail may contain a frame that failed to load. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 780 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 781 | if (ds && ds->hasUnreachableURL()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 782 | return; |
| 783 | |
| 784 | if (!preliminary_capture) |
| 785 | last_indexed_page_id_ = load_id; |
| 786 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 787 | // Get the URL for this page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 788 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 789 | if (url.is_empty()) |
| 790 | return; |
| 791 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 792 | // Retrieve the frame's full text. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 793 | std::wstring contents; |
| 794 | CaptureText(main_frame, &contents); |
| 795 | if (contents.size()) { |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 796 | base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 797 | std::string language = DetermineTextLanguage(contents); |
| 798 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", |
| 799 | base::TimeTicks::Now() - begin_time); |
[email protected] | 7893a98 | 2010-01-07 23:25:52 | [diff] [blame] | 800 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 801 | // Send the text to the browser for indexing (the browser might decide not |
| 802 | // to index, if the URL is HTTPS for instance) and language discovery. |
| 803 | Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents, |
| 804 | language)); |
[email protected] | 5c426692 | 2009-07-10 16:41:27 | [diff] [blame] | 805 | } |
| 806 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 807 | // thumbnail |
| 808 | SendThumbnail(); |
| 809 | } |
| 810 | |
| 811 | void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { |
| 812 | contents->clear(); |
| 813 | if (!frame) |
| 814 | return; |
| 815 | |
| 816 | #ifdef TIME_TEXT_RETRIEVAL |
| 817 | double begin = time_util::GetHighResolutionTimeNow(); |
| 818 | #endif |
| 819 | |
| 820 | // get the contents of the frame |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 821 | *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 822 | |
| 823 | #ifdef TIME_TEXT_RETRIEVAL |
| 824 | double end = time_util::GetHighResolutionTimeNow(); |
| 825 | char buf[128]; |
| 826 | sprintf_s(buf, "%d chars retrieved for indexing in %gms\n", |
| 827 | contents.size(), (end - begin)*1000); |
| 828 | OutputDebugStringA(buf); |
| 829 | #endif |
| 830 | |
| 831 | // When the contents are clipped to the maximum, we don't want to have a |
| 832 | // partial word indexed at the end that might have been clipped. Therefore, |
| 833 | // terminate the string at the last space to ensure no words are clipped. |
| 834 | if (contents->size() == kMaxIndexChars) { |
| 835 | size_t last_space_index = contents->find_last_of(kWhitespaceWide); |
| 836 | if (last_space_index == std::wstring::npos) |
| 837 | return; // don't index if we got a huge block of text with no spaces |
| 838 | contents->resize(last_space_index); |
| 839 | } |
| 840 | } |
| 841 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 842 | bool RenderView::CaptureThumbnail(WebView* view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 843 | int w, |
| 844 | int h, |
| 845 | SkBitmap* thumbnail, |
| 846 | ThumbnailScore* score) { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 847 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 848 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 849 | skia::PlatformCanvas canvas; |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 850 | |
| 851 | // Paint |view| into |canvas|. |
| 852 | if (!PaintViewIntoCanvas(view, canvas)) |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 853 | return false; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 854 | |
| 855 | skia::BitmapPlatformDevice& device = |
| 856 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 857 | |
| 858 | const SkBitmap& src_bmp = device.accessBitmap(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 859 | |
[email protected] | cab34d6a | 2009-09-24 01:14:52 | [diff] [blame] | 860 | SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 861 | float dest_aspect = dest_rect.width() / dest_rect.height(); |
| 862 | |
| 863 | // Get the src rect so that we can preserve the aspect ratio while filling |
| 864 | // the destination. |
| 865 | SkIRect src_rect; |
| 866 | if (src_bmp.width() < dest_rect.width() || |
| 867 | src_bmp.height() < dest_rect.height()) { |
| 868 | // Source image is smaller: we clip the part of source image within the |
| 869 | // dest rect, and then stretch it to fill the dest rect. We don't respect |
| 870 | // the aspect ratio in this case. |
| 871 | src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| 872 | static_cast<S16CPU>(dest_rect.height())); |
| 873 | score->good_clipping = false; |
| 874 | } else { |
| 875 | float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| 876 | if (src_aspect > dest_aspect) { |
| 877 | // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| 878 | // the wider screen. |
| 879 | S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| 880 | S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| 881 | src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| 882 | score->good_clipping = false; |
| 883 | } else { |
| 884 | src_rect.set(0, 0, src_bmp.width(), |
| 885 | static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| 886 | score->good_clipping = true; |
| 887 | } |
| 888 | } |
| 889 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 890 | score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 891 | |
| 892 | SkBitmap subset; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 893 | device.accessBitmap(false).extractSubset(&subset, src_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 894 | |
| 895 | // Resample the subset that we want to get it the right size. |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 896 | *thumbnail = skia::ImageOperations::Resize( |
| 897 | subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 898 | |
| 899 | score->boring_score = CalculateBoringScore(thumbnail); |
| 900 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 901 | HISTOGRAM_TIMES("Renderer4.Thumbnail", |
| 902 | base::TimeTicks::Now() - beginning_time); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 903 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 904 | } |
| 905 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 906 | bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| 907 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 908 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 909 | skia::PlatformCanvas canvas; |
| 910 | if (!PaintViewIntoCanvas(view, canvas)) |
| 911 | return false; |
| 912 | |
| 913 | skia::BitmapPlatformDevice& device = |
| 914 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 915 | |
| 916 | const SkBitmap& bitmap = device.accessBitmap(false); |
| 917 | if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 918 | return false; |
| 919 | |
| 920 | HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 921 | base::TimeTicks::Now() - beginning_time); |
| 922 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 926 | if (!webview()) |
| 927 | return; |
| 928 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 929 | history_list_offset_ = params.current_history_list_offset; |
| 930 | history_list_length_ = params.current_history_list_length; |
| 931 | |
[email protected] | 8c785c6 | 2009-07-13 14:20:15 | [diff] [blame] | 932 | if (devtools_agent_.get()) |
| 933 | devtools_agent_->OnNavigate(); |
| 934 | |
[email protected] | 42219753 | 2010-01-25 17:38:23 | [diff] [blame] | 935 | if (notification_provider_.get()) |
| 936 | notification_provider_->OnNavigate(); |
| 937 | |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 938 | child_process_logging::SetActiveURL(params.url); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 939 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 940 | AboutHandler::MaybeHandle(params.url); |
| 941 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 942 | bool is_reload = |
| 943 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD || |
| 944 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 945 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 946 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 947 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 948 | // We cannot reload if we do not have any history state. This happens, for |
| 949 | // example, when recovering from a crash. Our workaround here is a bit of |
| 950 | // a hack since it means that reload after a crashed tab does not cause an |
| 951 | // end-to-end cache validation. |
| 952 | is_reload = false; |
| 953 | } |
| 954 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 955 | // A navigation resulting from loading a javascript URL should not be treated |
| 956 | // as a browser initiated event. Instead, we want it to look as if the page |
| 957 | // initiated any load resulting from JS execution. |
| 958 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 959 | NavigationState* state = NavigationState::CreateBrowserInitiated( |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 960 | params.page_id, |
| 961 | params.pending_history_list_offset, |
| 962 | params.transition, |
| 963 | params.request_time); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 964 | if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) { |
| 965 | // We're doing a load of a page that was restored from the last session. |
| 966 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 967 | // which can result in stale data for pages that are set to expire. We |
| 968 | // explicitly override that by setting the policy here so that as |
| 969 | // necessary we load from the network. |
| 970 | state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy); |
| 971 | } |
| 972 | pending_navigation_state_.reset(state); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 973 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 974 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 975 | NavigationState* navigation_state = pending_navigation_state_.get(); |
| 976 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 977 | // If we are reloading, then WebKit will use the history state of the current |
| 978 | // page, so we should just ignore any given history state. Otherwise, if we |
| 979 | // have history state, then we need to navigate to it, which corresponds to a |
| 980 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 981 | if (is_reload) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 982 | if (navigation_state) |
| 983 | navigation_state->set_load_type(NavigationState::RELOAD); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 984 | bool ignore_cache = (params.navigation_type == |
| 985 | ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE); |
| 986 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 987 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 988 | // 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] | 989 | DCHECK_NE(params.page_id, -1); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 990 | if (navigation_state) |
| 991 | navigation_state->set_load_type(NavigationState::HISTORY_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 992 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 993 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 994 | } else { |
| 995 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 996 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 997 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 998 | // A session history navigation should have been accompanied by state. |
| 999 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1000 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1001 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1002 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1003 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1004 | if (params.referrer.is_valid()) { |
| 1005 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 1006 | WebString::fromUTF8(params.referrer.spec())); |
| 1007 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1008 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1009 | if (navigation_state) |
| 1010 | navigation_state->set_load_type(NavigationState::NORMAL_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1011 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1012 | } |
| 1013 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1014 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 1015 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | // Stop loading the current page |
| 1019 | void RenderView::OnStop() { |
| 1020 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 1021 | webview()->mainFrame()->stopLoading(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1022 | } |
| 1023 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1024 | // Reload current focused frame. |
| 1025 | // E.g. called by right-clicking on the frame and picking "reload this frame". |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1026 | void RenderView::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1027 | if (webview() && webview()->focusedFrame()) { |
| 1028 | // We always obey the cache (ignore_cache=false) here. |
| 1029 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1030 | // a cache-ignoring reload of the frame. |
| 1031 | webview()->focusedFrame()->reload(false); |
| 1032 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1033 | } |
| 1034 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1035 | void RenderView::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1036 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1037 | } |
| 1038 | |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1039 | void RenderView::OnExecuteEditCommand(const std::string& name, |
| 1040 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1041 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1042 | return; |
| 1043 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1044 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1045 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1046 | } |
| 1047 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1048 | void RenderView::OnSetupDevToolsClient() { |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 1049 | DCHECK(!devtools_client_.get()); |
| 1050 | devtools_client_.reset(new DevToolsClient(this)); |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1051 | } |
| 1052 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1053 | void RenderView::OnUpdateTargetURLAck() { |
| 1054 | // Check if there is a targeturl waiting to be sent. |
| 1055 | if (target_url_status_ == TARGET_PENDING) { |
| 1056 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1057 | pending_target_url_)); |
| 1058 | } |
| 1059 | |
| 1060 | target_url_status_ = TARGET_NONE; |
| 1061 | } |
| 1062 | |
| 1063 | void RenderView::OnUndo() { |
| 1064 | if (!webview()) |
| 1065 | return; |
| 1066 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1067 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1068 | UserMetricsRecordAction("Undo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | void RenderView::OnRedo() { |
| 1072 | if (!webview()) |
| 1073 | return; |
| 1074 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1075 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1076 | UserMetricsRecordAction("Redo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | void RenderView::OnCut() { |
| 1080 | if (!webview()) |
| 1081 | return; |
| 1082 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1083 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1084 | UserMetricsRecordAction("Cut"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | void RenderView::OnCopy() { |
| 1088 | if (!webview()) |
| 1089 | return; |
| 1090 | |
[email protected] | 6f496b2 | 2010-05-27 22:59:20 | [diff] [blame] | 1091 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1092 | webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument(); |
| 1093 | delegate->Copy(); |
| 1094 | return; |
| 1095 | } |
| 1096 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1097 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1098 | UserMetricsRecordAction("Copy"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1099 | } |
| 1100 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1101 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1102 | void RenderView::OnCopyToFindPboard() { |
| 1103 | if (!webview()) |
| 1104 | return; |
| 1105 | |
| 1106 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1107 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1108 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1109 | if (frame->hasSelection()) { |
| 1110 | string16 selection = frame->selectionAsText(); |
| 1111 | RenderThread::current()->Send( |
| 1112 | new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection)); |
| 1113 | } |
| 1114 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1115 | UserMetricsRecordAction("CopyToFindPboard"); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1116 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1117 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1118 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1119 | void RenderView::OnPaste() { |
| 1120 | if (!webview()) |
| 1121 | return; |
| 1122 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1123 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1124 | UserMetricsRecordAction("Paste"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1125 | } |
| 1126 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1127 | void RenderView::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1128 | if (!webview()) |
| 1129 | return; |
| 1130 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1131 | WebFrame* frame = webview()->focusedFrame(); |
| 1132 | if (!frame->hasSelection()) |
| 1133 | frame->selectWordAroundCaret(); |
| 1134 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1135 | } |
| 1136 | |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1137 | void RenderView::OnAdvanceToNextMisspelling() { |
| 1138 | if (!webview()) |
| 1139 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1140 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1141 | WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 1142 | } |
| 1143 | |
| 1144 | void RenderView::OnToggleSpellPanel(bool is_currently_visible) { |
| 1145 | if (!webview()) |
| 1146 | return; |
| 1147 | // We need to tell the webView whether the spelling panel is visible or not so |
| 1148 | // that it won't need to make ipc calls later. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1149 | spelling_panel_visible_ = is_currently_visible; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1150 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1151 | WebString::fromUTF8("ToggleSpellPanel")); |
| 1152 | } |
| 1153 | |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1154 | void RenderView::OnToggleSpellCheck() { |
| 1155 | if (!webview()) |
| 1156 | return; |
| 1157 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1158 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1159 | frame->enableContinuousSpellChecking( |
| 1160 | !frame->isContinuousSpellCheckingEnabled()); |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1161 | } |
| 1162 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1163 | void RenderView::OnDelete() { |
| 1164 | if (!webview()) |
| 1165 | return; |
| 1166 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1167 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1168 | UserMetricsRecordAction("DeleteSelection"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | void RenderView::OnSelectAll() { |
| 1172 | if (!webview()) |
| 1173 | return; |
| 1174 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1175 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1176 | WebString::fromUTF8("SelectAll")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1177 | UserMetricsRecordAction("SelectAll"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | void RenderView::OnSetInitialFocus(bool reverse) { |
| 1181 | if (!webview()) |
| 1182 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1183 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /////////////////////////////////////////////////////////////////////////////// |
| 1187 | |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1188 | void RenderView::SetContentSettings(const ContentSettings& settings) { |
| 1189 | current_content_settings_ = settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1190 | } |
| 1191 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1192 | // Tell the embedding application that the URL of the active page has changed |
| 1193 | void RenderView::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1194 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1195 | DCHECK(ds); |
| 1196 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1197 | const WebURLRequest& request = ds->request(); |
| 1198 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1199 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1200 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1201 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1202 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1203 | |
| 1204 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1205 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1206 | params.is_post = false; |
| 1207 | params.page_id = page_id_; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1208 | params.is_content_filtered = response.isContentFiltered(); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1209 | if (!navigation_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1210 | // SSL state specified in the request takes precedence over the one in the |
| 1211 | // response. |
| 1212 | // So far this is only intended for error pages that are not expected to be |
| 1213 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1214 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1215 | params.security_info = navigation_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1216 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1217 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1221 | if (ds->hasUnreachableURL()) { |
| 1222 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1223 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1224 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1225 | } |
| 1226 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1227 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1228 | params.should_update_history = !ds->hasUnreachableURL() && |
| 1229 | !response.isMultipartPayload(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1230 | |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1231 | params.searchable_form_url = navigation_state->searchable_form_url(); |
| 1232 | params.searchable_form_encoding = |
| 1233 | navigation_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1234 | |
| 1235 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1236 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1237 | if (password_form_data) |
| 1238 | params.password_form = *password_form_data; |
| 1239 | |
| 1240 | params.gesture = navigation_gesture_; |
| 1241 | navigation_gesture_ = NavigationGestureUnknown; |
| 1242 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1243 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1244 | // Top-level navigation. |
| 1245 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 1246 | // Clear "block" flags for the new page. This needs to happen before any of |
| 1247 | // allowScripts(), allowImages(), allowPlugins() is called for the new page |
| 1248 | // so that these functions can correctly detect that a piece of content |
| 1249 | // flipped from "not blocked" to "blocked". |
| 1250 | ClearBlockedContentSettings(); |
| 1251 | |
[email protected] | 62d2a11 | 2010-04-07 00:53:02 | [diff] [blame] | 1252 | // Set content settings. Default them from the parent window if one exists. |
| 1253 | // This makes sure about:blank windows work as expected. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1254 | HostContentSettings::iterator host_content_settings = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1255 | host_content_settings_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1256 | if (host_content_settings != host_content_settings_.end()) { |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1257 | SetContentSettings(host_content_settings->second); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1258 | |
| 1259 | // These content settings were merely recorded transiently for this load. |
| 1260 | // We can erase them now. If at some point we reload this page, the |
| 1261 | // browser will send us new, up-to-date content settings. |
| 1262 | host_content_settings_.erase(host_content_settings); |
[email protected] | 3a387ae | 2010-04-08 01:58:40 | [diff] [blame] | 1263 | } else if (frame->opener()) { |
| 1264 | WebView* opener_view = frame->opener()->view(); |
| 1265 | RenderView* opener = FromWebView(opener_view); |
| 1266 | SetContentSettings(opener->current_content_settings_); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1267 | } |
| 1268 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1269 | // Set zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1270 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1271 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1272 | if (host_zoom != host_zoom_levels_.end()) { |
| 1273 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1274 | // This zoom level was merely recorded transiently for this load. We can |
| 1275 | // erase it now. If at some point we reload this page, the browser will |
| 1276 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1277 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1278 | } |
| 1279 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1280 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1281 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1282 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1283 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1284 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 1285 | // If the main frame does a load, it should not be reported as a subframe |
| 1286 | // navigation. This can occur in the following case: |
| 1287 | // 1. You're on a site with frames. |
| 1288 | // 2. You do a subframe navigation. This is stored with transition type |
| 1289 | // MANUAL_SUBFRAME. |
| 1290 | // 3. You navigate to some non-frame site, say, google.com. |
| 1291 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1292 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1293 | // We don't want that, because any navigation that changes the toplevel |
| 1294 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1295 | // update the URL bar, etc). |
| 1296 | params.transition = PageTransition::LINK; |
| 1297 | } |
| 1298 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1299 | // If we have a valid consumed client redirect source, |
| 1300 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1301 | // so we set the referrer and transition to match. |
| 1302 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1303 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1304 | params.referrer = completed_client_redirect_src_; |
| 1305 | params.transition = static_cast<PageTransition::Type>( |
| 1306 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 1307 | } else { |
| 1308 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1309 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1310 | params.referrer = GURL( |
| 1311 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1312 | } |
| 1313 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1314 | string16 method = request.httpMethod(); |
| 1315 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1316 | params.is_post = true; |
| 1317 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1318 | // Save some histogram data so we can compute the average memory used per |
| 1319 | // page load of the glyphs. |
| 1320 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1321 | webkit_glue::GetGlyphPageCount()); |
| 1322 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1323 | // This message needs to be sent before any of allowScripts(), |
| 1324 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1325 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1326 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1327 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1328 | } else { |
| 1329 | // Subframe navigation: the type depends on whether this navigation |
| 1330 | // generated a new session history entry. When they do generate a session |
| 1331 | // history entry, it means the user initiated the navigation and we should |
| 1332 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1333 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1334 | if (page_id_ > last_page_id_sent_to_browser_) |
| 1335 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 1336 | else |
| 1337 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 1338 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1339 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1340 | } |
| 1341 | |
| 1342 | last_page_id_sent_to_browser_ = |
| 1343 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1344 | |
| 1345 | // 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] | 1346 | // we don't want the transition type to persist. Just clear it. |
| 1347 | navigation_state->set_transition_type(PageTransition::LINK); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1348 | |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 1349 | if (accessibility_.get()) { |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 1350 | accessibility_->clear(); |
[email protected] | 1745596 | 2010-02-24 01:39:35 | [diff] [blame] | 1351 | accessibility_.reset(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1352 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1356 | void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1357 | // Ignore all but top level navigations... |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1358 | if (!frame->parent()) { |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1359 | Send(new ViewHostMsg_UpdateTitle( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1360 | routing_id_, |
| 1361 | page_id_, |
| 1362 | UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ? |
| 1363 | title.substr(0, chrome::kMaxTitleChars) : title))); |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1364 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | void RenderView::UpdateEncoding(WebFrame* frame, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1368 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1369 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1370 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1371 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1372 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1373 | last_encoding_name_ = encoding_name; |
| 1374 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1375 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 1379 | // Sends the previous session history state to the browser so it will be saved |
| 1380 | // before we navigate to a new page. This must be called *before* the page ID |
| 1381 | // has been updated so we know what it was. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1382 | void RenderView::UpdateSessionHistory(WebFrame* frame) { |
| 1383 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1384 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1385 | // there is no past session history to record. |
| 1386 | if (page_id_ == -1) |
| 1387 | return; |
| 1388 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1389 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1390 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1391 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1392 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1393 | |
| 1394 | Send(new ViewHostMsg_UpdateState( |
| 1395 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1396 | } |
| 1397 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1398 | void RenderView::OpenURL( |
| 1399 | const GURL& url, const GURL& referrer, WebNavigationPolicy policy) { |
| 1400 | Send(new ViewHostMsg_OpenURL( |
| 1401 | routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); |
| 1402 | } |
| 1403 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1404 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1405 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1406 | void RenderView::LoadNavigationErrorPage(WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1407 | const WebURLRequest& failed_request, |
| 1408 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1409 | const std::string& html, |
| 1410 | bool replace) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1411 | GURL failed_url = error.unreachableURL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1412 | |
| 1413 | std::string alt_html; |
| 1414 | if (html.empty()) { |
| 1415 | // Use a local error page. |
| 1416 | int resource_id; |
| 1417 | DictionaryValue error_strings; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1418 | if (error.reason == net::ERR_CACHE_MISS && |
| 1419 | EqualsASCII(failed_request.httpMethod(), "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1420 | GetFormRepostErrorValues(failed_url, &error_strings); |
| 1421 | resource_id = IDR_ERROR_NO_DETAILS_HTML; |
| 1422 | } else { |
| 1423 | GetLocalizedErrorValues(error, &error_strings); |
| 1424 | resource_id = IDR_NET_ERROR_HTML; |
| 1425 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1426 | |
| 1427 | alt_html = GetAltHTMLForTemplate(error_strings, resource_id); |
| 1428 | } else { |
| 1429 | alt_html = html; |
| 1430 | } |
| 1431 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1432 | frame->loadHTMLString(alt_html, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1433 | GURL(kUnreachableWebDataURL), |
| 1434 | failed_url, |
| 1435 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1436 | } |
| 1437 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1438 | void RenderView::BindDOMAutomationController(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1439 | dom_automation_controller_.set_message_sender(this); |
| 1440 | dom_automation_controller_.set_routing_id(routing_id_); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1441 | dom_automation_controller_.BindToJavascript(frame, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1442 | L"domAutomationController"); |
| 1443 | } |
| 1444 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1445 | bool RenderView::RunJavaScriptMessage(int type, |
| 1446 | const std::wstring& message, |
| 1447 | const std::wstring& default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1448 | const GURL& frame_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1449 | std::wstring* result) { |
| 1450 | bool success = false; |
| 1451 | std::wstring result_temp; |
| 1452 | if (!result) |
| 1453 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1454 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1455 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1456 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1457 | return success; |
| 1458 | } |
| 1459 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1460 | bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
| 1461 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1462 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1463 | // it is particularly important that we do not call willEnterModalLoop as |
| 1464 | // that would defer resource loads for the dialog itself. |
| 1465 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1466 | RenderThread::current()->DoNotNotifyWebKitOfModalLoop(); |
| 1467 | |
| 1468 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1469 | return Send(message); |
| 1470 | } |
| 1471 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1472 | void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { |
| 1473 | if (!osd_url.is_empty()) |
| 1474 | Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
| 1475 | autodetected)); |
| 1476 | } |
| 1477 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1478 | void RenderView::OnAutoFillSuggestionsReturned( |
| 1479 | int query_id, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1480 | const std::vector<string16>& values, |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1481 | const std::vector<string16>& labels, |
| 1482 | int default_suggestion_index) { |
| 1483 | if (webview() && query_id == autofill_query_id_) { |
| 1484 | webview()->applyAutoFillSuggestions( |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1485 | autofill_query_node_, values, labels, default_suggestion_index); |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1486 | } |
| 1487 | autofill_query_node_.reset(); |
| 1488 | } |
| 1489 | |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 1490 | void RenderView::OnAutoFillForms( |
| 1491 | const std::vector<webkit_glue::FormData>& forms) { |
| 1492 | form_manager_.FillForms(forms); |
| 1493 | } |
| 1494 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1495 | void RenderView::OnAutocompleteSuggestionsReturned( |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 1496 | int query_id, |
| 1497 | const std::vector<string16>& suggestions, |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1498 | int default_suggestion_index) { |
[email protected] | 7e089f27 | 2009-11-03 17:07:18 | [diff] [blame] | 1499 | if (webview() && query_id == autofill_query_id_) { |
[email protected] | 9e3444c | 2010-02-11 21:30:08 | [diff] [blame] | 1500 | webview()->applyAutocompleteSuggestions( |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 1501 | autofill_query_node_, suggestions, default_suggestion_index); |
| 1502 | } |
| 1503 | autofill_query_node_.reset(); |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1504 | } |
| 1505 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 1506 | void RenderView::OnAutoFillFormDataFilled(int query_id, |
| 1507 | const webkit_glue::FormData& form) { |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 1508 | if (query_id != autofill_query_id_) |
| 1509 | return; |
| 1510 | |
| 1511 | form_manager_.FillForm(form); |
| 1512 | } |
| 1513 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1514 | void RenderView::OnAllowScriptToClose(bool script_can_close) { |
| 1515 | script_can_close_ = script_can_close; |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1516 | } |
| 1517 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1518 | uint32 RenderView::GetCPBrowsingContext() { |
| 1519 | uint32 context = 0; |
| 1520 | Send(new ViewHostMsg_GetCPBrowsingContext(&context)); |
| 1521 | return context; |
| 1522 | } |
| 1523 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1524 | void RenderView::AddSearchProvider(const std::string& url) { |
| 1525 | AddGURLSearchProvider(GURL(url), |
| 1526 | false); // not autodetected |
| 1527 | } |
| 1528 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1529 | void RenderView::OnMissingPluginStatus( |
| 1530 | WebPluginDelegateProxy* delegate, |
| 1531 | int status) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1532 | #if defined(OS_WIN) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1533 | if (!first_default_plugin_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1534 | // Show the InfoBar for the first available plugin. |
| 1535 | if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1536 | first_default_plugin_ = delegate->AsWeakPtr(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1537 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1538 | } |
| 1539 | } else { |
| 1540 | // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) |
| 1541 | // to start the download/install. |
| 1542 | if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { |
| 1543 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1544 | } |
| 1545 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1546 | #else |
[email protected] | 76c3b31 | 2010-05-20 21:38:29 | [diff] [blame] | 1547 | // TODO(port): Implement the infobar that accompanies the default plugin. |
| 1548 | // Linux: http://crbug.com/10952 |
| 1549 | // Mac: http://crbug.com/17392 |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1550 | NOTIMPLEMENTED(); |
| 1551 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1552 | } |
| 1553 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1554 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1555 | |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 1556 | WebView* RenderView::createView( |
| 1557 | WebFrame* creator, |
| 1558 | const WebWindowFeatures& features) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1559 | // Check to make sure we aren't overloading on popups. |
| 1560 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1561 | return NULL; |
| 1562 | |
| 1563 | // This window can't be closed from a window.close() call until we receive a |
| 1564 | // message from the Browser process explicitly allowing it. |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1565 | script_can_close_ = false; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1566 | |
| 1567 | int32 routing_id = MSG_ROUTING_NONE; |
| 1568 | bool user_gesture = creator->isProcessingUserGesture(); |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1569 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1570 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1571 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1572 | render_thread_->Send( |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 1573 | new ViewHostMsg_CreateWindow( |
| 1574 | routing_id_, |
| 1575 | user_gesture, |
| 1576 | WindowFeaturesToContainerType(features), |
| 1577 | session_storage_namespace_id_, |
| 1578 | &routing_id, |
| 1579 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1580 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1581 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1582 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1583 | RenderView* view = RenderView::Create(render_thread_, |
[email protected] | 659f73fa | 2009-10-13 13:43:42 | [diff] [blame] | 1584 | 0, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1585 | routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1586 | renderer_preferences_, |
| 1587 | webkit_preferences_, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1588 | shared_popup_counter_, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1589 | routing_id, |
| 1590 | cloned_session_storage_namespace_id); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1591 | view->opened_by_user_gesture_ = user_gesture; |
| 1592 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1593 | // Record whether the creator frame is trying to suppress the opener field. |
| 1594 | view->opener_suppressed_ = opener_suppressed; |
| 1595 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1596 | // Record the security origin of the creator. |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 1597 | GURL creator_url(creator->securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1598 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1599 | creator_url = GURL(); |
| 1600 | view->creator_url_ = creator_url; |
| 1601 | |
| 1602 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1603 | // the new render view (we don't need the browser to send the URL back down). |
| 1604 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1605 | |
| 1606 | return view->webview(); |
| 1607 | } |
| 1608 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1609 | WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1610 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1611 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1612 | popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1613 | return widget->webwidget(); |
| 1614 | } |
| 1615 | |
| 1616 | WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) { |
| 1617 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1618 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1619 | WebKit::WebPopupTypeSelect); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1620 | widget->ConfigureAsExternalPopupMenu(info); |
| 1621 | return widget->webwidget(); |
| 1622 | } |
| 1623 | |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1624 | WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) { |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1625 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1626 | return WebStorageNamespace::createSessionStorageNamespace(quota); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1627 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1628 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1629 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1630 | } |
| 1631 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1632 | void RenderView::didAddMessageToConsole( |
| 1633 | const WebConsoleMessage& message, const WebString& source_name, |
| 1634 | unsigned source_line) { |
| 1635 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 1636 | UTF16ToWideHack(message.text), |
| 1637 | static_cast<int32>(source_line), |
| 1638 | UTF16ToWideHack(source_name))); |
| 1639 | } |
| 1640 | |
| 1641 | void RenderView::printPage(WebFrame* frame) { |
[email protected] | 71a1426 | 2009-09-22 20:02:58 | [diff] [blame] | 1642 | DCHECK(frame); |
| 1643 | Print(frame, true); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | void RenderView::didStartLoading() { |
| 1647 | if (is_loading_) { |
| 1648 | DLOG(WARNING) << "didStartLoading called while loading"; |
| 1649 | return; |
| 1650 | } |
| 1651 | |
| 1652 | is_loading_ = true; |
| 1653 | // Clear the pointer so that we can assign it only when there is an unknown |
| 1654 | // plugin on a page. |
| 1655 | first_default_plugin_.reset(); |
| 1656 | |
| 1657 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
| 1658 | } |
| 1659 | |
| 1660 | void RenderView::didStopLoading() { |
| 1661 | if (!is_loading_) { |
| 1662 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1663 | return; |
| 1664 | } |
| 1665 | |
| 1666 | is_loading_ = false; |
| 1667 | |
| 1668 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1669 | // when done loading. This currently isn't an issue as the favicon is only |
| 1670 | // displayed when done loading. Ideally we would send notification when |
| 1671 | // finished parsing the head, but webkit doesn't support that yet. |
| 1672 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1673 | GURL favicon_url(webview()->mainFrame()->favIconURL()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1674 | if (!favicon_url.is_empty()) |
| 1675 | Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); |
| 1676 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1677 | AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1678 | true); // autodetected |
| 1679 | |
| 1680 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1681 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 1682 | MessageLoop::current()->PostDelayedTask( |
| 1683 | FROM_HERE, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1684 | method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_, |
| 1685 | false), |
| 1686 | kDelayForCaptureMs); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1687 | } |
| 1688 | |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1689 | bool RenderView::isSmartInsertDeleteEnabled() { |
| 1690 | #if defined(OS_MACOSX) |
| 1691 | return true; |
| 1692 | #else |
| 1693 | return false; |
| 1694 | #endif |
| 1695 | } |
| 1696 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1697 | bool RenderView::isSelectTrailingWhitespaceEnabled() { |
| 1698 | #if defined(OS_WIN) |
| 1699 | return true; |
| 1700 | #else |
| 1701 | return false; |
| 1702 | #endif |
| 1703 | } |
| 1704 | |
| 1705 | void RenderView::setInputMethodEnabled(bool enabled) { |
| 1706 | // Save the updated IME status and mark the input focus has been updated. |
| 1707 | // The IME status is to be sent to a browser process next time when |
| 1708 | // the input caret is rendered. |
| 1709 | if (!ime_control_busy_) { |
| 1710 | ime_control_updated_ = true; |
| 1711 | ime_control_new_state_ = enabled; |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | void RenderView::didChangeSelection(bool is_empty_selection) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 1716 | #if defined(USE_X11) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1717 | if (!handling_input_event_) |
| 1718 | return; |
| 1719 | // TODO(estade): investigate incremental updates to the selection so that we |
| 1720 | // don't send the entire selection over IPC every time. |
| 1721 | if (!is_empty_selection) { |
| 1722 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 1723 | // the selection hasn't actually changed. We don't want to report these |
| 1724 | // because it will cause us to continually claim the X clipboard. |
| 1725 | const std::string& this_selection = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1726 | webview()->focusedFrame()->selectionAsText().utf8(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1727 | if (this_selection == last_selection_) |
| 1728 | return; |
| 1729 | |
| 1730 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1731 | this_selection)); |
| 1732 | last_selection_ = this_selection; |
| 1733 | } else { |
| 1734 | last_selection_.clear(); |
| 1735 | } |
| 1736 | #endif |
| 1737 | } |
| 1738 | |
| 1739 | void RenderView::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1740 | const std::string& name = UTF16ToUTF8(command_name); |
| 1741 | if (StartsWithASCII(name, "Move", true) || |
| 1742 | StartsWithASCII(name, "Insert", true) || |
| 1743 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1744 | return; |
| 1745 | UserMetricsRecordAction(name); |
| 1746 | } |
| 1747 | |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1748 | bool RenderView::handleCurrentKeyboardEvent() { |
| 1749 | if (edit_commands_.empty()) |
| 1750 | return false; |
| 1751 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1752 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1753 | if (!frame) |
| 1754 | return false; |
| 1755 | |
| 1756 | EditCommands::iterator it = edit_commands_.begin(); |
| 1757 | EditCommands::iterator end = edit_commands_.end(); |
| 1758 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1759 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1760 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1761 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1762 | // key (but it's the exception). Once one edit command is not executed, it |
| 1763 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1764 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 1765 | WebString::fromUTF8(it->value))) |
| 1766 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1767 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1768 | } |
| 1769 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1770 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1771 | } |
| 1772 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1773 | void RenderView::spellCheck(const WebString& text, |
| 1774 | int& misspelled_offset, |
| 1775 | int& misspelled_length) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1776 | EnsureDocumentTag(); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1777 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1778 | string16 word(text); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1779 | RenderThread* thread = RenderThread::current(); |
| 1780 | // Will be NULL during unit tests. |
| 1781 | if (thread) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1782 | thread->spellchecker()->SpellCheckWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1783 | word.c_str(), word.size(), document_tag_, |
| 1784 | &misspelled_offset, &misspelled_length, NULL); |
| 1785 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | WebString RenderView::autoCorrectWord(const WebKit::WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1789 | string16 autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1790 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | b86c8c1 | 2009-10-05 22:01:26 | [diff] [blame] | 1791 | if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1792 | EnsureDocumentTag(); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1793 | RenderThread* thread = RenderThread::current(); |
| 1794 | // Will be NULL during unit tests. |
| 1795 | if (thread) { |
| 1796 | autocorrect_word = |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1797 | thread->spellchecker()->GetAutoCorrectionWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1798 | word, document_tag_); |
| 1799 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1800 | } |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1801 | return autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1802 | } |
| 1803 | |
[email protected] | c49085c7 | 2009-10-02 16:28:56 | [diff] [blame] | 1804 | void RenderView::showSpellingUI(bool show) { |
| 1805 | Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); |
| 1806 | } |
| 1807 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1808 | bool RenderView::isShowingSpellingUI() { |
| 1809 | return spelling_panel_visible_; |
| 1810 | } |
| 1811 | |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1812 | void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1813 | Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
| 1814 | word)); |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1815 | } |
| 1816 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1817 | bool RenderView::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 1818 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1819 | WebFileChooserCompletion* chooser_completion) { |
| 1820 | ViewHostMsg_RunFileChooser_Params ipc_params; |
| 1821 | ipc_params.mode = params.multiSelect ? |
| 1822 | ViewHostMsg_RunFileChooser_Params::OpenMultiple : |
| 1823 | ViewHostMsg_RunFileChooser_Params::Open; |
| 1824 | ipc_params.title = params.title; |
| 1825 | ipc_params.default_file_name = |
| 1826 | webkit_glue::WebStringToFilePath(params.initialValue); |
| 1827 | |
| 1828 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1829 | } |
| 1830 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1831 | void RenderView::runModalAlertDialog( |
| 1832 | WebFrame* frame, const WebString& message) { |
| 1833 | RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, |
| 1834 | UTF16ToWideHack(message), |
| 1835 | std::wstring(), |
| 1836 | frame->url(), |
| 1837 | NULL); |
| 1838 | } |
| 1839 | |
| 1840 | bool RenderView::runModalConfirmDialog( |
| 1841 | WebFrame* frame, const WebString& message) { |
| 1842 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, |
| 1843 | UTF16ToWideHack(message), |
| 1844 | std::wstring(), |
| 1845 | frame->url(), |
| 1846 | NULL); |
| 1847 | } |
| 1848 | |
| 1849 | bool RenderView::runModalPromptDialog( |
| 1850 | WebFrame* frame, const WebString& message, const WebString& default_value, |
| 1851 | WebString* actual_value) { |
| 1852 | std::wstring result; |
| 1853 | bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, |
| 1854 | UTF16ToWideHack(message), |
| 1855 | UTF16ToWideHack(default_value), |
| 1856 | frame->url(), |
| 1857 | &result); |
| 1858 | if (ok) |
| 1859 | actual_value->assign(WideToUTF16Hack(result)); |
| 1860 | return ok; |
| 1861 | } |
| 1862 | |
| 1863 | bool RenderView::runModalBeforeUnloadDialog( |
| 1864 | WebFrame* frame, const WebString& message) { |
| 1865 | bool success = false; |
| 1866 | // This is an ignored return value, but is included so we can accept the same |
| 1867 | // response as RunJavaScriptMessage. |
| 1868 | std::wstring ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1869 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1870 | routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1871 | &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1872 | return success; |
| 1873 | } |
| 1874 | |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1875 | void RenderView::showContextMenu( |
| 1876 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1877 | ContextMenuParams params = ContextMenuParams(data); |
| 1878 | if (!params.misspelled_word.empty() && RenderThread::current()) { |
| 1879 | int misspelled_offset, misspelled_length; |
[email protected] | c76a36a | 2010-01-26 22:44:04 | [diff] [blame] | 1880 | bool spelled_right = RenderThread::current()->spellchecker()-> |
| 1881 | SpellCheckWord( |
| 1882 | params.misspelled_word.c_str(), params.misspelled_word.size(), |
| 1883 | document_tag_, |
| 1884 | &misspelled_offset, &misspelled_length, |
| 1885 | ¶ms.dictionary_suggestions); |
| 1886 | if (spelled_right) |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1887 | params.misspelled_word.clear(); |
| 1888 | } |
| 1889 | |
| 1890 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1891 | } |
| 1892 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1893 | void RenderView::setStatusText(const WebString& text) { |
| 1894 | } |
| 1895 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1896 | void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1897 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1898 | if (latest_url == target_url_) |
| 1899 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1900 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1901 | // Tell the browser to display a destination link. |
| 1902 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1903 | target_url_status_ == TARGET_PENDING) { |
| 1904 | // If we have a request in-flight, save the URL to be sent when we |
| 1905 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1906 | // any existing pending sends. |
| 1907 | pending_target_url_ = latest_url; |
| 1908 | target_url_status_ = TARGET_PENDING; |
| 1909 | } else { |
| 1910 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 1911 | target_url_ = latest_url; |
| 1912 | target_url_status_ = TARGET_INFLIGHT; |
| 1913 | } |
| 1914 | } |
| 1915 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1916 | void RenderView::StartNavStateSyncTimerIfNecessary() { |
| 1917 | int delay; |
| 1918 | if (send_content_state_immediately_) |
| 1919 | delay = 0; |
| 1920 | else if (is_hidden()) |
| 1921 | delay = kDelaySecondsForContentStateSyncHidden; |
| 1922 | else |
| 1923 | delay = kDelaySecondsForContentStateSync; |
| 1924 | |
| 1925 | if (nav_state_sync_timer_.IsRunning()) { |
| 1926 | // The timer is already running. If the delay of the timer maches the amount |
| 1927 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1928 | // gets started with the right delay. |
| 1929 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 1930 | return; |
| 1931 | nav_state_sync_timer_.Stop(); |
| 1932 | } |
| 1933 | |
| 1934 | nav_state_sync_timer_.Start( |
| 1935 | TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState); |
| 1936 | } |
| 1937 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1938 | void RenderView::setMouseOverURL(const WebURL& url) { |
| 1939 | mouse_over_url_ = GURL(url); |
| 1940 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1941 | } |
| 1942 | |
| 1943 | void RenderView::setKeyboardFocusURL(const WebURL& url) { |
| 1944 | focus_url_ = GURL(url); |
| 1945 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1946 | } |
| 1947 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1948 | void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) { |
| 1949 | Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text), |
| 1950 | hint)); |
| 1951 | } |
| 1952 | |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1953 | void RenderView::startDragging(const WebDragData& data, |
| 1954 | WebDragOperationsMask mask, |
| 1955 | const WebImage& image, |
| 1956 | const WebPoint& imageOffset) { |
| 1957 | #if WEBKIT_USING_SKIA |
| 1958 | SkBitmap bitmap(image.getSkBitmap()); |
| 1959 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 1960 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1961 | #endif |
| 1962 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1963 | Send(new ViewHostMsg_StartDragging(routing_id_, |
| 1964 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1965 | mask, |
| 1966 | bitmap, |
| 1967 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1968 | } |
| 1969 | |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1970 | bool RenderView::acceptsLoadDrops() { |
| 1971 | return renderer_preferences_.can_accept_load_drops; |
| 1972 | } |
| 1973 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1974 | void RenderView::focusNext() { |
| 1975 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 1976 | } |
| 1977 | |
| 1978 | void RenderView::focusPrevious() { |
| 1979 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 1980 | } |
| 1981 | |
| 1982 | void RenderView::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1983 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 1984 | } |
| 1985 | |
| 1986 | int RenderView::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1987 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | int RenderView::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1991 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1992 | } |
| 1993 | |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame^] | 1994 | void RenderView::didUpdateInspectorSetting(const WebString& key, |
| 1995 | const WebString& value) { |
| 1996 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 1997 | key.utf8(), |
| 1998 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1999 | } |
| 2000 | |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2001 | void RenderView::queryAutofillSuggestions(const WebNode& node, |
| 2002 | const WebString& name, |
| 2003 | const WebString& value) { |
| 2004 | static int query_counter = 0; |
| 2005 | autofill_query_id_ = query_counter++; |
| 2006 | autofill_query_node_ = node; |
[email protected] | e250e49 | 2010-04-06 21:35:36 | [diff] [blame] | 2007 | |
| 2008 | const WebFormControlElement& element = |
[email protected] | f40b49e | 2010-05-05 22:38:45 | [diff] [blame] | 2009 | node.toConst<WebFormControlElement>(); |
[email protected] | e250e49 | 2010-04-06 21:35:36 | [diff] [blame] | 2010 | |
[email protected] | dede934 | 2010-04-12 16:51:11 | [diff] [blame] | 2011 | webkit_glue::FormField field; |
| 2012 | FormManager::WebFormControlElementToFormField(element, true, &field); |
[email protected] | e250e49 | 2010-04-06 21:35:36 | [diff] [blame] | 2013 | |
[email protected] | 72eb2da | 2010-04-14 00:31:08 | [diff] [blame] | 2014 | // WebFormControlElementToFormField does not scrape the DOM for the field |
| 2015 | // label, so find the label here. |
| 2016 | // TODO(jhawkins): Add form and field identities so we can use the cached form |
| 2017 | // data in FormManager. |
| 2018 | field.set_label(FormManager::LabelForElement(element)); |
| 2019 | |
[email protected] | dede934 | 2010-04-12 16:51:11 | [diff] [blame] | 2020 | Send(new ViewHostMsg_QueryFormFieldAutofill( |
| 2021 | routing_id_, autofill_query_id_, field)); |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | void RenderView::removeAutofillSuggestions(const WebString& name, |
| 2025 | const WebString& value) { |
| 2026 | Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value)); |
| 2027 | } |
| 2028 | |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2029 | void RenderView::didAcceptAutoFillSuggestion( |
| 2030 | const WebKit::WebNode& node, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 2031 | const WebKit::WebString& value, |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2032 | const WebKit::WebString& label) { |
| 2033 | static int query_counter = 0; |
| 2034 | autofill_query_id_ = query_counter++; |
| 2035 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 2036 | webkit_glue::FormData form; |
[email protected] | f40b49e | 2010-05-05 22:38:45 | [diff] [blame] | 2037 | const WebInputElement element = node.toConst<WebInputElement>(); |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2038 | if (!form_manager_.FindFormWithFormControlElement( |
[email protected] | da59227 | 2010-04-14 20:08:49 | [diff] [blame] | 2039 | element, FormManager::REQUIRE_NONE, &form)) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2040 | return; |
| 2041 | |
| 2042 | Send(new ViewHostMsg_FillAutoFillFormData( |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 2043 | routing_id_, autofill_query_id_, form, value, label)); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2044 | } |
| 2045 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2046 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2047 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2048 | // We are supposed to get a single call to Show for a newly created RenderView |
| 2049 | // that was created via RenderView::CreateWebView. So, we wait until this |
| 2050 | // point to dispatch the ShowView message. |
| 2051 | // |
| 2052 | // This method provides us with the information about how to display the newly |
| 2053 | // created RenderView (i.e., as a constrained popup or as a new tab). |
| 2054 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2055 | void RenderView::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2056 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 2057 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2058 | |
| 2059 | if (did_show_) |
| 2060 | return; |
| 2061 | did_show_ = true; |
| 2062 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2063 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2064 | if (!opened_by_user_gesture_) { |
| 2065 | // We exempt background tabs for compat with older versions of Chrome. |
| 2066 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2067 | // we probably don't need this check. |
| 2068 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2069 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2070 | } |
| 2071 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2072 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2073 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2074 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2075 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2076 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2077 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2078 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2079 | } |
| 2080 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2081 | void RenderView::closeWidgetSoon() { |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 2082 | if (script_can_close_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2083 | RenderWidget::closeWidgetSoon(); |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 2084 | } |
| 2085 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2086 | void RenderView::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2087 | DCHECK(did_show_) << "should already have shown the view"; |
| 2088 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2089 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2090 | // showModalDialog to function properly. |
| 2091 | // |
| 2092 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2093 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2094 | // handed manner. |
| 2095 | // |
| 2096 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 2097 | RenderThread::current()->DoNotSuspendWebKitSharedTimer(); |
| 2098 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2099 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2100 | } |
| 2101 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2102 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2103 | |
| 2104 | WebPlugin* RenderView::createPlugin( |
| 2105 | WebFrame* frame, const WebPluginParams& params) { |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2106 | FilePath path; |
| 2107 | std::string actual_mime_type; |
| 2108 | render_thread_->Send(new ViewHostMsg_GetPluginPath( |
| 2109 | params.url, frame->top()->url(), params.mimeType.utf8(), &path, |
| 2110 | &actual_mime_type)); |
| 2111 | if (path.value().empty()) |
| 2112 | return NULL; |
| 2113 | |
| 2114 | if (actual_mime_type.empty()) |
| 2115 | actual_mime_type = params.mimeType.utf8(); |
| 2116 | |
[email protected] | 53af1d6 | 2010-05-14 03:40:26 | [diff] [blame] | 2117 | scoped_refptr<pepper::PluginModule> pepper_module = |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2118 | PepperPluginRegistry::GetInstance()->GetModule(path); |
[email protected] | 53af1d6 | 2010-05-14 03:40:26 | [diff] [blame] | 2119 | if (pepper_module) { |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2120 | return new pepper::WebPluginImpl(pepper_module, params, |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 2121 | pepper_delegate_.AsWeakPtr()); |
| 2122 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2123 | |
| 2124 | return new webkit_glue::WebPluginImpl(frame, params, path, actual_mime_type, |
| 2125 | AsWeakPtr()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { |
[email protected] | 14396e9 | 2010-05-06 20:40:56 | [diff] [blame] | 2129 | WebApplicationCacheHostImpl* appcache_host = |
| 2130 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2131 | int appcache_host_id = appcache_host ? appcache_host->host_id() : 0; |
| 2132 | return new WebWorkerProxy(client, RenderThread::current(), routing_id_, |
| 2133 | appcache_host_id); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2134 | } |
| 2135 | |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2136 | WebSharedWorker* RenderView::createSharedWorker( |
| 2137 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2138 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2139 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2140 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2141 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2142 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2143 | ViewHostMsg_CreateWorker_Params params; |
| 2144 | params.url = url; |
| 2145 | params.is_shared = true; |
| 2146 | params.name = name; |
| 2147 | params.document_id = document_id; |
| 2148 | params.render_view_route_id = routing_id_; |
| 2149 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2150 | params.parent_appcache_host_id = 0; |
| 2151 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2152 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2153 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2154 | if (url_mismatch) { |
| 2155 | return NULL; |
| 2156 | } else { |
| 2157 | return new WebSharedWorkerProxy(RenderThread::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2158 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2159 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2160 | route_id, |
| 2161 | routing_id_); |
| 2162 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2163 | } |
| 2164 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2165 | WebMediaPlayer* RenderView::createMediaPlayer( |
| 2166 | WebFrame* frame, WebMediaPlayerClient* client) { |
| 2167 | scoped_refptr<media::FilterFactoryCollection> factory = |
| 2168 | new media::FilterFactoryCollection(); |
| 2169 | // Add in any custom filter factories first. |
| 2170 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 2171 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 2172 | // Add the chrome specific audio renderer. |
| 2173 | factory->AddFactory( |
| 2174 | AudioRendererImpl::CreateFactory(audio_message_filter())); |
| 2175 | } |
| 2176 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2177 | WebApplicationCacheHostImpl* appcache_host = |
| 2178 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2179 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2180 | // TODO(hclam): obtain the following parameters from |client|. |
| 2181 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = |
| 2182 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 2183 | GURL(), // referrer |
| 2184 | "null", // frame origin |
| 2185 | "null", // main_frame_origin |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2186 | base::GetCurrentProcId(), |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2187 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2188 | routing_id()); |
| 2189 | |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2190 | // A simple data source that keeps all data in memory. |
| 2191 | media::FilterFactory* simple_data_source_factory = |
| 2192 | webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(), |
| 2193 | bridge_factory); |
| 2194 | // A sophisticated data source that does memory caching. |
| 2195 | media::FilterFactory* buffered_data_source_factory = |
| 2196 | webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(), |
| 2197 | bridge_factory); |
| 2198 | if (cmd_line->HasSwitch(switches::kSimpleDataSource)) { |
| 2199 | factory->AddFactory(simple_data_source_factory); |
| 2200 | factory->AddFactory(buffered_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2201 | } else { |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2202 | factory->AddFactory(buffered_data_source_factory); |
| 2203 | factory->AddFactory(simple_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2204 | } |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2205 | |
| 2206 | webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL; |
| 2207 | if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) { |
| 2208 | factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_); |
| 2209 | } else { |
[email protected] | b57509eb | 2010-03-30 01:26:28 | [diff] [blame] | 2210 | bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); |
| 2211 | factory_factory = |
| 2212 | new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging); |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2216 | } |
| 2217 | |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2218 | WebApplicationCacheHost* RenderView::createApplicationCacheHost( |
| 2219 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
| 2220 | return new RendererWebApplicationCacheHostImpl( |
| 2221 | FromWebView(frame->view()), client, |
| 2222 | RenderThread::current()->appcache_dispatcher()->backend_proxy()); |
| 2223 | } |
| 2224 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 2225 | WebCookieJar* RenderView::cookieJar() { |
| 2226 | return &cookie_jar_; |
| 2227 | } |
| 2228 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2229 | void RenderView::willClose(WebFrame* frame) { |
| 2230 | if (!frame->parent()) { |
| 2231 | const GURL& url = frame->url(); |
| 2232 | if (url.SchemeIs("http") || url.SchemeIs("https")) |
| 2233 | DumpLoadHistograms(); |
| 2234 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2235 | |
| 2236 | WebDataSource* ds = frame->dataSource(); |
| 2237 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2238 | navigation_state->user_script_idle_scheduler()->Cancel(); |
[email protected] | 174e60e | 2010-05-06 00:21:16 | [diff] [blame] | 2239 | |
| 2240 | form_manager_.ResetFrame(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2241 | } |
| 2242 | |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2243 | bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 2244 | if (!enabled_per_settings) |
| 2245 | return false; |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 2246 | return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2250 | if (enabled_per_settings && |
| 2251 | AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) |
| 2252 | return true; |
| 2253 | |
| 2254 | if (IsWhitelistedForContentSettings(frame)) |
| 2255 | return true; |
| 2256 | |
| 2257 | DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES); |
| 2258 | return false; // Other protocols fall through here. |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2259 | } |
| 2260 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2261 | void RenderView::loadURLExternally( |
| 2262 | WebFrame* frame, const WebURLRequest& request, |
| 2263 | WebNavigationPolicy policy) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2264 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2265 | if (policy == WebKit::WebNavigationPolicyDownload) { |
| 2266 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
| 2267 | } else { |
| 2268 | OpenURL(request.url(), referrer, policy); |
| 2269 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | WebNavigationPolicy RenderView::decidePolicyForNavigation( |
| 2273 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2274 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2275 | // Webkit is asking whether to navigate to a new URL. |
| 2276 | // This is fine normally, except if we're showing UI from one security |
| 2277 | // context and they're trying to navigate to a different context. |
| 2278 | const GURL& url = request.url(); |
| 2279 | |
| 2280 | // 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] | 2281 | // navigations. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2282 | if (renderer_preferences_.browser_handles_top_level_requests && |
| 2283 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2284 | last_top_level_navigation_page_id_ = page_id_; |
| 2285 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2286 | OpenURL(url, referrer, default_policy); |
| 2287 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | // A content initiated navigation may have originated from a link-click, |
| 2291 | // script, drag-n-drop operation, etc. |
| 2292 | bool is_content_initiated = |
| 2293 | NavigationState::FromDataSource(frame->provisionalDataSource())-> |
| 2294 | is_content_initiated(); |
| 2295 | |
| 2296 | // We only care about navigations that are within the current tab (as opposed |
| 2297 | // to, for example, opening a new window). |
| 2298 | // But we sometimes navigate to about:blank to clear a tab, and we want to |
| 2299 | // still allow that. |
| 2300 | if (default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2301 | is_content_initiated && frame->parent() == NULL && |
| 2302 | !url.SchemeIs(chrome::kAboutScheme)) { |
| 2303 | // When we received such unsolicited navigations, we sometimes want to |
| 2304 | // punt them up to the browser to handle. |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 2305 | if (CrossesExtensionExtents(frame, url) || |
| 2306 | BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2307 | frame->isViewSourceModeEnabled() || |
[email protected] | 918059b | 2010-05-25 17:08:42 | [diff] [blame] | 2308 | url.SchemeIs(chrome::kViewSourceScheme)) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2309 | OpenURL(url, GURL(), default_policy); |
| 2310 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2311 | } |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2312 | |
| 2313 | // We forward navigations from extensions to the browser if they are |
| 2314 | // top-level events, even if the browser hasn't expressed interest. |
| 2315 | // |
| 2316 | // Note that we've already forwarded cross-extension extents navigations |
| 2317 | // above. |
| 2318 | if (BindingsPolicy::is_extension_enabled(enabled_bindings_) && |
| 2319 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
| 2320 | OpenURL(url, GURL(), default_policy); |
| 2321 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2322 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2326 | // its own process. This is done by sites like Gmail that try to open links |
| 2327 | // in new windows without script connections back to the original page. We |
| 2328 | // treat such cases as browser navigations (in which we will create a new |
| 2329 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2330 | // |
| 2331 | // We use the following heuristic to decide whether to fork a new page in its |
| 2332 | // own process: |
| 2333 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2334 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2335 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2336 | // |
| 2337 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2338 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2339 | bool is_fork = |
| 2340 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 2341 | GURL(frame->url()) == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2342 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2343 | historyBackListCount() < 1 && |
| 2344 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2345 | // The parent page must have set the child's window.opener to null before |
| 2346 | // redirecting to the desired URL. |
| 2347 | frame->opener() == NULL && |
| 2348 | // Must be a top-level frame. |
| 2349 | frame->parent() == NULL && |
| 2350 | // Must not have issued the request from this page. |
| 2351 | is_content_initiated && |
| 2352 | // Must be targeted at the current tab. |
| 2353 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2354 | // Must be a JavaScript navigation, which appears as "other". |
| 2355 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2356 | |
| 2357 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2358 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2359 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2360 | // should let the browser handle it. |
| 2361 | bool is_noreferrer_and_blank_target = |
| 2362 | // Frame should be top level and not yet navigated. |
| 2363 | frame->parent() == NULL && |
| 2364 | frame->url().isEmpty() && |
| 2365 | historyBackListCount() < 1 && |
| 2366 | historyForwardListCount() < 1 && |
| 2367 | // Links with rel=noreferrer will have no Referer field, and their |
| 2368 | // resulting frame will have its window.opener suppressed. |
| 2369 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2370 | // typos on the unusual spelling of Referer. |
| 2371 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2372 | opener_suppressed_ && |
| 2373 | frame->opener() == NULL && |
| 2374 | // Links with target=_blank will have no name. |
| 2375 | frame->name().isNull() && |
| 2376 | // Another frame (with a non-empty creator) should have initiated the |
| 2377 | // request, targeted at this frame. |
| 2378 | !creator_url_.is_empty() && |
| 2379 | is_content_initiated && |
| 2380 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2381 | type == WebKit::WebNavigationTypeOther; |
| 2382 | |
| 2383 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2384 | // Open the URL via the browser, not via WebKit. |
| 2385 | OpenURL(url, GURL(), default_policy); |
| 2386 | return WebKit::WebNavigationPolicyIgnore; |
| 2387 | } |
| 2388 | |
| 2389 | return default_policy; |
| 2390 | } |
| 2391 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2392 | bool RenderView::canHandleRequest( |
| 2393 | WebFrame* frame, const WebURLRequest& request) { |
| 2394 | // We allow WebKit to think that everything can be handled even though |
| 2395 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2396 | return true; |
| 2397 | } |
| 2398 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2399 | WebURLError RenderView::cannotHandleRequestError( |
| 2400 | WebFrame* frame, const WebURLRequest& request) { |
| 2401 | NOTREACHED(); // Since we said we can handle all requests. |
| 2402 | return WebURLError(); |
| 2403 | } |
| 2404 | |
| 2405 | WebURLError RenderView::cancelledError( |
| 2406 | WebFrame* frame, const WebURLRequest& request) { |
| 2407 | WebURLError error; |
| 2408 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2409 | error.reason = net::ERR_ABORTED; |
| 2410 | error.unreachableURL = request.url(); |
| 2411 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | void RenderView::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2415 | WebFrame*, const WebURLError&) { |
| 2416 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2417 | } |
| 2418 | |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2419 | void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame, |
| 2420 | const WebKit::WebFormElement& form) { |
| 2421 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2422 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2423 | // This method gets called before any of those handlers run, so save away |
| 2424 | // a copy of the password in case it gets lost. |
| 2425 | NavigationState* navigation_state = |
| 2426 | NavigationState::FromDataSource(frame->dataSource()); |
| 2427 | navigation_state->set_password_form_data( |
| 2428 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2429 | } |
| 2430 | |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 2431 | void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2432 | NavigationState* navigation_state = |
| 2433 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2434 | |
| 2435 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 2436 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 2437 | |
| 2438 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2439 | WebSearchableFormData web_searchable_form_data(form); |
| 2440 | navigation_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2441 | navigation_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2442 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2443 | PasswordForm* password_form_data = |
| 2444 | PasswordFormDomManager::CreatePasswordForm(form); |
| 2445 | navigation_state->set_password_form_data(password_form_data); |
| 2446 | |
| 2447 | // If the password has been cleared, recover it from the form contents already |
| 2448 | // stored by willSendSubmitEvent into the dataSource's NavigationState (as |
| 2449 | // opposed to the provisionalDataSource's, which is what we're storing into |
| 2450 | // now.) |
| 2451 | if (password_form_data && password_form_data->password_value.empty()) { |
| 2452 | NavigationState* old_navigation_state = |
| 2453 | NavigationState::FromDataSource(frame->dataSource()); |
| 2454 | if (old_navigation_state) { |
| 2455 | PasswordForm* old_form_data = old_navigation_state->password_form_data(); |
| 2456 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2457 | password_form_data->password_value = old_form_data->password_value; |
| 2458 | } |
| 2459 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2460 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2461 | FormData form_data; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 2462 | if (FormManager::WebFormElementToFormData( |
[email protected] | 3347bab3 | 2010-04-09 04:11:09 | [diff] [blame] | 2463 | form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data)) |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2464 | Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | void RenderView::willPerformClientRedirect( |
| 2468 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2469 | double fire_time) { |
| 2470 | // Ignore |
| 2471 | } |
| 2472 | |
| 2473 | void RenderView::didCancelClientRedirect(WebFrame* frame) { |
| 2474 | // Ignore |
| 2475 | } |
| 2476 | |
| 2477 | void RenderView::didCompleteClientRedirect( |
| 2478 | WebFrame* frame, const WebURL& from) { |
| 2479 | if (!frame->parent()) |
| 2480 | completed_client_redirect_src_ = from; |
| 2481 | } |
| 2482 | |
| 2483 | void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
| 2484 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2485 | // non-null NavigationState. |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 2486 | bool content_initiated = !pending_navigation_state_.get(); |
| 2487 | NavigationState* state = content_initiated ? |
| 2488 | NavigationState::CreateContentInitiated() : |
| 2489 | pending_navigation_state_.release(); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2490 | if (content_initiated) { |
| 2491 | switch (ds->request().cachePolicy()) { |
| 2492 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
| 2493 | state->set_load_type(NavigationState::LINK_LOAD_NORMAL); |
| 2494 | break; |
| 2495 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
| 2496 | state->set_load_type(NavigationState::LINK_LOAD_RELOAD); |
| 2497 | break; |
| 2498 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
| 2499 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); |
| 2500 | break; |
| 2501 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
| 2502 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); |
| 2503 | break; |
| 2504 | } |
| 2505 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2506 | |
| 2507 | state->set_user_script_idle_scheduler( |
| 2508 | new UserScriptIdleScheduler(this, frame)); |
| 2509 | ds->setExtraData(state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | void RenderView::didStartProvisionalLoad(WebFrame* frame) { |
| 2513 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2514 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2515 | |
| 2516 | navigation_state->set_start_load_time(Time::Now()); |
| 2517 | |
| 2518 | // Update the request time if WebKit has better knowledge of it. |
| 2519 | if (navigation_state->request_time().is_null()) { |
| 2520 | double event_time = ds->triggeringEventTime(); |
| 2521 | if (event_time != 0.0) |
| 2522 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 2523 | } |
| 2524 | |
| 2525 | bool is_top_most = !frame->parent(); |
| 2526 | if (is_top_most) { |
| 2527 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
| 2528 | NavigationGestureUnknown : NavigationGestureAuto; |
| 2529 | |
| 2530 | // Make sure redirect tracking state is clear for the new load. |
| 2531 | completed_client_redirect_src_ = GURL(); |
| 2532 | } else if (frame->parent()->isLoading()) { |
| 2533 | // 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] | 2534 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2535 | navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); |
| 2536 | } |
| 2537 | |
| 2538 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
| 2539 | routing_id_, is_top_most, ds->request().url())); |
| 2540 | } |
| 2541 | |
| 2542 | void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) { |
| 2543 | if (frame->parent()) |
| 2544 | return; |
| 2545 | // Received a redirect on the main frame. |
| 2546 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 2547 | if (!data_source) { |
| 2548 | // Should only be invoked when we have a data source. |
| 2549 | NOTREACHED(); |
| 2550 | return; |
| 2551 | } |
| 2552 | std::vector<GURL> redirects; |
| 2553 | GetRedirectChain(data_source, &redirects); |
| 2554 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2555 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 2556 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2557 | } |
| 2558 | } |
| 2559 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2560 | void RenderView::didFailProvisionalLoad(WebFrame* frame, |
| 2561 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2562 | // Notify the browser that we failed a provisional load with an error. |
| 2563 | // |
| 2564 | // Note: It is important this notification occur before DidStopLoading so the |
| 2565 | // SSL manager can react to the provisional load failure before being |
| 2566 | // notified the load stopped. |
| 2567 | // |
| 2568 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2569 | DCHECK(ds); |
| 2570 | |
| 2571 | const WebURLRequest& failed_request = ds->request(); |
| 2572 | |
| 2573 | bool show_repost_interstitial = |
| 2574 | (error.reason == net::ERR_CACHE_MISS && |
| 2575 | EqualsASCII(failed_request.httpMethod(), "POST")); |
| 2576 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
| 2577 | routing_id_, !frame->parent(), error.reason, error.unreachableURL, |
| 2578 | show_repost_interstitial)); |
| 2579 | |
| 2580 | // Don't display an error page if this is simply a cancelled load. Aside |
| 2581 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 2582 | if (error.reason == net::ERR_ABORTED) |
| 2583 | return; |
| 2584 | |
| 2585 | // Make sure we never show errors in view source mode. |
| 2586 | frame->enableViewSourceMode(false); |
| 2587 | |
| 2588 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2589 | |
| 2590 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 2591 | // 'replace' load. This is necessary to avoid messing up session history. |
| 2592 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 2593 | // as session history is concerned. |
| 2594 | // |
| 2595 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 2596 | // the page id. |
| 2597 | // |
| 2598 | bool replace = |
| 2599 | navigation_state->pending_page_id() != -1 || |
| 2600 | navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME; |
| 2601 | |
| 2602 | // If we failed on a browser initiated request, then make sure that our error |
| 2603 | // page load is regarded as the same browser initiated request. |
| 2604 | if (!navigation_state->is_content_initiated()) { |
| 2605 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
| 2606 | navigation_state->pending_page_id(), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2607 | navigation_state->pending_history_list_offset(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2608 | navigation_state->transition_type(), |
| 2609 | navigation_state->request_time())); |
| 2610 | } |
| 2611 | |
| 2612 | // Provide the user with a more helpful error page? |
| 2613 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 2614 | return; |
| 2615 | |
| 2616 | // Fallback to a local error page. |
| 2617 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), |
| 2618 | replace); |
| 2619 | } |
| 2620 | |
| 2621 | void RenderView::didReceiveDocumentData( |
| 2622 | WebFrame* frame, const char* data, size_t data_len, |
| 2623 | bool& prevent_default) { |
| 2624 | NavigationState* navigation_state = |
| 2625 | NavigationState::FromDataSource(frame->dataSource()); |
| 2626 | if (!navigation_state->postpone_loading_data()) |
| 2627 | return; |
| 2628 | |
| 2629 | // We're going to call commitDocumentData ourselves... |
| 2630 | prevent_default = true; |
| 2631 | |
| 2632 | // Continue buffering the response data for the original 404 page. If it |
| 2633 | // grows too large, then we'll just let it through. |
| 2634 | navigation_state->append_postponed_data(data, data_len); |
| 2635 | if (navigation_state->postponed_data().size() >= 512) { |
| 2636 | navigation_state->set_postpone_loading_data(false); |
| 2637 | frame->commitDocumentData(navigation_state->postponed_data().data(), |
| 2638 | navigation_state->postponed_data().size()); |
| 2639 | navigation_state->clear_postponed_data(); |
| 2640 | } |
| 2641 | } |
| 2642 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2643 | void RenderView::didCommitProvisionalLoad(WebFrame* frame, |
| 2644 | bool is_new_navigation) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2645 | NavigationState* navigation_state = |
| 2646 | NavigationState::FromDataSource(frame->dataSource()); |
| 2647 | |
| 2648 | navigation_state->set_commit_load_time(Time::Now()); |
| 2649 | if (is_new_navigation) { |
| 2650 | // When we perform a new navigation, we need to update the previous session |
| 2651 | // history entry with state for the page we are leaving. |
| 2652 | UpdateSessionHistory(frame); |
| 2653 | |
| 2654 | // We bump our Page ID to correspond with the new session history entry. |
| 2655 | page_id_ = next_page_id_++; |
| 2656 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 2657 | // Any pending translation is now obsolete. |
| 2658 | translate_helper_.CancelPendingTranslation(); |
| 2659 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2660 | // Advance our offset in session history, applying the length limit. There |
| 2661 | // is now no forward history. |
| 2662 | history_list_offset_++; |
| 2663 | if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) |
| 2664 | history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; |
| 2665 | history_list_length_ = history_list_offset_ + 1; |
| 2666 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 2667 | MessageLoop::current()->PostDelayedTask( |
| 2668 | FROM_HERE, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2669 | method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, |
| 2670 | page_id_, true), |
| 2671 | kDelayForForcedCaptureMs); |
| 2672 | } else { |
| 2673 | // Inspect the navigation_state on this frame to see if the navigation |
| 2674 | // corresponds to a session history navigation... Note: |frame| may or |
| 2675 | // may not be the toplevel frame, but for the case of capturing session |
| 2676 | // history, the first committed frame suffices. We keep track of whether |
| 2677 | // we've seen this commit before so that only capture session history once |
| 2678 | // per navigation. |
| 2679 | // |
| 2680 | // Note that we need to check if the page ID changed. In the case of a |
| 2681 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 2682 | // previous URL and the current page ID, which would be wrong. |
| 2683 | if (navigation_state->pending_page_id() != -1 && |
| 2684 | navigation_state->pending_page_id() != page_id_ && |
| 2685 | !navigation_state->request_committed()) { |
| 2686 | // This is a successful session history navigation! |
| 2687 | UpdateSessionHistory(frame); |
| 2688 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2689 | |
| 2690 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | // Remember that we've already processed this request, so we don't update |
| 2695 | // the session history again. We do this regardless of whether this is |
| 2696 | // a session history navigation, because if we attempted a session history |
| 2697 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 2698 | // new navigation. |
| 2699 | navigation_state->set_request_committed(true); |
| 2700 | |
| 2701 | UpdateURL(frame); |
| 2702 | |
| 2703 | // If this committed load was initiated by a client redirect, we're |
| 2704 | // at the last stop now, so clear it. |
| 2705 | completed_client_redirect_src_ = GURL(); |
| 2706 | |
| 2707 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2708 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | void RenderView::didClearWindowObject(WebFrame* frame) { |
| 2712 | if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) |
| 2713 | BindDOMAutomationController(frame); |
| 2714 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) { |
| 2715 | dom_ui_bindings_.set_message_sender(this); |
| 2716 | dom_ui_bindings_.set_routing_id(routing_id_); |
| 2717 | dom_ui_bindings_.BindToJavascript(frame, L"chrome"); |
| 2718 | } |
| 2719 | if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { |
| 2720 | external_host_bindings_.set_message_sender(this); |
| 2721 | external_host_bindings_.set_routing_id(routing_id_); |
| 2722 | external_host_bindings_.BindToJavascript(frame, L"externalHost"); |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | void RenderView::didCreateDocumentElement(WebFrame* frame) { |
| 2727 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 2728 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 2729 | frame, UserScript::DOCUMENT_START); |
| 2730 | } |
[email protected] | 078b3461 | 2009-09-19 19:31:51 | [diff] [blame] | 2731 | if (view_type_ == ViewType::EXTENSION_TOOLSTRIP || |
| 2732 | view_type_ == ViewType::EXTENSION_MOLE) { |
| 2733 | InjectToolstripCSS(); |
| 2734 | ExtensionProcessBindings::SetViewType(webview(), view_type_); |
| 2735 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2736 | |
| 2737 | // Notify the browser about non-blank documents loading in the top frame. |
| 2738 | GURL url = frame->url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 2739 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2740 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2741 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
| 2746 | UpdateTitle(frame, title); |
| 2747 | |
| 2748 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2749 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2750 | } |
| 2751 | |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 2752 | void RenderView::didChangeIcons(WebFrame* frame) { |
| 2753 | if (!frame->parent()) { |
| 2754 | Send(new ViewHostMsg_UpdateFavIconURL( |
| 2755 | routing_id_, |
| 2756 | page_id_, |
| 2757 | frame->favIconURL())); |
| 2758 | } |
| 2759 | } |
| 2760 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2761 | void RenderView::didFinishDocumentLoad(WebFrame* frame) { |
| 2762 | WebDataSource* ds = frame->dataSource(); |
| 2763 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2764 | DCHECK(navigation_state); |
| 2765 | navigation_state->set_finish_document_load_time(Time::Now()); |
| 2766 | |
| 2767 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_)); |
| 2768 | |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 2769 | // The document has now been fully loaded. Scan for forms to be sent up to |
| 2770 | // the browser. |
| 2771 | // TODO(jhawkins): Make these use the FormManager. |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2772 | form_manager_.ExtractForms(frame); |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 2773 | SendForms(frame); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2774 | SendPasswordForms(frame, false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2775 | |
| 2776 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2777 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2778 | |
| 2779 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 2780 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 2781 | frame, UserScript::DOCUMENT_END); |
| 2782 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2783 | |
| 2784 | navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad(); |
| 2785 | } |
| 2786 | |
| 2787 | void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) { |
| 2788 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 2789 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 2790 | frame, UserScript::DOCUMENT_IDLE); |
| 2791 | } |
| 2792 | |
| 2793 | WebFrame* main_frame = webview()->mainFrame(); |
| 2794 | if (frame == main_frame) { |
| 2795 | while (!pending_code_execution_queue_.empty()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 2796 | linked_ptr<ViewMsg_ExecuteCode_Params>& params = |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2797 | pending_code_execution_queue_.front(); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 2798 | ExecuteCodeImpl(main_frame, *params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2799 | pending_code_execution_queue_.pop(); |
| 2800 | } |
| 2801 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | void RenderView::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | dd3c3e68 | 2010-05-12 18:51:26 | [diff] [blame] | 2805 | if (webview()->mainFrame() == frame) |
| 2806 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { |
| 2810 | // Ignore |
| 2811 | } |
| 2812 | |
| 2813 | void RenderView::didFinishLoad(WebFrame* frame) { |
| 2814 | WebDataSource* ds = frame->dataSource(); |
| 2815 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2816 | DCHECK(navigation_state); |
| 2817 | navigation_state->set_finish_load_time(Time::Now()); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2818 | navigation_state->user_script_idle_scheduler()->DidFinishLoad(); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2819 | |
| 2820 | // Let the password manager know which password forms are actually visible. |
| 2821 | SendPasswordForms(frame, true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2822 | } |
| 2823 | |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 2824 | void RenderView::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2825 | WebFrame* frame, bool is_new_navigation) { |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 2826 | |
| 2827 | // Determine if the UserScriptIdleScheduler already ran scripts on this page, |
| 2828 | // since a new one gets created by didCreateDataSource. |
| 2829 | NavigationState* state = |
| 2830 | NavigationState::FromDataSource(frame->dataSource()); |
| 2831 | bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run(); |
| 2832 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2833 | // If this was a reference fragment navigation that we initiated, then we |
| 2834 | // could end up having a non-null pending navigation state. We just need to |
| 2835 | // update the ExtraData on the datasource so that others who read the |
| 2836 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 2837 | // initiate this navigation, then we need to take care to reset any pre- |
| 2838 | // existing navigation state to a content-initiated navigation state. |
| 2839 | // DidCreateDataSource conveniently takes care of this for us. |
| 2840 | didCreateDataSource(frame, frame->dataSource()); |
| 2841 | |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 2842 | if (idle_scheduler_ran) { |
| 2843 | // Update the new UserScriptIdleScheduler so we don't re-run scripts. |
| 2844 | NavigationState* new_state = |
| 2845 | NavigationState::FromDataSource(frame->dataSource()); |
| 2846 | new_state->user_script_idle_scheduler()->set_has_run(true); |
| 2847 | } |
| 2848 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2849 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 2850 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2851 | UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2852 | } |
| 2853 | |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2854 | void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2855 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2856 | } |
| 2857 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2858 | void RenderView::assignIdentifierToRequest( |
| 2859 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 2860 | // Ignore |
| 2861 | } |
| 2862 | |
| 2863 | void RenderView::willSendRequest( |
| 2864 | WebFrame* frame, unsigned identifier, WebURLRequest& request, |
| 2865 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 2866 | WebFrame* top_frame = frame->top(); |
| 2867 | if (!top_frame) |
| 2868 | top_frame = frame; |
| 2869 | WebDataSource* data_source = top_frame->provisionalDataSource(); |
| 2870 | if (!data_source) |
| 2871 | data_source = top_frame->dataSource(); |
| 2872 | if (data_source) { |
| 2873 | NavigationState* state = NavigationState::FromDataSource(data_source); |
| 2874 | if (state && state->is_cache_policy_override_set()) |
| 2875 | request.setCachePolicy(state->cache_policy_override()); |
| 2876 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2877 | request.setRequestorID(routing_id_); |
[email protected] | c5bbc245 | 2010-03-08 08:33:50 | [diff] [blame] | 2878 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 2879 | request.clearHTTPHeaderField("Referer"); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2880 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 2881 | // Temporary metrics, see site_isolation_metrics.h |
| 2882 | SiteIsolationMetrics::AddRequest(identifier, request.targetType()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | void RenderView::didReceiveResponse( |
| 2886 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2887 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 2888 | // Temporary metrics, see site_isolation_metrics.h |
| 2889 | SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame, |
| 2890 | identifier, |
| 2891 | response); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2892 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2893 | // Only do this for responses that correspond to a provisional data source |
| 2894 | // of the top-most frame. If we have a provisional data source, then we |
| 2895 | // can't have any sub-resources yet, so we know that this response must |
| 2896 | // correspond to a frame load. |
| 2897 | if (!frame->provisionalDataSource() || frame->parent()) |
| 2898 | return; |
| 2899 | |
| 2900 | // If we are in view source mode, then just let the user see the source of |
| 2901 | // the server's 404 error page. |
| 2902 | if (frame->isViewSourceModeEnabled()) |
| 2903 | return; |
| 2904 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 2905 | NavigationState* navigation_state = |
| 2906 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2907 | CHECK(navigation_state); |
| 2908 | |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 2909 | // Record that this was a page loaded over SPDY. |
| 2910 | if (response.wasFetchedViaSPDY()) { |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 2911 | navigation_state->set_was_fetched_via_spdy(true); |
| 2912 | } |
| 2913 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 2914 | // Record that npn protocol was negotiated when fetching this page. |
| 2915 | if (response.wasNpnNegotiated()) { |
| 2916 | navigation_state->set_was_npn_negotiated(true); |
| 2917 | } |
| 2918 | |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 2919 | // Consider loading an alternate error page for 404 responses. |
| 2920 | if (response.httpStatusCode() != 404) |
| 2921 | return; |
| 2922 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2923 | // Can we even load an alternate error page for this URL? |
| 2924 | if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid()) |
| 2925 | return; |
| 2926 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2927 | navigation_state->set_postpone_loading_data(true); |
| 2928 | navigation_state->clear_postponed_data(); |
| 2929 | } |
| 2930 | |
| 2931 | void RenderView::didFinishResourceLoad( |
| 2932 | WebFrame* frame, unsigned identifier) { |
| 2933 | NavigationState* navigation_state = |
| 2934 | NavigationState::FromDataSource(frame->dataSource()); |
| 2935 | if (!navigation_state->postpone_loading_data()) |
| 2936 | return; |
| 2937 | |
| 2938 | // The server returned a 404 and the content was < 512 bytes (which we |
| 2939 | // suppressed). Go ahead and fetch the alternate page content. |
| 2940 | |
| 2941 | const GURL& frame_url = frame->url(); |
| 2942 | |
| 2943 | const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); |
| 2944 | DCHECK(error_page_url.is_valid()); |
| 2945 | |
| 2946 | WebURLError original_error; |
| 2947 | original_error.unreachableURL = frame_url; |
| 2948 | |
| 2949 | navigation_state->set_alt_error_page_fetcher( |
| 2950 | new AltErrorPageResourceFetcher( |
| 2951 | error_page_url, frame, original_error, |
| 2952 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 2953 | } |
| 2954 | |
| 2955 | void RenderView::didFailResourceLoad( |
| 2956 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 2957 | // Ignore |
| 2958 | } |
| 2959 | |
| 2960 | void RenderView::didLoadResourceFromMemoryCache( |
| 2961 | WebFrame* frame, const WebURLRequest& request, |
| 2962 | const WebURLResponse& response) { |
| 2963 | // Let the browser know we loaded a resource from the memory cache. This |
| 2964 | // message is needed to display the correct SSL indicators. |
| 2965 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 2966 | routing_id_, |
| 2967 | request.url(), |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 2968 | frame->securityOrigin().toString().utf8(), |
| 2969 | frame->top()->securityOrigin().toString().utf8(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2970 | response.securityInfo())); |
| 2971 | } |
| 2972 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2973 | void RenderView::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2974 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 2975 | } |
| 2976 | |
| 2977 | void RenderView::didRunInsecureContent( |
| 2978 | WebFrame* frame, const WebSecurityOrigin& origin) { |
| 2979 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 2980 | routing_id_, |
| 2981 | origin.toString().utf8())); |
| 2982 | } |
| 2983 | |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 2984 | bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2985 | if (enabled_per_settings && |
| 2986 | AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) |
| 2987 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 2988 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2989 | if (IsWhitelistedForContentSettings(frame)) |
| 2990 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 2991 | |
| 2992 | return false; // Other protocols fall through here. |
| 2993 | } |
| 2994 | |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 2995 | bool RenderView::allowDatabase( |
| 2996 | WebFrame* frame, const WebString& name, const WebString& display_name, |
| 2997 | unsigned long estimated_size) { |
| 2998 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 2999 | if (origin.isEmpty()) |
| 3000 | return false; // Uninitialized document? |
| 3001 | |
| 3002 | bool result; |
| 3003 | if (!Send(new ViewHostMsg_AllowDatabase(routing_id_, |
| 3004 | origin.toString().utf8(), name, display_name, estimated_size, &result))) |
| 3005 | return false; |
| 3006 | if (!result) |
| 3007 | DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES); |
| 3008 | return result; |
| 3009 | } |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3010 | void RenderView::didNotAllowScript(WebKit::WebFrame* frame) { |
| 3011 | DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 3012 | } |
| 3013 | |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3014 | void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) { |
| 3015 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 3016 | } |
| 3017 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3018 | void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
| 3019 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3020 | } |
| 3021 | |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3022 | void RenderView::didCreateScriptContext(WebFrame* frame) { |
| 3023 | EventBindings::HandleContextCreated(frame, false); |
| 3024 | } |
| 3025 | |
| 3026 | void RenderView::didDestroyScriptContext(WebFrame* frame) { |
| 3027 | EventBindings::HandleContextDestroyed(frame); |
| 3028 | } |
| 3029 | |
| 3030 | void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) { |
| 3031 | EventBindings::HandleContextCreated(frame, true); |
| 3032 | } |
| 3033 | |
[email protected] | fc86daa | 2010-03-30 23:52:53 | [diff] [blame] | 3034 | void RenderView::logCrossFramePropertyAccess(WebFrame* frame, |
| 3035 | WebFrame* target, |
| 3036 | bool cross_origin, |
| 3037 | const WebString& property_name, |
| 3038 | unsigned long long event_id) { |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 3039 | // TODO(johnnyg): track the individual properties and repeat event_ids. |
| 3040 | if (cross_origin) |
| 3041 | cross_origin_access_count_++; |
| 3042 | else |
| 3043 | same_origin_access_count_++; |
| 3044 | } |
| 3045 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3046 | void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { |
[email protected] | d8a179c | 2010-01-31 00:58:14 | [diff] [blame] | 3047 | CheckPreferredSize(); |
| 3048 | } |
| 3049 | |
| 3050 | void RenderView::CheckPreferredSize() { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3051 | // We don't always want to send the change messages over IPC, only if we've |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 3052 | // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3053 | // message. |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3054 | if (!send_preferred_size_changes_ || !webview()) |
| 3055 | return; |
[email protected] | dfca5acf | 2010-03-22 03:28:43 | [diff] [blame] | 3056 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3057 | // WebCore likes to tell us things have changed even when they haven't, so |
| 3058 | // cache the width and height and only send the IPC message when we're sure |
| 3059 | // they're different. |
| 3060 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3061 | webview()->mainFrame()->documentElementScrollHeight()); |
| 3062 | if (size == preferred_size_) |
| 3063 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3064 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3065 | preferred_size_ = size; |
| 3066 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3067 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3068 | } |
| 3069 | |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3070 | void RenderView::didChangeScrollOffset(WebFrame* frame) { |
| 3071 | StartNavStateSyncTimerIfNecessary(); |
| 3072 | } |
| 3073 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3074 | void RenderView::reportFindInPageMatchCount(int request_id, int count, |
| 3075 | bool final_update) { |
| 3076 | // If we have a message that has been queued up, then we should just replace |
| 3077 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 3078 | // wants it. |
| 3079 | if (queued_find_reply_message_.get()) { |
| 3080 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 3081 | routing_id_, |
| 3082 | request_id, |
| 3083 | count, |
| 3084 | gfx::Rect(), |
| 3085 | -1, // Don't update active match ordinal. |
| 3086 | final_update); |
| 3087 | queued_find_reply_message_.reset(msg); |
| 3088 | } else { |
| 3089 | // Send the search result over to the browser process. |
| 3090 | Send(new ViewHostMsg_Find_Reply( |
| 3091 | routing_id_, |
| 3092 | request_id, |
| 3093 | count, |
| 3094 | gfx::Rect(), |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3095 | -1, // Don't update active match ordinal. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3096 | final_update)); |
| 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | void RenderView::reportFindInPageSelection(int request_id, |
| 3101 | int active_match_ordinal, |
| 3102 | const WebRect& selection_rect) { |
| 3103 | // Send the search result over to the browser process. |
| 3104 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3105 | request_id, |
| 3106 | -1, |
| 3107 | selection_rect, |
| 3108 | active_match_ordinal, |
| 3109 | false)); |
| 3110 | } |
| 3111 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3112 | void RenderView::ReportNoFindInPageResults(int request_id) { |
| 3113 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3114 | request_id, |
| 3115 | 0, |
| 3116 | gfx::Rect(), |
| 3117 | 0, |
| 3118 | true)); |
| 3119 | } |
| 3120 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3121 | // webkit_glue::WebPluginPageDelegate ----------------------------------------- |
| 3122 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3123 | webkit_glue::WebPluginDelegate* RenderView::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] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3129 | bool use_pepper_host = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3130 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3131 | // Check for trusted Pepper plugins. |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3132 | const char kPepperPrefix[] = "pepper-"; |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3133 | if (StartsWithASCII(mime_type, kPepperPrefix, true)) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3134 | if (CommandLine::ForCurrentProcess()-> |
| 3135 | HasSwitch(switches::kInternalPepper)) { |
| 3136 | in_process_plugin = true; |
| 3137 | use_pepper_host = true; |
| 3138 | } else { |
| 3139 | // In process Pepper plugins must be explicitly enabled. |
| 3140 | return NULL; |
| 3141 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3142 | } else { |
| 3143 | FilePath internal_pdf_path; |
| 3144 | PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path); |
| 3145 | if (file_path == internal_pdf_path) { |
| 3146 | in_process_plugin = true; |
| 3147 | use_pepper_host = true; |
| 3148 | } |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3149 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3150 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3151 | // Check for Native Client modules. |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3152 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { |
| 3153 | if (mime_type == "application/x-nacl-srpc") { |
| 3154 | in_process_plugin = true; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3155 | use_pepper_host = true; |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3156 | } |
| 3157 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3158 | |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3159 | if (in_process_plugin) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3160 | if (use_pepper_host) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3161 | WebPluginDelegatePepper* pepper_plugin = |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3162 | WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr()); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3163 | current_pepper_plugins_.insert(pepper_plugin); |
| 3164 | return pepper_plugin; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3165 | } else { |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3166 | #if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac. |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3167 | return WebPluginDelegateImpl::Create( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3168 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3169 | #else |
[email protected] | 596b2c4 | 2010-01-14 20:40:43 | [diff] [blame] | 3170 | NOTIMPLEMENTED(); |
| 3171 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3172 | #endif |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3173 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3174 | } |
| 3175 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3176 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3180 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3181 | RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( |
| 3182 | routing_id(), window)); |
| 3183 | #endif |
| 3184 | } |
| 3185 | |
| 3186 | void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3187 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3188 | RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( |
| 3189 | routing_id(), window)); |
| 3190 | #endif |
| 3191 | CleanupWindowInPluginMoves(window); |
| 3192 | } |
| 3193 | |
| 3194 | void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { |
| 3195 | SchedulePluginMove(move); |
| 3196 | } |
| 3197 | |
| 3198 | void RenderView::DidStartLoadingForPlugin() { |
| 3199 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3200 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | void RenderView::DidStopLoadingForPlugin() { |
| 3204 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3205 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3206 | } |
| 3207 | |
| 3208 | void RenderView::ShowModalHTMLDialogForPlugin( |
| 3209 | const GURL& url, |
| 3210 | const gfx::Size& size, |
| 3211 | const std::string& json_arguments, |
| 3212 | std::string* json_retval) { |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3213 | SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog( |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3214 | routing_id_, url, size.width(), size.height(), json_arguments, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3215 | json_retval)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3216 | } |
| 3217 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3218 | WebCookieJar* RenderView::GetCookieJar() { |
| 3219 | return &cookie_jar_; |
| 3220 | } |
| 3221 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3222 | void RenderView::SyncNavigationState() { |
| 3223 | if (!webview()) |
| 3224 | return; |
| 3225 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3226 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3227 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3228 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3229 | |
| 3230 | Send(new ViewHostMsg_UpdateState( |
| 3231 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3232 | } |
| 3233 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3234 | bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) { |
| 3235 | // Make sure webview was not shut down. |
| 3236 | if (!webview()) |
| 3237 | return false; |
| 3238 | // Create an image resource fetcher and assign it with a call back object. |
| 3239 | image_fetchers_.insert(new ImageResourceFetcher( |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3240 | image_url, webview()->mainFrame(), id, image_size, |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3241 | NewCallback(this, &RenderView::DidDownloadImage))); |
| 3242 | return true; |
| 3243 | } |
| 3244 | |
| 3245 | void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3246 | const SkBitmap& image) { |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3247 | // Notify requester of image download status. |
[email protected] | 51bd3661 | 2009-10-20 22:49:47 | [diff] [blame] | 3248 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, |
| 3249 | fetcher->id(), |
| 3250 | fetcher->image_url(), |
| 3251 | image.isNull(), |
| 3252 | image)); |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3253 | // Dispose of the image fetcher. |
| 3254 | DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end()); |
| 3255 | image_fetchers_.erase(fetcher); |
| 3256 | // We're in the callback from the ImageResourceFetcher, best to delay |
| 3257 | // deletion. |
| 3258 | MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3259 | } |
| 3260 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3261 | void RenderView::OnDownloadFavIcon(int id, |
| 3262 | const GURL& image_url, |
| 3263 | int image_size) { |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3264 | bool data_image_failed = false; |
| 3265 | if (image_url.SchemeIs("data")) { |
| 3266 | SkBitmap data_image = ImageFromDataUrl(image_url); |
| 3267 | data_image_failed = data_image.empty(); |
| 3268 | if (!data_image_failed) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3269 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false, |
| 3270 | data_image)); |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3274 | if (data_image_failed || |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3275 | !DownloadImage(id, image_url, image_size)) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3276 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true, |
| 3277 | SkBitmap())); |
| 3278 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3279 | } |
| 3280 | |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3281 | SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
| 3282 | std::string mime_type, char_set, data; |
| 3283 | if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 3284 | // Decode the favicon using WebKit's image decoder. |
| 3285 | webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); |
| 3286 | const unsigned char* src_data = |
| 3287 | reinterpret_cast<const unsigned char*>(&data[0]); |
| 3288 | |
| 3289 | return decoder.Decode(src_data, data.size()); |
| 3290 | } |
| 3291 | return SkBitmap(); |
| 3292 | } |
| 3293 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3294 | void RenderView::OnGetApplicationInfo(int page_id) { |
| 3295 | webkit_glue::WebApplicationInfo app_info; |
| 3296 | if (page_id == page_id_) |
| 3297 | webkit_glue::GetApplicationInfo(webview(), &app_info); |
| 3298 | |
| 3299 | // Prune out any data URLs in the set of icons. The browser process expects |
| 3300 | // any icon with a data URL to have originated from a favicon. We don't want |
| 3301 | // to decode arbitrary data URLs in the browser process. See |
| 3302 | // http://b/issue?id=1162972 |
| 3303 | for (size_t i = 0; i < app_info.icons.size(); ++i) { |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 3304 | if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3305 | app_info.icons.erase(app_info.icons.begin() + i); |
| 3306 | --i; |
| 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); |
| 3311 | } |
| 3312 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3313 | GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3314 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3315 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3316 | // If the URL that failed was secure, then the embedding web page was not |
| 3317 | // expecting a network attacker to be able to manipulate its contents. As |
| 3318 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3319 | // attacker to manipulate the contents of the response if we tried to use |
| 3320 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3321 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | // Grab the base URL from the browser process. |
| 3325 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3326 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3327 | |
| 3328 | // Strip query params from the failed URL. |
| 3329 | GURL::Replacements remove_params; |
| 3330 | remove_params.ClearUsername(); |
| 3331 | remove_params.ClearPassword(); |
| 3332 | remove_params.ClearQuery(); |
| 3333 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3334 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3335 | std::string spec_to_send = url_to_send.spec(); |
| 3336 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3337 | if (failed_url.has_query()) |
| 3338 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3339 | |
| 3340 | // Construct the query params to send to link doctor. |
| 3341 | std::string params(alternate_error_page_url_.query()); |
| 3342 | params.append("&url="); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3343 | params.append(EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3344 | params.append("&sourceid=chrome"); |
| 3345 | params.append("&error="); |
| 3346 | switch (error_type) { |
| 3347 | case DNS_ERROR: |
| 3348 | params.append("dnserror"); |
| 3349 | break; |
| 3350 | |
| 3351 | case HTTP_404: |
| 3352 | params.append("http404"); |
| 3353 | break; |
| 3354 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3355 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3356 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3357 | break; |
| 3358 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3359 | default: |
| 3360 | NOTREACHED() << "unknown ErrorPageType"; |
| 3361 | } |
| 3362 | |
| 3363 | // OK, build the final url to return. |
| 3364 | GURL::Replacements link_doctor_params; |
| 3365 | link_doctor_params.SetQueryStr(params); |
| 3366 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3367 | return url; |
| 3368 | } |
| 3369 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3370 | webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() { |
[email protected] | f40b49e | 2010-05-05 22:38:45 | [diff] [blame] | 3371 | WebPlugin* plugin = |
| 3372 | webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3373 | return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate(); |
| 3374 | } |
| 3375 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3376 | void RenderView::OnFind(int request_id, const string16& search_text, |
| 3377 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3378 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3379 | |
| 3380 | if (main_frame->document().isPluginDocument()) { |
| 3381 | webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument(); |
| 3382 | if (options.findNext) { |
| 3383 | // Just navigate back/forward. |
| 3384 | delegate->SelectFindResult(options.forward); |
| 3385 | } else { |
| 3386 | if (delegate->SupportsFind()) { |
| 3387 | delegate->StartFind(UTF16ToUTF8(search_text), |
| 3388 | options.matchCase, |
| 3389 | request_id); |
| 3390 | } else { |
| 3391 | ReportNoFindInPageResults(request_id); |
| 3392 | } |
| 3393 | } |
| 3394 | return; |
| 3395 | } |
| 3396 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3397 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3398 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3399 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 3400 | |
| 3401 | bool multi_frame = (frame_after_main != main_frame); |
| 3402 | |
| 3403 | // If we have multiple frames, we don't want to wrap the search within the |
| 3404 | // frame, so we check here if we only have main_frame in the chain. |
| 3405 | bool wrap_within_frame = !multi_frame; |
| 3406 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 3407 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3408 | bool result = false; |
| 3409 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3410 | // If something is selected when we start searching it means we cannot just |
| 3411 | // increment the current match ordinal; we need to re-generate it. |
| 3412 | WebRange current_selection = focused_frame->selectionRange(); |
| 3413 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3414 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3415 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3416 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3417 | |
| 3418 | if (!result) { |
| 3419 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3420 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3421 | |
| 3422 | // Find the next frame, but skip the invisible ones. |
| 3423 | do { |
| 3424 | // What is the next frame to search? (we might be going backwards). Note |
| 3425 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3426 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3427 | search_frame->traverseNext(true) : |
| 3428 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3429 | } while (!search_frame->hasVisibleContent() && |
| 3430 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3431 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 3432 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3433 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3434 | |
| 3435 | // If we have multiple frames and we have wrapped back around to the |
| 3436 | // focused frame, we need to search it once more allowing wrap within |
| 3437 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 3438 | // reported matches, but no frames after the focused_frame contain a |
| 3439 | // match for the search word(s). |
| 3440 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3441 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3442 | request_id, search_text, options, true, // Force wrapping. |
| 3443 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3444 | } |
| 3445 | } |
| 3446 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3447 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3448 | } while (!result && search_frame != focused_frame); |
| 3449 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3450 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3451 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3452 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3453 | } else { |
| 3454 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 3455 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 3456 | // yet what is active. |
| 3457 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 3458 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3459 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3460 | // If we find no matches then this will be our last status update. |
| 3461 | // Otherwise the scoping effort will send more results. |
| 3462 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3463 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3464 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 3465 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3466 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3467 | match_count, |
| 3468 | selection_rect, |
| 3469 | ordinal, |
| 3470 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3471 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3472 | // Scoping effort begins, starting with the mainframe. |
| 3473 | search_frame = main_frame; |
| 3474 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3475 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3476 | |
| 3477 | do { |
| 3478 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3479 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3480 | |
| 3481 | // We don't start another scoping effort unless at least one match has |
| 3482 | // been found. |
| 3483 | if (result) { |
| 3484 | // Start new scoping request. If the scoping function determines that it |
| 3485 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3486 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3487 | search_text, |
| 3488 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3489 | true); // reset the tickmarks |
| 3490 | } |
| 3491 | |
| 3492 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 3493 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3494 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3495 | } while (search_frame != main_frame); |
| 3496 | } |
| 3497 | } |
| 3498 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3499 | void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) { |
| 3500 | WebView* view = webview(); |
| 3501 | if (!view) |
| 3502 | return; |
| 3503 | |
| 3504 | WebDocument doc = view->mainFrame()->document(); |
| 3505 | if (doc.isPluginDocument()) { |
| 3506 | GetDelegateForPluginDocument()->StopFind(); |
| 3507 | return; |
| 3508 | } |
| 3509 | |
| 3510 | bool clear_selection = |
| 3511 | params.action == ViewMsg_StopFinding_Params::kClearSelection; |
| 3512 | if (clear_selection) |
| 3513 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 3514 | |
| 3515 | WebFrame* frame = view->mainFrame(); |
| 3516 | while (frame) { |
| 3517 | frame->stopFinding(clear_selection); |
| 3518 | frame = frame->traverseNext(false); |
| 3519 | } |
| 3520 | |
| 3521 | if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) { |
| 3522 | WebFrame* focused_frame = view->focusedFrame(); |
| 3523 | if (focused_frame) { |
| 3524 | WebDocument doc = focused_frame->document(); |
| 3525 | if (!doc.isNull()) { |
| 3526 | WebNode node = doc.focusedNode(); |
| 3527 | if (!node.isNull()) |
| 3528 | node.simulateClick(); |
| 3529 | } |
| 3530 | } |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | void RenderView::OnFindReplyAck() { |
| 3535 | // Check if there is any queued up request waiting to be sent. |
| 3536 | if (queued_find_reply_message_.get()) { |
| 3537 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 3538 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3539 | } |
| 3540 | } |
| 3541 | |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3542 | // static |
| 3543 | std::string RenderView::DetermineTextLanguage(const std::wstring& text) { |
[email protected] | 70082aab | 2010-02-24 01:44:40 | [diff] [blame] | 3544 | // Text with less than 100 bytes will probably not provide good results. |
| 3545 | // Report it as unknown language. |
| 3546 | if (text.length() < 100) |
| 3547 | return kUnknownLanguageCode; |
| 3548 | |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3549 | std::string language = kUnknownLanguageCode; |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3550 | int num_languages = 0; |
| 3551 | bool is_reliable = false; |
[email protected] | 8dc5a205 | 2010-01-19 21:32:42 | [diff] [blame] | 3552 | string16 input = WideToUTF16(text); |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3553 | Language cld_language = |
[email protected] | 8dc5a205 | 2010-01-19 21:32:42 | [diff] [blame] | 3554 | DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable, |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3555 | &num_languages, NULL); |
[email protected] | 70082aab | 2010-02-24 01:44:40 | [diff] [blame] | 3556 | if (is_reliable && cld_language != NUM_LANGUAGES && |
| 3557 | cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 3558 | // We should not use LanguageCode_ISO_639_1 because it does not cover all |
| 3559 | // the languages CLD can detect. As a result, it'll return the invalid |
[email protected] | 8d022a9 | 2010-02-04 02:49:26 | [diff] [blame] | 3560 | // language code for tradtional Chinese among others. |
| 3561 | // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and |
| 3562 | // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN |
| 3563 | // for Simplified Chinese. |
| 3564 | language = LanguageCodeWithDialects(cld_language); |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3565 | } |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3566 | return language; |
[email protected] | 7893a98 | 2010-01-07 23:25:52 | [diff] [blame] | 3567 | } |
| 3568 | |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3569 | bool RenderView::AllowContentType(ContentSettingsType settings_type) { |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3570 | // CONTENT_SETTING_ASK is only valid for cookies. |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3571 | return current_content_settings_.settings[settings_type] != |
| 3572 | CONTENT_SETTING_BLOCK; |
| 3573 | } |
| 3574 | |
| 3575 | void RenderView::DidBlockContentType(ContentSettingsType settings_type) { |
| 3576 | if (!content_blocked_[settings_type]) { |
| 3577 | content_blocked_[settings_type] = true; |
| 3578 | Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type)); |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3579 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3580 | } |
| 3581 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 3582 | void RenderView::ClearBlockedContentSettings() { |
| 3583 | for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 3584 | content_blocked_[i] = false; |
| 3585 | } |
| 3586 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3587 | void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { |
| 3588 | Send(new ViewHostMsg_DnsPrefetch(host_names)); |
| 3589 | } |
| 3590 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3591 | void RenderView::OnZoom(PageZoom::Function function) { |
| 3592 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 3593 | return; |
| 3594 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 3595 | webview()->hidePopups(); |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 3596 | // Should we be saving zoom levels for plugins? It's not clear, so for now |
| 3597 | // don't. |
| 3598 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 3599 | webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument(); |
| 3600 | int zoom; |
| 3601 | if (function == PageZoom::RESET) { |
| 3602 | zoom = 0; |
| 3603 | } else if (function == PageZoom::ZOOM_OUT) { |
| 3604 | zoom = -1; |
| 3605 | } else if (function == PageZoom::ZOOM_IN) { |
| 3606 | zoom = 1; |
| 3607 | } else { |
| 3608 | NOTREACHED(); |
[email protected] | 754bb3b | 2010-03-26 20:12:11 | [diff] [blame] | 3609 | return; |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 3610 | } |
| 3611 | delegate->Zoom(zoom); |
| 3612 | return; |
| 3613 | } |
| 3614 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3615 | int zoom_level = webview()->zoomLevel(); |
| 3616 | int new_zoom_level = webview()->setZoomLevel(false, |
| 3617 | (function == PageZoom::RESET) ? 0 : (zoom_level + function)); |
| 3618 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3619 | // Tell the browser which url got zoomed so it can update the saved values. |
| 3620 | Send(new ViewHostMsg_DidZoomURL( |
| 3621 | GURL(webview()->mainFrame()->url()), new_zoom_level)); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3622 | } |
| 3623 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3624 | void RenderView::OnSetContentSettingsForLoadingURL( |
| 3625 | const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 3626 | const ContentSettings& content_settings) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3627 | host_content_settings_[url] = content_settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 3628 | } |
| 3629 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3630 | void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 3631 | int zoom_level) { |
| 3632 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3633 | } |
| 3634 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 3635 | void RenderView::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3636 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3637 | } |
| 3638 | |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3639 | void RenderView::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3640 | WebString no_encoding; |
| 3641 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3642 | } |
| 3643 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 3644 | bool RenderView::GetAllChildFrames( |
| 3645 | WebFrame* parent_frame, |
| 3646 | std::vector<WebFrame*>* frames_vector) const { |
| 3647 | if (!parent_frame) |
| 3648 | return false; |
| 3649 | for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 3650 | child_frame = child_frame->nextSibling()) { |
| 3651 | frames_vector->push_back(child_frame); |
| 3652 | GetAllChildFrames(child_frame, frames_vector); |
| 3653 | } |
| 3654 | return true; |
| 3655 | } |
| 3656 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3657 | WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { |
| 3658 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3659 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3660 | |
| 3661 | // xpath string can represent a frame deep down the tree (across multiple |
| 3662 | // frame DOMs). |
| 3663 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 3664 | // should break into 2 xpaths |
| 3665 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
| 3666 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3667 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3668 | |
| 3669 | std::wstring xpath_remaining = xpath; |
| 3670 | while (!xpath_remaining.empty()) { |
| 3671 | std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n'); |
| 3672 | std::wstring xpath_child; |
| 3673 | if (delim_pos != std::wstring::npos) { |
| 3674 | xpath_child = xpath_remaining.substr(0, delim_pos); |
| 3675 | xpath_remaining.erase(0, delim_pos + 1); |
| 3676 | } else { |
| 3677 | xpath_remaining.swap(xpath_child); |
| 3678 | } |
| 3679 | frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3680 | } |
| 3681 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3682 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3683 | } |
| 3684 | |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 3685 | void RenderView::EvaluateScript(const std::wstring& frame_xpath, |
| 3686 | const std::wstring& script) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3687 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 3688 | if (!web_frame) |
| 3689 | return; |
| 3690 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3691 | web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3692 | } |
| 3693 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3694 | void RenderView::InsertCSS(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 3695 | const std::string& css, |
| 3696 | const std::string& id) { |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3697 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 3698 | if (!web_frame) |
| 3699 | return; |
| 3700 | |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 3701 | web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3702 | } |
| 3703 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3704 | void RenderView::OnPepperPluginDestroy( |
| 3705 | WebPluginDelegatePepper* pepper_plugin) { |
| 3706 | std::set<WebPluginDelegatePepper*>::iterator found_pepper = |
| 3707 | current_pepper_plugins_.find(pepper_plugin); |
| 3708 | if (found_pepper == current_pepper_plugins_.end()) { |
| 3709 | NOTREACHED(); |
| 3710 | return; |
| 3711 | } |
| 3712 | current_pepper_plugins_.erase(found_pepper); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3713 | |
| 3714 | // The plugin could have been destroyed while it was waiting for a file |
| 3715 | // choose callback, so check all pending completion callbacks and NULL them. |
| 3716 | for (std::deque< linked_ptr<PendingFileChooser> >::iterator i = |
| 3717 | file_chooser_completions_.begin(); |
| 3718 | i != file_chooser_completions_.end(); /* nothing */) { |
| 3719 | if ((*i)->completion == pepper_plugin) { |
| 3720 | // We NULL the first one instead of deleting it because the plugin might |
| 3721 | // be the one waiting for a file choose callback. If the callback later |
| 3722 | // comes, we don't want to send the result to the next callback in line. |
| 3723 | if (i == file_chooser_completions_.begin()) |
| 3724 | (*i)->completion = NULL; |
| 3725 | else |
| 3726 | i = file_chooser_completions_.erase(i); |
| 3727 | } else { |
| 3728 | ++i; |
| 3729 | } |
| 3730 | } |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3731 | } |
| 3732 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3733 | void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath, |
| 3734 | const std::wstring& jscript) { |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 3735 | EvaluateScript(frame_xpath, jscript); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3736 | } |
| 3737 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3738 | void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 3739 | const std::string& css, |
| 3740 | const std::string& id) { |
| 3741 | InsertCSS(frame_xpath, css, id); |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 3742 | |
| 3743 | // Notify RenderViewHost that css has been inserted into the frame. |
| 3744 | Send(new ViewHostMsg_OnCSSInserted(routing_id_)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3745 | } |
| 3746 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3747 | void RenderView::OnAddMessageToConsole( |
| 3748 | const string16& frame_xpath, |
| 3749 | const string16& message, |
| 3750 | const WebConsoleMessage::Level& level) { |
| 3751 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 3752 | if (web_frame) |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3753 | web_frame->addMessageToConsole(WebConsoleMessage(level, message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3754 | } |
| 3755 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 3756 | void RenderView::OnAllowBindings(int enabled_bindings_flags) { |
| 3757 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | void RenderView::OnSetDOMUIProperty(const std::string& name, |
| 3761 | const std::string& value) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 3762 | DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3763 | dom_ui_bindings_.SetProperty(name, value); |
| 3764 | } |
| 3765 | |
| 3766 | void RenderView::OnReservePageIDRange(int size_of_range) { |
| 3767 | next_page_id_ += size_of_range + 1; |
| 3768 | } |
| 3769 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3770 | void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 3771 | const gfx::Point& screen_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3772 | bool ended, |
| 3773 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 3774 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3775 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 3776 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | void RenderView::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3780 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3781 | } |
| 3782 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3783 | void RenderView::OnFillPasswordForm( |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 3784 | const webkit_glue::PasswordFormDomManager::FillData& form_data) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3785 | webkit_glue::FillPasswordForm(this->webview(), form_data); |
| 3786 | } |
| 3787 | |
| 3788 | void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3789 | const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3790 | const gfx::Point& screen_point, |
| 3791 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3792 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3793 | drop_data.ToDragData(), |
| 3794 | drop_data.identity, |
| 3795 | client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3796 | screen_point, |
| 3797 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3798 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3799 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3800 | } |
| 3801 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3802 | void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3803 | const gfx::Point& screen_point, |
| 3804 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3805 | WebDragOperation operation = webview()->dragTargetDragOver( |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3806 | client_point, |
| 3807 | screen_point, |
| 3808 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3809 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3810 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | void RenderView::OnDragTargetDragLeave() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3814 | webview()->dragTargetDragLeave(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3815 | } |
| 3816 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3817 | void RenderView::OnDragTargetDrop(const gfx::Point& client_point, |
| 3818 | const gfx::Point& screen_point) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3819 | webview()->dragTargetDrop(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 3823 | webkit_preferences_ = prefs; |
| 3824 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
| 3828 | alternate_error_page_url_ = url; |
| 3829 | } |
| 3830 | |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 3831 | void RenderView::OnCustomContextMenuAction(unsigned action) { |
| 3832 | webview()->performCustomContextMenuAction(action); |
| 3833 | } |
| 3834 | |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 3835 | void RenderView::OnTranslatePage(int page_id, |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 3836 | const std::string& translate_script, |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 3837 | const std::string& source_lang, |
| 3838 | const std::string& target_lang) { |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 3839 | translate_helper_.TranslatePage(page_id, source_lang, target_lang, |
| 3840 | translate_script); |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 3841 | } |
| 3842 | |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 3843 | void RenderView::OnRevertTranslation(int page_id) { |
| 3844 | translate_helper_.RevertTranslation(page_id); |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 3845 | } |
| 3846 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3847 | void RenderView::OnInstallMissingPlugin() { |
| 3848 | // This could happen when the first default plugin is deleted. |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3849 | if (first_default_plugin_) |
| 3850 | first_default_plugin_->InstallMissingPlugin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3851 | } |
| 3852 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3853 | void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3854 | // This could happen if we navigated to a different page before the user |
| 3855 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3856 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3857 | return; |
| 3858 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3859 | WebVector<WebString> ws_file_names(paths.size()); |
| 3860 | for (size_t i = 0; i < paths.size(); ++i) |
| 3861 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 3862 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3863 | if (file_chooser_completions_.front()->completion) |
| 3864 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 3865 | file_chooser_completions_.pop_front(); |
| 3866 | |
| 3867 | // If there are more pending file chooser requests, schedule one now. |
| 3868 | if (!file_chooser_completions_.empty()) { |
| 3869 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 3870 | file_chooser_completions_.front()->params)); |
| 3871 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | void RenderView::OnEnableViewSourceMode() { |
| 3875 | if (!webview()) |
| 3876 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3877 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3878 | if (!main_frame) |
| 3879 | return; |
| 3880 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3881 | main_frame->enableViewSourceMode(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3882 | } |
| 3883 | |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 3884 | void RenderView::OnEnablePreferredSizeChangedMode(int flags) { |
| 3885 | DCHECK(flags != kPreferredSizeNothing); |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3886 | if (send_preferred_size_changes_) |
| 3887 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 3888 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 3889 | |
| 3890 | // WebKit doesn't send a notification of the effective height of the page |
| 3891 | // changes, so poll for it. |
| 3892 | // TODO: Add a notification for this to WebKit, remove polling. After that's |
| 3893 | // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight. |
| 3894 | // http://crbug.com/44850 |
| 3895 | if (flags & kPreferredSizeHeightThisIsSlow) { |
| 3896 | preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this, |
| 3897 | &RenderView::CheckPreferredSize); |
| 3898 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 3899 | } |
| 3900 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3901 | void RenderView::OnDisableScrollbarsForSmallWindows( |
| 3902 | const gfx::Size& disable_scrollbar_size_limit) { |
| 3903 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 3904 | } |
| 3905 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3906 | void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { |
| 3907 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 3908 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3909 | #if defined(TOOLKIT_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 3910 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 3911 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 3912 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 3913 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3914 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 3915 | webview()->setScrollbarColors( |
| 3916 | renderer_prefs.thumb_inactive_color, |
| 3917 | renderer_prefs.thumb_active_color, |
| 3918 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3919 | webview()->setSelectionColors( |
| 3920 | renderer_prefs.active_selection_bg_color, |
| 3921 | renderer_prefs.active_selection_fg_color, |
| 3922 | renderer_prefs.inactive_selection_bg_color, |
| 3923 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | 61c6440 | 2010-05-25 22:05:01 | [diff] [blame] | 3924 | didInvalidateRect(gfx::Rect(size_)); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3925 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 3926 | #endif |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3927 | } |
| 3928 | |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 3929 | void RenderView::OnMediaPlayerActionAt(const gfx::Point& location, |
| 3930 | const WebMediaPlayerAction& action) { |
| 3931 | if (webview()) |
| 3932 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 3933 | } |
| 3934 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 3935 | void RenderView::OnNotifyRendererViewType(ViewType::Type type) { |
[email protected] | 078b3461 | 2009-09-19 19:31:51 | [diff] [blame] | 3936 | // When this is first set, the bindings aren't fully loaded. We only need |
| 3937 | // to call through this API after the page has already been loaded. It's |
| 3938 | // also called in didCreateDocumentElement to bootstrap. |
| 3939 | if (view_type_ != ViewType::INVALID) { |
| 3940 | if (type == ViewType::EXTENSION_MOLE || |
| 3941 | type == ViewType::EXTENSION_TOOLSTRIP) { |
| 3942 | ExtensionProcessBindings::SetViewType(webview(), type); |
| 3943 | } |
| 3944 | } |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 3945 | view_type_ = type; |
| 3946 | } |
| 3947 | |
| 3948 | void RenderView::OnUpdateBrowserWindowId(int window_id) { |
| 3949 | browser_window_id_ = window_id; |
| 3950 | } |
| 3951 | |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 3952 | void RenderView::OnGetAccessibilityTree() { |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 3953 | if (accessibility_.get()) |
[email protected] | 9f4db51 | 2010-05-10 20:21:41 | [diff] [blame] | 3954 | accessibility_->clear(); |
[email protected] | 039a1da | 2010-05-12 02:08:11 | [diff] [blame] | 3955 | accessibility_.reset(WebAccessibilityCache::create()); |
| 3956 | accessibility_->initialize(webview()); |
[email protected] | 9f4db51 | 2010-05-10 20:21:41 | [diff] [blame] | 3957 | |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 3958 | WebAccessibilityObject src_tree = webview()->accessibilityObject(); |
| 3959 | webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get()); |
| 3960 | Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree)); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 3961 | } |
| 3962 | |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 3963 | void RenderView::OnSetAccessibilityFocus(int acc_obj_id) { |
| 3964 | if (!accessibility_.get()) |
| 3965 | return; |
| 3966 | if (accessibility_->isValidId(acc_obj_id)) { |
| 3967 | // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number. |
| 3968 | // By convention, calling SetFocus on the root of the tree (id = 1000) |
| 3969 | // should clear the current focus. Otherwise set the focus to the new |
| 3970 | // node. |
| 3971 | if (acc_obj_id == 1000) |
| 3972 | webview()->clearFocusedNode(); |
| 3973 | else |
| 3974 | accessibility_->getObjectById(acc_obj_id).setFocused(true); |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) { |
| 3979 | if (!accessibility_.get()) |
| 3980 | return; |
| 3981 | if (accessibility_->isValidId(acc_obj_id)) { |
| 3982 | accessibility_->getObjectById(acc_obj_id).performDefaultAction(); |
| 3983 | } |
| 3984 | } |
| 3985 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3986 | void RenderView::OnGetAllSavableResourceLinksForCurrentPage( |
| 3987 | const GURL& page_url) { |
| 3988 | // Prepare list to storage all savable resource links. |
| 3989 | std::vector<GURL> resources_list; |
| 3990 | std::vector<GURL> referrers_list; |
| 3991 | std::vector<GURL> frames_list; |
| 3992 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 3993 | &referrers_list, |
| 3994 | &frames_list); |
| 3995 | |
[email protected] | dbeb395 | 2009-10-13 18:01:18 | [diff] [blame] | 3996 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 3997 | webview(), |
| 3998 | page_url, |
| 3999 | &result, |
| 4000 | chrome::kSavableSchemes)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4001 | // If something is wrong when collecting all savable resource links, |
| 4002 | // send empty list to embedder(browser) to tell it failed. |
| 4003 | referrers_list.clear(); |
| 4004 | resources_list.clear(); |
| 4005 | frames_list.clear(); |
| 4006 | } |
| 4007 | |
| 4008 | // Send result of all savable resource links to embedder. |
| 4009 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_, |
| 4010 | resources_list, |
| 4011 | referrers_list, |
| 4012 | frames_list)); |
| 4013 | } |
| 4014 | |
| 4015 | void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | f6b4853 | 2009-02-12 01:56:32 | [diff] [blame] | 4016 | const std::vector<GURL>& links, |
[email protected] | fde6714d1 | 2009-02-18 22:39:31 | [diff] [blame] | 4017 | const std::vector<FilePath>& local_paths, |
| 4018 | const FilePath& local_directory_name) { |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4019 | |
| 4020 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 4021 | WebVector<WebURL> weburl_links(links); |
| 4022 | |
| 4023 | // Convert std::vector of std::strings to WebVector<WebString> |
| 4024 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 4025 | for (size_t i = 0; i < local_paths.size(); i++) |
| 4026 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 4027 | |
| 4028 | WebPageSerializer::serialize(webview()->mainFrame(), |
| 4029 | true, this, weburl_links, webstring_paths, |
| 4030 | webkit_glue::FilePathToWebString( |
| 4031 | local_directory_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4032 | } |
| 4033 | |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4034 | void RenderView::didSerializeDataForFrame(const WebURL& frame_url, |
| 4035 | const WebCString& data, |
| 4036 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4037 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4038 | routing_id_, |
| 4039 | frame_url, |
| 4040 | data.data(), |
| 4041 | static_cast<int32>(status))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4042 | } |
| 4043 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4044 | void RenderView::OnMsgShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4045 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4046 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4047 | } |
| 4048 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4049 | void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4050 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4051 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4052 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 4053 | // calling the FrameLoader's CloseURL method directly. This should be |
| 4054 | // revisited to avoid having two ways to close a page. Having a single way |
| 4055 | // to close that can run onunload is also useful for fixing |
| 4056 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4057 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4058 | if (main_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4059 | const GURL& url = main_frame->url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4060 | // TODO(davemoore) this code should be removed once willClose() gets |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4061 | // called when a page is destroyed. DumpLoadHistograms() is safe to call |
| 4062 | // multiple times for the same frame, but it will simplify things. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4063 | if (url.SchemeIs(chrome::kHttpScheme) || |
| 4064 | url.SchemeIs(chrome::kHttpsScheme)) |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4065 | DumpLoadHistograms(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4066 | } |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4067 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4068 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 4069 | // Reset stats |
| 4070 | cross_origin_access_count_ = 0; |
| 4071 | same_origin_access_count_ = 0; |
| 4072 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4073 | // Just echo back the params in the ACK. |
| 4074 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | void RenderView::OnThemeChanged() { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4078 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4079 | gfx::NativeTheme::instance()->CloseHandles(); |
[email protected] | 61c6440 | 2010-05-25 22:05:01 | [diff] [blame] | 4080 | didInvalidateRect(gfx::Rect(size_)); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4081 | #else // defined(OS_WIN) |
| 4082 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 4083 | NOTIMPLEMENTED(); |
| 4084 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4085 | } |
| 4086 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 4087 | void RenderView::OnMessageFromExternalHost(const std::string& message, |
| 4088 | const std::string& origin, |
| 4089 | const std::string& target) { |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4090 | if (message.empty()) |
| 4091 | return; |
| 4092 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 4093 | external_host_bindings_.ForwardMessageFromExternalHost(message, origin, |
| 4094 | target); |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4095 | } |
| 4096 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 4097 | void RenderView::OnDisassociateFromPopupCount() { |
| 4098 | if (decrement_shared_popup_at_destruction_) |
| 4099 | shared_popup_counter_->data--; |
| 4100 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 4101 | decrement_shared_popup_at_destruction_ = false; |
| 4102 | } |
| 4103 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4104 | bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 4105 | const WebURLError& error, |
| 4106 | bool replace) { |
| 4107 | // We only show alternate error pages in the main frame. They are |
| 4108 | // intended to assist the user when navigating, so there is not much |
| 4109 | // value in showing them for failed subframes. Ideally, we would be |
| 4110 | // able to use the TYPED transition type for this, but that flag is |
| 4111 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4112 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4113 | return false; |
| 4114 | |
| 4115 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4116 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4117 | int ec = error.reason; |
| 4118 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 4119 | ec != net::ERR_CONNECTION_FAILED && |
| 4120 | ec != net::ERR_CONNECTION_REFUSED && |
| 4121 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4122 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4123 | return false; |
| 4124 | |
| 4125 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4126 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4127 | if (!error_page_url.is_valid()) |
| 4128 | return false; |
| 4129 | |
| 4130 | // Load an empty page first so there is an immediate response to the error, |
| 4131 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4132 | frame->loadHTMLString(std::string(), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4133 | GURL(kUnreachableWebDataURL), |
| 4134 | error.unreachableURL, |
| 4135 | replace); |
| 4136 | |
| 4137 | // Now, create a fetcher for the error page and associate it with the data |
| 4138 | // source we just created via the LoadHTMLString call. That way if another |
| 4139 | // navigation occurs, the fetcher will get destroyed. |
| 4140 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4141 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4142 | navigation_state->set_alt_error_page_fetcher( |
| 4143 | new AltErrorPageResourceFetcher( |
| 4144 | error_page_url, frame, error, |
| 4145 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 4146 | return true; |
| 4147 | } |
| 4148 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4149 | std::string RenderView::GetAltHTMLForTemplate( |
| 4150 | const DictionaryValue& error_strings, int template_resource_id) const { |
[email protected] | 8a16266e | 2009-09-10 21:08:39 | [diff] [blame] | 4151 | const base::StringPiece template_html( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4152 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4153 | template_resource_id)); |
| 4154 | |
| 4155 | if (template_html.empty()) { |
| 4156 | NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
| 4157 | return ""; |
| 4158 | } |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4159 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4160 | // "t" is the id of the templates root node. |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4161 | return jstemplate_builder::GetTemplatesHtml( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4162 | template_html, &error_strings, "t"); |
| 4163 | } |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 4164 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4165 | void RenderView::AltErrorPageFinished(WebFrame* frame, |
| 4166 | const WebURLError& original_error, |
| 4167 | const std::string& html) { |
| 4168 | // Here, we replace the blank page we loaded previously. |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4169 | |
| 4170 | // If we failed to download the alternate error page, fall back to the |
| 4171 | // original error page if present. Otherwise, LoadNavigationErrorPage |
| 4172 | // will simply display a default error page. |
| 4173 | const std::string* html_to_load = &html; |
| 4174 | if (html.empty()) { |
| 4175 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4176 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4177 | html_to_load = &navigation_state->postponed_data(); |
| 4178 | } |
| 4179 | LoadNavigationErrorPage( |
| 4180 | frame, WebURLRequest(), original_error, *html_to_load, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4181 | } |
| 4182 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4183 | void RenderView::OnMoveOrResizeStarted() { |
| 4184 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4185 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4186 | } |
| 4187 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4188 | void RenderView::OnResize(const gfx::Size& new_size, |
| 4189 | const gfx::Rect& resizer_rect) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4190 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4191 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4192 | |
| 4193 | if (send_preferred_size_changes_) { |
| 4194 | // If resizing to a size larger than |disable_scrollbars_size_limit_| in |
| 4195 | // either width or height, allow scroll bars. |
| 4196 | bool allow_scrollbars = ( |
| 4197 | disable_scrollbars_size_limit_.width() <= new_size.width() || |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 4198 | disable_scrollbars_size_limit_.height() <= new_size.height()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4199 | webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars); |
| 4200 | } |
| 4201 | } |
| 4202 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4203 | RenderWidget::OnResize(new_size, resizer_rect); |
| 4204 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 4205 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4206 | void RenderView::DidInitiatePaint() { |
| 4207 | // Notify any pepper plugins that we started painting. The plugin "should" |
| 4208 | // never notified that we started painting, this is used for internal |
| 4209 | // bookkeeping only, so we know that the set can not change under us. |
| 4210 | for (std::set<WebPluginDelegatePepper*>::iterator i = |
| 4211 | current_pepper_plugins_.begin(); |
| 4212 | i != current_pepper_plugins_.end(); ++i) |
| 4213 | (*i)->RenderViewInitiatedPaint(); |
| 4214 | } |
| 4215 | |
| 4216 | void RenderView::DidFlushPaint() { |
| 4217 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 4218 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 4219 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 4220 | // won't change out from under us. |
| 4221 | std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_; |
| 4222 | for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin(); |
| 4223 | i != plugins.end(); ++i) { |
| 4224 | // The copy above makes sure our iterator is never invalid if some plugins |
| 4225 | // are destroyed. But some plugin may decide to close all of its views in |
| 4226 | // response to a paint in one of them, so we need to make sure each one is |
| 4227 | // still "current" before using it. |
| 4228 | if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end()) |
| 4229 | (*i)->RenderViewFlushedPaint(); |
| 4230 | } |
| 4231 | |
| 4232 | WebFrame* main_frame = webview()->mainFrame(); |
| 4233 | |
| 4234 | // If we have a provisional frame we are between the start and commit stages |
| 4235 | // of loading and we don't want to save stats. |
| 4236 | if (!main_frame->provisionalDataSource()) { |
| 4237 | WebDataSource* ds = main_frame->dataSource(); |
| 4238 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4239 | DCHECK(navigation_state); |
| 4240 | |
| 4241 | Time now = Time::Now(); |
| 4242 | if (navigation_state->first_paint_time().is_null()) { |
| 4243 | navigation_state->set_first_paint_time(now); |
| 4244 | } |
| 4245 | if (navigation_state->first_paint_after_load_time().is_null() && |
| 4246 | !navigation_state->finish_load_time().is_null()) { |
| 4247 | navigation_state->set_first_paint_after_load_time(now); |
| 4248 | } |
| 4249 | } |
| 4250 | } |
| 4251 | |
| 4252 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4253 | void RenderView::OnClearFocusedNode() { |
| 4254 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4255 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4256 | } |
| 4257 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4258 | void RenderView::OnSetBackground(const SkBitmap& background) { |
| 4259 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4260 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4261 | |
| 4262 | SetBackground(background); |
| 4263 | } |
| 4264 | |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4265 | void RenderView::OnSetActive(bool active) { |
| 4266 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4267 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4268 | |
| 4269 | #if defined(OS_MACOSX) |
| 4270 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4271 | for (plugin_it = plugin_delegates_.begin(); |
| 4272 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4273 | (*plugin_it)->SetWindowFocus(active); |
| 4274 | } |
| 4275 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4276 | } |
| 4277 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4278 | #if defined(OS_MACOSX) |
| 4279 | void RenderView::OnSetWindowVisibility(bool visible) { |
| 4280 | // Inform plugins that their container has changed visibility. |
| 4281 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4282 | for (plugin_it = plugin_delegates_.begin(); |
| 4283 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4284 | (*plugin_it)->SetContainerVisibility(visible); |
| 4285 | } |
| 4286 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4287 | |
| 4288 | void RenderView::OnWindowFrameChanged(gfx::Rect window_frame, |
| 4289 | gfx::Rect view_frame) { |
| 4290 | // Inform plugins that their window's frame has changed. |
| 4291 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4292 | for (plugin_it = plugin_delegates_.begin(); |
| 4293 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4294 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 4295 | } |
| 4296 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4297 | #endif // OS_MACOSX |
| 4298 | |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4299 | void RenderView::SendExtensionRequest(const std::string& name, |
[email protected] | e4dad9fb | 2009-10-06 18:15:58 | [diff] [blame] | 4300 | const ListValue& args, |
[email protected] | bb64b51 | 2010-04-02 21:01:39 | [diff] [blame] | 4301 | const GURL& source_url, |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 4302 | int request_id, |
[email protected] | 2f25d7b9 | 2009-06-10 00:06:47 | [diff] [blame] | 4303 | bool has_callback) { |
[email protected] | bb64b51 | 2010-04-02 21:01:39 | [diff] [blame] | 4304 | Send(new ViewHostMsg_ExtensionRequest(routing_id_, |
| 4305 | name, |
| 4306 | args, |
| 4307 | source_url, |
| 4308 | request_id, |
[email protected] | 2f25d7b9 | 2009-06-10 00:06:47 | [diff] [blame] | 4309 | has_callback)); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4310 | } |
| 4311 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 4312 | void RenderView::OnExtensionResponse(int request_id, |
| 4313 | bool success, |
| 4314 | const std::string& response, |
| 4315 | const std::string& error) { |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 4316 | ExtensionProcessBindings::HandleResponse( |
| 4317 | request_id, success, response, error); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4318 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4319 | |
[email protected] | 078b3461 | 2009-09-19 19:31:51 | [diff] [blame] | 4320 | void RenderView::InjectToolstripCSS() { |
| 4321 | if (view_type_ != ViewType::EXTENSION_TOOLSTRIP) |
| 4322 | return; |
| 4323 | |
| 4324 | static const base::StringPiece toolstrip_css( |
| 4325 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4326 | IDR_EXTENSION_TOOLSTRIP_CSS)); |
| 4327 | std::string css = toolstrip_css.as_string(); |
| 4328 | InsertCSS(L"", css, "ToolstripDefaultCSS"); |
| 4329 | } |
| 4330 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4331 | void RenderView::OnExtensionMessageInvoke(const std::string& function_name, |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4332 | const ListValue& args, |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4333 | bool requires_incognito_access, |
| 4334 | const GURL& event_url) { |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4335 | RendererExtensionBindings::Invoke( |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4336 | function_name, args, this, requires_incognito_access, event_url); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4337 | } |
| 4338 | |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4339 | // Dump all load time histograms. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4340 | // |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4341 | // There are 13 histograms measuring various times. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4342 | // The time points we keep are |
| 4343 | // request: time document was requested by user |
| 4344 | // start: time load of document started |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 4345 | // commit: time load of document started |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4346 | // finish_document: main document loaded, before onload() |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4347 | // finish: after onload() and all resources are loaded |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4348 | // first_paint: first paint performed |
| 4349 | // first_paint_after_load: first paint performed after load is finished |
| 4350 | // begin: request if it was user requested, start otherwise |
| 4351 | // |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4352 | // The times that we histogram are |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 4353 | // request->start, |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4354 | // start->commit, |
| 4355 | // commit->finish_document, |
| 4356 | // finish_document->finish, |
| 4357 | // begin->commit, |
| 4358 | // begin->finishDoc, |
| 4359 | // begin->finish, |
| 4360 | // begin->first_paint, |
| 4361 | // begin->first_paint_after_load |
| 4362 | // commit->finishDoc, |
| 4363 | // commit->first_paint, |
| 4364 | // commit->first_paint_after_load, |
| 4365 | // finish->first_paint_after_load, |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4366 | // |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4367 | // It's possible for the request time not to be set, if a client |
| 4368 | // redirect had been done (the user never requested the page) |
| 4369 | // Also, it's possible to load a page without ever laying it out |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4370 | // so first_paint and first_paint_after_load can be 0. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4371 | void RenderView::DumpLoadHistograms() const { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4372 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4373 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4374 | NavigationState::FromDataSource(main_frame->dataSource()); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4375 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4376 | // If we've already dumped, do nothing. |
| 4377 | if (navigation_state->load_histograms_recorded()) |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4378 | return; |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4379 | Time start = navigation_state->start_load_time(); |
| 4380 | if (start.is_null()) |
| 4381 | return; // Probably very premature abandonment of page. |
| 4382 | Time commit = navigation_state->commit_load_time(); |
| 4383 | if (commit.is_null()) |
| 4384 | return; // Probably very premature abandonment of page. |
| 4385 | // We properly handle null values for the next 3 variables. |
| 4386 | Time request = navigation_state->request_time(); |
| 4387 | Time first_paint = navigation_state->first_paint_time(); |
| 4388 | Time first_paint_after_load = navigation_state->first_paint_after_load_time(); |
| 4389 | |
| 4390 | Time finish = navigation_state->finish_load_time(); |
| 4391 | Time finish_doc = navigation_state->finish_document_load_time(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4392 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4393 | // Handle case where user hits "stop" or "back" before loading completely. |
| 4394 | bool abandoned_page = finish.is_null(); |
| 4395 | if (abandoned_page) { |
| 4396 | finish = Time::Now(); |
| 4397 | navigation_state->set_finish_load_time(finish); |
| 4398 | } |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4399 | if (finish_doc.is_null()) { |
| 4400 | finish_doc = Time::Now(); |
| 4401 | navigation_state->set_finish_document_load_time(finish_doc); |
| 4402 | } |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4403 | UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2); |
| 4404 | |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 4405 | LogNavigationState(navigation_state, main_frame->dataSource()); |
| 4406 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4407 | NavigationState::LoadType load_type = navigation_state->load_type(); |
| 4408 | UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type, |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4409 | NavigationState::kLoadTypeMax); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4410 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 4411 | // Site isolation metrics. |
| 4412 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess", |
| 4413 | cross_origin_access_count_); |
| 4414 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess", |
| 4415 | same_origin_access_count_); |
| 4416 | |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4417 | |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4418 | Time begin; |
| 4419 | // Client side redirects will have no request time. |
| 4420 | if (request.is_null()) { |
| 4421 | begin = start; |
| 4422 | } else { |
| 4423 | begin = request; |
| 4424 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request); |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4425 | } |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4426 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start); |
| 4427 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4428 | "Renderer4.CommitToFinishDoc", finish_doc - commit); |
| 4429 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4430 | "Renderer4.FinishDocToFinish", finish - finish_doc); |
| 4431 | |
| 4432 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4433 | |
| 4434 | static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10)); |
| 4435 | static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10)); |
| 4436 | static const size_t kBeginToFinishDocBucketCount(100); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4437 | TimeDelta begin_to_finish_doc = finish_doc - begin; |
| 4438 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4439 | |
| 4440 | static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10)); |
| 4441 | static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10)); |
| 4442 | static const size_t kBeginToFinishBucketCount(100); |
| 4443 | TimeDelta begin_to_finish = finish_doc - begin; |
| 4444 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish, |
| 4445 | kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount); |
| 4446 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4447 | switch (load_type) { |
| 4448 | case NavigationState::UNDEFINED_LOAD: |
| 4449 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad", |
| 4450 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4451 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4452 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad", |
| 4453 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4454 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4455 | break; |
| 4456 | case NavigationState::RELOAD: |
| 4457 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload", |
| 4458 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4459 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4460 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload", |
| 4461 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4462 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4463 | break; |
| 4464 | case NavigationState::HISTORY_LOAD: |
| 4465 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad", |
| 4466 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4467 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4468 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad", |
| 4469 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4470 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4471 | break; |
| 4472 | case NavigationState::NORMAL_LOAD: |
| 4473 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad", |
| 4474 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4475 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4476 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad", |
| 4477 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4478 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4479 | break; |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4480 | case NavigationState::LINK_LOAD_NORMAL: |
| 4481 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal", |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4482 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4483 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4484 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal", |
| 4485 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4486 | kBeginToFinishBucketCount); |
| 4487 | break; |
| 4488 | case NavigationState::LINK_LOAD_RELOAD: |
| 4489 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload", |
| 4490 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4491 | kBeginToFinishDocBucketCount); |
| 4492 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload", |
| 4493 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4494 | kBeginToFinishBucketCount); |
| 4495 | break; |
| 4496 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4497 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk", |
| 4498 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4499 | kBeginToFinishDocBucketCount); |
| 4500 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk", |
| 4501 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4502 | kBeginToFinishBucketCount); |
| 4503 | break; |
| 4504 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 4505 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly", |
| 4506 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4507 | kBeginToFinishDocBucketCount); |
| 4508 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly", |
| 4509 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4510 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4511 | break; |
| 4512 | default: |
| 4513 | break; |
| 4514 | } |
| 4515 | |
| 4516 | static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") && |
| 4517 | !FieldTrialList::Find("DnsImpact")->group_name().empty()); |
| 4518 | if (use_dns_histogram) { |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4519 | UMA_HISTOGRAM_ENUMERATION( |
| 4520 | FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"), |
| 4521 | abandoned_page ? 1 : 0, 2); |
| 4522 | UMA_HISTOGRAM_ENUMERATION( |
| 4523 | FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"), |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4524 | load_type, NavigationState::kLoadTypeMax); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4525 | switch (load_type) { |
| 4526 | case NavigationState::NORMAL_LOAD: |
| 4527 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4528 | "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"), |
| 4529 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4530 | kBeginToFinishBucketCount); |
| 4531 | break; |
| 4532 | case NavigationState::LINK_LOAD_NORMAL: |
| 4533 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4534 | "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"), |
| 4535 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4536 | kBeginToFinishBucketCount); |
| 4537 | break; |
| 4538 | case NavigationState::LINK_LOAD_RELOAD: |
| 4539 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4540 | "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"), |
| 4541 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4542 | kBeginToFinishBucketCount); |
| 4543 | break; |
| 4544 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4545 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4546 | "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"), |
| 4547 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4548 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4549 | break; |
| 4550 | default: |
| 4551 | break; |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") && |
| 4556 | !FieldTrialList::Find("GlobalSdch")->group_name().empty()); |
| 4557 | if (use_sdch_histogram) { |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4558 | UMA_HISTOGRAM_ENUMERATION( |
| 4559 | FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"), |
| 4560 | load_type, NavigationState::kLoadTypeMax); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4561 | switch (load_type) { |
| 4562 | case NavigationState::NORMAL_LOAD: |
| 4563 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4564 | "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"), |
| 4565 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4566 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4567 | break; |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4568 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4569 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4570 | "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"), |
| 4571 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4572 | kBeginToFinishBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4573 | break; |
| 4574 | case NavigationState::LINK_LOAD_RELOAD: |
| 4575 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4576 | "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"), |
| 4577 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4578 | kBeginToFinishBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4579 | break; |
| 4580 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4581 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4582 | "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"), |
| 4583 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4584 | kBeginToFinishBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4585 | break; |
| 4586 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 4587 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4588 | "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"), |
| 4589 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4590 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4591 | break; |
| 4592 | default: |
| 4593 | break; |
| 4594 | } |
| 4595 | } |
| 4596 | |
| 4597 | static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") && |
| 4598 | !FieldTrialList::Find("CacheSize")->group_name().empty()); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4599 | if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type && |
| 4600 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4601 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
| 4602 | "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"), |
| 4603 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4604 | kBeginToFinishDocBucketCount); |
[email protected] | e695fbd6 | 2009-06-30 16:31:54 | [diff] [blame] | 4605 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 4606 | static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") && |
| 4607 | !FieldTrialList::Find("SpdyImpact")->group_name().empty()); |
| 4608 | if (use_spdy_histogram) { |
| 4609 | switch (load_type) { |
| 4610 | case NavigationState::LINK_LOAD_NORMAL: |
| 4611 | if (navigation_state->was_npn_negotiated()) { |
| 4612 | DCHECK(FieldTrialList::Find("SpdyImpact")->group_name() == |
| 4613 | "_npn_with_http" || |
| 4614 | FieldTrialList::Find("SpdyImpact")->group_name() == |
| 4615 | "_npn_with_spdy"); |
| 4616 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
| 4617 | "Renderer4.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 4618 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4619 | kBeginToFinishBucketCount); |
| 4620 | } |
| 4621 | break; |
| 4622 | default: |
| 4623 | break; |
| 4624 | } |
| 4625 | } |
| 4626 | |
[email protected] | 0a32257a | 2009-07-09 18:10:41 | [diff] [blame] | 4627 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish", |
| 4628 | finish - start, kBeginToFinishMin, |
| 4629 | kBeginToFinishMax, kBeginToFinishBucketCount); |
| 4630 | if (!request.is_null()) |
| 4631 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish", |
| 4632 | finish - request, kBeginToFinishMin, |
| 4633 | kBeginToFinishMax, kBeginToFinishBucketCount); |
[email protected] | e695fbd6 | 2009-06-30 16:31:54 | [diff] [blame] | 4634 | |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4635 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit); |
| 4636 | |
| 4637 | if (!first_paint.is_null()) { |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4638 | DCHECK(begin <= first_paint); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4639 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4640 | "Renderer4.BeginToFirstPaint", first_paint - begin); |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4641 | DCHECK(commit <= first_paint); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4642 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4643 | "Renderer4.CommitToFirstPaint", first_paint - commit); |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4644 | } |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4645 | |
| 4646 | if (!first_paint_after_load.is_null()) { |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4647 | DCHECK(begin <= first_paint_after_load); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4648 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4649 | "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin); |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4650 | DCHECK(commit <= first_paint_after_load); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4651 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4652 | "Renderer4.CommitToFirstPaintAfterLoad", |
| 4653 | first_paint_after_load - commit); |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4654 | DCHECK(finish <= first_paint_after_load); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4655 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4656 | "Renderer4.FinishToFirstPaintAfterLoad", |
| 4657 | first_paint_after_load - finish); |
| 4658 | } |
| 4659 | |
| 4660 | navigation_state->set_load_histograms_recorded(true); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 4661 | |
| 4662 | // Since there are currently no guarantees that renderer histograms will be |
| 4663 | // sent to the browser, we initiate a PostTask here to be sure that we send |
| 4664 | // the histograms we generated. Without this call, pages that don't have an |
| 4665 | // on-close-handler might generate data that is lost when the renderer is |
| 4666 | // shutdown abruptly (perchance because the user closed the tab). |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4667 | // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it |
| 4668 | // should post when the onload is complete, so that it doesn't interfere with |
| 4669 | // the next load. |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 4670 | if (RenderThread::current()) { |
| 4671 | RenderThread::current()->SendHistograms( |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 4672 | chrome::kHistogramSynchronizerReservedSequenceNumber); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 4673 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4674 | } |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4675 | |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 4676 | void RenderView::LogNavigationState(const NavigationState* state, |
| 4677 | const WebDataSource* ds) const { |
| 4678 | // Because this function gets called on every page load, |
| 4679 | // take extra care to optimize it away if logging is turned off. |
| 4680 | if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 4681 | return; |
| 4682 | |
| 4683 | DCHECK(state); |
| 4684 | DCHECK(ds); |
| 4685 | GURL url(ds->request().url()); |
| 4686 | Time start = state->start_load_time(); |
| 4687 | Time finish = state->finish_load_time(); |
| 4688 | // TODO(mbelshe): should we log more stats? |
| 4689 | LOG(INFO) << "PLT: " |
| 4690 | << (finish - start).InMilliseconds() |
| 4691 | << "ms " |
| 4692 | << url.spec(); |
| 4693 | } |
| 4694 | |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 4695 | void RenderView::focusAccessibilityObject( |
| 4696 | const WebAccessibilityObject& acc_obj) { |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4697 | #if defined(OS_WIN) |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 4698 | // TODO(dglazkov): Current logic implies that focus change can only be made |
| 4699 | // after at least one call to RenderView::OnGetAccessibilityInfo, which is |
| 4700 | // where accessibility is initialized. We should determine whether that's |
| 4701 | // right. |
| 4702 | if (!accessibility_.get()) |
| 4703 | return; |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4704 | |
| 4705 | // Retrieve the accessibility object id of the AccessibilityObject. |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 4706 | int acc_obj_id = accessibility_->addOrGetId(acc_obj); |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4707 | |
| 4708 | // If id is valid, alert the browser side that an accessibility focus change |
| 4709 | // occurred. |
| 4710 | if (acc_obj_id >= 0) |
| 4711 | Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id)); |
| 4712 | |
| 4713 | #else // defined(OS_WIN) |
| 4714 | // TODO(port): accessibility not yet implemented |
| 4715 | NOTIMPLEMENTED(); |
| 4716 | #endif |
| 4717 | } |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4718 | |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 4719 | void RenderView::SendForms(WebFrame* frame) { |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4720 | // TODO(jhawkins): Use FormManager once we have strict ordering of form |
| 4721 | // control elements in the cache. |
| 4722 | WebVector<WebFormElement> web_forms; |
| 4723 | frame->forms(web_forms); |
| 4724 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 4725 | std::vector<FormData> forms; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4726 | for (size_t i = 0; i < web_forms.size(); ++i) { |
| 4727 | const WebFormElement& web_form = web_forms[i]; |
| 4728 | |
| 4729 | FormData form; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4730 | if (FormManager::WebFormElementToFormData( |
[email protected] | 573c1c27 | 2010-05-25 19:28:06 | [diff] [blame] | 4731 | web_form, FormManager::REQUIRE_NONE, false, &form)) |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4732 | forms.push_back(form); |
| 4733 | } |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 4734 | |
| 4735 | if (!forms.empty()) |
| 4736 | Send(new ViewHostMsg_FormsSeen(routing_id_, forms)); |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 4737 | } |
| 4738 | |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 4739 | void RenderView::didChangeAccessibilityObjectState( |
| 4740 | const WebKit::WebAccessibilityObject& acc_obj) { |
| 4741 | #if defined(OS_WIN) |
| 4742 | // TODO(dglazkov): Current logic implies that a state change can only be made |
| 4743 | // after at least one call to RenderView::OnGetAccessibilityInfo, which is |
| 4744 | // where accessibility is initialized. We should determine whether that's |
| 4745 | // right. |
| 4746 | if (!accessibility_.get()) |
| 4747 | return; |
| 4748 | |
| 4749 | // Retrieve the accessibility object id of the AccessibilityObject. |
| 4750 | int acc_obj_id = accessibility_->addOrGetId(acc_obj); |
| 4751 | |
| 4752 | // If id is valid, alert the browser side that an accessibility object state |
| 4753 | // change occurred. |
| 4754 | if (acc_obj_id >= 0) |
| 4755 | Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_, |
| 4756 | acc_obj_id)); |
| 4757 | |
| 4758 | #else // defined(OS_WIN) |
| 4759 | // TODO(port): accessibility not yet implemented |
| 4760 | NOTIMPLEMENTED(); |
| 4761 | #endif |
| 4762 | } |
| 4763 | |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 4764 | void RenderView::SendPasswordForms(WebFrame* frame, bool only_visible) { |
[email protected] | 55ced00 | 2010-05-21 04:49:59 | [diff] [blame] | 4765 | // Make sure that this security origin is allowed to use password manager. |
| 4766 | WebSecurityOrigin security_origin = frame->securityOrigin(); |
| 4767 | if (!security_origin.canAccessPasswordManager()) |
| 4768 | return; |
| 4769 | |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 4770 | WebVector<WebFormElement> forms; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4771 | frame->forms(forms); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4772 | |
| 4773 | std::vector<PasswordForm> password_forms; |
| 4774 | for (size_t i = 0; i < forms.size(); ++i) { |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 4775 | const WebFormElement& form = forms[i]; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4776 | |
| 4777 | // Respect autocomplete=off. |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 4778 | if (!form.autoComplete()) |
| 4779 | continue; |
| 4780 | if (only_visible && !form.hasNonEmptyBoundingBox()) |
| 4781 | continue; |
| 4782 | scoped_ptr<PasswordForm> password_form( |
| 4783 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 4784 | if (password_form.get()) |
| 4785 | password_forms.push_back(*password_form); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4786 | } |
| 4787 | |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 4788 | if (password_forms.empty()) |
| 4789 | return; |
| 4790 | if (only_visible) |
| 4791 | Send(new ViewHostMsg_PasswordFormsVisible(routing_id_, password_forms)); |
| 4792 | else |
| 4793 | Send(new ViewHostMsg_PasswordFormsFound(routing_id_, password_forms)); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4794 | } |
[email protected] | 0fda727 | 2009-06-26 15:49:33 | [diff] [blame] | 4795 | |
| 4796 | void RenderView::Print(WebFrame* frame, bool script_initiated) { |
| 4797 | DCHECK(frame); |
| 4798 | if (print_helper_.get() == NULL) { |
| 4799 | print_helper_.reset(new PrintWebViewHelper(this)); |
| 4800 | } |
| 4801 | print_helper_->Print(frame, script_initiated); |
| 4802 | } |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4803 | |
| 4804 | void RenderView::OnSetEditCommandsForNextKeyEvent( |
| 4805 | const EditCommands& edit_commands) { |
| 4806 | edit_commands_ = edit_commands; |
| 4807 | } |
| 4808 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4809 | void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4810 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4811 | if (!main_frame) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4812 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, |
| 4813 | false)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4814 | return; |
| 4815 | } |
| 4816 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 4817 | WebDataSource* ds = main_frame->dataSource(); |
| 4818 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4819 | if (!navigation_state->user_script_idle_scheduler()->has_run()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4820 | pending_code_execution_queue_.push( |
| 4821 | linked_ptr<ViewMsg_ExecuteCode_Params>( |
| 4822 | new ViewMsg_ExecuteCode_Params(params))); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 4823 | return; |
| 4824 | } |
| 4825 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4826 | ExecuteCodeImpl(main_frame, params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | void RenderView::ExecuteCodeImpl(WebFrame* frame, |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4830 | const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | d146b83 | 2009-12-23 02:45:48 | [diff] [blame] | 4831 | // Don't execute scripts in gallery pages. |
| 4832 | GURL frame_url = GURL(frame->url()); |
| 4833 | if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) { |
| 4834 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
| 4835 | return; |
| 4836 | } |
| 4837 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4838 | std::vector<WebFrame*> frame_vector; |
| 4839 | frame_vector.push_back(frame); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4840 | if (params.all_frames) |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4841 | GetAllChildFrames(frame, &frame_vector); |
| 4842 | |
| 4843 | for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); |
| 4844 | frame_it != frame_vector.end(); ++frame_it) { |
| 4845 | WebFrame* frame = *frame_it; |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4846 | if (params.is_javascript) { |
| 4847 | if (!UrlMatchesPermissions(frame->url(), params.host_permissions)) |
| 4848 | continue; |
| 4849 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4850 | std::vector<WebScriptSource> sources; |
| 4851 | sources.push_back( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4852 | WebScriptSource(WebString::fromUTF8(params.code))); |
| 4853 | UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4854 | frame->executeScriptInIsolatedWorld( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4855 | UserScriptSlave::GetIsolatedWorldId(params.extension_id), |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4856 | &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 4857 | } else { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4858 | frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4859 | } |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4860 | } |
| 4861 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4862 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4863 | } |
| 4864 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 4865 | void RenderView::Close() { |
| 4866 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 4867 | WebView* doomed = webview(); |
| 4868 | RenderWidget::Close(); |
| 4869 | Singleton<ViewMap>::get()->erase(doomed); |
| 4870 | } |
| 4871 | |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4872 | void RenderView::DidHandleKeyEvent() { |
| 4873 | edit_commands_.clear(); |
| 4874 | } |
| 4875 | |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4876 | #if defined(OS_MACOSX) |
| 4877 | void RenderView::OnWasHidden() { |
| 4878 | RenderWidget::OnWasHidden(); |
| 4879 | |
| 4880 | // Inform plugins that their container is no longer visible. |
| 4881 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4882 | for (plugin_it = plugin_delegates_.begin(); |
| 4883 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4884 | (*plugin_it)->SetContainerVisibility(false); |
| 4885 | } |
| 4886 | } |
| 4887 | |
| 4888 | void RenderView::OnWasRestored(bool needs_repainting) { |
| 4889 | RenderWidget::OnWasRestored(needs_repainting); |
| 4890 | |
| 4891 | // Inform plugins that their container is now visible. |
| 4892 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4893 | for (plugin_it = plugin_delegates_.begin(); |
| 4894 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4895 | (*plugin_it)->SetContainerVisibility(true); |
| 4896 | } |
| 4897 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4898 | |
| 4899 | void RenderView::OnSetFocus(bool enable) { |
| 4900 | RenderWidget::OnSetFocus(enable); |
| 4901 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4902 | if (webview() && webview()->isActive()) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4903 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4904 | for (plugin_it = plugin_delegates_.begin(); |
| 4905 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 4906 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 4907 | // activation state to change just like a call to setIsActive. |
| 4908 | if (enable) |
| 4909 | (*plugin_it)->SetWindowFocus(true); |
| 4910 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4911 | } |
| 4912 | } |
| 4913 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4914 | #endif // OS_MACOSX |
| 4915 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 4916 | void RenderView::EnsureDocumentTag() { |
| 4917 | // TODO(darin): There's actually no reason for this to be here. We should |
| 4918 | // have the browser side manage the document tag. |
| 4919 | #if defined(OS_MACOSX) |
| 4920 | if (!has_document_tag_) { |
| 4921 | // Make the call to get the tag. |
| 4922 | Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); |
| 4923 | has_document_tag_ = true; |
| 4924 | } |
| 4925 | #endif |
| 4926 | } |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 4927 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4928 | #if defined(OS_MACOSX) |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 4929 | gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle( |
| 4930 | bool opaque) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4931 | gfx::PluginWindowHandle window = NULL; |
| 4932 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 4933 | routing_id(), opaque, &window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4934 | return window; |
| 4935 | } |
| 4936 | |
| 4937 | void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) { |
| 4938 | if (window) |
| 4939 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
| 4940 | } |
| 4941 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4942 | void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window, |
| 4943 | int32 width, |
| 4944 | int32 height, |
| 4945 | uint64 io_surface_identifier) { |
| 4946 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4947 | routing_id(), window, width, height, io_surface_identifier)); |
| 4948 | } |
| 4949 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4950 | void RenderView::AcceleratedSurfaceSetTransportDIB( |
| 4951 | gfx::PluginWindowHandle window, |
| 4952 | int32 width, |
| 4953 | int32 height, |
| 4954 | TransportDIB::Handle transport_dib) { |
| 4955 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4956 | routing_id(), window, width, height, transport_dib)); |
| 4957 | } |
| 4958 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4959 | TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB( |
| 4960 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4961 | TransportDIB::Handle dib_handle; |
| 4962 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 4963 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4964 | return dib_handle; |
| 4965 | // Return an invalid handle if Send() fails. |
| 4966 | return TransportDIB::DefaultHandleValue(); |
| 4967 | } |
| 4968 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4969 | void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4970 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 4971 | } |
| 4972 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4973 | void RenderView::AcceleratedSurfaceBuffersSwapped( |
| 4974 | gfx::PluginWindowHandle window) { |
| 4975 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4976 | } |
| 4977 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 4978 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4979 | bool RenderView::ScheduleFileChooser( |
| 4980 | const ViewHostMsg_RunFileChooser_Params& params, |
| 4981 | WebFileChooserCompletion* completion) { |
| 4982 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 4983 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 4984 | // This sanity check prevents too many file choose requests from getting |
| 4985 | // queued which could DoS the user. Getting these is most likely a |
| 4986 | // programming error (there are many ways to DoS the user so it's not |
| 4987 | // considered a "real" security check), either in JS requesting many file |
| 4988 | // choosers to pop up, or in a plugin. |
| 4989 | // |
| 4990 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 4991 | // a file picker, which will address this issue in a better way. |
| 4992 | return false; |
| 4993 | } |
| 4994 | |
| 4995 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 4996 | new PendingFileChooser(params, completion))); |
| 4997 | if (file_chooser_completions_.size() == 1) { |
| 4998 | // Actually show the browse dialog when this is the first request. |
| 4999 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 5000 | } |
| 5001 | return true; |
| 5002 | } |
| 5003 | |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 5004 | void RenderView::OnPageTranslated() { |
| 5005 | WebFrame* frame = webview()->mainFrame(); |
| 5006 | if (!frame) |
| 5007 | return; |
| 5008 | |
| 5009 | // The page is translated, so try to extract the form data again. |
| 5010 | form_manager_.ExtractForms(frame); |
| 5011 | SendForms(frame); |
| 5012 | } |
| 5013 | |
[email protected] | 8a5f700 | 2010-03-31 13:47:35 | [diff] [blame] | 5014 | WebKit::WebGeolocationService* RenderView::geolocationService() { |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5015 | if (!geolocation_dispatcher_.get()) |
| 5016 | geolocation_dispatcher_.reset(new GeolocationDispatcher(this)); |
| 5017 | return geolocation_dispatcher_.get(); |
| 5018 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5019 | |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5020 | bool RenderView::IsNonLocalTopLevelNavigation( |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5021 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5022 | // Must be a top level frame. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5023 | if (frame->parent() != NULL) |
| 5024 | return false; |
| 5025 | |
| 5026 | // Skip if navigation is on the same page (using '#'). |
| 5027 | GURL frame_origin = GURL(frame->url()).GetOrigin(); |
| 5028 | if (url.GetOrigin() != frame_origin || url.ref().empty()) { |
| 5029 | // The link click could stay on the same page, in cases where it sends some |
| 5030 | // parameters to the same URL. |
| 5031 | if (type == WebKit::WebNavigationTypeLinkClicked) |
| 5032 | return true; |
| 5033 | |
| 5034 | if (last_top_level_navigation_page_id_ != page_id_ && |
| 5035 | // Not interested in reloads. |
| 5036 | type != WebKit::WebNavigationTypeReload && |
| 5037 | type != WebKit::WebNavigationTypeFormSubmitted) { |
| 5038 | return true; |
| 5039 | } |
| 5040 | } |
| 5041 | return false; |
| 5042 | } |