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" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 // Getting the file path will touch the file system. Fixing | 315 // Getting the file path will touch the file system. Fixing |
316 // crbug.com/59849 would also fix this. Suppress the error for now. | 316 // crbug.com/59849 would also fix this. Suppress the error for now. |
317 base::ThreadRestrictions::ScopedAllowIO allow_io; | 317 base::ThreadRestrictions::ScopedAllowIO allow_io; |
318 resource_file_path = resource.GetFilePath(); | 318 resource_file_path = resource.GetFilePath(); |
319 } | 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(bool is_incognito, | |
329 ExtensionInfoMap* extension_info_map) | |
Tom Sepez
2012/04/11 20:31:16
nit: Indentation.
Peng
2012/04/11 21:40:13
Done.
| |
330 : is_incognito_(is_incognito), | |
331 extension_info_map_(extension_info_map) {} | |
332 | |
333 virtual ~ExtensionResourceProtocolHandler() {} | |
334 | |
335 virtual net::URLRequestJob* MaybeCreateJob( | |
336 net::URLRequest* request) const OVERRIDE; | |
337 | |
338 private: | |
339 const bool is_incognito_; | |
340 ExtensionInfoMap* const extension_info_map_; | |
341 DISALLOW_COPY_AND_ASSIGN(ExtensionResourceProtocolHandler); | |
342 }; | |
343 | |
344 // Creates URLRequestJobs for extension:// URLs. | |
Tom Sepez
2012/04/11 20:31:16
chrome-extension-resource:// urls. Suspect the c
Peng
2012/04/11 21:40:13
Done.
| |
345 net::URLRequestJob* | |
346 ExtensionResourceProtocolHandler::MaybeCreateJob( | |
347 net::URLRequest* request) const { | |
348 LOG(ERROR)<< "host()=" << request->url().host() | |
Tom Sepez
2012/04/11 20:31:16
Debugging?
Peng
2012/04/11 21:40:13
Done.
| |
349 << "\npath()=" << request->url().path(); | |
350 if (!request->url().has_host() || !request->url().has_path()) | |
351 return NULL; | |
352 | |
353 FilePath path; | |
354 PathService::Get(chrome::DIR_RESOURCES_EXT, &path); | |
355 path = path.Append(request->url().host()).Append(request->url().path()); | |
356 | |
357 return new net::URLRequestFileJob(request, path); | |
358 } | |
359 | |
325 } // namespace | 360 } // namespace |
326 | 361 |
327 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 362 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
328 bool is_incognito, | 363 bool is_incognito, |
329 ExtensionInfoMap* extension_info_map) { | 364 ExtensionInfoMap* extension_info_map) { |
330 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 365 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
331 } | 366 } |
367 | |
368 net::URLRequestJobFactory::ProtocolHandler* | |
369 CreateExtensionResourceProtocolHandler( | |
370 bool is_incognito, | |
371 ExtensionInfoMap* extension_info_map) { | |
372 return new ExtensionResourceProtocolHandler(is_incognito, extension_info_map); | |
373 } | |
OLD | NEW |