| 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_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 Loading... |
| 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/browser/renderer_host/render_view_host.h" | 39 #include "content/browser/renderer_host/render_view_host.h" |
| 40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/devtools_agent_host_registry.h" | 41 #include "content/public/browser/devtools_agent_host_registry.h" |
| 42 #include "content/public/browser/navigation_controller.h" | 42 #include "content/public/browser/navigation_controller.h" |
| 43 #include "content/public/browser/notification_observer.h" | 43 #include "content/public/browser/notification_observer.h" |
| 44 #include "content/public/browser/notification_registrar.h" | 44 #include "content/public/browser/notification_registrar.h" |
| 45 #include "content/public/browser/notification_source.h" | 45 #include "content/public/browser/notification_source.h" |
| 46 #include "content/public/browser/render_process_host.h" | 46 #include "content/public/browser/render_process_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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 DCHECK(CalledOnValidThread()); | 316 DCHECK(CalledOnValidThread()); |
| 317 for (PrerenderContentsDataList::iterator it = prerender_list_.begin(); | 317 for (PrerenderContentsDataList::iterator it = prerender_list_.begin(); |
| 318 it != prerender_list_.end(); ) { | 318 it != prerender_list_.end(); ) { |
| 319 PrerenderContentsDataList::iterator cur = it++; | 319 PrerenderContentsDataList::iterator cur = it++; |
| 320 if (cur->contents_->origin() == ORIGIN_OMNIBOX) | 320 if (cur->contents_->origin() == ORIGIN_OMNIBOX) |
| 321 cur->contents_->Destroy(FINAL_STATUS_CANCELLED); | 321 cur->contents_->Destroy(FINAL_STATUS_CANCELLED); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 bool PrerenderManager::MaybeUsePrerenderedPage(WebContents* web_contents, | 325 bool PrerenderManager::MaybeUsePrerenderedPage(WebContents* web_contents, |
| 326 const GURL& url, | 326 const GURL& url) { |
| 327 const GURL& opener_url) { | |
| 328 DCHECK(CalledOnValidThread()); | 327 DCHECK(CalledOnValidThread()); |
| 328 DCHECK(!IsWebContentsPrerendering(web_contents)); |
| 329 RecordNavigation(url); | 329 RecordNavigation(url); |
| 330 | 330 |
| 331 scoped_ptr<PrerenderContents> prerender_contents( | 331 scoped_ptr<PrerenderContents> prerender_contents( |
| 332 GetEntryButNotSpecifiedWC(url, web_contents)); | 332 GetEntryButNotSpecifiedWC(url, web_contents)); |
| 333 if (prerender_contents.get() == NULL) | 333 if (prerender_contents.get() == NULL) |
| 334 return false; | 334 return false; |
| 335 | 335 |
| 336 // Do not use the prerendered version if the opener url corresponding to the | 336 // Do not use the prerendered version if the opener url corresponding to the |
| 337 // window.opener property has the same origin as the url. | 337 // window.opener property has the same origin as the url. |
| 338 // NOTE: This is broken in the cases where the document domain is modified | 338 // NOTE: This is broken in the cases where the document domain is modified |
| 339 // using the javascript property for "document.domain". | 339 // using the javascript property for "document.domain". |
| 340 if (opener_url.GetOrigin() == url.GetOrigin()) { | 340 // TODO(cbentzel): I think the document.domain case is fixed now. |
| 341 if (web_contents->GetOpenerOrigin() == url.GetOrigin()) { |
| 341 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER); | 342 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER); |
| 342 return false; | 343 return false; |
| 343 } | 344 } |
| 344 | 345 |
| 345 // Even if we match, the location.hash might be different. Record this as a | 346 // Even if we match, the location.hash might be different. Record this as a |
| 346 // separate final status. | 347 // separate final status. |
| 347 GURL matching_url; | 348 GURL matching_url; |
| 348 bool url_matches = prerender_contents->MatchesURL(url, &matching_url); | 349 bool url_matches = prerender_contents->MatchesURL(url, &matching_url); |
| 349 DCHECK(url_matches); | 350 DCHECK(url_matches); |
| 350 if (url_matches && url.ref() != matching_url.ref()) { | 351 if (url_matches && url.ref() != matching_url.ref()) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - | 417 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - |
| 417 prerender_contents->load_start_time(), | 418 prerender_contents->load_start_time(), |
| 418 config_.max_age); | 419 config_.max_age); |
| 419 } | 420 } |
| 420 | 421 |
| 421 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); | 422 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); |
| 422 histograms_->RecordUsedPrerender(prerender_contents->origin()); | 423 histograms_->RecordUsedPrerender(prerender_contents->origin()); |
| 423 prerender_contents->set_final_status(FINAL_STATUS_USED); | 424 prerender_contents->set_final_status(FINAL_STATUS_USED); |
| 424 | 425 |
| 425 new_render_view_host->Send( | 426 new_render_view_host->Send( |
| 426 new ChromeViewMsg_SetIsPrerendering(new_render_view_host->routing_id(), | 427 new PrerenderMsg_SetIsPrerendering(new_render_view_host->routing_id(), |
| 427 false)); | 428 false)); |
| 428 | 429 |
| 429 TabContentsWrapper* new_tab_contents = | 430 TabContentsWrapper* new_tab_contents = |
| 430 prerender_contents->ReleasePrerenderContents(); | 431 prerender_contents->ReleasePrerenderContents(); |
| 431 TabContentsWrapper* old_tab_contents = | 432 TabContentsWrapper* old_tab_contents = |
| 432 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); | 433 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); |
| 433 DCHECK(new_tab_contents); | 434 DCHECK(new_tab_contents); |
| 434 DCHECK(old_tab_contents); | 435 DCHECK(old_tab_contents); |
| 435 | 436 |
| 436 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); | 437 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1195 if (!render_process_host || !render_process_host->GetBrowserContext()) |
| 1195 return NULL; | 1196 return NULL; |
| 1196 Profile* profile = Profile::FromBrowserContext( | 1197 Profile* profile = Profile::FromBrowserContext( |
| 1197 render_process_host->GetBrowserContext()); | 1198 render_process_host->GetBrowserContext()); |
| 1198 if (!profile) | 1199 if (!profile) |
| 1199 return NULL; | 1200 return NULL; |
| 1200 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1201 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
| 1201 } | 1202 } |
| 1202 | 1203 |
| 1203 } // namespace prerender | 1204 } // namespace prerender |
| OLD | NEW |