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/in_process_webkit/session_storage_namespace.h" | 39 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
40 #include "content/browser/renderer_host/render_view_host.h" | 40 #include "content/browser/renderer_host/render_view_host.h" |
41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
42 #include "content/public/browser/devtools_agent_host_registry.h" | 42 #include "content/public/browser/devtools_agent_host_registry.h" |
43 #include "content/public/browser/navigation_controller.h" | 43 #include "content/public/browser/navigation_controller.h" |
44 #include "content/public/browser/notification_observer.h" | 44 #include "content/public/browser/notification_observer.h" |
45 #include "content/public/browser/notification_registrar.h" | 45 #include "content/public/browser/notification_registrar.h" |
46 #include "content/public/browser/notification_source.h" | 46 #include "content/public/browser/notification_source.h" |
47 #include "content/public/browser/render_process_host.h" | 47 #include "content/public/browser/render_process_host.h" |
48 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 DCHECK(CalledOnValidThread()); | 309 DCHECK(CalledOnValidThread()); |
310 for (PrerenderContentsDataList::iterator it = prerender_list_.begin(); | 310 for (PrerenderContentsDataList::iterator it = prerender_list_.begin(); |
311 it != prerender_list_.end(); ) { | 311 it != prerender_list_.end(); ) { |
312 PrerenderContentsDataList::iterator cur = it++; | 312 PrerenderContentsDataList::iterator cur = it++; |
313 if (cur->contents_->origin() == ORIGIN_OMNIBOX) | 313 if (cur->contents_->origin() == ORIGIN_OMNIBOX) |
314 cur->contents_->Destroy(FINAL_STATUS_CANCELLED); | 314 cur->contents_->Destroy(FINAL_STATUS_CANCELLED); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 bool PrerenderManager::MaybeUsePrerenderedPage(WebContents* web_contents, | 318 bool PrerenderManager::MaybeUsePrerenderedPage(WebContents* web_contents, |
319 const GURL& url, | 319 const GURL& url) { |
320 const GURL& opener_url) { | |
321 DCHECK(CalledOnValidThread()); | 320 DCHECK(CalledOnValidThread()); |
321 DCHECK(web_contents); | |
322 DCHECK(!IsWebContentsPrerendering(web_contents)); | |
322 RecordNavigation(url); | 323 RecordNavigation(url); |
323 | 324 |
324 scoped_ptr<PrerenderContents> prerender_contents( | 325 scoped_ptr<PrerenderContents> prerender_contents( |
325 GetEntryButNotSpecifiedWC(url, web_contents)); | 326 GetEntryButNotSpecifiedWC(url, web_contents)); |
326 if (prerender_contents.get() == NULL) | 327 if (prerender_contents.get() == NULL) |
327 return false; | 328 return false; |
328 | 329 |
329 // Do not use the prerendered version if the opener url corresponding to the | 330 // Do not use the prerendered version if the opener url corresponding to the |
330 // window.opener property has the same origin as the url. | 331 // window.opener property has the same origin as the url. |
331 // NOTE: This is broken in the cases where the document domain is modified | 332 // NOTE: This is broken in the cases where the document domain is modified |
332 // using the javascript property for "document.domain". | 333 // using the javascript property for "document.domain". |
333 if (opener_url.GetOrigin() == url.GetOrigin()) { | 334 // TODO(cbentzel): I think the document.domain case is fixed now. |
335 if (web_contents->GetOpenerOrigin() == url.GetOrigin()) { | |
334 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER); | 336 prerender_contents.release()->Destroy(FINAL_STATUS_WINDOW_OPENER); |
335 return false; | 337 return false; |
336 } | 338 } |
337 | 339 |
338 // Even if we match, the location.hash might be different. Record this as a | 340 // Even if we match, the location.hash might be different. Record this as a |
339 // separate final status. | 341 // separate final status. |
340 GURL matching_url; | 342 GURL matching_url; |
341 bool url_matches = prerender_contents->MatchesURL(url, &matching_url); | 343 bool url_matches = prerender_contents->MatchesURL(url, &matching_url); |
342 DCHECK(url_matches); | 344 DCHECK(url_matches); |
343 if (url_matches && url.ref() != matching_url.ref()) { | 345 if (url_matches && url.ref() != matching_url.ref()) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - | 411 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - |
410 prerender_contents->load_start_time(), | 412 prerender_contents->load_start_time(), |
411 config_.max_age); | 413 config_.max_age); |
412 } | 414 } |
413 | 415 |
414 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); | 416 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); |
415 histograms_->RecordUsedPrerender(prerender_contents->origin()); | 417 histograms_->RecordUsedPrerender(prerender_contents->origin()); |
416 prerender_contents->set_final_status(FINAL_STATUS_USED); | 418 prerender_contents->set_final_status(FINAL_STATUS_USED); |
417 | 419 |
418 new_render_view_host->Send( | 420 new_render_view_host->Send( |
419 new ChromeViewMsg_SetIsPrerendering(new_render_view_host->routing_id(), | 421 new PrerenderMsg_SetIsPrerendering(new_render_view_host->routing_id(), |
420 false)); | 422 false)); |
dominich
2012/02/29 19:44:35
nit: indent is off by one.
| |
421 | 423 |
422 TabContentsWrapper* new_tab_contents = | 424 TabContentsWrapper* new_tab_contents = |
423 prerender_contents->ReleasePrerenderContents(); | 425 prerender_contents->ReleasePrerenderContents(); |
424 TabContentsWrapper* old_tab_contents = | 426 TabContentsWrapper* old_tab_contents = |
425 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); | 427 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); |
426 DCHECK(new_tab_contents); | 428 DCHECK(new_tab_contents); |
427 DCHECK(old_tab_contents); | 429 DCHECK(old_tab_contents); |
428 | 430 |
429 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); | 431 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); |
430 | 432 |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1176 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1178 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1177 return NULL; | 1179 return NULL; |
1178 Profile* profile = Profile::FromBrowserContext( | 1180 Profile* profile = Profile::FromBrowserContext( |
1179 render_process_host->GetBrowserContext()); | 1181 render_process_host->GetBrowserContext()); |
1180 if (!profile) | 1182 if (!profile) |
1181 return NULL; | 1183 return NULL; |
1182 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1184 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1183 } | 1185 } |
1184 | 1186 |
1185 } // namespace prerender | 1187 } // namespace prerender |
OLD | NEW |