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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 int route_id, | 220 int route_id, |
221 const GURL& url, | 221 const GURL& url, |
222 const content::Referrer& referrer, | 222 const content::Referrer& referrer, |
223 const gfx::Size& size) { | 223 const gfx::Size& size) { |
224 #if defined(OS_ANDROID) | 224 #if defined(OS_ANDROID) |
225 // TODO(jcivelli): http://crbug.com/113322 We should have an option to disable | 225 // TODO(jcivelli): http://crbug.com/113322 We should have an option to disable |
226 // link-prerender and enable omnibox-prerender only. | 226 // link-prerender and enable omnibox-prerender only. |
227 return NULL; | 227 return NULL; |
228 #else | 228 #else |
229 DCHECK(!size.IsEmpty()); | 229 DCHECK(!size.IsEmpty()); |
230 if (PrerenderData* parent_prerender_data = | 230 bool is_same_domain = false; |
mmenke
2012/10/05 21:15:44
Having an origin here instead of a bool would remo
| |
231 FindPrerenderDataForChildAndRoute(process_id, route_id)) { | 231 SessionStorageNamespace* session_storage_namespace = NULL; |
232 // Instead of prerendering from inside of a running prerender, we will defer | |
233 // this request until its launcher is made visible. | |
234 if (PrerenderContents* contents = parent_prerender_data->contents_) { | |
235 pending_prerender_list_.push_back( | |
236 linked_ptr<PrerenderData>(new PrerenderData(this))); | |
237 PrerenderHandle* prerender_handle = | |
238 new PrerenderHandle(pending_prerender_list_.back().get()); | |
239 contents->AddPendingPrerender( | |
240 prerender_handle->weak_ptr_factory_.GetWeakPtr(), | |
241 ORIGIN_LINK_REL_PRERENDER, url, referrer, size); | |
242 return prerender_handle; | |
243 } | |
244 } | |
245 | |
246 // Unit tests pass in a process_id == -1. | 232 // Unit tests pass in a process_id == -1. |
247 SessionStorageNamespace* session_storage_namespace = NULL; | |
248 if (process_id != -1) { | 233 if (process_id != -1) { |
249 RenderViewHost* source_render_view_host = | 234 RenderViewHost* source_render_view_host = |
250 RenderViewHost::FromID(process_id, route_id); | 235 RenderViewHost::FromID(process_id, route_id); |
251 if (!source_render_view_host) | 236 if (!source_render_view_host) |
252 return NULL; | 237 return NULL; |
253 WebContents* source_web_contents = | 238 WebContents* source_web_contents = |
254 WebContents::FromRenderViewHost(source_render_view_host); | 239 WebContents::FromRenderViewHost(source_render_view_host); |
255 if (!source_web_contents) | 240 if (!source_web_contents) |
256 return NULL; | 241 return NULL; |
242 is_same_domain = (source_web_contents->GetURL().host() == url.host()); | |
mmenke
2012/10/05 21:15:44
Nothing actionable, but just noting that cross dom
| |
257 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 243 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
258 session_storage_namespace = | 244 session_storage_namespace = |
259 source_web_contents->GetController() | 245 source_web_contents->GetController() |
260 .GetDefaultSessionStorageNamespace(); | 246 .GetDefaultSessionStorageNamespace(); |
261 } | 247 } |
262 | 248 |
263 return AddPrerender(ORIGIN_LINK_REL_PRERENDER, | 249 if (PrerenderData* parent_prerender_data = |
250 FindPrerenderDataForChildAndRoute(process_id, route_id)) { | |
251 // Instead of prerendering from inside of a running prerender, we will defer | |
252 // this request until its launcher is made visible. | |
253 if (PrerenderContents* contents = parent_prerender_data->contents_) { | |
254 pending_prerender_list_.push_back( | |
255 linked_ptr<PrerenderData>(new PrerenderData(this))); | |
256 PrerenderHandle* prerender_handle = | |
257 new PrerenderHandle(pending_prerender_list_.back().get()); | |
258 contents->AddPendingPrerender( | |
259 prerender_handle->weak_ptr_factory_.GetWeakPtr(), | |
260 is_same_domain ? ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN | |
261 : ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN, | |
262 url, referrer, size); | |
263 return prerender_handle; | |
264 } | |
265 } | |
266 | |
267 return AddPrerender(is_same_domain ? ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN | |
268 : ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN, | |
264 process_id, url, referrer, size, | 269 process_id, url, referrer, size, |
265 session_storage_namespace); | 270 session_storage_namespace); |
266 #endif | 271 #endif |
267 } | 272 } |
268 | 273 |
269 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( | 274 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( |
270 const GURL& url, | 275 const GURL& url, |
271 SessionStorageNamespace* session_storage_namespace, | 276 SessionStorageNamespace* session_storage_namespace, |
272 const gfx::Size& size) { | 277 const gfx::Size& size) { |
273 if (!IsOmniboxEnabled(profile_)) | 278 if (!IsOmniboxEnabled(profile_)) |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 int process_id, | 956 int process_id, |
952 const GURL& url_arg, | 957 const GURL& url_arg, |
953 const content::Referrer& referrer, | 958 const content::Referrer& referrer, |
954 const gfx::Size& size, | 959 const gfx::Size& size, |
955 SessionStorageNamespace* session_storage_namespace) { | 960 SessionStorageNamespace* session_storage_namespace) { |
956 DCHECK(CalledOnValidThread()); | 961 DCHECK(CalledOnValidThread()); |
957 | 962 |
958 if (!IsEnabled()) | 963 if (!IsEnabled()) |
959 return NULL; | 964 return NULL; |
960 | 965 |
961 if (origin == ORIGIN_LINK_REL_PRERENDER && | 966 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
967 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && | |
962 IsGoogleSearchResultURL(referrer.url)) { | 968 IsGoogleSearchResultURL(referrer.url)) { |
963 origin = ORIGIN_GWS_PRERENDER; | 969 origin = ORIGIN_GWS_PRERENDER; |
964 } | 970 } |
965 | 971 |
966 DeleteOldEntries(); | 972 DeleteOldEntries(); |
967 DeletePendingDeleteEntries(); | 973 DeletePendingDeleteEntries(); |
968 | 974 |
969 GURL url = url_arg; | 975 GURL url = url_arg; |
970 GURL alias_url; | 976 GURL alias_url; |
971 uint8 experiment = GetQueryStringBasedExperiment(url_arg); | 977 uint8 experiment = GetQueryStringBasedExperiment(url_arg); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1334 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1340 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1335 return NULL; | 1341 return NULL; |
1336 Profile* profile = Profile::FromBrowserContext( | 1342 Profile* profile = Profile::FromBrowserContext( |
1337 render_process_host->GetBrowserContext()); | 1343 render_process_host->GetBrowserContext()); |
1338 if (!profile) | 1344 if (!profile) |
1339 return NULL; | 1345 return NULL; |
1340 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1346 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1341 } | 1347 } |
1342 | 1348 |
1343 } // namespace prerender | 1349 } // namespace prerender |
OLD | NEW |