Chromium Code Reviews

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: Update Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 607 matching lines...)
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(),
630 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
631 if (host.empty())
632 return FilePath();
633
634 FilePath relative_path = ExtensionURLToRelativeFilePath(url);
635 if (relative_path.empty())
636 return FilePath();
637
638 FilePath path = root.AppendASCII(host).Append(relative_path);
639 base::ThreadRestrictions::ScopedAllowIO allow_io;
Aaron Boodman 2012/04/18 17:52:24 This shouldn't be needed. If you are hitting a DCH
Peng 2012/04/18 18:29:16 I are hitting a DCHECK here. PathExists() and Abso
Aaron Boodman 2012/04/18 18:51:01 I see. I remember the background on why this is ne
640 if (!file_util::PathExists(path) ||
641 !file_util::AbsolutePath(&path) ||
642 !root.IsParent(path)) {
643 return FilePath();
644 }
645 return path;
646 }
647
628 FilePath GetUserDataTempDir() { 648 FilePath GetUserDataTempDir() {
629 // We do file IO in this function, but only when the current profile's 649 // 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. 650 // 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 651 // Developers are not likely to see these situations often, so do an
632 // explicit thread check. 652 // explicit thread check.
633 base::ThreadRestrictions::AssertIOAllowed(); 653 base::ThreadRestrictions::AssertIOAllowed();
634 654
635 // The following enum used to be sent as a histogram to diagnose issues 655 // 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 656 // 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 657 // the enum makes it clear exactly why the temp directory can not be
(...skipping 49 matching lines...)
687 return temp_path; 707 return temp_path;
688 708
689 return FilePath(); 709 return FilePath();
690 } 710 }
691 711
692 void DeleteFile(const FilePath& path, bool recursive) { 712 void DeleteFile(const FilePath& path, bool recursive) {
693 file_util::Delete(path, recursive); 713 file_util::Delete(path, recursive);
694 } 714 }
695 715
696 } // namespace extension_file_util 716 } // namespace extension_file_util
OLDNEW

Powered by Google App Engine