Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 int route_id, | 225 int route_id, |
| 226 const GURL& url, | 226 const GURL& url, |
| 227 const content::Referrer& referrer, | 227 const content::Referrer& referrer, |
| 228 const gfx::Size& size) { | 228 const gfx::Size& size) { |
| 229 #if defined(OS_ANDROID) | 229 #if defined(OS_ANDROID) |
| 230 // TODO(jcivelli): http://crbug.com/113322 We should have an option to disable | 230 // TODO(jcivelli): http://crbug.com/113322 We should have an option to disable |
| 231 // link-prerender and enable omnibox-prerender only. | 231 // link-prerender and enable omnibox-prerender only. |
| 232 return NULL; | 232 return NULL; |
| 233 #else | 233 #else |
| 234 DCHECK(!size.IsEmpty()); | 234 DCHECK(!size.IsEmpty()); |
| 235 if (PrerenderData* parent_prerender_data = | 235 bool is_same_domain = false; |
| 236 FindPrerenderDataForChildAndRoute(process_id, route_id)) { | 236 SessionStorageNamespace* session_storage_namespace = NULL; |
| 237 // Instead of prerendering from inside of a running prerender, we will defer | |
| 238 // this request until its launcher is made visible. | |
| 239 if (PrerenderContents* contents = parent_prerender_data->contents_) { | |
| 240 pending_prerender_list_.push_back( | |
| 241 linked_ptr<PrerenderData>(new PrerenderData(this))); | |
| 242 PrerenderHandle* prerender_handle = | |
| 243 new PrerenderHandle(pending_prerender_list_.back().get()); | |
| 244 contents->AddPendingPrerender( | |
| 245 prerender_handle->weak_ptr_factory_.GetWeakPtr(), | |
| 246 ORIGIN_LINK_REL_PRERENDER, url, referrer, size); | |
| 247 return prerender_handle; | |
| 248 } | |
| 249 } | |
| 250 | |
| 251 // Unit tests pass in a process_id == -1. | 237 // Unit tests pass in a process_id == -1. |
| 252 SessionStorageNamespace* session_storage_namespace = NULL; | |
| 253 if (process_id != -1) { | 238 if (process_id != -1) { |
| 254 RenderViewHost* source_render_view_host = | 239 RenderViewHost* source_render_view_host = |
| 255 RenderViewHost::FromID(process_id, route_id); | 240 RenderViewHost::FromID(process_id, route_id); |
| 256 if (!source_render_view_host) | 241 if (!source_render_view_host) |
| 257 return NULL; | 242 return NULL; |
| 258 WebContents* source_web_contents = | 243 WebContents* source_web_contents = |
| 259 WebContents::FromRenderViewHost(source_render_view_host); | 244 WebContents::FromRenderViewHost(source_render_view_host); |
| 260 if (!source_web_contents) | 245 if (!source_web_contents) |
| 261 return NULL; | 246 return NULL; |
| 247 is_same_domain = (source_web_contents->GetURL().host() == url.host()); | |
| 262 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 248 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
| 263 session_storage_namespace = | 249 session_storage_namespace = |
| 264 source_web_contents->GetController() | 250 source_web_contents->GetController() |
| 265 .GetDefaultSessionStorageNamespace(); | 251 .GetDefaultSessionStorageNamespace(); |
| 266 } | 252 } |
| 267 | 253 |
| 268 return AddPrerender(ORIGIN_LINK_REL_PRERENDER, | 254 if (PrerenderData* parent_prerender_data = |
| 255 FindPrerenderDataForChildAndRoute(process_id, route_id)) { | |
| 256 // Instead of prerendering from inside of a running prerender, we will defer | |
| 257 // this request until its launcher is made visible. | |
| 258 if (PrerenderContents* contents = parent_prerender_data->contents_) { | |
| 259 pending_prerender_list_.push_back( | |
| 260 linked_ptr<PrerenderData>(new PrerenderData(this))); | |
| 261 PrerenderHandle* prerender_handle = | |
| 262 new PrerenderHandle(pending_prerender_list_.back().get()); | |
| 263 contents->AddPendingPrerender( | |
| 264 prerender_handle->weak_ptr_factory_.GetWeakPtr(), | |
| 265 is_same_domain ? ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN | |
| 266 : ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN, | |
| 267 url, referrer, size); | |
| 268 return prerender_handle; | |
| 269 } | |
| 270 } | |
| 271 | |
| 272 return AddPrerender(is_same_domain ? ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN | |
| 273 : ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN, | |
|
mmenke
2012/10/17 15:12:16
rather than duplicating this logic, suggest replac
gavinp
2012/10/17 20:57:49
Done.
| |
| 269 process_id, url, referrer, size, | 274 process_id, url, referrer, size, |
| 270 session_storage_namespace); | 275 session_storage_namespace); |
| 271 #endif | 276 #endif |
| 272 } | 277 } |
| 273 | 278 |
| 274 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( | 279 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( |
| 275 const GURL& url, | 280 const GURL& url, |
| 276 SessionStorageNamespace* session_storage_namespace, | 281 SessionStorageNamespace* session_storage_namespace, |
| 277 const gfx::Size& size) { | 282 const gfx::Size& size) { |
| 278 if (!IsOmniboxEnabled(profile_)) | 283 if (!IsOmniboxEnabled(profile_)) |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 int process_id, | 985 int process_id, |
| 981 const GURL& url_arg, | 986 const GURL& url_arg, |
| 982 const content::Referrer& referrer, | 987 const content::Referrer& referrer, |
| 983 const gfx::Size& size, | 988 const gfx::Size& size, |
| 984 SessionStorageNamespace* session_storage_namespace) { | 989 SessionStorageNamespace* session_storage_namespace) { |
| 985 DCHECK(CalledOnValidThread()); | 990 DCHECK(CalledOnValidThread()); |
| 986 | 991 |
| 987 if (!IsEnabled()) | 992 if (!IsEnabled()) |
| 988 return NULL; | 993 return NULL; |
| 989 | 994 |
| 990 if (origin == ORIGIN_LINK_REL_PRERENDER && | 995 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
| 996 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && | |
|
mmenke
2012/10/17 15:12:16
Random comment: Wonder if we even need an origin
| |
| 991 IsGoogleSearchResultURL(referrer.url)) { | 997 IsGoogleSearchResultURL(referrer.url)) { |
| 992 origin = ORIGIN_GWS_PRERENDER; | 998 origin = ORIGIN_GWS_PRERENDER; |
| 993 } | 999 } |
| 994 | 1000 |
| 995 DeleteOldEntries(); | 1001 DeleteOldEntries(); |
| 996 DeletePendingDeleteEntries(); | 1002 DeletePendingDeleteEntries(); |
| 997 | 1003 |
| 998 GURL url = url_arg; | 1004 GURL url = url_arg; |
| 999 GURL alias_url; | 1005 GURL alias_url; |
| 1000 uint8 experiment = GetQueryStringBasedExperiment(url_arg); | 1006 uint8 experiment = GetQueryStringBasedExperiment(url_arg); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1363 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1369 if (!render_process_host || !render_process_host->GetBrowserContext()) |
| 1364 return NULL; | 1370 return NULL; |
| 1365 Profile* profile = Profile::FromBrowserContext( | 1371 Profile* profile = Profile::FromBrowserContext( |
| 1366 render_process_host->GetBrowserContext()); | 1372 render_process_host->GetBrowserContext()); |
| 1367 if (!profile) | 1373 if (!profile) |
| 1368 return NULL; | 1374 return NULL; |
| 1369 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1375 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
| 1370 } | 1376 } |
| 1371 | 1377 |
| 1372 } // namespace prerender | 1378 } // namespace prerender |
| OLD | NEW |