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