Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc

Issue 425653002: content: ResourceType cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: REBASE Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 url, 219 url,
220 render_process_id, 220 render_process_id,
221 render_view_id, 221 render_view_id,
222 g_external_protocol_handler_delegate); 222 g_external_protocol_handler_delegate);
223 } 223 }
224 #endif // !defined(OS_ANDROID) 224 #endif // !defined(OS_ANDROID)
225 225
226 void AppendComponentUpdaterThrottles( 226 void AppendComponentUpdaterThrottles(
227 net::URLRequest* request, 227 net::URLRequest* request,
228 content::ResourceContext* resource_context, 228 content::ResourceContext* resource_context,
229 ResourceType::Type resource_type, 229 ResourceType resource_type,
230 ScopedVector<content::ResourceThrottle>* throttles) { 230 ScopedVector<content::ResourceThrottle>* throttles) {
231 const char* crx_id = NULL; 231 const char* crx_id = NULL;
232 component_updater::ComponentUpdateService* cus = 232 component_updater::ComponentUpdateService* cus =
233 g_browser_process->component_updater(); 233 g_browser_process->component_updater();
234 if (!cus) 234 if (!cus)
235 return; 235 return;
236 // Check for PNaCl pexe request. 236 // Check for PNaCl pexe request.
237 if (resource_type == ResourceType::OBJECT) { 237 if (resource_type == content::RESOURCE_TYPE_OBJECT) {
238 const net::HttpRequestHeaders& headers = request->extra_request_headers(); 238 const net::HttpRequestHeaders& headers = request->extra_request_headers();
239 std::string accept_headers; 239 std::string accept_headers;
240 if (headers.GetHeader("Accept", &accept_headers)) { 240 if (headers.GetHeader("Accept", &accept_headers)) {
241 if (accept_headers.find("application/x-pnacl") != std::string::npos && 241 if (accept_headers.find("application/x-pnacl") != std::string::npos &&
242 pnacl::NeedsOnDemandUpdate()) 242 pnacl::NeedsOnDemandUpdate())
243 crx_id = "hnimpnehoodheedghdeeijklkeaacbdc"; 243 crx_id = "hnimpnehoodheedghdeeijklkeaacbdc";
244 } 244 }
245 } 245 }
246 246
247 if (crx_id) { 247 if (crx_id) {
(...skipping 20 matching lines...) Expand all
268 #if defined(ENABLE_EXTENSIONS) 268 #if defined(ENABLE_EXTENSIONS)
269 CHECK(stream_target_info_.empty()); 269 CHECK(stream_target_info_.empty());
270 #endif 270 #endif
271 } 271 }
272 272
273 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest( 273 bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest(
274 int child_id, 274 int child_id,
275 int route_id, 275 int route_id,
276 const std::string& method, 276 const std::string& method,
277 const GURL& url, 277 const GURL& url,
278 ResourceType::Type resource_type, 278 ResourceType resource_type,
279 content::ResourceContext* resource_context) { 279 content::ResourceContext* resource_context) {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
281 281
282 // Handle a PREFETCH resource type. If prefetch is disabled, squelch the 282 // Handle a PREFETCH resource type. If prefetch is disabled, squelch the
283 // request. Otherwise, do a normal request to warm the cache. 283 // request. Otherwise, do a normal request to warm the cache.
284 if (resource_type == ResourceType::PREFETCH) { 284 if (resource_type == content::RESOURCE_TYPE_PREFETCH) {
285 // All PREFETCH requests should be GETs, but be defensive about it. 285 // All PREFETCH requests should be GETs, but be defensive about it.
286 if (method != "GET") 286 if (method != "GET")
287 return false; 287 return false;
288 288
289 // If prefetch is disabled, kill the request. 289 // If prefetch is disabled, kill the request.
290 if (!prefetch::IsPrefetchEnabled(resource_context)) 290 if (!prefetch::IsPrefetchEnabled(resource_context))
291 return false; 291 return false;
292 } 292 }
293 293
294 return true; 294 return true;
295 } 295 }
296 296
297 void ChromeResourceDispatcherHostDelegate::RequestBeginning( 297 void ChromeResourceDispatcherHostDelegate::RequestBeginning(
298 net::URLRequest* request, 298 net::URLRequest* request,
299 content::ResourceContext* resource_context, 299 content::ResourceContext* resource_context,
300 content::AppCacheService* appcache_service, 300 content::AppCacheService* appcache_service,
301 ResourceType::Type resource_type, 301 ResourceType resource_type,
302 int child_id, 302 int child_id,
303 int route_id, 303 int route_id,
304 ScopedVector<content::ResourceThrottle>* throttles) { 304 ScopedVector<content::ResourceThrottle>* throttles) {
305 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 305 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
306 bool is_prerendering = 306 bool is_prerendering =
307 info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender; 307 info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender;
308 if (is_prerendering) { 308 if (is_prerendering) {
309 // Requests with the IGNORE_LIMITS flag set (i.e., sync XHRs) 309 // Requests with the IGNORE_LIMITS flag set (i.e., sync XHRs)
310 // should remain at MAXIMUM_PRIORITY. 310 // should remain at MAXIMUM_PRIORITY.
311 if (request->load_flags() & net::LOAD_IGNORE_LIMITS) { 311 if (request->load_flags() & net::LOAD_IGNORE_LIMITS) {
312 DCHECK_EQ(request->priority(), net::MAXIMUM_PRIORITY); 312 DCHECK_EQ(request->priority(), net::MAXIMUM_PRIORITY);
313 } else { 313 } else {
314 request->SetPriority(net::IDLE); 314 request->SetPriority(net::IDLE);
315 } 315 }
316 } 316 }
317 317
318 ProfileIOData* io_data = ProfileIOData::FromResourceContext( 318 ProfileIOData* io_data = ProfileIOData::FromResourceContext(
319 resource_context); 319 resource_context);
320 320
321 #if defined(OS_ANDROID) 321 #if defined(OS_ANDROID)
322 // TODO(davidben): This is insufficient to integrate with prerender properly. 322 // TODO(davidben): This is insufficient to integrate with prerender properly.
323 // https://crbug.com/370595 323 // https://crbug.com/370595
324 if (resource_type == ResourceType::MAIN_FRAME && !is_prerendering) { 324 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME && !is_prerendering) {
325 throttles->push_back( 325 throttles->push_back(
326 InterceptNavigationDelegate::CreateThrottleFor(request)); 326 InterceptNavigationDelegate::CreateThrottleFor(request));
327 } 327 }
328 #else 328 #else
329 if (resource_type == ResourceType::MAIN_FRAME) { 329 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
330 // Redirect some navigations to apps that have registered matching URL 330 // Redirect some navigations to apps that have registered matching URL
331 // handlers ('url_handlers' in the manifest). 331 // handlers ('url_handlers' in the manifest).
332 content::ResourceThrottle* url_to_app_throttle = 332 content::ResourceThrottle* url_to_app_throttle =
333 AppUrlRedirector::MaybeCreateThrottleFor(request, io_data); 333 AppUrlRedirector::MaybeCreateThrottleFor(request, io_data);
334 if (url_to_app_throttle) 334 if (url_to_app_throttle)
335 throttles->push_back(url_to_app_throttle); 335 throttles->push_back(url_to_app_throttle);
336 336
337 if (!is_prerendering) { 337 if (!is_prerendering) {
338 // Experimental: Launch ephemeral apps from search results. 338 // Experimental: Launch ephemeral apps from search results.
339 content::ResourceThrottle* ephemeral_app_throttle = 339 content::ResourceThrottle* ephemeral_app_throttle =
340 EphemeralAppThrottle::MaybeCreateThrottleForLaunch( 340 EphemeralAppThrottle::MaybeCreateThrottleForLaunch(
341 request, io_data); 341 request, io_data);
342 if (ephemeral_app_throttle) 342 if (ephemeral_app_throttle)
343 throttles->push_back(ephemeral_app_throttle); 343 throttles->push_back(ephemeral_app_throttle);
344 } 344 }
345 } 345 }
346 #endif 346 #endif
347 347
348 #if defined(OS_CHROMEOS) 348 #if defined(OS_CHROMEOS)
349 // Check if we need to add offline throttle. This should be done only 349 // Check if we need to add offline throttle. This should be done only
350 // for main frames. 350 // for main frames.
351 if (resource_type == ResourceType::MAIN_FRAME) { 351 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
352 // We check offline first, then check safe browsing so that we still can 352 // We check offline first, then check safe browsing so that we still can
353 // block unsafe site after we remove offline page. 353 // block unsafe site after we remove offline page.
354 throttles->push_back(new OfflineResourceThrottle(request, 354 throttles->push_back(new OfflineResourceThrottle(request,
355 appcache_service)); 355 appcache_service));
356 } 356 }
357 357
358 // Check if we need to add merge session throttle. This throttle will postpone 358 // Check if we need to add merge session throttle. This throttle will postpone
359 // loading of main frames and XHR request. 359 // loading of main frames and XHR request.
360 if (resource_type == ResourceType::MAIN_FRAME || 360 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME ||
361 resource_type == ResourceType::XHR) { 361 resource_type == content::RESOURCE_TYPE_XHR) {
362 // Add interstitial page while merge session process (cookie 362 // Add interstitial page while merge session process (cookie
363 // reconstruction from OAuth2 refresh token in ChromeOS login) is still in 363 // reconstruction from OAuth2 refresh token in ChromeOS login) is still in
364 // progress while we are attempting to load a google property. 364 // progress while we are attempting to load a google property.
365 if (!MergeSessionThrottle::AreAllSessionMergedAlready() && 365 if (!MergeSessionThrottle::AreAllSessionMergedAlready() &&
366 request->url().SchemeIsHTTPOrHTTPS()) { 366 request->url().SchemeIsHTTPOrHTTPS()) {
367 throttles->push_back(new MergeSessionThrottle(request, resource_type)); 367 throttles->push_back(new MergeSessionThrottle(request, resource_type));
368 } 368 }
369 } 369 }
370 #endif 370 #endif
371 371
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 new chrome::InterceptDownloadResourceThrottle( 436 new chrome::InterceptDownloadResourceThrottle(
437 request, child_id, route_id, request_id)); 437 request, child_id, route_id, request_id));
438 #endif 438 #endif
439 } 439 }
440 440
441 // If this isn't a new request, we've seen this before and added the standard 441 // If this isn't a new request, we've seen this before and added the standard
442 // resource throttles already so no need to add it again. 442 // resource throttles already so no need to add it again.
443 if (!request->is_pending()) { 443 if (!request->is_pending()) {
444 AppendStandardResourceThrottles(request, 444 AppendStandardResourceThrottles(request,
445 resource_context, 445 resource_context,
446 ResourceType::MAIN_FRAME, 446 content::RESOURCE_TYPE_MAIN_FRAME,
447 throttles); 447 throttles);
448 } 448 }
449 } 449 }
450 450
451 ResourceDispatcherHostLoginDelegate* 451 ResourceDispatcherHostLoginDelegate*
452 ChromeResourceDispatcherHostDelegate::CreateLoginDelegate( 452 ChromeResourceDispatcherHostDelegate::CreateLoginDelegate(
453 net::AuthChallengeInfo* auth_info, net::URLRequest* request) { 453 net::AuthChallengeInfo* auth_info, net::URLRequest* request) {
454 return CreateLoginPrompt(auth_info, request); 454 return CreateLoginPrompt(auth_info, request);
455 } 455 }
456 456
(...skipping 16 matching lines...) Expand all
473 BrowserThread::PostTask(BrowserThread::UI, 473 BrowserThread::PostTask(BrowserThread::UI,
474 FROM_HERE, 474 FROM_HERE,
475 base::Bind(&LaunchURL, url, child_id, route_id)); 475 base::Bind(&LaunchURL, url, child_id, route_id));
476 return true; 476 return true;
477 #endif 477 #endif
478 } 478 }
479 479
480 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( 480 void ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles(
481 net::URLRequest* request, 481 net::URLRequest* request,
482 content::ResourceContext* resource_context, 482 content::ResourceContext* resource_context,
483 ResourceType::Type resource_type, 483 ResourceType resource_type,
484 ScopedVector<content::ResourceThrottle>* throttles) { 484 ScopedVector<content::ResourceThrottle>* throttles) {
485 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 485 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
486 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) 486 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
487 // Insert safe browsing at the front of the list, so it gets to decide on 487 // Insert safe browsing at the front of the list, so it gets to decide on
488 // policies first. 488 // policies first.
489 if (io_data->safe_browsing_enabled()->GetValue() 489 if (io_data->safe_browsing_enabled()->GetValue()
490 #if defined(OS_ANDROID) 490 #if defined(OS_ANDROID)
491 || io_data->IsDataReductionProxyEnabled() 491 || io_data->IsDataReductionProxyEnabled()
492 #endif 492 #endif
493 ) { 493 ) {
494 bool is_subresource_request = resource_type != ResourceType::MAIN_FRAME; 494 bool is_subresource_request =
495 resource_type != content::RESOURCE_TYPE_MAIN_FRAME;
495 content::ResourceThrottle* throttle = 496 content::ResourceThrottle* throttle =
496 SafeBrowsingResourceThrottleFactory::Create(request, 497 SafeBrowsingResourceThrottleFactory::Create(request,
497 resource_context, 498 resource_context,
498 is_subresource_request, 499 is_subresource_request,
499 safe_browsing_.get()); 500 safe_browsing_.get());
500 if (throttle) 501 if (throttle)
501 throttles->push_back(throttle); 502 throttles->push_back(throttle);
502 } 503 }
503 #endif 504 #endif
504 505
505 #if defined(ENABLE_MANAGED_USERS) 506 #if defined(ENABLE_MANAGED_USERS)
506 bool is_subresource_request = resource_type != ResourceType::MAIN_FRAME; 507 bool is_subresource_request =
508 resource_type != content::RESOURCE_TYPE_MAIN_FRAME;
507 throttles->push_back(new SupervisedUserResourceThrottle( 509 throttles->push_back(new SupervisedUserResourceThrottle(
508 request, !is_subresource_request, 510 request, !is_subresource_request,
509 io_data->supervised_user_url_filter())); 511 io_data->supervised_user_url_filter()));
510 #endif 512 #endif
511 513
512 #if defined(ENABLE_EXTENSIONS) 514 #if defined(ENABLE_EXTENSIONS)
513 content::ResourceThrottle* throttle = 515 content::ResourceThrottle* throttle =
514 user_script_listener_->CreateResourceThrottle(request->url(), 516 user_script_listener_->CreateResourceThrottle(request->url(),
515 resource_type); 517 resource_type);
516 if (throttle) 518 if (throttle)
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 url_request->GetTotalReceivedBytes())); 733 url_request->GetTotalReceivedBytes()));
732 } 734 }
733 } 735 }
734 736
735 // static 737 // static
736 void ChromeResourceDispatcherHostDelegate:: 738 void ChromeResourceDispatcherHostDelegate::
737 SetExternalProtocolHandlerDelegateForTesting( 739 SetExternalProtocolHandlerDelegateForTesting(
738 ExternalProtocolHandler::Delegate* delegate) { 740 ExternalProtocolHandler::Delegate* delegate) {
739 g_external_protocol_handler_delegate = delegate; 741 g_external_protocol_handler_delegate = delegate;
740 } 742 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698