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