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 FilePath root_path; |
| 343 PathService::Get(chrome::DIR_RESOURCES_EXTENSION, &root_path); |
| 344 FilePath path = |
| 345 extension_file_util::ExtensionResourceURLToFilePath( |
| 346 request->url(), root_path); |
| 347 return new net::URLRequestFileJob(request, path); |
| 348 } |
| 349 |
325 } // namespace | 350 } // namespace |
326 | 351 |
327 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 352 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
328 bool is_incognito, | 353 bool is_incognito, |
329 ExtensionInfoMap* extension_info_map) { | 354 ExtensionInfoMap* extension_info_map) { |
330 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 355 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
331 } | 356 } |
| 357 |
| 358 net::URLRequestJobFactory::ProtocolHandler* |
| 359 CreateExtensionResourceProtocolHandler() { |
| 360 return new ExtensionResourceProtocolHandler(); |
| 361 } |
OLD | NEW |