| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // that requires the browser to perform the transition instead of WebKit. | 97 // that requires the browser to perform the transition instead of WebKit. |
| 98 // Examples include prerendering a site that redirects to an app URL, | 98 // Examples include prerendering a site that redirects to an app URL, |
| 99 // or if --enable-strict-site-isolation is specified and the prerendered | 99 // or if --enable-strict-site-isolation is specified and the prerendered |
| 100 // frame redirects to a different origin. | 100 // frame redirects to a different origin. |
| 101 // TODO(cbentzel): Consider supporting this if it is a common case during | 101 // TODO(cbentzel): Consider supporting this if it is a common case during |
| 102 // prerenders. | 102 // prerenders. |
| 103 prerender_contents_->Destroy(FINAL_STATUS_OPEN_URL); | 103 prerender_contents_->Destroy(FINAL_STATUS_OPEN_URL); |
| 104 return NULL; | 104 return NULL; |
| 105 } | 105 } |
| 106 | 106 |
| 107 virtual bool ShouldAddNavigationToHistory( | |
| 108 const history::HistoryAddPageArgs& add_page_args, | |
| 109 content::NavigationType navigation_type) OVERRIDE { | |
| 110 add_page_vector_.push_back(add_page_args); | |
| 111 return false; | |
| 112 } | |
| 113 | |
| 114 virtual bool CanDownload(RenderViewHost* render_view_host, | 107 virtual bool CanDownload(RenderViewHost* render_view_host, |
| 115 int request_id, | 108 int request_id, |
| 116 const std::string& request_method) OVERRIDE { | 109 const std::string& request_method) OVERRIDE { |
| 117 prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); | 110 prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); |
| 118 // Cancel the download. | 111 // Cancel the download. |
| 119 return false; | 112 return false; |
| 120 } | 113 } |
| 121 | 114 |
| 122 virtual void OnStartDownload(WebContents* source, | 115 virtual void OnStartDownload(WebContents* source, |
| 123 DownloadItem* download) OVERRIDE { | 116 DownloadItem* download) OVERRIDE { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 virtual void RegisterProtocolHandler(WebContents* web_contents, | 156 virtual void RegisterProtocolHandler(WebContents* web_contents, |
| 164 const std::string& protocol, | 157 const std::string& protocol, |
| 165 const GURL& url, | 158 const GURL& url, |
| 166 const string16& title, | 159 const string16& title, |
| 167 bool user_gesture) OVERRIDE { | 160 bool user_gesture) OVERRIDE { |
| 168 // TODO(mmenke): Consider supporting this if it is a common case during | 161 // TODO(mmenke): Consider supporting this if it is a common case during |
| 169 // prerenders. | 162 // prerenders. |
| 170 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); | 163 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); |
| 171 } | 164 } |
| 172 | 165 |
| 173 // Commits the History of Pages to the given TabContents. | |
| 174 void CommitHistory(TabContents* tab) { | |
| 175 for (size_t i = 0; i < add_page_vector_.size(); ++i) | |
| 176 tab->history_tab_helper()->UpdateHistoryForNavigation( | |
| 177 add_page_vector_[i]); | |
| 178 } | |
| 179 | |
| 180 private: | 166 private: |
| 181 typedef std::vector<history::HistoryAddPageArgs> AddPageVector; | |
| 182 | |
| 183 // Caches pages to be added to the history. | |
| 184 AddPageVector add_page_vector_; | |
| 185 | |
| 186 PrerenderContents* prerender_contents_; | 167 PrerenderContents* prerender_contents_; |
| 187 }; | 168 }; |
| 188 | 169 |
| 189 void PrerenderContents::AddPendingPrerender( | 170 void PrerenderContents::AddPendingPrerender( |
| 190 const base::WeakPtr<PrerenderHandle> weak_prerender_handle, | 171 const base::WeakPtr<PrerenderHandle> weak_prerender_handle, |
| 191 const GURL& url, | 172 const GURL& url, |
| 192 const content::Referrer& referrer, | 173 const content::Referrer& referrer, |
| 193 const gfx::Size& size) { | 174 const gfx::Size& size) { |
| 194 pending_prerenders_.push_back( | 175 pending_prerenders_.push_back( |
| 195 PendingPrerenderInfo(weak_prerender_handle, url, referrer, size)); | 176 PendingPrerenderInfo(weak_prerender_handle, url, referrer, size)); |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 RenderViewHost* PrerenderContents::GetRenderViewHostMutable() { | 671 RenderViewHost* PrerenderContents::GetRenderViewHostMutable() { |
| 691 return const_cast<RenderViewHost*>(GetRenderViewHost()); | 672 return const_cast<RenderViewHost*>(GetRenderViewHost()); |
| 692 } | 673 } |
| 693 | 674 |
| 694 const RenderViewHost* PrerenderContents::GetRenderViewHost() const { | 675 const RenderViewHost* PrerenderContents::GetRenderViewHost() const { |
| 695 if (!prerender_contents_.get()) | 676 if (!prerender_contents_.get()) |
| 696 return NULL; | 677 return NULL; |
| 697 return prerender_contents_->web_contents()->GetRenderViewHost(); | 678 return prerender_contents_->web_contents()->GetRenderViewHost(); |
| 698 } | 679 } |
| 699 | 680 |
| 681 void PrerenderContents::DidNavigate( |
| 682 const history::HistoryAddPageArgs& add_page_args) { |
| 683 add_page_vector_.push_back(add_page_args); |
| 684 } |
| 685 |
| 700 void PrerenderContents::CommitHistory(TabContents* tab) { | 686 void PrerenderContents::CommitHistory(TabContents* tab) { |
| 701 if (tab_contents_delegate_.get()) | 687 for (size_t i = 0; i < add_page_vector_.size(); ++i) |
| 702 tab_contents_delegate_->CommitHistory(tab); | 688 prerender_contents_->history_tab_helper()->UpdateHistoryForNavigation( |
| 689 add_page_vector_[i]); |
| 703 } | 690 } |
| 704 | 691 |
| 705 Value* PrerenderContents::GetAsValue() const { | 692 Value* PrerenderContents::GetAsValue() const { |
| 706 if (!prerender_contents_.get()) | 693 if (!prerender_contents_.get()) |
| 707 return NULL; | 694 return NULL; |
| 708 DictionaryValue* dict_value = new DictionaryValue(); | 695 DictionaryValue* dict_value = new DictionaryValue(); |
| 709 dict_value->SetString("url", prerender_url_.spec()); | 696 dict_value->SetString("url", prerender_url_.spec()); |
| 710 base::TimeTicks current_time = base::TimeTicks::Now(); | 697 base::TimeTicks current_time = base::TimeTicks::Now(); |
| 711 base::TimeDelta duration = current_time - load_start_time_; | 698 base::TimeDelta duration = current_time - load_start_time_; |
| 712 dict_value->SetInteger("duration", duration.InSeconds()); | 699 dict_value->SetInteger("duration", duration.InSeconds()); |
| 713 return dict_value; | 700 return dict_value; |
| 714 } | 701 } |
| 715 | 702 |
| 716 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 703 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
| 717 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) | 704 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) |
| 718 return false; | 705 return false; |
| 719 const WebContents* web_contents = prerender_contents_->web_contents(); | 706 const WebContents* web_contents = prerender_contents_->web_contents(); |
| 720 return (web_contents->GetSiteInstance() != | 707 return (web_contents->GetSiteInstance() != |
| 721 web_contents->GetPendingSiteInstance()); | 708 web_contents->GetPendingSiteInstance()); |
| 722 } | 709 } |
| 723 | 710 |
| 724 | 711 |
| 725 } // namespace prerender | 712 } // namespace prerender |
| OLD | NEW |