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