| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 replacements.SetPathStr(new_path); | 62 replacements.SetPathStr(new_path); |
| 63 GURL file_url = extension_url.ReplaceComponents(replacements); | 63 GURL file_url = extension_url.ReplaceComponents(replacements); |
| 64 if (!file_url.is_valid()) | 64 if (!file_url.is_valid()) |
| 65 return FilePath(); | 65 return FilePath(); |
| 66 | 66 |
| 67 // Convert the result back to a FilePath. | 67 // Convert the result back to a FilePath. |
| 68 FilePath ret_val; | 68 FilePath ret_val; |
| 69 if (!net::FileURLToFilePath(file_url, &ret_val)) | 69 if (!net::FileURLToFilePath(file_url, &ret_val)) |
| 70 return FilePath(); | 70 return FilePath(); |
| 71 | 71 |
| 72 // Converting the extension_url back to a path removes all .. and . references |
| 73 // that may have been in extension_path that would cause isParent to break. |
| 74 FilePath sanitized_extension_path; |
| 75 if (!net::FileURLToFilePath(extension_url, &sanitized_extension_path)) |
| 76 return FilePath(); |
| 77 |
| 72 // Double-check that the path we ended up with is actually inside the | 78 // Double-check that the path we ended up with is actually inside the |
| 73 // extension root. | 79 // extension root. |
| 74 if (!extension_path.IsParent(ret_val)) | 80 if (!sanitized_extension_path.IsParent(ret_val)) |
| 75 return FilePath(); | 81 return FilePath(); |
| 76 | 82 |
| 77 return ret_val; | 83 return ret_val; |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Unittesting helpers. | 86 // Unittesting helpers. |
| 81 FilePath::StringType ExtensionResource::NormalizeSeperators( | 87 FilePath::StringType ExtensionResource::NormalizeSeperators( |
| 82 FilePath::StringType path) const { | 88 FilePath::StringType path) const { |
| 83 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 89 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 84 FilePath::StringType ret_val; | 90 FilePath::StringType ret_val; |
| 85 for (size_t i = 0; i < path.length(); i++) { | 91 for (size_t i = 0; i < path.length(); i++) { |
| 86 if (FilePath::IsSeparator(path[i])) | 92 if (FilePath::IsSeparator(path[i])) |
| 87 path[i] = FilePath::kSeparators[0]; | 93 path[i] = FilePath::kSeparators[0]; |
| 88 } | 94 } |
| 89 #endif // FILE_PATH_USES_WIN_SEPARATORS | 95 #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 90 return path; | 96 return path; |
| 91 } | 97 } |
| 92 | 98 |
| 93 bool ExtensionResource::ComparePathWithDefault(const FilePath& path) const { | 99 bool ExtensionResource::ComparePathWithDefault(const FilePath& path) const { |
| 94 if (NormalizeSeperators(path.value()) == | 100 if (NormalizeSeperators(path.value()) == |
| 95 NormalizeSeperators(full_resource_path_.value())) { | 101 NormalizeSeperators(full_resource_path_.value())) { |
| 96 return true; | 102 return true; |
| 97 } else { | 103 } else { |
| 98 return false; | 104 return false; |
| 99 } | 105 } |
| 100 } | 106 } |
| OLD | NEW |