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 Origin origin = ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN; |
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 if (source_web_contents->GetURL().host() == url.host()) |
| 248 origin = ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN; |
262 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 249 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
263 session_storage_namespace = | 250 session_storage_namespace = |
264 source_web_contents->GetController() | 251 source_web_contents->GetController() |
265 .GetDefaultSessionStorageNamespace(); | 252 .GetDefaultSessionStorageNamespace(); |
266 } | 253 } |
267 | 254 |
268 return AddPrerender(ORIGIN_LINK_REL_PRERENDER, | 255 if (PrerenderData* parent_prerender_data = |
269 process_id, url, referrer, size, | 256 FindPrerenderDataForChildAndRoute(process_id, route_id)) { |
| 257 // Instead of prerendering from inside of a running prerender, we will defer |
| 258 // this request until its launcher is made visible. |
| 259 if (PrerenderContents* contents = parent_prerender_data->contents_) { |
| 260 pending_prerender_list_.push_back( |
| 261 linked_ptr<PrerenderData>(new PrerenderData(this))); |
| 262 PrerenderHandle* prerender_handle = |
| 263 new PrerenderHandle(pending_prerender_list_.back().get()); |
| 264 contents->AddPendingPrerender( |
| 265 prerender_handle->weak_ptr_factory_.GetWeakPtr(), origin, |
| 266 url, referrer, size); |
| 267 return prerender_handle; |
| 268 } |
| 269 } |
| 270 |
| 271 return AddPrerender(origin, process_id, url, referrer, size, |
270 session_storage_namespace); | 272 session_storage_namespace); |
271 #endif | 273 #endif |
272 } | 274 } |
273 | 275 |
274 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( | 276 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( |
275 const GURL& url, | 277 const GURL& url, |
276 SessionStorageNamespace* session_storage_namespace, | 278 SessionStorageNamespace* session_storage_namespace, |
277 const gfx::Size& size) { | 279 const gfx::Size& size) { |
278 if (!IsOmniboxEnabled(profile_)) | 280 if (!IsOmniboxEnabled(profile_)) |
279 return NULL; | 281 return NULL; |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 int process_id, | 982 int process_id, |
981 const GURL& url_arg, | 983 const GURL& url_arg, |
982 const content::Referrer& referrer, | 984 const content::Referrer& referrer, |
983 const gfx::Size& size, | 985 const gfx::Size& size, |
984 SessionStorageNamespace* session_storage_namespace) { | 986 SessionStorageNamespace* session_storage_namespace) { |
985 DCHECK(CalledOnValidThread()); | 987 DCHECK(CalledOnValidThread()); |
986 | 988 |
987 if (!IsEnabled()) | 989 if (!IsEnabled()) |
988 return NULL; | 990 return NULL; |
989 | 991 |
990 if (origin == ORIGIN_LINK_REL_PRERENDER && | 992 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
| 993 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && |
991 IsGoogleSearchResultURL(referrer.url)) { | 994 IsGoogleSearchResultURL(referrer.url)) { |
992 origin = ORIGIN_GWS_PRERENDER; | 995 origin = ORIGIN_GWS_PRERENDER; |
993 } | 996 } |
994 | 997 |
995 DeleteOldEntries(); | 998 DeleteOldEntries(); |
996 DeletePendingDeleteEntries(); | 999 DeletePendingDeleteEntries(); |
997 | 1000 |
998 GURL url = url_arg; | 1001 GURL url = url_arg; |
999 GURL alias_url; | 1002 GURL alias_url; |
1000 uint8 experiment = GetQueryStringBasedExperiment(url_arg); | 1003 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()) | 1366 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1364 return NULL; | 1367 return NULL; |
1365 Profile* profile = Profile::FromBrowserContext( | 1368 Profile* profile = Profile::FromBrowserContext( |
1366 render_process_host->GetBrowserContext()); | 1369 render_process_host->GetBrowserContext()); |
1367 if (!profile) | 1370 if (!profile) |
1368 return NULL; | 1371 return NULL; |
1369 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1372 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1370 } | 1373 } |
1371 | 1374 |
1372 } // namespace prerender | 1375 } // namespace prerender |
OLD | NEW |