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

Side by Side Diff: extensions/common/extension_resource.cc

Issue 13196006: Move path functions from file_util to FilePath object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try Created 7 years, 8 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 | Annotate | Revision Log
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 "extensions/common/extension_resource.h" 5 #include "extensions/common/extension_resource.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return full_resource_path_; 45 return full_resource_path_;
46 } 46 }
47 47
48 // static 48 // static
49 base::FilePath ExtensionResource::GetFilePath( 49 base::FilePath ExtensionResource::GetFilePath(
50 const base::FilePath& extension_root, 50 const base::FilePath& extension_root,
51 const base::FilePath& relative_path, 51 const base::FilePath& relative_path,
52 SymlinkPolicy symlink_policy) { 52 SymlinkPolicy symlink_policy) {
53 // We need to resolve the parent references in the extension_root 53 // We need to resolve the parent references in the extension_root
54 // path on its own because IsParent doesn't like parent references. 54 // path on its own because IsParent doesn't like parent references.
55 base::FilePath clean_extension_root(extension_root); 55 base::FilePath clean_extension_root(
56 if (!file_util::AbsolutePath(&clean_extension_root)) 56 base::MakeAbsoluteFilePath(extension_root));
57 if (clean_extension_root.empty())
57 return base::FilePath(); 58 return base::FilePath();
58 59
59 base::FilePath full_path = clean_extension_root.Append(relative_path); 60 base::FilePath full_path = clean_extension_root.Append(relative_path);
60 61
61 // If we are allowing the file to be a symlink outside of the root, then the 62 // If we are allowing the file to be a symlink outside of the root, then the
62 // path before resolving the symlink must still be within it. 63 // path before resolving the symlink must still be within it.
63 if (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE) { 64 if (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE) {
64 std::vector<base::FilePath::StringType> components; 65 std::vector<base::FilePath::StringType> components;
65 relative_path.GetComponents(&components); 66 relative_path.GetComponents(&components);
66 int depth = 0; 67 int depth = 0;
67 68
68 for (std::vector<base::FilePath::StringType>::const_iterator 69 for (std::vector<base::FilePath::StringType>::const_iterator
69 i = components.begin(); i != components.end(); i++) { 70 i = components.begin(); i != components.end(); i++) {
70 if (*i == base::FilePath::kParentDirectory) { 71 if (*i == base::FilePath::kParentDirectory) {
71 depth--; 72 depth--;
72 } else if (*i != base::FilePath::kCurrentDirectory) { 73 } else if (*i != base::FilePath::kCurrentDirectory) {
73 depth++; 74 depth++;
74 } 75 }
75 if (depth < 0) { 76 if (depth < 0) {
76 return base::FilePath(); 77 return base::FilePath();
77 } 78 }
78 } 79 }
79 } 80 }
80 81
81 // We must resolve the absolute path of the combined path when 82 // We must resolve the absolute path of the combined path when
82 // the relative path contains references to a parent folder (i.e., '..'). 83 // the relative path contains references to a parent folder (i.e., '..').
83 // We also check if the path exists because the posix version of AbsolutePath 84 // We also check if the path exists because the posix version of
84 // will fail if the path doesn't exist, and we want the same behavior on 85 // MakeAbsoluteFilePath will fail if the path doesn't exist, and we want the
85 // Windows... So until the posix and Windows version of AbsolutePath are 86 // same behavior on Windows... So until the posix and Windows version of
86 // unified, we need an extra call to PathExists, unfortunately. 87 // MakeAbsoluteFilePath are unified, we need an extra call to PathExists,
87 // TODO(mad): Fix this once AbsolutePath is unified. 88 // unfortunately.
88 if (file_util::AbsolutePath(&full_path) && 89 // TODO(mad): Fix this once MakeAbsoluteFilePath is unified.
89 file_util::PathExists(full_path) && 90 full_path = base::MakeAbsoluteFilePath(full_path);
91 if (file_util::PathExists(full_path) &&
90 (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE || 92 (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE ||
91 clean_extension_root.IsParent(full_path))) { 93 clean_extension_root.IsParent(full_path))) {
92 return full_path; 94 return full_path;
93 } 95 }
94 96
95 return base::FilePath(); 97 return base::FilePath();
96 } 98 }
97 99
98 // Unit-testing helpers. 100 // Unit-testing helpers.
99 base::FilePath::StringType ExtensionResource::NormalizeSeperators( 101 base::FilePath::StringType ExtensionResource::NormalizeSeperators(
(...skipping 17 matching lines...) Expand all
117 GetFilePath(); 119 GetFilePath();
118 if (NormalizeSeperators(path.value()) == 120 if (NormalizeSeperators(path.value()) ==
119 NormalizeSeperators(full_resource_path_.value())) { 121 NormalizeSeperators(full_resource_path_.value())) {
120 return true; 122 return true;
121 } else { 123 } else {
122 return false; 124 return false;
123 } 125 }
124 } 126 }
125 127
126 } // namespace extensions 128 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698