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