OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_resource.h" | 5 #include "chrome/common/extensions/extension_resource.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/extensions/extension_l10n_util.h" | 10 #include "chrome/browser/extensions/extension_l10n_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 full_resource_path_ = GetFilePath(extension_root_, relative_path_); | 33 full_resource_path_ = GetFilePath(extension_root_, relative_path_); |
34 return full_resource_path_; | 34 return full_resource_path_; |
35 } | 35 } |
36 | 36 |
37 // Static version... | 37 // Static version... |
38 FilePath ExtensionResource::GetFilePath(const FilePath& extension_root, | 38 FilePath ExtensionResource::GetFilePath(const FilePath& extension_root, |
39 const FilePath& relative_path) { | 39 const FilePath& relative_path) { |
40 std::vector<FilePath> l10n_relative_paths; | 40 std::vector<FilePath> l10n_relative_paths; |
41 extension_l10n_util::GetL10nRelativePaths(relative_path, | 41 extension_l10n_util::GetL10nRelativePaths(relative_path, |
42 &l10n_relative_paths); | 42 &l10n_relative_paths); |
| 43 // We need to resolve the parent references in the extension_root |
| 44 // path on its own because IsParent doesn't like parent references. |
| 45 FilePath clean_extension_root(extension_root); |
| 46 if (!file_util::AbsolutePath(&clean_extension_root)) |
| 47 return FilePath(); |
43 | 48 |
44 // Stat l10n file(s), and return new path if it exists. | 49 // Stat l10n file(s), and return new path if it exists. |
45 for (size_t i = 0; i < l10n_relative_paths.size(); ++i) { | 50 for (size_t i = 0; i < l10n_relative_paths.size(); ++i) { |
46 FilePath full_path; | 51 FilePath full_path = clean_extension_root.Append(l10n_relative_paths[i]); |
47 if (extension_root.AppendAndResolveRelative(l10n_relative_paths[i], | 52 if (file_util::AbsolutePath(&full_path) && |
48 &full_path) && | 53 clean_extension_root.IsParent(full_path) && |
49 extension_root.IsParent(full_path) && | |
50 file_util::PathExists(full_path)) { | 54 file_util::PathExists(full_path)) { |
51 return full_path; | 55 return full_path; |
52 } | 56 } |
53 } | 57 } |
54 | 58 |
55 // Fall back to root resource. | 59 // Fall back to root resource. |
56 FilePath full_path; | 60 FilePath full_path = clean_extension_root.Append(relative_path); |
57 if (extension_root.AppendAndResolveRelative(relative_path, &full_path) && | 61 if (file_util::AbsolutePath(&full_path) && |
58 extension_root.IsParent(full_path)) { | 62 clean_extension_root.IsParent(full_path)) { |
59 return full_path; | 63 return full_path; |
60 } | 64 } |
61 | 65 |
62 return FilePath(); | 66 return FilePath(); |
63 } | 67 } |
64 | 68 |
65 // Unittesting helpers. | 69 // Unittesting helpers. |
66 FilePath::StringType ExtensionResource::NormalizeSeperators( | 70 FilePath::StringType ExtensionResource::NormalizeSeperators( |
67 FilePath::StringType path) const { | 71 FilePath::StringType path) const { |
68 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 72 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
(...skipping 10 matching lines...) Expand all Loading... |
79 // Make sure we have a cached value to test against... | 83 // Make sure we have a cached value to test against... |
80 if (full_resource_path_.empty()) | 84 if (full_resource_path_.empty()) |
81 GetFilePath(); | 85 GetFilePath(); |
82 if (NormalizeSeperators(path.value()) == | 86 if (NormalizeSeperators(path.value()) == |
83 NormalizeSeperators(full_resource_path_.value())) { | 87 NormalizeSeperators(full_resource_path_.value())) { |
84 return true; | 88 return true; |
85 } else { | 89 } else { |
86 return false; | 90 return false; |
87 } | 91 } |
88 } | 92 } |
OLD | NEW |