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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/background_contents_service.h" | 8 #include "chrome/browser/background_contents_service.h" |
| 9 #include "chrome/browser/browsing_instance.h" | 9 #include "chrome/browser/browsing_instance.h" |
| 10 #include "chrome/browser/prerender/prerender_final_status.h" | 10 #include "chrome/browser/prerender/prerender_final_status.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 Source<Profile>(profile_)); | 77 Source<Profile>(profile_)); |
| 78 render_view_host_->CreateRenderView(string16()); | 78 render_view_host_->CreateRenderView(string16()); |
| 79 | 79 |
| 80 // Register to cancel if Authentication is required. | 80 // Register to cancel if Authentication is required. |
| 81 registrar_.Add(this, NotificationType::AUTH_NEEDED, | 81 registrar_.Add(this, NotificationType::AUTH_NEEDED, |
| 82 NotificationService::AllSources()); | 82 NotificationService::AllSources()); |
| 83 | 83 |
| 84 registrar_.Add(this, NotificationType::AUTH_CANCELLED, | 84 registrar_.Add(this, NotificationType::AUTH_CANCELLED, |
| 85 NotificationService::AllSources()); | 85 NotificationService::AllSources()); |
| 86 | 86 |
| 87 // Register all responses to see if we should cancel. | |
| 88 registrar_.Add(this, NotificationType::DOWNLOAD_INITIATED, | |
| 89 NotificationService::AllSources()); | |
| 90 | |
| 87 DCHECK(load_start_time_.is_null()); | 91 DCHECK(load_start_time_.is_null()); |
| 88 load_start_time_ = base::TimeTicks::Now(); | 92 load_start_time_ = base::TimeTicks::Now(); |
| 89 | 93 |
| 90 ViewMsg_Navigate_Params params; | 94 ViewMsg_Navigate_Params params; |
| 91 params.url = prerender_url_; | 95 params.url = prerender_url_; |
| 92 params.transition = PageTransition::LINK; | 96 params.transition = PageTransition::LINK; |
| 93 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; | 97 params.navigation_type = ViewMsg_Navigate_Params::PRERENDER; |
| 94 render_view_host_->Navigate(params); | 98 render_view_host_->Navigate(params); |
| 95 } | 99 } |
| 96 | 100 |
| 97 void PrerenderContents::set_final_status(FinalStatus final_status) { | 101 void PrerenderContents::set_final_status(FinalStatus final_status) { |
| 98 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 102 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); |
| 99 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); | 103 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 104 | |
| 100 final_status_ = final_status; | 105 final_status_ = final_status; |
| 101 } | 106 } |
| 102 | 107 |
| 103 FinalStatus PrerenderContents::final_status() const { | 108 FinalStatus PrerenderContents::final_status() const { |
| 104 return final_status_; | 109 return final_status_; |
| 105 } | 110 } |
| 106 | 111 |
| 107 PrerenderContents::~PrerenderContents() { | 112 PrerenderContents::~PrerenderContents() { |
| 108 DCHECK(final_status_ != FINAL_STATUS_MAX); | 113 DCHECK(final_status_ != FINAL_STATUS_MAX); |
| 109 RecordFinalStatus(final_status_); | 114 RecordFinalStatus(final_status_); |
| (...skipping 69 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()); | |
|
cbentzel
2011/02/15 20:51:23
Nit: DCHECK_EQ
dominich
2011/02/15 21:25:43
Done.
| |
| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 has_stopped_loading_ = true; | 364 has_stopped_loading_ = true; |
| 342 } | 365 } |
| 343 | 366 |
| 344 void PrerenderContents::Destroy(FinalStatus final_status) { | 367 void PrerenderContents::Destroy(FinalStatus final_status) { |
| 345 prerender_manager_->RemoveEntry(this); | 368 prerender_manager_->RemoveEntry(this); |
| 346 set_final_status(final_status); | 369 set_final_status(final_status); |
| 347 delete this; | 370 delete this; |
| 348 } | 371 } |
| 349 | 372 |
| 350 } // namespace prerender | 373 } // namespace prerender |
| OLD | NEW |