Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/prerender/prerender_contents.cc

Issue 10198040: New link rel=prerender api, using WebKit::WebPrerenderingPlatform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: is this closer? Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <utility> 8 #include <utility>
9 9
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 public: 89 public:
90 virtual PrerenderContents* CreatePrerenderContents( 90 virtual PrerenderContents* CreatePrerenderContents(
91 PrerenderManager* prerender_manager, PrerenderTracker* prerender_tracker, 91 PrerenderManager* prerender_manager, PrerenderTracker* prerender_tracker,
92 Profile* profile, const GURL& url, const content::Referrer& referrer, 92 Profile* profile, const GURL& url, const content::Referrer& referrer,
93 Origin origin, uint8 experiment_id) OVERRIDE { 93 Origin origin, uint8 experiment_id) OVERRIDE {
94 return new PrerenderContents(prerender_manager, prerender_tracker, profile, 94 return new PrerenderContents(prerender_manager, prerender_tracker, profile,
95 url, referrer, origin, experiment_id); 95 url, referrer, origin, experiment_id);
96 } 96 }
97 }; 97 };
98 98
99 PrerenderContents::PendingPrerenderData::PendingPrerenderData( 99 struct PrerenderContents::PendingPrerenderInfo {
100 Origin origin, 100 PendingPrerenderInfo(const GURL& url,
101 const content::Referrer& referrer,
102 gfx::Size size);
mmenke 2012/05/01 16:23:21 Might want to make size a const. Should be optimi
gavinp 2012/05/01 18:50:22 Done.
103 GURL url;
104 content::Referrer referrer;
105 gfx::Size size;
mmenke 2012/05/01 16:23:21 nit: All these could be const.
gavinp 2012/05/01 18:50:22 Done.
106 };
107
108 PrerenderContents::PendingPrerenderInfo::PendingPrerenderInfo(
101 const GURL& url, 109 const GURL& url,
102 const content::Referrer& referrer) 110 const content::Referrer& referrer,
103 : origin(origin), 111 gfx::Size size)
104 url(url), 112 : url(url),
105 referrer(referrer) { 113 referrer(referrer),
114 size(size) {
106 } 115 }
107 116
108 // TabContentsDelegateImpl ----------------------------------------------------- 117 // TabContentsDelegateImpl -----------------------------------------------------
109 118
110 class PrerenderContents::TabContentsDelegateImpl 119 class PrerenderContents::TabContentsDelegateImpl
111 : public content::WebContentsDelegate { 120 : public content::WebContentsDelegate {
112 public: 121 public:
113 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) : 122 explicit TabContentsDelegateImpl(PrerenderContents* prerender_contents) :
114 prerender_contents_(prerender_contents) { 123 prerender_contents_(prerender_contents) {
115 } 124 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 private: 199 private:
191 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > 200 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> >
192 AddPageVector; 201 AddPageVector;
193 202
194 // Caches pages to be added to the history. 203 // Caches pages to be added to the history.
195 AddPageVector add_page_vector_; 204 AddPageVector add_page_vector_;
196 205
197 PrerenderContents* prerender_contents_; 206 PrerenderContents* prerender_contents_;
198 }; 207 };
199 208
200 void PrerenderContents::AddPendingPrerender(Origin origin, 209 void PrerenderContents::AddPendingPrerender(const GURL& url,
201 const GURL& url, 210 const content::Referrer& referrer,
202 const content::Referrer& referrer) { 211 const gfx::Size& size) {
203 pending_prerender_list_.push_back( 212 pending_prerender_list_.push_back(PendingPrerenderInfo(url, referrer, size));
204 PendingPrerenderData(origin, url, referrer));
205 } 213 }
206 214
207 bool PrerenderContents::IsPendingEntry(const GURL& url) const { 215 bool PrerenderContents::IsPendingEntry(const GURL& url) const {
208 for (PendingPrerenderList::const_iterator it = 216 for (PendingPrerenderList::const_iterator it =
209 pending_prerender_list_.begin(); 217 pending_prerender_list_.begin();
210 it != pending_prerender_list_.end(); 218 it != pending_prerender_list_.end();
211 ++it) { 219 ++it) {
212 if (it->url == url) 220 if (it->url == url)
213 return true; 221 return true;
214 } 222 }
215 return false; 223 return false;
216 } 224 }
217 225
218 void PrerenderContents::StartPendingPrerenders() { 226 void PrerenderContents::StartPendingPrerenders() {
219 PendingPrerenderList pending_prerender_list; 227 PendingPrerenderList pending_prerender_list;
220 pending_prerender_list.swap(pending_prerender_list_); 228 pending_prerender_list.swap(pending_prerender_list_);
221 for (PendingPrerenderList::iterator it = pending_prerender_list.begin(); 229 for (PendingPrerenderList::iterator it = pending_prerender_list.begin();
222 it != pending_prerender_list.end(); 230 it != pending_prerender_list.end();
223 ++it) { 231 ++it) {
224 prerender_manager_->AddPrerender(it->origin, 232 RenderViewHost* render_view_host = RenderViewHost::FromID(child_id_,
225 std::make_pair(child_id_, route_id_), 233 route_id_);
226 it->url, 234 prerender_manager_->AddPrerenderFromLinkRelPrerender(
227 it->referrer, 235 child_id_, route_id_, it->url, it->referrer, it->size,
228 NULL); 236 render_view_host->GetSessionStorageNamespace());
229 } 237 }
230 } 238 }
231 239
232 PrerenderContents::PrerenderContents( 240 PrerenderContents::PrerenderContents(
233 PrerenderManager* prerender_manager, 241 PrerenderManager* prerender_manager,
234 PrerenderTracker* prerender_tracker, 242 PrerenderTracker* prerender_tracker,
235 Profile* profile, 243 Profile* profile,
236 const GURL& url, 244 const GURL& url,
237 const content::Referrer& referrer, 245 const content::Referrer& referrer,
238 Origin origin, 246 Origin origin,
(...skipping 21 matching lines...) Expand all
260 bool PrerenderContents::Init() { 268 bool PrerenderContents::Init() {
261 return AddAliasURL(prerender_url_); 269 return AddAliasURL(prerender_url_);
262 } 270 }
263 271
264 // static 272 // static
265 PrerenderContents::Factory* PrerenderContents::CreateFactory() { 273 PrerenderContents::Factory* PrerenderContents::CreateFactory() {
266 return new PrerenderContentsFactoryImpl(); 274 return new PrerenderContentsFactoryImpl();
267 } 275 }
268 276
269 void PrerenderContents::StartPrerendering( 277 void PrerenderContents::StartPrerendering(
270 const RenderViewHost* source_render_view_host, 278 int creator_child_id,
279 const gfx::Size& size,
271 content::SessionStorageNamespace* session_storage_namespace) { 280 content::SessionStorageNamespace* session_storage_namespace) {
272 DCHECK(profile_ != NULL); 281 DCHECK(profile_ != NULL);
273 DCHECK(!prerendering_has_started_); 282 DCHECK(!prerendering_has_started_);
274 DCHECK(prerender_contents_.get() == NULL); 283 DCHECK(prerender_contents_.get() == NULL);
284 DCHECK_EQ(-1, creator_child_id_);
285 DCHECK(size_.IsEmpty());
286
287 creator_child_id_ = creator_child_id;
288 size_ = size;
275 289
276 prerendering_has_started_ = true; 290 prerendering_has_started_ = true;
277 DCHECK(creator_child_id_ == -1); 291 DCHECK_EQ(1U, alias_urls_.size());
278 DCHECK(alias_urls_.size() == 1);
279 if (source_render_view_host)
280 creator_child_id_ = source_render_view_host->GetProcess()->GetID();
281 InformRenderProcessAboutPrerender(prerender_url_, true, 292 InformRenderProcessAboutPrerender(prerender_url_, true,
282 creator_child_id_); 293 creator_child_id_);
283 294
284 WebContents* new_contents = CreateWebContents(session_storage_namespace); 295 WebContents* new_contents = CreateWebContents(session_storage_namespace);
285 prerender_contents_.reset(new TabContentsWrapper(new_contents)); 296 prerender_contents_.reset(new TabContentsWrapper(new_contents));
286 content::WebContentsObserver::Observe(new_contents); 297 content::WebContentsObserver::Observe(new_contents);
287 298
288 gfx::Rect tab_bounds = prerender_manager_->config().default_tab_bounds; 299 if (size_.IsEmpty()) {
289 if (source_render_view_host) { 300 size_ = prerender_manager_->config().default_tab_bounds.size();
290 DCHECK(source_render_view_host->GetView() != NULL);
291 WebContents* source_wc =
292 source_render_view_host->GetDelegate()->GetAsWebContents();
293 if (source_wc) {
294 // Set the size of the new TC to that of the old TC.
295 source_wc->GetView()->GetContainerBounds(&tab_bounds);
296 }
297 } else {
298 #if !defined(OS_ANDROID) 301 #if !defined(OS_ANDROID)
299 // Try to get the active tab of the active browser and use that for tab 302 // Try to get the active tab of the active browser and use that for tab
300 // bounds. If the browser has never been active, we will fail to get a size 303 // bounds. If the browser has never been active, we will fail to get a size
301 // but we shouldn't be prerendering in that case anyway. 304 // but we shouldn't be prerendering in that case anyway.
302 // 305 //
303 // This code is unneeded on Android as we do not have a Browser object so we 306 // This code is unneeded on Android as we do not have a Browser object so we
304 // can't get the size, and |default_tab_bounds| will be set to the right 307 // can't get the size, and |default_tab_bounds| will be set to the right
305 // value. 308 // value.
306 Browser* active_browser = BrowserList::GetLastActiveWithProfile(profile_); 309 if (Browser* active_browser =
307 if (active_browser) { 310 BrowserList::GetLastActiveWithProfile(profile_)) {
308 WebContents* active_web_contents = active_browser->GetWebContentsAt( 311 WebContents* active_web_contents = active_browser->GetWebContentsAt(
309 active_browser->active_index()); 312 active_browser->active_index());
313 gfx::Rect container_bounds;
310 if (active_web_contents) 314 if (active_web_contents)
311 active_web_contents->GetView()->GetContainerBounds(&tab_bounds); 315 active_web_contents->GetView()->GetContainerBounds(&container_bounds);
316 size_ = container_bounds.size();
312 } 317 }
313 #endif // !defined(OS_ANDROID) 318 #endif // !defined(OS_ANDROID)
314 } 319 }
315 320
316 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); 321 tab_contents_delegate_.reset(new TabContentsDelegateImpl(this));
317 new_contents->SetDelegate(tab_contents_delegate_.get()); 322 new_contents->SetDelegate(tab_contents_delegate_.get());
318 323
319 // Set the size of the prerender WebContents. 324 // Set the size of the prerender WebContents.
320 prerender_contents_->web_contents()->GetView()->SizeContents( 325 prerender_contents_->web_contents()->GetView()->SizeContents(size_);
321 tab_bounds.size());
322 326
323 // Register as an observer of the RenderViewHost so we get messages. 327 // Register as an observer of the RenderViewHost so we get messages.
324 render_view_host_observer_.reset( 328 render_view_host_observer_.reset(
325 new PrerenderRenderViewHostObserver(this, GetRenderViewHostMutable())); 329 new PrerenderRenderViewHostObserver(this, GetRenderViewHostMutable()));
326 330
327 child_id_ = GetRenderViewHost()->GetProcess()->GetID(); 331 child_id_ = GetRenderViewHost()->GetProcess()->GetID();
328 route_id_ = GetRenderViewHost()->GetRoutingID(); 332 route_id_ = GetRenderViewHost()->GetRoutingID();
329 333
330 // Register this with the ResourceDispatcherHost as a prerender 334 // Register this with the ResourceDispatcherHost as a prerender
331 // RenderViewHost. This must be done before the Navigate message to catch all 335 // RenderViewHost. This must be done before the Navigate message to catch all
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 bool PrerenderContents::IsCrossSiteNavigationPending() const { 709 bool PrerenderContents::IsCrossSiteNavigationPending() const {
706 if (!prerender_contents_.get() || !prerender_contents_->web_contents()) 710 if (!prerender_contents_.get() || !prerender_contents_->web_contents())
707 return false; 711 return false;
708 const WebContents* web_contents = prerender_contents_->web_contents(); 712 const WebContents* web_contents = prerender_contents_->web_contents();
709 return (web_contents->GetSiteInstance() != 713 return (web_contents->GetSiteInstance() !=
710 web_contents->GetPendingSiteInstance()); 714 web_contents->GetPendingSiteInstance());
711 } 715 }
712 716
713 717
714 } // namespace prerender 718 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698