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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 | 9 |
10 // Represents a resource inside an extension. For example, an image, or a | 10 // Represents a resource inside an extension. For example, an image, or a |
11 // JavaScript file. This is more complicated than just a simple FilePath | 11 // JavaScript file. This is more complicated than just a simple FilePath |
12 // because extension resources can come from multiple physical file locations | 12 // because extension resources can come from multiple physical file locations |
13 // depending on locale. | 13 // depending on locale. |
14 class ExtensionResource { | 14 class ExtensionResource { |
15 public: | 15 public: |
16 ExtensionResource(); | 16 ExtensionResource(); |
17 | 17 |
18 ExtensionResource(const FilePath& extension_root, | 18 ExtensionResource(const FilePath& extension_root, |
19 const FilePath& relative_path); | 19 const FilePath& relative_path); |
20 | 20 |
21 // Returns actual path to the resource (default or locale specific). | 21 // Returns actual path to the resource (default or locale specific). |
22 // *** MIGHT HIT FILESYSTEM. Do not call on UI thread! *** | 22 // *** MIGHT HIT FILESYSTEM. Do not call on UI thread! *** |
23 const FilePath& GetFilePath() const; | 23 const FilePath& GetFilePath() const; |
24 | 24 |
| 25 // Static version to avoid creating an instance of ExtensionResource |
| 26 // when all we want is the localization code. |
| 27 // *** MIGHT HIT FILESYSTEM. Do not call on UI thread! *** |
| 28 static FilePath GetFilePath(const FilePath& extension_root, |
| 29 const FilePath& relative_path); |
| 30 |
25 // Getters | 31 // Getters |
26 const FilePath& extension_root() const { return extension_root_; } | 32 const FilePath& extension_root() const { return extension_root_; } |
27 const FilePath& relative_path() const { return relative_path_; } | 33 const FilePath& relative_path() const { return relative_path_; } |
28 | 34 |
29 // Unittest helpers. | 35 // Unittest helpers. |
30 FilePath::StringType NormalizeSeperators(FilePath::StringType path) const; | 36 FilePath::StringType NormalizeSeperators(FilePath::StringType path) const; |
31 bool ComparePathWithDefault(const FilePath& path) const; | 37 bool ComparePathWithDefault(const FilePath& path) const; |
32 | 38 |
33 private: | 39 private: |
34 // Returns normalized full path to the resource. | |
35 // Resource doesn't have to exist. | |
36 FilePath CombinePathsSafely(const FilePath& extension_root, | |
37 const FilePath& relative_path) const; | |
38 | |
39 // Extension root. | 40 // Extension root. |
40 FilePath extension_root_; | 41 FilePath extension_root_; |
41 | 42 |
42 // Relative path to resource. | 43 // Relative path to resource. |
43 FilePath relative_path_; | 44 FilePath relative_path_; |
44 | 45 |
45 // Full path to extension resource. Starts empty. | 46 // Full path to extension resource. Starts empty. |
46 mutable FilePath full_resource_path_; | 47 mutable FilePath full_resource_path_; |
47 }; | 48 }; |
48 | 49 |
49 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ | 50 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_RESOURCE_H_ |
OLD | NEW |