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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 int route_id, | 215 int route_id, |
216 const GURL& url, | 216 const GURL& url, |
217 const content::Referrer& referrer, | 217 const content::Referrer& referrer, |
218 const gfx::Size& size) { | 218 const gfx::Size& size) { |
219 #if defined(OS_ANDROID) | 219 #if defined(OS_ANDROID) |
220 // TODO(jcivelli): http://crbug.com/113322 We should have an option to disable | 220 // TODO(jcivelli): http://crbug.com/113322 We should have an option to disable |
221 // link-prerender and enable omnibox-prerender only. | 221 // link-prerender and enable omnibox-prerender only. |
222 return NULL; | 222 return NULL; |
223 #else | 223 #else |
224 DCHECK(!size.IsEmpty()); | 224 DCHECK(!size.IsEmpty()); |
225 if (PrerenderData* parent_prerender_data = | 225 bool is_same_domain = false; |
226 FindPrerenderDataForChildAndRoute(process_id, route_id)) { | 226 SessionStorageNamespace* session_storage_namespace = NULL; |
227 // Instead of prerendering from inside of a running prerender, we will defer | |
228 // this request until its launcher is made visible. | |
229 if (PrerenderContents* contents = parent_prerender_data->contents_) { | |
230 pending_prerender_list_.push_back( | |
231 linked_ptr<PrerenderData>(new PrerenderData(this))); | |
232 PrerenderHandle* prerender_handle = | |
233 new PrerenderHandle(pending_prerender_list_.back().get()); | |
234 contents->AddPendingPrerender( | |
235 prerender_handle->weak_ptr_factory_.GetWeakPtr(), | |
236 url, referrer, size); | |
237 return prerender_handle; | |
238 } | |
239 } | |
240 | |
241 // Unit tests pass in a process_id == -1. | 227 // Unit tests pass in a process_id == -1. |
242 SessionStorageNamespace* session_storage_namespace = NULL; | |
243 if (process_id != -1) { | 228 if (process_id != -1) { |
244 RenderViewHost* source_render_view_host = | 229 RenderViewHost* source_render_view_host = |
245 RenderViewHost::FromID(process_id, route_id); | 230 RenderViewHost::FromID(process_id, route_id); |
246 if (!source_render_view_host) | 231 if (!source_render_view_host) |
247 return NULL; | 232 return NULL; |
248 WebContents* source_web_contents = | 233 WebContents* source_web_contents = |
249 WebContents::FromRenderViewHost(source_render_view_host); | 234 WebContents::FromRenderViewHost(source_render_view_host); |
250 if (!source_web_contents) | 235 if (!source_web_contents) |
251 return NULL; | 236 return NULL; |
| 237 is_same_domain = (source_web_contents->GetURL().host() == url.host()); |
252 // TODO(ajwong): This does not correctly handle storage for isolated apps. | 238 // TODO(ajwong): This does not correctly handle storage for isolated apps. |
253 session_storage_namespace = | 239 session_storage_namespace = |
254 source_web_contents->GetController() | 240 source_web_contents->GetController() |
255 .GetDefaultSessionStorageNamespace(); | 241 .GetDefaultSessionStorageNamespace(); |
256 } | 242 } |
257 | 243 |
258 return AddPrerender(ORIGIN_LINK_REL_PRERENDER, | 244 if (PrerenderData* parent_prerender_data = |
| 245 FindPrerenderDataForChildAndRoute(process_id, route_id)) { |
| 246 // Instead of prerendering from inside of a running prerender, we will defer |
| 247 // this request until its launcher is made visible. |
| 248 if (PrerenderContents* contents = parent_prerender_data->contents_) { |
| 249 pending_prerender_list_.push_back( |
| 250 linked_ptr<PrerenderData>(new PrerenderData(this))); |
| 251 PrerenderHandle* prerender_handle = |
| 252 new PrerenderHandle(pending_prerender_list_.back().get()); |
| 253 contents->AddPendingPrerender( |
| 254 prerender_handle->weak_ptr_factory_.GetWeakPtr(), |
| 255 is_same_domain ? ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN |
| 256 : ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN, |
| 257 url, referrer, size); |
| 258 return prerender_handle; |
| 259 } |
| 260 } |
| 261 |
| 262 return AddPrerender(is_same_domain ? ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN |
| 263 : ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN, |
259 process_id, url, referrer, size, | 264 process_id, url, referrer, size, |
260 session_storage_namespace); | 265 session_storage_namespace); |
261 #endif | 266 #endif |
262 } | 267 } |
263 | 268 |
264 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( | 269 PrerenderHandle* PrerenderManager::AddPrerenderFromOmnibox( |
265 const GURL& url, | 270 const GURL& url, |
266 SessionStorageNamespace* session_storage_namespace, | 271 SessionStorageNamespace* session_storage_namespace, |
267 const gfx::Size& size) { | 272 const gfx::Size& size) { |
268 if (!IsOmniboxEnabled(profile_)) | 273 if (!IsOmniboxEnabled(profile_)) |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 int process_id, | 910 int process_id, |
906 const GURL& url_arg, | 911 const GURL& url_arg, |
907 const content::Referrer& referrer, | 912 const content::Referrer& referrer, |
908 const gfx::Size& size, | 913 const gfx::Size& size, |
909 SessionStorageNamespace* session_storage_namespace) { | 914 SessionStorageNamespace* session_storage_namespace) { |
910 DCHECK(CalledOnValidThread()); | 915 DCHECK(CalledOnValidThread()); |
911 | 916 |
912 if (!IsEnabled()) | 917 if (!IsEnabled()) |
913 return NULL; | 918 return NULL; |
914 | 919 |
915 if (origin == ORIGIN_LINK_REL_PRERENDER && | 920 if (origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN && |
916 IsGoogleSearchResultURL(referrer.url)) { | 921 IsGoogleSearchResultURL(referrer.url)) { |
917 origin = ORIGIN_GWS_PRERENDER; | 922 origin = ORIGIN_GWS_PRERENDER; |
918 } | 923 } |
919 | 924 |
920 DeleteOldEntries(); | 925 DeleteOldEntries(); |
921 DeletePendingDeleteEntries(); | 926 DeletePendingDeleteEntries(); |
922 | 927 |
923 GURL url = url_arg; | 928 GURL url = url_arg; |
924 GURL alias_url; | 929 GURL alias_url; |
925 uint8 experiment = GetQueryStringBasedExperiment(url_arg); | 930 uint8 experiment = GetQueryStringBasedExperiment(url_arg); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1293 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1289 return NULL; | 1294 return NULL; |
1290 Profile* profile = Profile::FromBrowserContext( | 1295 Profile* profile = Profile::FromBrowserContext( |
1291 render_process_host->GetBrowserContext()); | 1296 render_process_host->GetBrowserContext()); |
1292 if (!profile) | 1297 if (!profile) |
1293 return NULL; | 1298 return NULL; |
1294 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1299 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1295 } | 1300 } |
1296 | 1301 |
1297 } // namespace prerender | 1302 } // namespace prerender |
OLD | NEW |