Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prerender/prerender_contents.h" | 5 #include "chrome/browser/prerender/prerender_contents.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/background_contents_service.h" | 9 #include "chrome/browser/background_contents_service.h" |
| 10 #include "chrome/browser/browsing_instance.h" | 10 #include "chrome/browser/browsing_instance.h" |
| 11 #include "chrome/browser/prerender/prerender_manager.h" | 11 #include "chrome/browser/prerender/prerender_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/renderer_host/resource_request_details.h" | |
| 14 #include "chrome/browser/renderer_host/site_instance.h" | 15 #include "chrome/browser/renderer_host/site_instance.h" |
| 15 #include "chrome/browser/renderer_preferences_util.h" | 16 #include "chrome/browser/renderer_preferences_util.h" |
| 16 #include "chrome/browser/ui/login/login_prompt.h" | 17 #include "chrome/browser/ui/login/login_prompt.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/common/view_types.h" | 21 #include "chrome/common/view_types.h" |
| 21 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| 22 #include "chrome/common/render_messages_params.h" | 23 #include "chrome/common/render_messages_params.h" |
| 23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 Source<Profile>(profile_)); | 76 Source<Profile>(profile_)); |
| 76 render_view_host_->CreateRenderView(string16()); | 77 render_view_host_->CreateRenderView(string16()); |
| 77 | 78 |
| 78 // Register to cancel if Authentication is required. | 79 // Register to cancel if Authentication is required. |
| 79 registrar_.Add(this, NotificationType::AUTH_NEEDED, | 80 registrar_.Add(this, NotificationType::AUTH_NEEDED, |
| 80 NotificationService::AllSources()); | 81 NotificationService::AllSources()); |
| 81 | 82 |
| 82 registrar_.Add(this, NotificationType::AUTH_CANCELLED, | 83 registrar_.Add(this, NotificationType::AUTH_CANCELLED, |
| 83 NotificationService::AllSources()); | 84 NotificationService::AllSources()); |
| 84 | 85 |
| 86 // Register all responses to see if we should cancel. | |
| 87 registrar_.Add(this, NotificationType::DOWNLOAD_INITIATED, | |
| 88 Source<RenderViewHostDelegate>(this)); | |
| 89 | |
| 85 DCHECK(load_start_time_.is_null()); | 90 DCHECK(load_start_time_.is_null()); |
| 86 load_start_time_ = base::TimeTicks::Now(); | 91 load_start_time_ = base::TimeTicks::Now(); |
| 87 | 92 |
| 88 ViewMsg_Navigate_Params params; | 93 ViewMsg_Navigate_Params params; |
| 89 params.url = prerender_url_; | 94 params.url = prerender_url_; |
| 90 params.transition = PageTransition::LINK; | 95 params.transition = PageTransition::LINK; |
| 91 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; | 96 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; |
| 92 render_view_host_->Navigate(params); | 97 render_view_host_->Navigate(params); |
| 93 } | 98 } |
| 94 | 99 |
| 95 void PrerenderContents::set_final_status(FinalStatus final_status) { | 100 void PrerenderContents::set_final_status(FinalStatus final_status) { |
| 96 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 101 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); |
| 97 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 102 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 103 | |
| 98 final_status_ = final_status; | 104 final_status_ = final_status; |
| 99 } | 105 } |
| 100 | 106 |
| 101 PrerenderContents::FinalStatus PrerenderContents::final_status() const { | 107 PrerenderContents::FinalStatus PrerenderContents::final_status() const { |
| 102 return final_status_; | 108 return final_status_; |
| 103 } | 109 } |
| 104 | 110 |
| 105 PrerenderContents::~PrerenderContents() { | 111 PrerenderContents::~PrerenderContents() { |
| 106 DCHECK(final_status_ != FINAL_STATUS_MAX); | 112 DCHECK(final_status_ != FINAL_STATUS_MAX); |
| 107 UMA_HISTOGRAM_ENUMERATION("Prerender.FinalStatus", | 113 UMA_HISTOGRAM_ENUMERATION("Prerender.FinalStatus", |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 return false; | 185 return false; |
| 180 } | 186 } |
| 181 | 187 |
| 182 void PrerenderContents::Observe(NotificationType type, | 188 void PrerenderContents::Observe(NotificationType type, |
| 183 const NotificationSource& source, | 189 const NotificationSource& source, |
| 184 const NotificationDetails& details) { | 190 const NotificationDetails& details) { |
| 185 switch (type.value) { | 191 switch (type.value) { |
| 186 case NotificationType::PROFILE_DESTROYED: | 192 case NotificationType::PROFILE_DESTROYED: |
| 187 Destroy(FINAL_STATUS_PROFILE_DESTROYED); | 193 Destroy(FINAL_STATUS_PROFILE_DESTROYED); |
| 188 return; | 194 return; |
| 195 | |
| 189 case NotificationType::APP_TERMINATING: | 196 case NotificationType::APP_TERMINATING: |
| 190 Destroy(FINAL_STATUS_APP_TERMINATING); | 197 Destroy(FINAL_STATUS_APP_TERMINATING); |
| 191 return; | 198 return; |
| 192 | 199 |
| 193 case NotificationType::AUTH_NEEDED: | 200 case NotificationType::AUTH_NEEDED: |
| 194 case NotificationType::AUTH_CANCELLED: { | 201 case NotificationType::AUTH_CANCELLED: { |
| 195 // Prerendered pages have a NULL controller and the login handler should | 202 // Prerendered pages have a NULL controller and the login handler should |
| 196 // be referencing us as the render view host delegate. | 203 // be referencing us as the render view host delegate. |
| 197 NavigationController* controller = | 204 NavigationController* controller = |
| 198 Source<NavigationController>(source).ptr(); | 205 Source<NavigationController>(source).ptr(); |
| 199 LoginNotificationDetails* details_ptr = | 206 LoginNotificationDetails* details_ptr = |
| 200 Details<LoginNotificationDetails>(details).ptr(); | 207 Details<LoginNotificationDetails>(details).ptr(); |
| 201 LoginHandler* handler = details_ptr->handler(); | 208 LoginHandler* handler = details_ptr->handler(); |
| 202 DCHECK(handler != NULL); | 209 DCHECK(handler != NULL); |
| 203 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate(); | 210 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate(); |
| 204 if (controller == NULL && delegate == this) | 211 if (controller == NULL && delegate == this) { |
| 205 Destroy(FINAL_STATUS_AUTH_NEEDED); | 212 Destroy(FINAL_STATUS_AUTH_NEEDED); |
| 213 return; | |
| 214 } | |
| 206 break; | 215 break; |
| 207 } | 216 } |
| 208 | 217 |
| 218 case NotificationType::DOWNLOAD_INITIATED: { | |
| 219 // If the download is started from a RenderViewHost that we are | |
| 220 // delegating, kill the prerender. This will also stop the download and | |
|
Randy Smith (Not in Mondays)
2011/02/10 16:57:10
Can you give me the context for how killing the pr
dominich
2011/02/10 18:46:22
You're right - changed the comment to reflect that
| |
| 221 // navigating to the page will restart it as expected. | |
| 222 DCHECK(Source<RenderViewHostDelegate>(source).ptr() == this); | |
| 223 Destroy(FINAL_STATUS_DOWNLOAD); | |
| 224 return; | |
| 225 } | |
| 226 | |
| 209 default: | 227 default: |
| 210 NOTREACHED() << "Unexpected notification sent."; | 228 NOTREACHED() << "Unexpected notification sent."; |
| 211 break; | 229 break; |
| 212 } | 230 } |
| 213 } | 231 } |
| 214 | 232 |
| 215 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, | 233 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, |
| 216 bool success, | 234 bool success, |
| 217 const std::wstring& prompt) { | 235 const std::wstring& prompt) { |
| 218 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); | 236 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 | 358 |
| 341 void PrerenderContents::DidStopLoading() { | 359 void PrerenderContents::DidStopLoading() { |
| 342 has_stopped_loading_ = true; | 360 has_stopped_loading_ = true; |
| 343 } | 361 } |
| 344 | 362 |
| 345 void PrerenderContents::Destroy(FinalStatus final_status) { | 363 void PrerenderContents::Destroy(FinalStatus final_status) { |
| 346 prerender_manager_->RemoveEntry(this); | 364 prerender_manager_->RemoveEntry(this); |
| 347 set_final_status(final_status); | 365 set_final_status(final_status); |
| 348 delete this; | 366 delete this; |
| 349 } | 367 } |
| OLD | NEW |