| 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/extensions/extension_protocols.h" | 5 #include "chrome/browser/extensions/extension_protocols.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "base/threading/worker_pool.h" | 18 #include "base/threading/worker_pool.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/extensions/extension_info_map.h" | 20 #include "chrome/browser/extensions/extension_info_map.h" |
| 21 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 21 #include "chrome/browser/net/chrome_url_request_context.h" | 22 #include "chrome/browser/net/chrome_url_request_context.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 24 #include "chrome/common/extensions/extension_file_util.h" | 25 #include "chrome/common/extensions/extension_file_util.h" |
| 25 #include "chrome/common/extensions/extension_resource.h" | 26 #include "chrome/common/extensions/extension_resource.h" |
| 26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 27 #include "content/public/browser/resource_request_info.h" | 28 #include "content/public/browser/resource_request_info.h" |
| 28 #include "googleurl/src/url_util.h" | 29 #include "googleurl/src/url_util.h" |
| 29 #include "grit/component_extension_resources_map.h" | 30 #include "grit/component_extension_resources_map.h" |
| 30 #include "net/base/mime_util.h" | 31 #include "net/base/mime_util.h" |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 FilePath resources_path; | 369 FilePath resources_path; |
| 369 FilePath relative_path; | 370 FilePath relative_path; |
| 370 // Try to load extension resources from chrome resource file if | 371 // Try to load extension resources from chrome resource file if |
| 371 // directory_path is a descendant of resources_path. resources_path | 372 // directory_path is a descendant of resources_path. resources_path |
| 372 // corresponds to src/chrome/browser/resources in source tree. | 373 // corresponds to src/chrome/browser/resources in source tree. |
| 373 if (PathService::Get(chrome::DIR_RESOURCES, &resources_path) && | 374 if (PathService::Get(chrome::DIR_RESOURCES, &resources_path) && |
| 374 // Since component extension resources are included in | 375 // Since component extension resources are included in |
| 375 // component_extension_resources.pak file in resources_path, calculate | 376 // component_extension_resources.pak file in resources_path, calculate |
| 376 // extension relative path against resources_path. | 377 // extension relative path against resources_path. |
| 377 resources_path.AppendRelativePath(directory_path, &relative_path)) { | 378 resources_path.AppendRelativePath(directory_path, &relative_path)) { |
| 378 relative_path = relative_path.Append( | 379 FilePath request_path = |
| 379 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); | 380 extension_file_util::ExtensionURLToRelativeFilePath(request->url()); |
| 380 relative_path = relative_path.NormalizePathSeparators(); | 381 int resource_id; |
| 381 | 382 if (ImageLoadingTracker::IsComponentExtensionResource(extension, |
| 382 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to | 383 request_path, &resource_id)) { |
| 383 // covert to FilePaths all the time. This will be more useful as we add | 384 relative_path = relative_path.Append(request_path); |
| 384 // more resources. | 385 relative_path = relative_path.NormalizePathSeparators(); |
| 385 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) { | 386 return new URLRequestResourceBundleJob( |
| 386 FilePath bm_resource_path = | 387 request, |
| 387 FilePath().AppendASCII(kComponentExtensionResources[i].name); | 388 network_delegate, |
| 388 bm_resource_path = bm_resource_path.NormalizePathSeparators(); | 389 relative_path, |
| 389 if (relative_path == bm_resource_path) { | 390 resource_id, |
| 390 return new URLRequestResourceBundleJob( | 391 content_security_policy, |
| 391 request, | 392 send_cors_header); |
| 392 network_delegate, | |
| 393 relative_path, | |
| 394 kComponentExtensionResources[i].value, | |
| 395 content_security_policy, | |
| 396 send_cors_header); | |
| 397 } | |
| 398 } | 393 } |
| 399 } | 394 } |
| 400 | 395 |
| 401 return new URLRequestExtensionJob(request, | 396 return new URLRequestExtensionJob(request, |
| 402 network_delegate, | 397 network_delegate, |
| 403 extension_id, | 398 extension_id, |
| 404 directory_path, | 399 directory_path, |
| 405 content_security_policy, | 400 content_security_policy, |
| 406 send_cors_header); | 401 send_cors_header); |
| 407 } | 402 } |
| 408 | 403 |
| 409 } // namespace | 404 } // namespace |
| 410 | 405 |
| 411 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 406 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
| 412 bool is_incognito, | 407 bool is_incognito, |
| 413 ExtensionInfoMap* extension_info_map) { | 408 ExtensionInfoMap* extension_info_map) { |
| 414 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 409 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
| 415 } | 410 } |
| OLD | NEW |