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/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 | 618 |
619 // It's still possible for someone to construct an annoying URL whose path | 619 // It's still possible for someone to construct an annoying URL whose path |
620 // would still wind up not being considered relative at this point. | 620 // would still wind up not being considered relative at this point. |
621 // For example: chrome-extension://id/c:////foo.html | 621 // For example: chrome-extension://id/c:////foo.html |
622 if (path.IsAbsolute()) | 622 if (path.IsAbsolute()) |
623 return FilePath(); | 623 return FilePath(); |
624 | 624 |
625 return path; | 625 return path; |
626 } | 626 } |
627 | 627 |
628 FilePath ExtensionResourceURLToFilePath(const GURL& url, const FilePath& root) { | |
629 std::string host = net::UnescapeURLComponent(url.host(), | |
Aaron Boodman
2012/04/16 18:54:36
This is duplicating a lot of code from above. Can
Aaron Boodman
2012/04/16 18:59:57
Actually, on second thought, it is a bit weird to
Peng
2012/04/17 13:52:05
* Remove duplicated code.
* Handle C-E-R:// in a n
| |
630 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); | |
631 if (host.empty()) | |
632 return FilePath(); | |
633 | |
634 std::string url_path = url.path(); | |
635 if (url_path.empty() || url_path[0] != '/') | |
636 return FilePath(); | |
637 | |
638 // Drop the leading slashes and convert %-encoded UTF8 to regular UTF8. | |
639 std::string file_path = net::UnescapeURLComponent(url_path, | |
640 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); | |
641 size_t skip = file_path.find_first_not_of("/\\"); | |
642 if (skip != file_path.npos) | |
643 file_path = file_path.substr(skip); | |
644 | |
645 #if defined(OS_POSIX) | |
646 FilePath path = root.Append(host).Append(file_path); | |
647 #elif defined(OS_WIN) | |
648 FilePath path = root.Append(UTF8ToWide(host)).Append(UTF8ToWide(file_path)); | |
649 #else | |
650 NOTIMPLEMENTED(); | |
651 return FilePath(); | |
652 #endif | |
653 | |
654 if (!file_util::PathExists(path) || | |
655 !file_util::AbsolutePath(&path) || | |
656 !root.IsParent(path)) { | |
657 return FilePath(); | |
658 } | |
659 return path; | |
660 } | |
661 | |
628 FilePath GetUserDataTempDir() { | 662 FilePath GetUserDataTempDir() { |
629 // We do file IO in this function, but only when the current profile's | 663 // We do file IO in this function, but only when the current profile's |
630 // Temp directory has never been used before, or in a rare error case. | 664 // Temp directory has never been used before, or in a rare error case. |
631 // Developers are not likely to see these situations often, so do an | 665 // Developers are not likely to see these situations often, so do an |
632 // explicit thread check. | 666 // explicit thread check. |
633 base::ThreadRestrictions::AssertIOAllowed(); | 667 base::ThreadRestrictions::AssertIOAllowed(); |
634 | 668 |
635 // The following enum used to be sent as a histogram to diagnose issues | 669 // The following enum used to be sent as a histogram to diagnose issues |
636 // accessing the temp path (crbug/70056). The histogram is gone, but | 670 // accessing the temp path (crbug/70056). The histogram is gone, but |
637 // the enum makes it clear exactly why the temp directory can not be | 671 // the enum makes it clear exactly why the temp directory can not be |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 return temp_path; | 721 return temp_path; |
688 | 722 |
689 return FilePath(); | 723 return FilePath(); |
690 } | 724 } |
691 | 725 |
692 void DeleteFile(const FilePath& path, bool recursive) { | 726 void DeleteFile(const FilePath& path, bool recursive) { |
693 file_util::Delete(path, recursive); | 727 file_util::Delete(path, recursive); |
694 } | 728 } |
695 | 729 |
696 } // namespace extension_file_util | 730 } // namespace extension_file_util |
OLD | NEW |