Chromium Code Reviews| 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/file_util.h" | |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 16 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "chrome/browser/extensions/extension_info_map.h" | 19 #include "chrome/browser/extensions/extension_info_map.h" |
| 19 #include "chrome/browser/net/chrome_url_request_context.h" | 20 #include "chrome/browser/net/chrome_url_request_context.h" |
| 20 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 234 |
| 234 virtual net::URLRequestJob* MaybeCreateJob( | 235 virtual net::URLRequestJob* MaybeCreateJob( |
| 235 net::URLRequest* request) const OVERRIDE; | 236 net::URLRequest* request) const OVERRIDE; |
| 236 | 237 |
| 237 private: | 238 private: |
| 238 const bool is_incognito_; | 239 const bool is_incognito_; |
| 239 ExtensionInfoMap* const extension_info_map_; | 240 ExtensionInfoMap* const extension_info_map_; |
| 240 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); | 241 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); |
| 241 }; | 242 }; |
| 242 | 243 |
| 243 // Creates URLRequestJobs for extension:// URLs. | 244 // Creates URLRequestJobs for chrome-extension:// URLs. |
| 244 net::URLRequestJob* | 245 net::URLRequestJob* |
| 245 ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const { | 246 ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const { |
| 246 // TODO(mpcomplete): better error code. | 247 // TODO(mpcomplete): better error code. |
| 247 if (!AllowExtensionResourceLoad( | 248 if (!AllowExtensionResourceLoad( |
| 248 request, is_incognito_, extension_info_map_)) { | 249 request, is_incognito_, extension_info_map_)) { |
| 249 return new net::URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); | 250 return new net::URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); |
| 250 } | 251 } |
| 251 | 252 |
| 252 // chrome-extension://extension-id/resource/path.js | 253 // chrome-extension://extension-id/resource/path.js |
| 253 const std::string& extension_id = request->url().host(); | 254 const std::string& extension_id = request->url().host(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 ExtensionResource resource(extension_id, directory_path, | 311 ExtensionResource resource(extension_id, directory_path, |
| 311 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); | 312 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); |
| 312 | 313 |
| 313 FilePath resource_file_path; | 314 FilePath resource_file_path; |
| 314 { | 315 { |
| 315 // Getting the file path will touch the file system. Fixing | 316 // Getting the file path will touch the file system. Fixing |
| 316 // crbug.com/59849 would also fix this. Suppress the error for now. | 317 // crbug.com/59849 would also fix this. Suppress the error for now. |
| 317 base::ThreadRestrictions::ScopedAllowIO allow_io; | 318 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 318 resource_file_path = resource.GetFilePath(); | 319 resource_file_path = resource.GetFilePath(); |
| 319 } | 320 } |
| 320 | |
| 321 return new URLRequestExtensionJob(request, resource_file_path, | 321 return new URLRequestExtensionJob(request, resource_file_path, |
| 322 content_security_policy, send_cors_header); | 322 content_security_policy, send_cors_header); |
| 323 } | 323 } |
| 324 | 324 |
| 325 class ExtensionResourceProtocolHandler | |
| 326 : public net::URLRequestJobFactory::ProtocolHandler { | |
| 327 public: | |
| 328 ExtensionResourceProtocolHandler() {} | |
| 329 virtual ~ExtensionResourceProtocolHandler() {} | |
| 330 | |
| 331 virtual net::URLRequestJob* MaybeCreateJob( | |
| 332 net::URLRequest* request) const OVERRIDE; | |
| 333 | |
| 334 private: | |
| 335 DISALLOW_COPY_AND_ASSIGN(ExtensionResourceProtocolHandler); | |
| 336 }; | |
| 337 | |
| 338 // Creates URLRequestJobs for chrome-extension-resource:// URLs. | |
| 339 net::URLRequestJob* | |
| 340 ExtensionResourceProtocolHandler::MaybeCreateJob( | |
| 341 net::URLRequest* request) const { | |
| 342 DCHECK(!request->url().has_host()); | |
| 343 | |
| 344 FilePath resource_root_path; | |
| 345 PathService::Get(chrome::DIR_RESOURCES_EXTENSION, &resource_root_path); | |
| 346 | |
| 347 FilePath relative_path = | |
| 348 extension_file_util::ExtensionURLToRelativeFilePath(request->url()); | |
|
Tom Sepez
2012/04/13 17:20:51
Is this where we count on unsafe directory travers
Peng
2012/04/17 13:52:05
This function just decode the escape and get the r
| |
| 349 | |
| 350 FilePath full_path = resource_root_path.Append(relative_path); | |
| 351 | |
| 352 if (!file_util::AbsolutePath(&full_path) || | |
| 353 !resource_root_path.IsParent(full_path) || | |
| 354 !file_util::PathExists(full_path)) { | |
| 355 full_path = FilePath(); | |
|
abarth-chromium
2012/04/13 17:11:24
This is an important security check, and I'm glad
Peng
2012/04/17 13:52:05
Done.
| |
| 356 } | |
| 357 | |
| 358 return new net::URLRequestFileJob(request, full_path); | |
| 359 } | |
| 360 | |
| 325 } // namespace | 361 } // namespace |
| 326 | 362 |
| 327 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 363 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
| 328 bool is_incognito, | 364 bool is_incognito, |
| 329 ExtensionInfoMap* extension_info_map) { | 365 ExtensionInfoMap* extension_info_map) { |
| 330 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 366 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
| 331 } | 367 } |
| 368 | |
| 369 net::URLRequestJobFactory::ProtocolHandler* | |
| 370 CreateExtensionResourceProtocolHandler() { | |
| 371 return new ExtensionResourceProtocolHandler(); | |
| 372 } | |
| OLD | NEW |