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