OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/ui/auto_login_prompter.h" | 23 #include "chrome/browser/ui/auto_login_prompter.h" |
24 #include "chrome/browser/ui/login/login_prompt.h" | 24 #include "chrome/browser/ui/login/login_prompt.h" |
25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/extensions/user_script.h" | 26 #include "chrome/common/extensions/user_script.h" |
27 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
28 #include "content/browser/renderer_host/render_view_host.h" | 28 #include "content/browser/renderer_host/render_view_host.h" |
29 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 29 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
30 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 30 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
31 #include "content/browser/renderer_host/resource_message_filter.h" | 31 #include "content/browser/renderer_host/resource_message_filter.h" |
32 #include "content/browser/resource_context.h" | 32 #include "content/browser/resource_context.h" |
33 #include "content/common/resource_messages.h" | |
34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
36 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
37 #include "net/base/ssl_config_service.h" | 36 #include "net/base/ssl_config_service.h" |
38 | 37 |
39 // TODO(oshima): Enable this for other platforms. | 38 // TODO(oshima): Enable this for other platforms. |
40 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
41 #include "chrome/browser/renderer_host/offline_resource_handler.h" | 40 #include "chrome/browser/renderer_host/offline_resource_handler.h" |
42 #endif | 41 #endif |
43 | 42 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 : resource_dispatcher_host_(resource_dispatcher_host), | 95 : resource_dispatcher_host_(resource_dispatcher_host), |
97 download_request_limiter_(g_browser_process->download_request_limiter()), | 96 download_request_limiter_(g_browser_process->download_request_limiter()), |
98 safe_browsing_(g_browser_process->safe_browsing_service()), | 97 safe_browsing_(g_browser_process->safe_browsing_service()), |
99 prerender_tracker_(prerender_tracker) { | 98 prerender_tracker_(prerender_tracker) { |
100 } | 99 } |
101 | 100 |
102 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { | 101 ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() { |
103 } | 102 } |
104 | 103 |
105 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( | 104 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( |
106 int child_id, int route_id, | 105 int child_id, |
107 const ResourceHostMsg_Request& request_data, | 106 int route_id, |
| 107 const std::string& method, |
| 108 const GURL& url, |
| 109 ResourceType::Type resource_type, |
108 const content::ResourceContext& resource_context, | 110 const content::ResourceContext& resource_context, |
109 const GURL& referrer) { | 111 const GURL& referrer) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
111 | 113 |
112 // Handle a PREFETCH resource type. If prefetch is disabled, squelch the | 114 // Handle a PREFETCH resource type. If prefetch is disabled, squelch the |
113 // request. Otherwise, do a normal request to warm the cache. | 115 // request. Otherwise, do a normal request to warm the cache. |
114 if (request_data.resource_type == ResourceType::PREFETCH) { | 116 if (resource_type == ResourceType::PREFETCH) { |
115 // All PREFETCH requests should be GETs, but be defensive about it. | 117 // All PREFETCH requests should be GETs, but be defensive about it. |
116 if (request_data.method != "GET") | 118 if (method != "GET") |
117 return false; | 119 return false; |
118 | 120 |
119 // If prefetch is disabled, kill the request. | 121 // If prefetch is disabled, kill the request. |
120 if (!ResourceDispatcherHost::is_prefetch_enabled()) | 122 if (!ResourceDispatcherHost::is_prefetch_enabled()) |
121 return false; | 123 return false; |
122 } | 124 } |
123 | 125 |
124 // Handle a PRERENDER motivated request. Very similar to rel=prefetch, these | 126 // Handle a PRERENDER motivated request. Very similar to rel=prefetch, these |
125 // rel=prerender requests instead launch an early render of the entire page. | 127 // rel=prerender requests instead launch an early render of the entire page. |
126 if (request_data.resource_type == ResourceType::PRERENDER) { | 128 if (resource_type == ResourceType::PRERENDER) { |
127 if (prerender::PrerenderManager::IsPrerenderingPossible()) { | 129 if (prerender::PrerenderManager::IsPrerenderingPossible()) { |
128 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 130 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
129 base::Bind(&AddPrerenderOnUI, | 131 base::Bind(&AddPrerenderOnUI, child_id, route_id, url, referrer)); |
130 child_id, | |
131 route_id, | |
132 request_data.url, | |
133 referrer)); | |
134 } | 132 } |
135 // Prerendering or not, this request should be aborted. | 133 // Prerendering or not, this request should be aborted. |
136 return false; | 134 return false; |
137 } | 135 } |
138 | 136 |
139 // Abort any prerenders that spawn requests that use invalid HTTP methods. | 137 // Abort any prerenders that spawn requests that use invalid HTTP methods. |
140 if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id) && | 138 if (prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id) && |
141 !prerender::PrerenderManager::IsValidHttpMethod(request_data.method)) { | 139 !prerender::PrerenderManager::IsValidHttpMethod(method)) { |
142 prerender_tracker_->TryCancelOnIOThread( | 140 prerender_tracker_->TryCancelOnIOThread( |
143 child_id, route_id, | 141 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD); |
144 prerender::FINAL_STATUS_INVALID_HTTP_METHOD); | |
145 return false; | 142 return false; |
146 } | 143 } |
147 | 144 |
148 return true; | 145 return true; |
149 } | 146 } |
150 | 147 |
151 ResourceHandler* ChromeResourceDispatcherHostDelegate::RequestBeginning( | 148 ResourceHandler* ChromeResourceDispatcherHostDelegate::RequestBeginning( |
152 ResourceHandler* handler, | 149 ResourceHandler* handler, |
153 net::URLRequest* request, | 150 net::URLRequest* request, |
154 const content::ResourceContext& resource_context, | 151 const content::ResourceContext& resource_context, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 AutoLoginPrompter::ShowInfoBarIfPossible(request, info->child_id(), | 346 AutoLoginPrompter::ShowInfoBarIfPossible(request, info->child_id(), |
350 info->route_id()); | 347 info->route_id()); |
351 } | 348 } |
352 | 349 |
353 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( | 350 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( |
354 net::URLRequest* request, | 351 net::URLRequest* request, |
355 ResourceResponse* response, | 352 ResourceResponse* response, |
356 ResourceMessageFilter* filter) { | 353 ResourceMessageFilter* filter) { |
357 LoadTimingObserver::PopulateTimingInfo(request, response); | 354 LoadTimingObserver::PopulateTimingInfo(request, response); |
358 } | 355 } |
OLD | NEW |