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