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

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

Issue 9623018: Prerendered pages are swapped in at browser::Navigate time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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_manager.h" 5 #include "chrome/browser/prerender/prerender_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/browser/prerender/prerender_manager_factory.h" 28 #include "chrome/browser/prerender/prerender_manager_factory.h"
29 #include "chrome/browser/prerender/prerender_tab_helper.h" 29 #include "chrome/browser/prerender/prerender_tab_helper.h"
30 #include "chrome/browser/prerender/prerender_tracker.h" 30 #include "chrome/browser/prerender/prerender_tracker.h"
31 #include "chrome/browser/prerender/prerender_util.h" 31 #include "chrome/browser/prerender/prerender_util.h"
32 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 33 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
34 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" 34 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
35 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 35 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
36 #include "chrome/common/chrome_notification_types.h" 36 #include "chrome/common/chrome_notification_types.h"
37 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/render_messages.h" 38 #include "chrome/common/prerender_messages.h"
39 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
40 #include "content/public/browser/devtools_agent_host_registry.h" 40 #include "content/public/browser/devtools_agent_host_registry.h"
41 #include "content/public/browser/navigation_controller.h" 41 #include "content/public/browser/navigation_controller.h"
42 #include "content/public/browser/notification_observer.h" 42 #include "content/public/browser/notification_observer.h"
43 #include "content/public/browser/notification_registrar.h" 43 #include "content/public/browser/notification_registrar.h"
44 #include "content/public/browser/notification_source.h" 44 #include "content/public/browser/notification_source.h"
45 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
46 #include "content/public/browser/render_view_host.h" 46 #include "content/public/browser/render_view_host.h"
47 #include "content/public/browser/session_storage_namespace.h" 47 #include "content/public/browser/session_storage_namespace.h"
48 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 DCHECK(CalledOnValidThread()); 317 DCHECK(CalledOnValidThread());
318 for (PrerenderContentsDataList::iterator it = prerender_list_.begin(); 318 for (PrerenderContentsDataList::iterator it = prerender_list_.begin();
319 it != prerender_list_.end(); ) { 319 it != prerender_list_.end(); ) {
320 PrerenderContentsDataList::iterator cur = it++; 320 PrerenderContentsDataList::iterator cur = it++;
321 if (cur->contents_->origin() == ORIGIN_OMNIBOX) 321 if (cur->contents_->origin() == ORIGIN_OMNIBOX)
322 cur->contents_->Destroy(FINAL_STATUS_CANCELLED); 322 cur->contents_->Destroy(FINAL_STATUS_CANCELLED);
323 } 323 }
324 } 324 }
325 325
326 bool PrerenderManager::MaybeUsePrerenderedPage(WebContents* web_contents, 326 bool PrerenderManager::MaybeUsePrerenderedPage(WebContents* web_contents,
327 const GURL& url, 327 const GURL& url) {
328 const GURL& opener_url) {
329 DCHECK(CalledOnValidThread()); 328 DCHECK(CalledOnValidThread());
329 DCHECK(!IsWebContentsPrerendering(web_contents));
330 RecordNavigation(url); 330 RecordNavigation(url);
331 331
332 scoped_ptr<PrerenderContents> prerender_contents( 332 scoped_ptr<PrerenderContents> prerender_contents(
333 GetEntryButNotSpecifiedWC(url, web_contents)); 333 GetEntryButNotSpecifiedWC(url, web_contents));
334 if (prerender_contents.get() == NULL) 334 if (prerender_contents.get() == NULL)
335 return false; 335 return false;
336 336
337 // Do not use the prerendered version if the opener url corresponding to the 337 // Do not use the prerendered version if there is an opener object.
338 // window.opener property has the same origin as the url. 338 if (web_contents->HasOpener()) {
339 // NOTE: This is broken in the cases where the document domain is modified
340 // using the javascript property for "document.domain".
341 if (opener_url.GetOrigin() == url.GetOrigin()) {
342 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER); 339 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER);
343 return false; 340 return false;
344 } 341 }
345 342
346 // Even if we match, the location.hash might be different. Record this as a 343 // Even if we match, the location.hash might be different. Record this as a
347 // separate final status. 344 // separate final status.
348 GURL matching_url; 345 GURL matching_url;
349 bool url_matches = prerender_contents->MatchesURL(url, &matching_url); 346 bool url_matches = prerender_contents->MatchesURL(url, &matching_url);
350 DCHECK(url_matches); 347 DCHECK(url_matches);
351 if (url_matches && url.ref() != matching_url.ref()) { 348 if (url_matches && url.ref() != matching_url.ref()) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - 414 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() -
418 prerender_contents->load_start_time(), 415 prerender_contents->load_start_time(),
419 GetMaxAge()); 416 GetMaxAge());
420 } 417 }
421 418
422 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); 419 histograms_->RecordPerSessionCount(++prerenders_per_session_count_);
423 histograms_->RecordUsedPrerender(prerender_contents->origin()); 420 histograms_->RecordUsedPrerender(prerender_contents->origin());
424 prerender_contents->set_final_status(FINAL_STATUS_USED); 421 prerender_contents->set_final_status(FINAL_STATUS_USED);
425 422
426 new_render_view_host->Send( 423 new_render_view_host->Send(
427 new ChromeViewMsg_SetIsPrerendering(new_render_view_host->GetRoutingID(), 424 new PrerenderMsg_SetIsPrerendering(new_render_view_host->GetRoutingID(),
428 false)); 425 false));
429 426
430 TabContentsWrapper* new_tab_contents = 427 TabContentsWrapper* new_tab_contents =
431 prerender_contents->ReleasePrerenderContents(); 428 prerender_contents->ReleasePrerenderContents();
432 TabContentsWrapper* old_tab_contents = 429 TabContentsWrapper* old_tab_contents =
433 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); 430 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
434 DCHECK(new_tab_contents); 431 DCHECK(new_tab_contents);
435 DCHECK(old_tab_contents); 432 DCHECK(old_tab_contents);
436 433
437 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); 434 MarkWebContentsAsPrerendered(new_tab_contents->web_contents());
438 435
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 if (!render_process_host || !render_process_host->GetBrowserContext()) 1199 if (!render_process_host || !render_process_host->GetBrowserContext())
1203 return NULL; 1200 return NULL;
1204 Profile* profile = Profile::FromBrowserContext( 1201 Profile* profile = Profile::FromBrowserContext(
1205 render_process_host->GetBrowserContext()); 1202 render_process_host->GetBrowserContext());
1206 if (!profile) 1203 if (!profile)
1207 return NULL; 1204 return NULL;
1208 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); 1205 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile);
1209 } 1206 }
1210 1207
1211 } // namespace prerender 1208 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698