OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/file_util.h" | 5 #include "extensions/common/file_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 453 |
454 // It's still possible for someone to construct an annoying URL whose path | 454 // It's still possible for someone to construct an annoying URL whose path |
455 // would still wind up not being considered relative at this point. | 455 // would still wind up not being considered relative at this point. |
456 // For example: chrome-extension://id/c:////foo.html | 456 // For example: chrome-extension://id/c:////foo.html |
457 if (path.IsAbsolute()) | 457 if (path.IsAbsolute()) |
458 return base::FilePath(); | 458 return base::FilePath(); |
459 | 459 |
460 return path; | 460 return path; |
461 } | 461 } |
462 | 462 |
463 base::FilePath ExtensionResourceURLToFilePath(const GURL& url, | |
464 const base::FilePath& root) { | |
465 std::string host = net::UnescapeURLComponent( | |
466 url.host(), | |
467 net::UnescapeRule::SPACES | | |
468 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); | |
469 if (host.empty()) | |
470 return base::FilePath(); | |
471 | |
472 base::FilePath relative_path = ExtensionURLToRelativeFilePath(url); | |
473 if (relative_path.empty()) | |
474 return base::FilePath(); | |
475 | |
476 base::FilePath path = root.AppendASCII(host).Append(relative_path); | |
477 if (!base::PathExists(path)) | |
478 return base::FilePath(); | |
479 path = base::MakeAbsoluteFilePath(path); | |
480 if (path.empty() || !root.IsParent(path)) | |
481 return base::FilePath(); | |
482 return path; | |
483 } | |
484 | |
485 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set, | 463 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set, |
486 const Extension* extension, | 464 const Extension* extension, |
487 int error_message_id, | 465 int error_message_id, |
488 std::string* error) { | 466 std::string* error) { |
489 for (ExtensionIconSet::IconMap::const_iterator iter = icon_set.map().begin(); | 467 for (ExtensionIconSet::IconMap::const_iterator iter = icon_set.map().begin(); |
490 iter != icon_set.map().end(); | 468 iter != icon_set.map().end(); |
491 ++iter) { | 469 ++iter) { |
492 const base::FilePath path = | 470 const base::FilePath path = |
493 extension->GetResource(iter->second).GetFilePath(); | 471 extension->GetResource(iter->second).GetFilePath(); |
494 if (!ValidateFilePath(path)) { | 472 if (!ValidateFilePath(path)) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { | 598 base::FilePath GetVerifiedContentsPath(const base::FilePath& extension_path) { |
621 return extension_path.Append(kMetadataFolder) | 599 return extension_path.Append(kMetadataFolder) |
622 .Append(kVerifiedContentsFilename); | 600 .Append(kVerifiedContentsFilename); |
623 } | 601 } |
624 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { | 602 base::FilePath GetComputedHashesPath(const base::FilePath& extension_path) { |
625 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); | 603 return extension_path.Append(kMetadataFolder).Append(kComputedHashesFilename); |
626 } | 604 } |
627 | 605 |
628 } // namespace file_util | 606 } // namespace file_util |
629 } // namespace extensions | 607 } // namespace extensions |
OLD | NEW |