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 |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/history/history_tab_helper.h" | 13 #include "chrome/browser/history/history_tab_helper.h" |
14 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/browser/prerender/prerender_final_status.h" | 15 #include "chrome/browser/prerender/prerender_final_status.h" |
16 #include "chrome/browser/prerender/prerender_handle.h" | 16 #include "chrome/browser/prerender/prerender_handle.h" |
17 #include "chrome/browser/prerender/prerender_manager.h" | 17 #include "chrome/browser/prerender/prerender_manager.h" |
18 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" | 18 #include "chrome/browser/prerender/prerender_render_view_host_observer.h" |
19 #include "chrome/browser/prerender/prerender_tracker.h" | 19 #include "chrome/browser/prerender/prerender_tracker.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/icon_messages.h" | 23 #include "chrome/common/icon_messages.h" |
24 #include "chrome/common/prerender_messages.h" | 24 #include "chrome/common/prerender_messages.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "content/public/browser/resource_request_details.h" | |
27 #include "content/public/browser/browser_child_process_host.h" | 26 #include "content/public/browser/browser_child_process_host.h" |
28 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
30 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/resource_request_details.h" |
31 #include "content/public/browser/session_storage_namespace.h" | 31 #include "content/public/browser/session_storage_namespace.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/browser/web_contents_delegate.h" | 33 #include "content/public/browser/web_contents_delegate.h" |
34 #include "content/public/browser/web_contents_view.h" | 34 #include "content/public/browser/web_contents_view.h" |
35 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
36 | 36 |
37 using content::DownloadItem; | 37 using content::DownloadItem; |
38 using content::OpenURLParams; | 38 using content::OpenURLParams; |
39 using content::RenderViewHost; | 39 using content::RenderViewHost; |
40 using content::ResourceRedirectDetails; | 40 using content::ResourceRedirectDetails; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( | 107 virtual bool ShouldAddNavigationToHistory( |
108 const history::HistoryAddPageArgs& add_page_args, | 108 const history::HistoryAddPageArgs& add_page_args, |
109 content::NavigationType navigation_type) OVERRIDE { | 109 content::NavigationType navigation_type) OVERRIDE { |
110 add_page_vector_.push_back( | 110 add_page_vector_.push_back(add_page_args); |
111 scoped_refptr<history::HistoryAddPageArgs>(add_page_args.Clone())); | |
112 return false; | 111 return false; |
113 } | 112 } |
114 | 113 |
115 virtual bool CanDownload(RenderViewHost* render_view_host, | 114 virtual bool CanDownload(RenderViewHost* render_view_host, |
116 int request_id, | 115 int request_id, |
117 const std::string& request_method) OVERRIDE { | 116 const std::string& request_method) OVERRIDE { |
118 prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); | 117 prerender_contents_->Destroy(FINAL_STATUS_DOWNLOAD); |
119 // Cancel the download. | 118 // Cancel the download. |
120 return false; | 119 return false; |
121 } | 120 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 bool user_gesture) OVERRIDE { | 167 bool user_gesture) OVERRIDE { |
169 // TODO(mmenke): Consider supporting this if it is a common case during | 168 // TODO(mmenke): Consider supporting this if it is a common case during |
170 // prerenders. | 169 // prerenders. |
171 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); | 170 prerender_contents_->Destroy(FINAL_STATUS_REGISTER_PROTOCOL_HANDLER); |
172 } | 171 } |
173 | 172 |
174 // Commits the History of Pages to the given TabContents. | 173 // Commits the History of Pages to the given TabContents. |
175 void CommitHistory(TabContents* tab) { | 174 void CommitHistory(TabContents* tab) { |
176 for (size_t i = 0; i < add_page_vector_.size(); ++i) | 175 for (size_t i = 0; i < add_page_vector_.size(); ++i) |
177 tab->history_tab_helper()->UpdateHistoryForNavigation( | 176 tab->history_tab_helper()->UpdateHistoryForNavigation( |
178 add_page_vector_[i].get()); | 177 add_page_vector_[i]); |
179 } | 178 } |
180 | 179 |
181 private: | 180 private: |
182 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > | 181 typedef std::vector<history::HistoryAddPageArgs> AddPageVector; |
183 AddPageVector; | |
184 | 182 |
185 // Caches pages to be added to the history. | 183 // Caches pages to be added to the history. |
186 AddPageVector add_page_vector_; | 184 AddPageVector add_page_vector_; |
187 | 185 |
188 PrerenderContents* prerender_contents_; | 186 PrerenderContents* prerender_contents_; |
189 }; | 187 }; |
190 | 188 |
191 void PrerenderContents::AddPendingPrerender( | 189 void PrerenderContents::AddPendingPrerender( |
192 const base::WeakPtr<PrerenderHandle> weak_prerender_handle, | 190 const base::WeakPtr<PrerenderHandle> weak_prerender_handle, |
193 const GURL& url, | 191 const GURL& url, |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 716 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
719 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) | 717 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) |
720 return false; | 718 return false; |
721 const WebContents* web_contents = prerender_contents_->web_contents(); | 719 const WebContents* web_contents = prerender_contents_->web_contents(); |
722 return (web_contents->GetSiteInstance() != | 720 return (web_contents->GetSiteInstance() != |
723 web_contents->GetPendingSiteInstance()); | 721 web_contents->GetPendingSiteInstance()); |
724 } | 722 } |
725 | 723 |
726 | 724 |
727 } // namespace prerender | 725 } // namespace prerender |
OLD | NEW |