| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 void PrerenderContents::Observer::OnPrerenderCreatedMatchCompleteReplacement( | 188 void PrerenderContents::Observer::OnPrerenderCreatedMatchCompleteReplacement( |
| 189 PrerenderContents* contents, PrerenderContents* replacement) { | 189 PrerenderContents* contents, PrerenderContents* replacement) { |
| 190 } | 190 } |
| 191 | 191 |
| 192 PrerenderContents::Observer::Observer() { | 192 PrerenderContents::Observer::Observer() { |
| 193 } | 193 } |
| 194 | 194 |
| 195 PrerenderContents::Observer::~Observer() { | 195 PrerenderContents::Observer::~Observer() { |
| 196 } | 196 } |
| 197 | 197 |
| 198 PrerenderContents::PendingPrerenderInfo::PendingPrerenderInfo( | |
| 199 base::WeakPtr<PrerenderHandle> weak_prerender_handle, | |
| 200 Origin origin, | |
| 201 const GURL& url, | |
| 202 const content::Referrer& referrer, | |
| 203 const gfx::Size& size) | |
| 204 : weak_prerender_handle(weak_prerender_handle), | |
| 205 origin(origin), | |
| 206 url(url), | |
| 207 referrer(referrer), | |
| 208 size(size) { | |
| 209 } | |
| 210 | |
| 211 PrerenderContents::PendingPrerenderInfo::~PendingPrerenderInfo() { | |
| 212 } | |
| 213 | |
| 214 void PrerenderContents::AddPendingPrerender( | |
| 215 scoped_ptr<PendingPrerenderInfo> pending_prerender_info) { | |
| 216 pending_prerenders_.push_back(pending_prerender_info.release()); | |
| 217 } | |
| 218 | |
| 219 void PrerenderContents::PrepareForUse() { | |
| 220 if (prerender_contents_.get()) { | |
| 221 prerender_contents_->SendToAllFrames( | |
| 222 new PrerenderMsg_SetIsPrerendering(MSG_ROUTING_NONE, false)); | |
| 223 } | |
| 224 | |
| 225 NotifyPrerenderStop(); | |
| 226 | |
| 227 SessionStorageNamespace* session_storage_namespace = NULL; | |
| 228 if (prerender_contents_) { | |
| 229 // TODO(ajwong): This does not correctly handle storage for isolated apps. | |
| 230 session_storage_namespace = prerender_contents_-> | |
| 231 GetController().GetDefaultSessionStorageNamespace(); | |
| 232 } | |
| 233 prerender_manager_->StartPendingPrerenders( | |
| 234 child_id_, &pending_prerenders_, session_storage_namespace); | |
| 235 pending_prerenders_.clear(); | |
| 236 | |
| 237 content::BrowserThread::PostTask( | |
| 238 content::BrowserThread::IO, | |
| 239 FROM_HERE, | |
| 240 base::Bind(&ResumeThrottles, resource_throttles_)); | |
| 241 resource_throttles_.clear(); | |
| 242 } | |
| 243 | |
| 244 PrerenderContents::PrerenderContents( | 198 PrerenderContents::PrerenderContents( |
| 245 PrerenderManager* prerender_manager, | 199 PrerenderManager* prerender_manager, |
| 246 Profile* profile, | 200 Profile* profile, |
| 247 const GURL& url, | 201 const GURL& url, |
| 248 const content::Referrer& referrer, | 202 const content::Referrer& referrer, |
| 249 Origin origin, | 203 Origin origin, |
| 250 uint8 experiment_id) | 204 uint8 experiment_id) |
| 251 : prerendering_has_started_(false), | 205 : prerendering_has_started_(false), |
| 252 session_storage_namespace_id_(-1), | 206 session_storage_namespace_id_(-1), |
| 253 prerender_manager_(prerender_manager), | 207 prerender_manager_(prerender_manager), |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 367 } |
| 414 | 368 |
| 415 bool PrerenderContents::GetRouteId(int* route_id) const { | 369 bool PrerenderContents::GetRouteId(int* route_id) const { |
| 416 CHECK(route_id); | 370 CHECK(route_id); |
| 417 DCHECK_GE(route_id_, -1); | 371 DCHECK_GE(route_id_, -1); |
| 418 *route_id = route_id_; | 372 *route_id = route_id_; |
| 419 return route_id_ != -1; | 373 return route_id_ != -1; |
| 420 } | 374 } |
| 421 | 375 |
| 422 void PrerenderContents::SetFinalStatus(FinalStatus final_status) { | 376 void PrerenderContents::SetFinalStatus(FinalStatus final_status) { |
| 423 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 377 DCHECK_GE(final_status, FINAL_STATUS_USED); |
| 424 DCHECK(final_status_ == FINAL_STATUS_MAX); | 378 DCHECK_LT(final_status, FINAL_STATUS_MAX); |
| 379 |
| 380 DCHECK_EQ(FINAL_STATUS_MAX, final_status_); |
| 425 | 381 |
| 426 final_status_ = final_status; | 382 final_status_ = final_status; |
| 427 } | 383 } |
| 428 | 384 |
| 429 PrerenderContents::~PrerenderContents() { | 385 PrerenderContents::~PrerenderContents() { |
| 430 DCHECK_NE(FINAL_STATUS_MAX, final_status()); | 386 DCHECK_NE(FINAL_STATUS_MAX, final_status()); |
| 431 DCHECK( | 387 DCHECK( |
| 432 prerendering_has_been_cancelled() || final_status() == FINAL_STATUS_USED); | 388 prerendering_has_been_cancelled() || final_status() == FINAL_STATUS_USED); |
| 433 DCHECK_NE(ORIGIN_MAX, origin()); | 389 DCHECK_NE(ORIGIN_MAX, origin()); |
| 434 // Since a lot of prerenders terminate before any meaningful cookie action | 390 // Since a lot of prerenders terminate before any meaningful cookie action |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 default: | 459 default: |
| 504 NOTREACHED() << "Unexpected notification sent."; | 460 NOTREACHED() << "Unexpected notification sent."; |
| 505 break; | 461 break; |
| 506 } | 462 } |
| 507 } | 463 } |
| 508 | 464 |
| 509 void PrerenderContents::OnRenderViewHostCreated( | 465 void PrerenderContents::OnRenderViewHostCreated( |
| 510 RenderViewHost* new_render_view_host) { | 466 RenderViewHost* new_render_view_host) { |
| 511 } | 467 } |
| 512 | 468 |
| 513 size_t PrerenderContents::pending_prerender_count() const { | |
| 514 return pending_prerenders_.size(); | |
| 515 } | |
| 516 | |
| 517 WebContents* PrerenderContents::CreateWebContents( | 469 WebContents* PrerenderContents::CreateWebContents( |
| 518 SessionStorageNamespace* session_storage_namespace) { | 470 SessionStorageNamespace* session_storage_namespace) { |
| 519 // TODO(ajwong): Remove the temporary map once prerendering is aware of | 471 // TODO(ajwong): Remove the temporary map once prerendering is aware of |
| 520 // multiple session storage namespaces per tab. | 472 // multiple session storage namespaces per tab. |
| 521 content::SessionStorageNamespaceMap session_storage_namespace_map; | 473 content::SessionStorageNamespaceMap session_storage_namespace_map; |
| 522 session_storage_namespace_map[std::string()] = session_storage_namespace; | 474 session_storage_namespace_map[std::string()] = session_storage_namespace; |
| 523 return WebContents::CreateWithSessionStorage( | 475 return WebContents::CreateWithSessionStorage( |
| 524 WebContents::CreateParams(profile_), session_storage_namespace_map); | 476 WebContents::CreateParams(profile_), session_storage_namespace_map); |
| 525 } | 477 } |
| 526 | 478 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 return dict_value; | 753 return dict_value; |
| 802 } | 754 } |
| 803 | 755 |
| 804 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 756 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
| 805 if (!prerender_contents_) | 757 if (!prerender_contents_) |
| 806 return false; | 758 return false; |
| 807 return (prerender_contents_->GetSiteInstance() != | 759 return (prerender_contents_->GetSiteInstance() != |
| 808 prerender_contents_->GetPendingSiteInstance()); | 760 prerender_contents_->GetPendingSiteInstance()); |
| 809 } | 761 } |
| 810 | 762 |
| 763 void PrerenderContents::PrepareForUse() { |
| 764 SetFinalStatus(FINAL_STATUS_USED); |
| 765 |
| 766 if (prerender_contents_.get()) { |
| 767 prerender_contents_->SendToAllFrames( |
| 768 new PrerenderMsg_SetIsPrerendering(MSG_ROUTING_NONE, false)); |
| 769 } |
| 770 |
| 771 NotifyPrerenderStop(); |
| 772 |
| 773 content::BrowserThread::PostTask( |
| 774 content::BrowserThread::IO, |
| 775 FROM_HERE, |
| 776 base::Bind(&ResumeThrottles, resource_throttles_)); |
| 777 resource_throttles_.clear(); |
| 778 } |
| 779 |
| 811 SessionStorageNamespace* PrerenderContents::GetSessionStorageNamespace() const { | 780 SessionStorageNamespace* PrerenderContents::GetSessionStorageNamespace() const { |
| 812 if (!prerender_contents()) | 781 if (!prerender_contents()) |
| 813 return NULL; | 782 return NULL; |
| 814 return prerender_contents()->GetController(). | 783 return prerender_contents()->GetController(). |
| 815 GetDefaultSessionStorageNamespace(); | 784 GetDefaultSessionStorageNamespace(); |
| 816 } | 785 } |
| 817 | 786 |
| 818 void PrerenderContents::OnCancelPrerenderForPrinting() { | 787 void PrerenderContents::OnCancelPrerenderForPrinting() { |
| 819 Destroy(FINAL_STATUS_WINDOW_PRINT); | 788 Destroy(FINAL_STATUS_WINDOW_PRINT); |
| 820 } | 789 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 DCHECK_GE(cookie_status_, 0); | 828 DCHECK_GE(cookie_status_, 0); |
| 860 DCHECK_LT(cookie_status_, kNumCookieStatuses); | 829 DCHECK_LT(cookie_status_, kNumCookieStatuses); |
| 861 } | 830 } |
| 862 | 831 |
| 863 void PrerenderContents::AddResourceThrottle( | 832 void PrerenderContents::AddResourceThrottle( |
| 864 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { | 833 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { |
| 865 resource_throttles_.push_back(throttle); | 834 resource_throttles_.push_back(throttle); |
| 866 } | 835 } |
| 867 | 836 |
| 868 } // namespace prerender | 837 } // namespace prerender |
| OLD | NEW |