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

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: 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(extension_root.AsAbsolute());
56 if (!file_util::AbsolutePath(&clean_extension_root)) 56 if (clean_extension_root.empty())
57 return base::FilePath(); 57 return base::FilePath();
58 58
59 base::FilePath full_path = clean_extension_root.Append(relative_path); 59 base::FilePath full_path = clean_extension_root.Append(relative_path);
60 60
61 // If we are allowing the file to be a symlink outside of the root, then the 61 // 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. 62 // path before resolving the symlink must still be within it.
63 if (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE) { 63 if (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE) {
64 std::vector<base::FilePath::StringType> components; 64 std::vector<base::FilePath::StringType> components;
65 relative_path.GetComponents(&components); 65 relative_path.GetComponents(&components);
66 int depth = 0; 66 int depth = 0;
67 67
68 for (std::vector<base::FilePath::StringType>::const_iterator 68 for (std::vector<base::FilePath::StringType>::const_iterator
69 i = components.begin(); i != components.end(); i++) { 69 i = components.begin(); i != components.end(); i++) {
70 if (*i == base::FilePath::kParentDirectory) { 70 if (*i == base::FilePath::kParentDirectory) {
71 depth--; 71 depth--;
72 } else if (*i != base::FilePath::kCurrentDirectory) { 72 } else if (*i != base::FilePath::kCurrentDirectory) {
73 depth++; 73 depth++;
74 } 74 }
75 if (depth < 0) { 75 if (depth < 0) {
76 return base::FilePath(); 76 return base::FilePath();
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 // We must resolve the absolute path of the combined path when 81 // We must resolve the absolute path of the combined path when
82 // the relative path contains references to a parent folder (i.e., '..'). 82 // 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 83 // We also check if the path exists because the posix version of AsAbsolute
84 // will fail if the path doesn't exist, and we want the same behavior on 84 // will fail if the path doesn't exist, and we want the same behavior on
85 // Windows... So until the posix and Windows version of AbsolutePath are 85 // Windows... So until the posix and Windows version of AsAbsolute are
86 // unified, we need an extra call to PathExists, unfortunately. 86 // unified, we need an extra call to PathExists, unfortunately.
87 // TODO(mad): Fix this once AbsolutePath is unified. 87 // TODO(mad): Fix this once AsAbsolute is unified.
88 if (file_util::AbsolutePath(&full_path) && 88 full_path = full_path.AsAbsolute();
89 file_util::PathExists(full_path) && 89 if (file_util::PathExists(full_path) &&
90 (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE || 90 (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE ||
91 clean_extension_root.IsParent(full_path))) { 91 clean_extension_root.IsParent(full_path))) {
92 return full_path; 92 return full_path;
93 } 93 }
94 94
95 return base::FilePath(); 95 return base::FilePath();
96 } 96 }
97 97
98 // Unit-testing helpers. 98 // Unit-testing helpers.
99 base::FilePath::StringType ExtensionResource::NormalizeSeperators( 99 base::FilePath::StringType ExtensionResource::NormalizeSeperators(
(...skipping 17 matching lines...) Expand all
117 GetFilePath(); 117 GetFilePath();
118 if (NormalizeSeperators(path.value()) == 118 if (NormalizeSeperators(path.value()) ==
119 NormalizeSeperators(full_resource_path_.value())) { 119 NormalizeSeperators(full_resource_path_.value())) {
120 return true; 120 return true;
121 } else { 121 } else {
122 return false; 122 return false;
123 } 123 }
124 } 124 }
125 125
126 } // namespace extensions 126 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698