| 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/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/download/download_request_limiter.h" | 10 #include "chrome/browser/download/download_request_limiter.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "chrome/browser/renderer_host/offline_resource_throttle.h" | 43 #include "chrome/browser/renderer_host/offline_resource_throttle.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 using content::BrowserThread; | 46 using content::BrowserThread; |
| 47 using content::RenderViewHost; | 47 using content::RenderViewHost; |
| 48 using content::ResourceDispatcherHostLoginDelegate; | 48 using content::ResourceDispatcherHostLoginDelegate; |
| 49 using content::ResourceRequestInfo; | 49 using content::ResourceRequestInfo; |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 | 52 |
| 53 void AddPrerenderOnUI( | |
| 54 int render_process_id, int render_view_id, | |
| 55 const GURL& url, const content::Referrer& referrer) { | |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 57 prerender::PrerenderManager* prerender_manager = | |
| 58 prerender::FindPrerenderManagerUsingRenderProcessId(render_process_id); | |
| 59 if (!prerender_manager) | |
| 60 return; | |
| 61 | |
| 62 prerender_manager->AddPrerenderFromLinkRelPrerender(render_process_id, | |
| 63 render_view_id, | |
| 64 url, | |
| 65 referrer); | |
| 66 } | |
| 67 | |
| 68 void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) { | 53 void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) { |
| 69 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, | 54 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, |
| 70 render_view_id); | 55 render_view_id); |
| 71 if (!rvh) | 56 if (!rvh) |
| 72 return; | 57 return; |
| 73 | 58 |
| 74 content::NotificationService::current()->Notify( | 59 content::NotificationService::current()->Notify( |
| 75 chrome::NOTIFICATION_DOWNLOAD_INITIATED, | 60 chrome::NOTIFICATION_DOWNLOAD_INITIATED, |
| 76 content::Source<RenderViewHost>(rvh), | 61 content::Source<RenderViewHost>(rvh), |
| 77 content::NotificationService::NoDetails()); | 62 content::NotificationService::NoDetails()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 105 if (resource_type == ResourceType::PREFETCH) { | 90 if (resource_type == ResourceType::PREFETCH) { |
| 106 // All PREFETCH requests should be GETs, but be defensive about it. | 91 // All PREFETCH requests should be GETs, but be defensive about it. |
| 107 if (method != "GET") | 92 if (method != "GET") |
| 108 return false; | 93 return false; |
| 109 | 94 |
| 110 // If prefetch is disabled, kill the request. | 95 // If prefetch is disabled, kill the request. |
| 111 if (!prerender::PrerenderManager::IsPrefetchEnabled()) | 96 if (!prerender::PrerenderManager::IsPrefetchEnabled()) |
| 112 return false; | 97 return false; |
| 113 } | 98 } |
| 114 | 99 |
| 115 // Handle a PRERENDER motivated request. Very similar to rel=prefetch, these | |
| 116 // rel=prerender requests instead launch an early render of the entire page. | |
| 117 if (resource_type == ResourceType::PRERENDER) { | |
| 118 if (prerender::PrerenderManager::IsPrerenderingPossible()) { | |
| 119 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 120 base::Bind(&AddPrerenderOnUI, child_id, route_id, url, referrer)); | |
| 121 } | |
| 122 // Prerendering or not, this request should be aborted. | |
| 123 return false; | |
| 124 } | |
| 125 | |
| 126 // Abort any prerenders that spawn requests that use invalid HTTP methods. | 100 // Abort any prerenders that spawn requests that use invalid HTTP methods. |
| 127 if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id) && | 101 if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id) && |
| 128 !prerender::PrerenderManager::IsValidHttpMethod(method)) { | 102 !prerender::PrerenderManager::IsValidHttpMethod(method)) { |
| 129 prerender_tracker_->TryCancelOnIOThread( | 103 prerender_tracker_->TryCancelOnIOThread( |
| 130 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD); | 104 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD); |
| 131 return false; | 105 return false; |
| 132 } | 106 } |
| 133 | 107 |
| 134 return true; | 108 return true; |
| 135 } | 109 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 311 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 338 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 312 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 339 | 313 |
| 340 // See if the response contains the Google-Accounts-SignIn header. If so, | 314 // See if the response contains the Google-Accounts-SignIn header. If so, |
| 341 // then the user has just finished signing in, and the server is allowing the | 315 // then the user has just finished signing in, and the server is allowing the |
| 342 // browser to suggest connecting the user's profile to the account. | 316 // browser to suggest connecting the user's profile to the account. |
| 343 OneClickSigninHelper::ShowInfoBarIfPossible(request, info->GetChildID(), | 317 OneClickSigninHelper::ShowInfoBarIfPossible(request, info->GetChildID(), |
| 344 info->GetRouteID()); | 318 info->GetRouteID()); |
| 345 #endif | 319 #endif |
| 346 } | 320 } |
| OLD | NEW |