| 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 19 matching lines...) Expand all Loading... |
| 30 if (!full_resource_path_.empty()) | 30 if (!full_resource_path_.empty()) |
| 31 return full_resource_path_; | 31 return full_resource_path_; |
| 32 | 32 |
| 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 // Stat l10n file, and return new path if it exists. | 40 std::vector<FilePath> l10n_relative_paths; |
| 41 FilePath l10n_relative_path = | 41 extension_l10n_util::GetL10nRelativePaths(relative_path, |
| 42 extension_l10n_util::GetL10nRelativePath(relative_path); | 42 &l10n_relative_paths); |
| 43 FilePath full_path; | 43 |
| 44 if (extension_root.AppendAndResolveRelative(l10n_relative_path, &full_path) && | 44 // Stat l10n file(s), and return new path if it exists. |
| 45 extension_root.IsParent(full_path) && | 45 for (size_t i = 0; i < l10n_relative_paths.size(); ++i) { |
| 46 file_util::PathExists(full_path)) { | 46 FilePath full_path; |
| 47 return full_path; | 47 if (extension_root.AppendAndResolveRelative(l10n_relative_paths[i], |
| 48 &full_path) && |
| 49 extension_root.IsParent(full_path) && |
| 50 file_util::PathExists(full_path)) { |
| 51 return full_path; |
| 52 } |
| 48 } | 53 } |
| 49 | 54 |
| 50 // Fall back to root resource. | 55 // Fall back to root resource. |
| 56 FilePath full_path; |
| 51 if (extension_root.AppendAndResolveRelative(relative_path, &full_path) && | 57 if (extension_root.AppendAndResolveRelative(relative_path, &full_path) && |
| 52 extension_root.IsParent(full_path)) { | 58 extension_root.IsParent(full_path)) { |
| 53 return full_path; | 59 return full_path; |
| 54 } | 60 } |
| 55 | 61 |
| 56 return FilePath(); | 62 return FilePath(); |
| 57 } | 63 } |
| 58 | 64 |
| 59 // Unittesting helpers. | 65 // Unittesting helpers. |
| 60 FilePath::StringType ExtensionResource::NormalizeSeperators( | 66 FilePath::StringType ExtensionResource::NormalizeSeperators( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 // Make sure we have a cached value to test against... | 79 // Make sure we have a cached value to test against... |
| 74 if (full_resource_path_.empty()) | 80 if (full_resource_path_.empty()) |
| 75 GetFilePath(); | 81 GetFilePath(); |
| 76 if (NormalizeSeperators(path.value()) == | 82 if (NormalizeSeperators(path.value()) == |
| 77 NormalizeSeperators(full_resource_path_.value())) { | 83 NormalizeSeperators(full_resource_path_.value())) { |
| 78 return true; | 84 return true; |
| 79 } else { | 85 } else { |
| 80 return false; | 86 return false; |
| 81 } | 87 } |
| 82 } | 88 } |
| OLD | NEW |