| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( | 492 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( |
| 493 const GURL& url, const std::string& mime_type) { | 493 const GURL& url, const std::string& mime_type) { |
| 494 // Special-case user scripts to get downloaded instead of viewed. | 494 // Special-case user scripts to get downloaded instead of viewed. |
| 495 return extensions::UserScript::IsURLUserScript(url, mime_type); | 495 return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 496 } | 496 } |
| 497 | 497 |
| 498 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( | 498 bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
| 499 content::ResourceContext* resource_context, | 499 content::ResourceContext* resource_context, |
| 500 const GURL& url, | 500 const GURL& url, |
| 501 const std::string& mime_type, | 501 const std::string& mime_type, |
| 502 GURL* security_origin, | 502 GURL* origin, |
| 503 std::string* target_id) { | 503 std::string* target_id) { |
| 504 #if !defined(OS_ANDROID) | 504 #if !defined(OS_ANDROID) |
| 505 ProfileIOData* io_data = | 505 ProfileIOData* io_data = |
| 506 ProfileIOData::FromResourceContext(resource_context); | 506 ProfileIOData::FromResourceContext(resource_context); |
| 507 bool profile_is_incognito = io_data->is_incognito(); | 507 bool profile_is_incognito = io_data->is_incognito(); |
| 508 const scoped_refptr<const ExtensionInfoMap> extension_info_map( | 508 const scoped_refptr<const ExtensionInfoMap> extension_info_map( |
| 509 io_data->GetExtensionInfoMap()); | 509 io_data->GetExtensionInfoMap()); |
| 510 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); | 510 std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); |
| 511 // Go through the white-listed extensions and try to use them to intercept | 511 // Go through the white-listed extensions and try to use them to intercept |
| 512 // the URL request. | 512 // the URL request. |
| 513 for (size_t i = 0; i < whitelist.size(); ++i) { | 513 for (size_t i = 0; i < whitelist.size(); ++i) { |
| 514 const char* extension_id = whitelist[i].c_str(); | 514 const char* extension_id = whitelist[i].c_str(); |
| 515 const Extension* extension = | 515 const Extension* extension = |
| 516 extension_info_map->extensions().GetByID(extension_id); | 516 extension_info_map->extensions().GetByID(extension_id); |
| 517 // The white-listed extension may not be installed, so we have to NULL check | 517 // The white-listed extension may not be installed, so we have to NULL check |
| 518 // |extension|. | 518 // |extension|. |
| 519 if (!extension || | 519 if (!extension || |
| 520 (profile_is_incognito && | 520 (profile_is_incognito && |
| 521 !extension_info_map->IsIncognitoEnabled(extension_id))) { | 521 !extension_info_map->IsIncognitoEnabled(extension_id))) { |
| 522 continue; | 522 continue; |
| 523 } | 523 } |
| 524 | 524 |
| 525 if (ExtensionCanHandleMimeType(extension, mime_type)) { | 525 if (ExtensionCanHandleMimeType(extension, mime_type)) { |
| 526 *security_origin = Extension::GetBaseURLFromExtensionId(extension_id); | 526 *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
| 527 *target_id = extension_id; | 527 *target_id = extension_id; |
| 528 return true; | 528 return true; |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 #endif | 531 #endif |
| 532 return false; | 532 return false; |
| 533 } | 533 } |
| 534 | 534 |
| 535 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( | 535 void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
| 536 content::ResourceContext* resource_context, | 536 content::ResourceContext* resource_context, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 if (!prerender::PrerenderManager::DoesURLHaveValidScheme(redirect_url) && | 633 if (!prerender::PrerenderManager::DoesURLHaveValidScheme(redirect_url) && |
| 634 ResourceRequestInfo::ForRequest(request)->GetAssociatedRenderView( | 634 ResourceRequestInfo::ForRequest(request)->GetAssociatedRenderView( |
| 635 &child_id, &route_id) && | 635 &child_id, &route_id) && |
| 636 prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id)) { | 636 prerender_tracker_->IsPrerenderingOnIOThread(child_id, route_id)) { |
| 637 ReportUnsupportedPrerenderScheme(redirect_url); | 637 ReportUnsupportedPrerenderScheme(redirect_url); |
| 638 prerender_tracker_->TryCancel( | 638 prerender_tracker_->TryCancel( |
| 639 child_id, route_id, prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); | 639 child_id, route_id, prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 640 request->Cancel(); | 640 request->Cancel(); |
| 641 } | 641 } |
| 642 } | 642 } |
| OLD | NEW |