| 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 "chrome/common/extensions/extension.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/common/extensions/manifest.h" |
| 12 #include "chrome/common/extensions/message_bundle.h" | 13 #include "chrome/common/extensions/message_bundle.h" |
| 14 #include "extensions/common/install_warning.h" |
| 13 | 15 |
| 14 class FilePath; | 16 class FilePath; |
| 15 class GURL; | 17 class GURL; |
| 16 | 18 |
| 17 namespace base { | 19 namespace base { |
| 18 class DictionaryValue; | 20 class DictionaryValue; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace extensions { | 23 namespace extensions { |
| 24 class Extension; |
| 22 class MessageBundle; | 25 class MessageBundle; |
| 23 } | 26 } |
| 24 | 27 |
| 25 // Utilities for manipulating the on-disk storage of extensions. | 28 // Utilities for manipulating the on-disk storage of extensions. |
| 26 namespace extension_file_util { | 29 namespace extension_file_util { |
| 27 | 30 |
| 28 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. | 31 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. |
| 29 // 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 |
| 30 // on failure. | 33 // on failure. |
| 31 FilePath InstallExtension(const FilePath& unpacked_source_dir, | 34 FilePath InstallExtension(const FilePath& unpacked_source_dir, |
| 32 const std::string& id, | 35 const std::string& id, |
| 33 const std::string& version, | 36 const std::string& version, |
| 34 const FilePath& extensions_dir); | 37 const FilePath& extensions_dir); |
| 35 | 38 |
| 36 // Removes all versions of the extension with |id| from |extensions_dir|. | 39 // Removes all versions of the extension with |id| from |extensions_dir|. |
| 37 void UninstallExtension(const FilePath& extensions_dir, | 40 void UninstallExtension(const FilePath& extensions_dir, |
| 38 const std::string& id); | 41 const std::string& id); |
| 39 | 42 |
| 40 // Loads and validates an extension from the specified directory. Returns NULL | 43 // Loads and validates an extension from the specified directory. Returns NULL |
| 41 // on failure, with a description of the error in |error|. | 44 // on failure, with a description of the error in |error|. |
| 42 scoped_refptr<extensions::Extension> LoadExtension( | 45 scoped_refptr<extensions::Extension> LoadExtension( |
| 43 const FilePath& extension_root, | 46 const FilePath& extension_root, |
| 44 extensions::Extension::Location location, | 47 extensions::Manifest::Location location, |
| 45 int flags, | 48 int flags, |
| 46 std::string* error); | 49 std::string* error); |
| 47 | 50 |
| 48 // The same as LoadExtension except use the provided |extension_id|. | 51 // The same as LoadExtension except use the provided |extension_id|. |
| 49 scoped_refptr<extensions::Extension> LoadExtension( | 52 scoped_refptr<extensions::Extension> LoadExtension( |
| 50 const FilePath& extension_root, | 53 const FilePath& extension_root, |
| 51 const std::string& extension_id, | 54 const std::string& extension_id, |
| 52 extensions::Extension::Location location, | 55 extensions::Manifest::Location location, |
| 53 int flags, | 56 int flags, |
| 54 std::string* error); | 57 std::string* error); |
| 55 | 58 |
| 56 // Loads an extension manifest from the specified directory. Returns NULL | 59 // Loads an extension manifest from the specified directory. Returns NULL |
| 57 // on failure, with a description of the error in |error|. | 60 // on failure, with a description of the error in |error|. |
| 58 base::DictionaryValue* LoadManifest(const FilePath& extension_root, | 61 base::DictionaryValue* LoadManifest(const FilePath& extension_root, |
| 59 std::string* error); | 62 std::string* error); |
| 60 | 63 |
| 61 // 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. |
| 62 bool ValidateFilePath(const FilePath& path); | 65 bool ValidateFilePath(const FilePath& path); |
| 63 | 66 |
| 64 // Returns true if the given extension object is valid and consistent. | 67 // Returns true if the given extension object is valid and consistent. |
| 65 // 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 |
| 66 // should not prevent the extension from running. | 69 // should not prevent the extension from running. |
| 67 // | 70 // |
| 68 // Otherwise, returns false, and a description of the error is | 71 // Otherwise, returns false, and a description of the error is |
| 69 // returned in |error|. | 72 // returned in |error|. |
| 70 bool ValidateExtension(const extensions::Extension* extension, | 73 bool ValidateExtension(const extensions::Extension* extension, |
| 71 std::string* error, | 74 std::string* error, |
| 72 extensions::Extension::InstallWarningVector* warnings); | 75 extensions::InstallWarning::Vector* warnings); |
| 73 | 76 |
| 74 // 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|. |
| 75 std::vector<FilePath> FindPrivateKeyFiles(const FilePath& extension_dir); | 78 std::vector<FilePath> FindPrivateKeyFiles(const FilePath& extension_dir); |
| 76 | 79 |
| 77 // 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 |
| 78 // 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 |
| 79 // file is in use). | 82 // file is in use). |
| 80 // | 83 // |
| 81 // |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 |
| 82 // map from extension id to full installation path. | 85 // map from extension id to full installation path. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 FilePath GetInstallTempDir(const FilePath& extensions_dir); | 126 FilePath GetInstallTempDir(const FilePath& extensions_dir); |
| 124 | 127 |
| 125 // Helper function to delete files. This is used to avoid ugly casts which | 128 // Helper function to delete files. This is used to avoid ugly casts which |
| 126 // would be necessary with PostMessage since file_util::Delete is overloaded. | 129 // would be necessary with PostMessage since file_util::Delete is overloaded. |
| 127 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. | 130 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. |
| 128 void DeleteFile(const FilePath& path, bool recursive); | 131 void DeleteFile(const FilePath& path, bool recursive); |
| 129 | 132 |
| 130 } // namespace extension_file_util | 133 } // namespace extension_file_util |
| 131 | 134 |
| 132 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 135 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| OLD | NEW |