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