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