OLD | NEW |
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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "chrome/common/extensions/manifest.h" | 12 #include "chrome/common/extensions/manifest.h" |
13 #include "chrome/common/extensions/message_bundle.h" | 13 #include "chrome/common/extensions/message_bundle.h" |
14 | 14 |
15 class FilePath; | |
16 class GURL; | 15 class GURL; |
17 | 16 |
18 namespace base { | 17 namespace base { |
19 class DictionaryValue; | 18 class DictionaryValue; |
| 19 class FilePath; |
20 } | 20 } |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
23 class Extension; | 23 class Extension; |
24 class MessageBundle; | 24 class MessageBundle; |
25 struct InstallWarning; | 25 struct InstallWarning; |
26 } | 26 } |
27 | 27 |
28 // Utilities for manipulating the on-disk storage of extensions. | 28 // Utilities for manipulating the on-disk storage of extensions. |
29 namespace extension_file_util { | 29 namespace extension_file_util { |
30 | 30 |
31 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. | 31 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. |
32 // The destination directory is returned on success, or empty path is returned | 32 // The destination directory is returned on success, or empty path is returned |
33 // on failure. | 33 // on failure. |
34 FilePath InstallExtension(const FilePath& unpacked_source_dir, | 34 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, |
35 const std::string& id, | 35 const std::string& id, |
36 const std::string& version, | 36 const std::string& version, |
37 const FilePath& extensions_dir); | 37 const base::FilePath& extensions_dir); |
38 | 38 |
39 // Removes all versions of the extension with |id| from |extensions_dir|. | 39 // Removes all versions of the extension with |id| from |extensions_dir|. |
40 void UninstallExtension(const FilePath& extensions_dir, | 40 void UninstallExtension(const base::FilePath& extensions_dir, |
41 const std::string& id); | 41 const std::string& id); |
42 | 42 |
43 // Loads and validates an extension from the specified directory. Returns NULL | 43 // Loads and validates an extension from the specified directory. Returns NULL |
44 // on failure, with a description of the error in |error|. | 44 // on failure, with a description of the error in |error|. |
45 scoped_refptr<extensions::Extension> LoadExtension( | 45 scoped_refptr<extensions::Extension> LoadExtension( |
46 const FilePath& extension_root, | 46 const base::FilePath& extension_root, |
47 extensions::Manifest::Location location, | 47 extensions::Manifest::Location location, |
48 int flags, | 48 int flags, |
49 std::string* error); | 49 std::string* error); |
50 | 50 |
51 // The same as LoadExtension except use the provided |extension_id|. | 51 // The same as LoadExtension except use the provided |extension_id|. |
52 scoped_refptr<extensions::Extension> LoadExtension( | 52 scoped_refptr<extensions::Extension> LoadExtension( |
53 const FilePath& extension_root, | 53 const base::FilePath& extension_root, |
54 const std::string& extension_id, | 54 const std::string& extension_id, |
55 extensions::Manifest::Location location, | 55 extensions::Manifest::Location location, |
56 int flags, | 56 int flags, |
57 std::string* error); | 57 std::string* error); |
58 | 58 |
59 // Loads an extension manifest from the specified directory. Returns NULL | 59 // Loads an extension manifest from the specified directory. Returns NULL |
60 // on failure, with a description of the error in |error|. | 60 // on failure, with a description of the error in |error|. |
61 base::DictionaryValue* LoadManifest(const FilePath& extension_root, | 61 base::DictionaryValue* LoadManifest(const base::FilePath& extension_root, |
62 std::string* error); | 62 std::string* error); |
63 | 63 |
64 // Returns true if the given file path exists and is not zero-length. | 64 // Returns true if the given file path exists and is not zero-length. |
65 bool ValidateFilePath(const FilePath& path); | 65 bool ValidateFilePath(const base::FilePath& path); |
66 | 66 |
67 // Returns true if the given extension object is valid and consistent. | 67 // Returns true if the given extension object is valid and consistent. |
68 // May also append a series of warning messages to |warnings|, but they | 68 // May also append a series of warning messages to |warnings|, but they |
69 // should not prevent the extension from running. | 69 // should not prevent the extension from running. |
70 // | 70 // |
71 // Otherwise, returns false, and a description of the error is | 71 // Otherwise, returns false, and a description of the error is |
72 // returned in |error|. | 72 // returned in |error|. |
73 bool ValidateExtension(const extensions::Extension* extension, | 73 bool ValidateExtension(const extensions::Extension* extension, |
74 std::string* error, | 74 std::string* error, |
75 std::vector<extensions::InstallWarning>* warnings); | 75 std::vector<extensions::InstallWarning>* warnings); |
76 | 76 |
77 // Returns a list of files that contain private keys inside |extension_dir|. | 77 // Returns a list of files that contain private keys inside |extension_dir|. |
78 std::vector<FilePath> FindPrivateKeyFiles(const FilePath& extension_dir); | 78 std::vector<base::FilePath> FindPrivateKeyFiles(const base::FilePath& extension_
dir); |
79 | 79 |
80 // Cleans up the extension install directory. It can end up with garbage in it | 80 // Cleans up the extension install directory. It can end up with garbage in it |
81 // if extensions can't initially be removed when they are uninstalled (eg if a | 81 // if extensions can't initially be removed when they are uninstalled (eg if a |
82 // file is in use). | 82 // file is in use). |
83 // | 83 // |
84 // |extensions_dir| is the install directory to look in. |extension_paths| is a | 84 // |extensions_dir| is the install directory to look in. |extension_paths| is a |
85 // map from extension id to full installation path. | 85 // map from extension id to full installation path. |
86 // | 86 // |
87 // Obsolete version directories are removed, as are directories that aren't | 87 // Obsolete version directories are removed, as are directories that aren't |
88 // found in |extension_paths|. | 88 // found in |extension_paths|. |
89 void GarbageCollectExtensions( | 89 void GarbageCollectExtensions( |
90 const FilePath& extensions_dir, | 90 const base::FilePath& extensions_dir, |
91 const std::multimap<std::string, FilePath>& extension_paths); | 91 const std::multimap<std::string, base::FilePath>& extension_paths); |
92 | 92 |
93 // Loads extension message catalogs and returns message bundle. | 93 // Loads extension message catalogs and returns message bundle. |
94 // Returns NULL on error, or if extension is not localized. | 94 // Returns NULL on error, or if extension is not localized. |
95 extensions::MessageBundle* LoadMessageBundle( | 95 extensions::MessageBundle* LoadMessageBundle( |
96 const FilePath& extension_path, | 96 const base::FilePath& extension_path, |
97 const std::string& default_locale, | 97 const std::string& default_locale, |
98 std::string* error); | 98 std::string* error); |
99 | 99 |
100 // Loads the extension message bundle substitution map. Contains at least | 100 // Loads the extension message bundle substitution map. Contains at least |
101 // extension_id item. | 101 // extension_id item. |
102 extensions::MessageBundle::SubstitutionMap* LoadMessageBundleSubstitutionMap( | 102 extensions::MessageBundle::SubstitutionMap* LoadMessageBundleSubstitutionMap( |
103 const FilePath& extension_path, | 103 const base::FilePath& extension_path, |
104 const std::string& extension_id, | 104 const std::string& extension_id, |
105 const std::string& default_locale); | 105 const std::string& default_locale); |
106 | 106 |
107 // We need to reserve the namespace of entries that start with "_" for future | 107 // We need to reserve the namespace of entries that start with "_" for future |
108 // use by Chrome. | 108 // use by Chrome. |
109 // If any files or directories are found using "_" prefix and are not on | 109 // If any files or directories are found using "_" prefix and are not on |
110 // reserved list we return false, and set error message. | 110 // reserved list we return false, and set error message. |
111 bool CheckForIllegalFilenames(const FilePath& extension_path, | 111 bool CheckForIllegalFilenames(const base::FilePath& extension_path, |
112 std::string* error); | 112 std::string* error); |
113 | 113 |
114 // Get a relative file path from a chrome-extension:// URL. | 114 // Get a relative file path from a chrome-extension:// URL. |
115 FilePath ExtensionURLToRelativeFilePath(const GURL& url); | 115 base::FilePath ExtensionURLToRelativeFilePath(const GURL& url); |
116 | 116 |
117 // Get a full file path from a chrome-extension-resource:// URL, If the URL | 117 // Get a full file path from a chrome-extension-resource:// URL, If the URL |
118 // points a file outside of root, this function will return empty FilePath. | 118 // points a file outside of root, this function will return empty FilePath. |
119 FilePath ExtensionResourceURLToFilePath(const GURL& url, const FilePath& root); | 119 base::FilePath ExtensionResourceURLToFilePath(const GURL& url, |
| 120 const base::FilePath& root); |
120 | 121 |
121 // Returns a path to a temporary directory for unpacking an extension that will | 122 // Returns a path to a temporary directory for unpacking an extension that will |
122 // be installed into |extensions_dir|. Creates the directory if necessary. | 123 // be installed into |extensions_dir|. Creates the directory if necessary. |
123 // The directory will be on the same file system as |extensions_dir| so | 124 // The directory will be on the same file system as |extensions_dir| so |
124 // that the extension directory can be efficiently renamed into place. Returns | 125 // that the extension directory can be efficiently renamed into place. Returns |
125 // an empty file path on failure. | 126 // an empty file path on failure. |
126 FilePath GetInstallTempDir(const FilePath& extensions_dir); | 127 base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir); |
127 | 128 |
128 // Helper function to delete files. This is used to avoid ugly casts which | 129 // Helper function to delete files. This is used to avoid ugly casts which |
129 // would be necessary with PostMessage since file_util::Delete is overloaded. | 130 // would be necessary with PostMessage since file_util::Delete is overloaded. |
130 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. | 131 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. |
131 void DeleteFile(const FilePath& path, bool recursive); | 132 void DeleteFile(const base::FilePath& path, bool recursive); |
132 | 133 |
133 } // namespace extension_file_util | 134 } // namespace extension_file_util |
134 | 135 |
135 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 136 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
OLD | NEW |