| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_resource_throttle.h" | 5 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // If this is a full prerender, cancel the prerender in response to | 177 // If this is a full prerender, cancel the prerender in response to |
| 178 // invalid requests. For prefetches, cancel invalid requests but keep the | 178 // invalid requests. For prefetches, cancel invalid requests but keep the |
| 179 // prefetch going, unless it's the main frame that's invalid. | 179 // prefetch going, unless it's the main frame that's invalid. |
| 180 if (prerender_contents->prerender_mode() == FULL_PRERENDER || | 180 if (prerender_contents->prerender_mode() == FULL_PRERENDER || |
| 181 resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { | 181 resource_type == content::RESOURCE_TYPE_MAIN_FRAME) { |
| 182 prerender_contents->Destroy(FINAL_STATUS_INVALID_HTTP_METHOD); | 182 prerender_contents->Destroy(FINAL_STATUS_INVALID_HTTP_METHOD); |
| 183 } | 183 } |
| 184 cancel = true; | 184 cancel = true; |
| 185 } else if (!PrerenderManager::DoesSubresourceURLHaveValidScheme(url) && | 185 } else if (!PrerenderManager::DoesSubresourceURLHaveValidScheme(url) && |
| 186 resource_type != content::RESOURCE_TYPE_MAIN_FRAME) { | 186 resource_type != content::RESOURCE_TYPE_MAIN_FRAME) { |
| 187 // Destroying the prerender for unsupported scheme only for non-main | 187 // For OFFLINE_ORIGIN, simply cancel this invalid request and continue. |
| 188 // resource to allow chrome://crash to actually crash in the | 188 // For other origins, fail the prerender here. |
| 189 // *RendererCrash tests instead of being intercepted here. The unsupported | 189 if (prerender_contents->origin() != ORIGIN_OFFLINE) { |
| 190 // scheme for the main resource is checked in WillRedirectRequestOnUI() | 190 // Destroying the prerender for unsupported scheme only for non-main |
| 191 // and PrerenderContents::CheckURL(). See http://crbug.com/673771. | 191 // resource to allow chrome://crash to actually crash in the |
| 192 prerender_contents->Destroy(FINAL_STATUS_UNSUPPORTED_SCHEME); | 192 // *RendererCrash tests instead of being intercepted here. The |
| 193 ReportUnsupportedPrerenderScheme(url); | 193 // unsupported |
| 194 // scheme for the main resource is checked in WillRedirectRequestOnUI() |
| 195 // and PrerenderContents::CheckURL(). See http://crbug.com/673771. |
| 196 prerender_contents->Destroy(FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 197 ReportUnsupportedPrerenderScheme(url); |
| 198 } |
| 194 cancel = true; | 199 cancel = true; |
| 195 #if defined(OS_ANDROID) | 200 #if defined(OS_ANDROID) |
| 196 } else if (resource_type == content::RESOURCE_TYPE_FAVICON) { | 201 } else if (resource_type == content::RESOURCE_TYPE_FAVICON) { |
| 197 // Delay icon fetching until the contents are getting swapped in | 202 // Delay icon fetching until the contents are getting swapped in |
| 198 // to conserve network usage in mobile devices. | 203 // to conserve network usage in mobile devices. |
| 199 prerender_contents->AddResourceThrottle(throttle); | 204 prerender_contents->AddResourceThrottle(throttle); |
| 200 return; | 205 return; |
| 201 #endif | 206 #endif |
| 202 } | 207 } |
| 203 } | 208 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return g_prerender_contents_for_testing; | 290 return g_prerender_contents_for_testing; |
| 286 return PrerenderContents::FromWebContents(web_contents_getter.Run()); | 291 return PrerenderContents::FromWebContents(web_contents_getter.Run()); |
| 287 } | 292 } |
| 288 | 293 |
| 289 void PrerenderResourceThrottle::SetPrerenderMode(PrerenderMode mode) { | 294 void PrerenderResourceThrottle::SetPrerenderMode(PrerenderMode mode) { |
| 290 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 295 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 291 load_flags_ = (mode == PREFETCH_ONLY) ? net::LOAD_PREFETCH : net::LOAD_NORMAL; | 296 load_flags_ = (mode == PREFETCH_ONLY) ? net::LOAD_PREFETCH : net::LOAD_NORMAL; |
| 292 } | 297 } |
| 293 | 298 |
| 294 } // namespace prerender | 299 } // namespace prerender |
| OLD | NEW |