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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 if (prerender_manager_->IsControlGroup(experiment_id())) | 315 if (prerender_manager_->IsControlGroup(experiment_id())) |
316 return; | 316 return; |
317 | 317 |
318 if (origin_ == ORIGIN_LOCAL_PREDICTOR && | 318 if (origin_ == ORIGIN_LOCAL_PREDICTOR && |
319 IsLocalPredictorPrerenderAlwaysControlEnabled()) { | 319 IsLocalPredictorPrerenderAlwaysControlEnabled()) { |
320 return; | 320 return; |
321 } | 321 } |
322 | 322 |
323 prerendering_has_started_ = true; | 323 prerendering_has_started_ = true; |
324 | 324 |
325 alias_session_storage_namespace = session_storage_namespace->CreateAlias(); | 325 prerender_contents_.reset(CreateWebContents(session_storage_namespace)); |
326 prerender_contents_.reset( | |
327 CreateWebContents(alias_session_storage_namespace.get())); | |
328 TabHelpers::AttachTabHelpers(prerender_contents_.get()); | 326 TabHelpers::AttachTabHelpers(prerender_contents_.get()); |
329 content::WebContentsObserver::Observe(prerender_contents_.get()); | 327 content::WebContentsObserver::Observe(prerender_contents_.get()); |
330 | 328 |
331 web_contents_delegate_.reset(new WebContentsDelegateImpl(this)); | 329 web_contents_delegate_.reset(new WebContentsDelegateImpl(this)); |
332 prerender_contents_.get()->SetDelegate(web_contents_delegate_.get()); | 330 prerender_contents_.get()->SetDelegate(web_contents_delegate_.get()); |
333 // Set the size of the prerender WebContents. | 331 // Set the size of the prerender WebContents. |
334 ResizeWebContents(prerender_contents_.get(), size_); | 332 ResizeWebContents(prerender_contents_.get(), size_); |
335 | 333 |
336 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); | 334 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); |
337 route_id_ = GetRenderViewHost()->GetRoutingID(); | 335 route_id_ = GetRenderViewHost()->GetRoutingID(); |
338 | 336 |
339 // Log transactions to see if we could merge session storage namespaces in | |
340 // the event of a mismatch. | |
341 alias_session_storage_namespace->AddTransactionLogProcessId(child_id_); | |
342 | |
343 // Add the RenderProcessHost to the Prerender Manager. | 337 // Add the RenderProcessHost to the Prerender Manager. |
344 prerender_manager()->AddPrerenderProcessHost( | 338 prerender_manager()->AddPrerenderProcessHost( |
345 GetRenderViewHost()->GetProcess()); | 339 GetRenderViewHost()->GetProcess()); |
346 | 340 |
347 // In the prerender tracker, create a Prerender Cookie Store to keep track of | 341 // In the prerender tracker, create a Prerender Cookie Store to keep track of |
348 // cookie changes performed by the prerender. Once the prerender is shown, | 342 // cookie changes performed by the prerender. Once the prerender is shown, |
349 // the cookie changes will be committed to the actual cookie store, | 343 // the cookie changes will be committed to the actual cookie store, |
350 // otherwise, they will be discarded. | 344 // otherwise, they will be discarded. |
351 // If |request_context| is NULL, the feature must be disabled, so the | 345 // If |request_context| is NULL, the feature must be disabled, so the |
352 // operation will not be performed. | 346 // operation will not be performed. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 content::RenderProcessHost* host = host_iterator.GetCurrentValue(); | 575 content::RenderProcessHost* host = host_iterator.GetCurrentValue(); |
582 host->Send(new PrerenderMsg_OnPrerenderAddAlias(url)); | 576 host->Send(new PrerenderMsg_OnPrerenderAddAlias(url)); |
583 } | 577 } |
584 | 578 |
585 return true; | 579 return true; |
586 } | 580 } |
587 | 581 |
588 bool PrerenderContents::Matches( | 582 bool PrerenderContents::Matches( |
589 const GURL& url, | 583 const GURL& url, |
590 const SessionStorageNamespace* session_storage_namespace) const { | 584 const SessionStorageNamespace* session_storage_namespace) const { |
| 585 // TODO(davidben): Remove any consumers that pass in a NULL |
| 586 // session_storage_namespace and only test with matches. |
591 if (session_storage_namespace && | 587 if (session_storage_namespace && |
592 session_storage_namespace_id_ != session_storage_namespace->id()) { | 588 session_storage_namespace_id_ != session_storage_namespace->id()) { |
593 return false; | 589 return false; |
594 } | 590 } |
595 return std::count_if(alias_urls_.begin(), alias_urls_.end(), | 591 return std::count_if(alias_urls_.begin(), alias_urls_.end(), |
596 std::bind2nd(std::equal_to<GURL>(), url)) != 0; | 592 std::bind2nd(std::equal_to<GURL>(), url)) != 0; |
597 } | 593 } |
598 | 594 |
599 void PrerenderContents::RenderProcessGone(base::TerminationStatus status) { | 595 void PrerenderContents::RenderProcessGone(base::TerminationStatus status) { |
600 Destroy(FINAL_STATUS_RENDERER_CRASHED); | 596 Destroy(FINAL_STATUS_RENDERER_CRASHED); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 size_t private_bytes, shared_bytes; | 735 size_t private_bytes, shared_bytes; |
740 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes) && | 736 if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes) && |
741 private_bytes > prerender_manager_->config().max_bytes) { | 737 private_bytes > prerender_manager_->config().max_bytes) { |
742 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); | 738 Destroy(FINAL_STATUS_MEMORY_LIMIT_EXCEEDED); |
743 } | 739 } |
744 } | 740 } |
745 | 741 |
746 WebContents* PrerenderContents::ReleasePrerenderContents() { | 742 WebContents* PrerenderContents::ReleasePrerenderContents() { |
747 prerender_contents_->SetDelegate(NULL); | 743 prerender_contents_->SetDelegate(NULL); |
748 content::WebContentsObserver::Observe(NULL); | 744 content::WebContentsObserver::Observe(NULL); |
749 if (alias_session_storage_namespace.get()) | |
750 alias_session_storage_namespace->RemoveTransactionLogProcessId(child_id_); | |
751 return prerender_contents_.release(); | 745 return prerender_contents_.release(); |
752 } | 746 } |
753 | 747 |
754 RenderViewHost* PrerenderContents::GetRenderViewHostMutable() { | 748 RenderViewHost* PrerenderContents::GetRenderViewHostMutable() { |
755 return const_cast<RenderViewHost*>(GetRenderViewHost()); | 749 return const_cast<RenderViewHost*>(GetRenderViewHost()); |
756 } | 750 } |
757 | 751 |
758 const RenderViewHost* PrerenderContents::GetRenderViewHost() const { | 752 const RenderViewHost* PrerenderContents::GetRenderViewHost() const { |
759 if (!prerender_contents_.get()) | 753 if (!prerender_contents_.get()) |
760 return NULL; | 754 return NULL; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 796 |
803 NotifyPrerenderStop(); | 797 NotifyPrerenderStop(); |
804 | 798 |
805 BrowserThread::PostTask( | 799 BrowserThread::PostTask( |
806 BrowserThread::IO, | 800 BrowserThread::IO, |
807 FROM_HERE, | 801 FROM_HERE, |
808 base::Bind(&ResumeThrottles, resource_throttles_)); | 802 base::Bind(&ResumeThrottles, resource_throttles_)); |
809 resource_throttles_.clear(); | 803 resource_throttles_.clear(); |
810 } | 804 } |
811 | 805 |
812 SessionStorageNamespace* PrerenderContents::GetSessionStorageNamespace() const { | |
813 if (!prerender_contents()) | |
814 return NULL; | |
815 return prerender_contents()->GetController(). | |
816 GetDefaultSessionStorageNamespace(); | |
817 } | |
818 | |
819 void PrerenderContents::OnCancelPrerenderForPrinting() { | 806 void PrerenderContents::OnCancelPrerenderForPrinting() { |
820 Destroy(FINAL_STATUS_WINDOW_PRINT); | 807 Destroy(FINAL_STATUS_WINDOW_PRINT); |
821 } | 808 } |
822 | 809 |
823 void PrerenderContents::RecordCookieEvent(CookieEvent event, | 810 void PrerenderContents::RecordCookieEvent(CookieEvent event, |
824 bool is_main_frame_http_request, | 811 bool is_main_frame_http_request, |
825 bool is_third_party_cookie, | 812 bool is_third_party_cookie, |
826 bool is_for_blocking_resource, | 813 bool is_for_blocking_resource, |
827 base::Time earliest_create_date) { | 814 base::Time earliest_create_date) { |
828 // We don't care about sent cookies that were created after this prerender | 815 // We don't care about sent cookies that were created after this prerender |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 void PrerenderContents::AddResourceThrottle( | 871 void PrerenderContents::AddResourceThrottle( |
885 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { | 872 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { |
886 resource_throttles_.push_back(throttle); | 873 resource_throttles_.push_back(throttle); |
887 } | 874 } |
888 | 875 |
889 void PrerenderContents::AddNetworkBytes(int64 bytes) { | 876 void PrerenderContents::AddNetworkBytes(int64 bytes) { |
890 network_bytes_ += bytes; | 877 network_bytes_ += bytes; |
891 } | 878 } |
892 | 879 |
893 } // namespace prerender | 880 } // namespace prerender |
OLD | NEW |