| 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 <map> | 8 #include <set> |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "extensions/common/manifest.h" | |
| 14 | 9 |
| 15 namespace base { | 10 namespace base { |
| 16 class DictionaryValue; | |
| 17 class FilePath; | 11 class FilePath; |
| 18 } | 12 } |
| 19 | 13 |
| 20 namespace extensions { | 14 namespace extensions { |
| 21 class Extension; | 15 class Extension; |
| 22 struct InstallWarning; | |
| 23 } | 16 } |
| 24 | 17 |
| 25 // Utilities for manipulating the on-disk storage of extensions. | 18 // DEPRECATED: Prefer extensions/common/file_util.cc. |
| 26 namespace extension_file_util { | 19 namespace extension_file_util { |
| 27 | 20 |
| 28 extern const base::FilePath::CharType kTempDirectoryName[]; | |
| 29 | |
| 30 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. | |
| 31 // The destination directory is returned on success, or empty path is returned | |
| 32 // on failure. | |
| 33 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, | |
| 34 const std::string& id, | |
| 35 const std::string& version, | |
| 36 const base::FilePath& extensions_dir); | |
| 37 | |
| 38 // Removes all versions of the extension with |id| from |extensions_dir|. | |
| 39 void UninstallExtension(const base::FilePath& extensions_dir, | |
| 40 const std::string& id); | |
| 41 | |
| 42 // Loads and validates an extension from the specified directory. Returns NULL | |
| 43 // on failure, with a description of the error in |error|. | |
| 44 scoped_refptr<extensions::Extension> LoadExtension( | |
| 45 const base::FilePath& extension_root, | |
| 46 extensions::Manifest::Location location, | |
| 47 int flags, | |
| 48 std::string* error); | |
| 49 | |
| 50 // The same as LoadExtension except use the provided |extension_id|. | |
| 51 scoped_refptr<extensions::Extension> LoadExtension( | |
| 52 const base::FilePath& extension_root, | |
| 53 const std::string& extension_id, | |
| 54 extensions::Manifest::Location location, | |
| 55 int flags, | |
| 56 std::string* error); | |
| 57 | |
| 58 // Loads an extension manifest from the specified directory. Returns NULL | |
| 59 // on failure, with a description of the error in |error|. | |
| 60 base::DictionaryValue* LoadManifest(const base::FilePath& extension_root, | |
| 61 std::string* error); | |
| 62 | |
| 63 // Returns true if the given extension object is valid and consistent. | |
| 64 // May also append a series of warning messages to |warnings|, but they | |
| 65 // should not prevent the extension from running. | |
| 66 // | |
| 67 // Otherwise, returns false, and a description of the error is | |
| 68 // returned in |error|. | |
| 69 bool ValidateExtension(const extensions::Extension* extension, | |
| 70 std::string* error, | |
| 71 std::vector<extensions::InstallWarning>* warnings); | |
| 72 | |
| 73 // Returns a list of paths (relative to the extension dir) for images that | 21 // Returns a list of paths (relative to the extension dir) for images that |
| 74 // the browser might load (like themes and page action icons) for the given | 22 // the browser might load (like themes and page action icons) for the given |
| 75 // extension. | 23 // extension. |
| 76 std::set<base::FilePath> GetBrowserImagePaths( | 24 std::set<base::FilePath> GetBrowserImagePaths( |
| 77 const extensions::Extension* extension); | 25 const extensions::Extension* extension); |
| 78 | 26 |
| 79 // Returns a list of files that contain private keys inside |extension_dir|. | |
| 80 std::vector<base::FilePath> FindPrivateKeyFiles( | |
| 81 const base::FilePath& extension_dir); | |
| 82 | |
| 83 // We need to reserve the namespace of entries that start with "_" for future | |
| 84 // use by Chrome. | |
| 85 // If any files or directories are found using "_" prefix and are not on | |
| 86 // reserved list we return false, and set error message. | |
| 87 bool CheckForIllegalFilenames(const base::FilePath& extension_path, | |
| 88 std::string* error); | |
| 89 | |
| 90 // Returns a path to a temporary directory for unpacking an extension that will | |
| 91 // be installed into |extensions_dir|. Creates the directory if necessary. | |
| 92 // The directory will be on the same file system as |extensions_dir| so | |
| 93 // that the extension directory can be efficiently renamed into place. Returns | |
| 94 // an empty file path on failure. | |
| 95 base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir); | |
| 96 | |
| 97 // Helper function to delete files. This is used to avoid ugly casts which | |
| 98 // would be necessary with PostMessage since base::Delete is overloaded. | |
| 99 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. | |
| 100 void DeleteFile(const base::FilePath& path, bool recursive); | |
| 101 | |
| 102 } // namespace extension_file_util | 27 } // namespace extension_file_util |
| 103 | 28 |
| 104 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 29 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| OLD | NEW |