Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: chrome/common/extensions/extension_file_util.cc

Issue 9909019: Add schema chrome-extension-resource:// for extension resources (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Make some test flaky for OSX Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 628
629 // It's still possible for someone to construct an annoying URL whose path 629 // It's still possible for someone to construct an annoying URL whose path
630 // would still wind up not being considered relative at this point. 630 // would still wind up not being considered relative at this point.
631 // For example: chrome-extension://id/c:////foo.html 631 // For example: chrome-extension://id/c:////foo.html
632 if (path.IsAbsolute()) 632 if (path.IsAbsolute())
633 return FilePath(); 633 return FilePath();
634 634
635 return path; 635 return path;
636 } 636 }
637 637
638 FilePath ExtensionResourceURLToFilePath(const GURL& url, const FilePath& root) {
639 std::string host = net::UnescapeURLComponent(url.host(),
640 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
641 if (host.empty())
642 return FilePath();
643
644 FilePath relative_path = ExtensionURLToRelativeFilePath(url);
645 if (relative_path.empty())
646 return FilePath();
647
648 FilePath path = root.AppendASCII(host).Append(relative_path);
649 if (!file_util::PathExists(path) ||
650 !file_util::AbsolutePath(&path) ||
651 !root.IsParent(path)) {
652 return FilePath();
653 }
654 return path;
655 }
656
638 FilePath GetUserDataTempDir() { 657 FilePath GetUserDataTempDir() {
639 // We do file IO in this function, but only when the current profile's 658 // We do file IO in this function, but only when the current profile's
640 // Temp directory has never been used before, or in a rare error case. 659 // Temp directory has never been used before, or in a rare error case.
641 // Developers are not likely to see these situations often, so do an 660 // Developers are not likely to see these situations often, so do an
642 // explicit thread check. 661 // explicit thread check.
643 base::ThreadRestrictions::AssertIOAllowed(); 662 base::ThreadRestrictions::AssertIOAllowed();
644 663
645 // The following enum used to be sent as a histogram to diagnose issues 664 // The following enum used to be sent as a histogram to diagnose issues
646 // accessing the temp path (crbug/70056). The histogram is gone, but 665 // accessing the temp path (crbug/70056). The histogram is gone, but
647 // the enum makes it clear exactly why the temp directory can not be 666 // 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
697 return temp_path; 716 return temp_path;
698 717
699 return FilePath(); 718 return FilePath();
700 } 719 }
701 720
702 void DeleteFile(const FilePath& path, bool recursive) { 721 void DeleteFile(const FilePath& path, bool recursive) {
703 file_util::Delete(path, recursive); 722 file_util::Delete(path, recursive);
704 } 723 }
705 724
706 } // namespace extension_file_util 725 } // namespace extension_file_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.h ('k') | chrome/common/extensions/extension_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698