Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_COMMON_FILE_UTIL_H_ | 5 #ifndef EXTENSIONS_COMMON_FILE_UTIL_H_ |
| 6 #define EXTENSIONS_COMMON_FILE_UTIL_H_ | 6 #define EXTENSIONS_COMMON_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "extensions/common/manifest.h" | |
| 10 | 15 |
| 11 class ExtensionIconSet; | 16 class ExtensionIconSet; |
| 12 class GURL; | 17 class GURL; |
| 13 | 18 |
| 14 namespace base { | 19 namespace base { |
| 15 class FilePath; | 20 class FilePath; |
| 16 } | 21 } |
| 17 | 22 |
| 18 namespace extensions { | 23 namespace extensions { |
| 19 class Extension; | 24 class Extension; |
| 25 struct InstallWarning; | |
| 20 class MessageBundle; | 26 class MessageBundle; |
| 21 | 27 |
| 28 // Utilities for manipulating the on-disk storage of extensions. | |
| 22 namespace file_util { | 29 namespace file_util { |
| 23 | 30 |
| 31 extern const base::FilePath::CharType kTempDirectoryName[]; | |
|
James Cook
2014/04/12 00:03:22
This code is unchanged except for putting it into
| |
| 32 | |
| 33 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. | |
| 34 // The destination directory is returned on success, or empty path is returned | |
| 35 // on failure. | |
| 36 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, | |
| 37 const std::string& id, | |
| 38 const std::string& version, | |
| 39 const base::FilePath& extensions_dir); | |
| 40 | |
| 41 // Removes all versions of the extension with |id| from |extensions_dir|. | |
| 42 void UninstallExtension(const base::FilePath& extensions_dir, | |
| 43 const std::string& id); | |
| 44 | |
| 45 // Loads and validates an extension from the specified directory. Returns NULL | |
| 46 // on failure, with a description of the error in |error|. | |
| 47 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_root, | |
| 48 Manifest::Location location, | |
| 49 int flags, | |
| 50 std::string* error); | |
| 51 | |
| 52 // The same as LoadExtension except use the provided |extension_id|. | |
| 53 scoped_refptr<Extension> LoadExtension(const base::FilePath& extension_root, | |
| 54 const std::string& extension_id, | |
| 55 Manifest::Location location, | |
| 56 int flags, | |
| 57 std::string* error); | |
| 58 | |
| 59 // Loads an extension manifest from the specified directory. Returns NULL | |
| 60 // on failure, with a description of the error in |error|. | |
| 61 base::DictionaryValue* LoadManifest(const base::FilePath& extension_root, | |
| 62 std::string* error); | |
| 63 | |
| 64 // Returns true if the given extension object is valid and consistent. | |
| 65 // May also append a series of warning messages to |warnings|, but they | |
| 66 // should not prevent the extension from running. | |
| 67 // | |
| 68 // Otherwise, returns false, and a description of the error is | |
| 69 // returned in |error|. | |
| 70 bool ValidateExtension(const Extension* extension, | |
| 71 std::string* error, | |
| 72 std::vector<InstallWarning>* warnings); | |
| 73 | |
| 74 // Returns a list of files that contain private keys inside |extension_dir|. | |
| 75 std::vector<base::FilePath> FindPrivateKeyFiles( | |
| 76 const base::FilePath& extension_dir); | |
| 77 | |
| 78 // We need to reserve the namespace of entries that start with "_" for future | |
| 79 // use by Chrome. | |
| 80 // If any files or directories are found using "_" prefix and are not on | |
| 81 // reserved list we return false, and set error message. | |
| 82 bool CheckForIllegalFilenames(const base::FilePath& extension_path, | |
| 83 std::string* error); | |
| 84 | |
| 85 // Returns a path to a temporary directory for unpacking an extension that will | |
| 86 // be installed into |extensions_dir|. Creates the directory if necessary. | |
| 87 // The directory will be on the same file system as |extensions_dir| so | |
| 88 // that the extension directory can be efficiently renamed into place. Returns | |
| 89 // an empty file path on failure. | |
| 90 base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir); | |
| 91 | |
| 92 // Helper function to delete files. This is used to avoid ugly casts which | |
| 93 // would be necessary with PostMessage since base::Delete is overloaded. | |
| 94 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. | |
| 95 void DeleteFile(const base::FilePath& path, bool recursive); | |
| 96 | |
| 24 // Get a relative file path from a chrome-extension:// URL. | 97 // Get a relative file path from a chrome-extension:// URL. |
| 25 base::FilePath ExtensionURLToRelativeFilePath(const GURL& url); | 98 base::FilePath ExtensionURLToRelativeFilePath(const GURL& url); |
| 26 | 99 |
| 27 // Get a full file path from a chrome-extension-resource:// URL, If the URL | 100 // Get a full file path from a chrome-extension-resource:// URL, If the URL |
| 28 // points a file outside of root, this function will return empty FilePath. | 101 // points a file outside of root, this function will return empty FilePath. |
| 29 base::FilePath ExtensionResourceURLToFilePath(const GURL& url, | 102 base::FilePath ExtensionResourceURLToFilePath(const GURL& url, |
| 30 const base::FilePath& root); | 103 const base::FilePath& root); |
| 31 | 104 |
| 32 // Returns true if the icons in the icon set exist. Oherwise, populates | 105 // Returns true if the icons in the icon set exist. Oherwise, populates |
| 33 // |error| with the |error_message_id| for an invalid file. | 106 // |error| with the |error_message_id| for an invalid file. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 46 // the extension_id item. | 119 // the extension_id item. |
| 47 std::map<std::string, std::string>* LoadMessageBundleSubstitutionMap( | 120 std::map<std::string, std::string>* LoadMessageBundleSubstitutionMap( |
| 48 const base::FilePath& extension_path, | 121 const base::FilePath& extension_path, |
| 49 const std::string& extension_id, | 122 const std::string& extension_id, |
| 50 const std::string& default_locale); | 123 const std::string& default_locale); |
| 51 | 124 |
| 52 } // namespace file_util | 125 } // namespace file_util |
| 53 } // namespace extensions | 126 } // namespace extensions |
| 54 | 127 |
| 55 #endif // EXTENSIONS_COMMON_FILE_UTIL_H_ | 128 #endif // EXTENSIONS_COMMON_FILE_UTIL_H_ |
| OLD | NEW |