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 there is an opener object. |
337 // window.opener property has the same origin as the url. | 337 if (web_contents->HasOpener()) { |
338 // NOTE: This is broken in the cases where the document domain is modified | |
339 // using the javascript property for "document.domain". | |
340 if (opener_url.GetOrigin() == url.GetOrigin()) { | |
341 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER); | 338 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER); |
342 return false; | 339 return false; |
343 } | 340 } |
344 | 341 |
345 // Even if we match, the location.hash might be different. Record this as a | 342 // Even if we match, the location.hash might be different. Record this as a |
346 // separate final status. | 343 // separate final status. |
347 GURL matching_url; | 344 GURL matching_url; |
348 bool url_matches = prerender_contents->MatchesURL(url, &matching_url); | 345 bool url_matches = prerender_contents->MatchesURL(url, &matching_url); |
349 DCHECK(url_matches); | 346 DCHECK(url_matches); |
350 if (url_matches && url.ref() != matching_url.ref()) { | 347 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() - | 413 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - |
417 prerender_contents->load_start_time(), | 414 prerender_contents->load_start_time(), |
418 GetMaxAge()); | 415 GetMaxAge()); |
419 } | 416 } |
420 | 417 |
421 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); | 418 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); |
422 histograms_->RecordUsedPrerender(prerender_contents->origin()); | 419 histograms_->RecordUsedPrerender(prerender_contents->origin()); |
423 prerender_contents->set_final_status(FINAL_STATUS_USED); | 420 prerender_contents->set_final_status(FINAL_STATUS_USED); |
424 | 421 |
425 new_render_view_host->Send( | 422 new_render_view_host->Send( |
426 new ChromeViewMsg_SetIsPrerendering(new_render_view_host->GetRoutingID(), | 423 new PrerenderMsg_SetIsPrerendering(new_render_view_host->GetRoutingID(), |
427 false)); | 424 false)); |
428 | 425 |
429 TabContentsWrapper* new_tab_contents = | 426 TabContentsWrapper* new_tab_contents = |
430 prerender_contents->ReleasePrerenderContents(); | 427 prerender_contents->ReleasePrerenderContents(); |
431 TabContentsWrapper* old_tab_contents = | 428 TabContentsWrapper* old_tab_contents = |
432 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); | 429 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); |
433 DCHECK(new_tab_contents); | 430 DCHECK(new_tab_contents); |
434 DCHECK(old_tab_contents); | 431 DCHECK(old_tab_contents); |
435 | 432 |
436 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); | 433 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); |
437 | 434 |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1197 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1201 return NULL; | 1198 return NULL; |
1202 Profile* profile = Profile::FromBrowserContext( | 1199 Profile* profile = Profile::FromBrowserContext( |
1203 render_process_host->GetBrowserContext()); | 1200 render_process_host->GetBrowserContext()); |
1204 if (!profile) | 1201 if (!profile) |
1205 return NULL; | 1202 return NULL; |
1206 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1203 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1207 } | 1204 } |
1208 | 1205 |
1209 } // namespace prerender | 1206 } // namespace prerender |
OLD | NEW |