| 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" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 Source<Profile>(profile_)); | 75 Source<Profile>(profile_)); |
| 76 render_view_host_->CreateRenderView(string16()); | 76 render_view_host_->CreateRenderView(string16()); |
| 77 | 77 |
| 78 // Register to cancel if Authentication is required. | 78 // Register to cancel if Authentication is required. |
| 79 registrar_.Add(this, NotificationType::AUTH_NEEDED, | 79 registrar_.Add(this, NotificationType::AUTH_NEEDED, |
| 80 NotificationService::AllSources()); | 80 NotificationService::AllSources()); |
| 81 | 81 |
| 82 registrar_.Add(this, NotificationType::AUTH_CANCELLED, | 82 registrar_.Add(this, NotificationType::AUTH_CANCELLED, |
| 83 NotificationService::AllSources()); | 83 NotificationService::AllSources()); |
| 84 | 84 |
| 85 // Register all responses to see if we should cancel. |
| 86 registrar_.Add(this, NotificationType::DOWNLOAD_INITIATED, |
| 87 NotificationService::AllSources()); |
| 88 |
| 85 DCHECK(load_start_time_.is_null()); | 89 DCHECK(load_start_time_.is_null()); |
| 86 load_start_time_ = base::TimeTicks::Now(); | 90 load_start_time_ = base::TimeTicks::Now(); |
| 87 | 91 |
| 88 ViewMsg_Navigate_Params params; | 92 ViewMsg_Navigate_Params params; |
| 89 params.url = prerender_url_; | 93 params.url = prerender_url_; |
| 90 params.transition = PageTransition::LINK; | 94 params.transition = PageTransition::LINK; |
| 91 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; | 95 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; |
| 92 render_view_host_->Navigate(params); | 96 render_view_host_->Navigate(params); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void PrerenderContents::set_final_status(FinalStatus final_status) { | 99 void PrerenderContents::set_final_status(FinalStatus final_status) { |
| 96 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 100 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); |
| 97 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 101 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 102 |
| 98 final_status_ = final_status; | 103 final_status_ = final_status; |
| 99 } | 104 } |
| 100 | 105 |
| 101 PrerenderContents::FinalStatus PrerenderContents::final_status() const { | 106 PrerenderContents::FinalStatus PrerenderContents::final_status() const { |
| 102 return final_status_; | 107 return final_status_; |
| 103 } | 108 } |
| 104 | 109 |
| 105 PrerenderContents::~PrerenderContents() { | 110 PrerenderContents::~PrerenderContents() { |
| 106 DCHECK(final_status_ != FINAL_STATUS_MAX); | 111 DCHECK(final_status_ != FINAL_STATUS_MAX); |
| 107 UMA_HISTOGRAM_ENUMERATION("Prerender.FinalStatus", | 112 UMA_HISTOGRAM_ENUMERATION("Prerender.FinalStatus", |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return false; | 184 return false; |
| 180 } | 185 } |
| 181 | 186 |
| 182 void PrerenderContents::Observe(NotificationType type, | 187 void PrerenderContents::Observe(NotificationType type, |
| 183 const NotificationSource& source, | 188 const NotificationSource& source, |
| 184 const NotificationDetails& details) { | 189 const NotificationDetails& details) { |
| 185 switch (type.value) { | 190 switch (type.value) { |
| 186 case NotificationType::PROFILE_DESTROYED: | 191 case NotificationType::PROFILE_DESTROYED: |
| 187 Destroy(FINAL_STATUS_PROFILE_DESTROYED); | 192 Destroy(FINAL_STATUS_PROFILE_DESTROYED); |
| 188 return; | 193 return; |
| 194 |
| 189 case NotificationType::APP_TERMINATING: | 195 case NotificationType::APP_TERMINATING: |
| 190 Destroy(FINAL_STATUS_APP_TERMINATING); | 196 Destroy(FINAL_STATUS_APP_TERMINATING); |
| 191 return; | 197 return; |
| 192 | 198 |
| 193 case NotificationType::AUTH_NEEDED: | 199 case NotificationType::AUTH_NEEDED: |
| 194 case NotificationType::AUTH_CANCELLED: { | 200 case NotificationType::AUTH_CANCELLED: { |
| 195 // Prerendered pages have a NULL controller and the login handler should | 201 // Prerendered pages have a NULL controller and the login handler should |
| 196 // be referencing us as the render view host delegate. | 202 // be referencing us as the render view host delegate. |
| 197 NavigationController* controller = | 203 NavigationController* controller = |
| 198 Source<NavigationController>(source).ptr(); | 204 Source<NavigationController>(source).ptr(); |
| 199 LoginNotificationDetails* details_ptr = | 205 LoginNotificationDetails* details_ptr = |
| 200 Details<LoginNotificationDetails>(details).ptr(); | 206 Details<LoginNotificationDetails>(details).ptr(); |
| 201 LoginHandler* handler = details_ptr->handler(); | 207 LoginHandler* handler = details_ptr->handler(); |
| 202 DCHECK(handler != NULL); | 208 DCHECK(handler != NULL); |
| 203 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate(); | 209 RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate(); |
| 204 if (controller == NULL && delegate == this) | 210 if (controller == NULL && delegate == this) { |
| 205 Destroy(FINAL_STATUS_AUTH_NEEDED); | 211 Destroy(FINAL_STATUS_AUTH_NEEDED); |
| 212 return; |
| 213 } |
| 214 break; |
| 215 } |
| 216 |
| 217 case NotificationType::DOWNLOAD_INITIATED: { |
| 218 // If the download is started from a RenderViewHost that we are |
| 219 // delegating, kill the prerender. This cancels any pending requests |
| 220 // though the download never actually started thanks to the |
| 221 // DownloadRequestLimiter. |
| 222 DCHECK(details == NotificationService::NoDetails()); |
| 223 RenderViewHost* rvh = Source<RenderViewHost>(source).ptr(); |
| 224 CHECK(rvh != NULL); |
| 225 if (rvh->delegate() == this) { |
| 226 Destroy(FINAL_STATUS_DOWNLOAD); |
| 227 return; |
| 228 } |
| 206 break; | 229 break; |
| 207 } | 230 } |
| 208 | 231 |
| 209 default: | 232 default: |
| 210 NOTREACHED() << "Unexpected notification sent."; | 233 NOTREACHED() << "Unexpected notification sent."; |
| 211 break; | 234 break; |
| 212 } | 235 } |
| 213 } | 236 } |
| 214 | 237 |
| 215 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, | 238 void PrerenderContents::OnMessageBoxClosed(IPC::Message* reply_msg, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 363 |
| 341 void PrerenderContents::DidStopLoading() { | 364 void PrerenderContents::DidStopLoading() { |
| 342 has_stopped_loading_ = true; | 365 has_stopped_loading_ = true; |
| 343 } | 366 } |
| 344 | 367 |
| 345 void PrerenderContents::Destroy(FinalStatus final_status) { | 368 void PrerenderContents::Destroy(FinalStatus final_status) { |
| 346 prerender_manager_->RemoveEntry(this); | 369 prerender_manager_->RemoveEntry(this); |
| 347 set_final_status(final_status); | 370 set_final_status(final_status); |
| 348 delete this; | 371 delete this; |
| 349 } | 372 } |
| OLD | NEW |