| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_UNPACKER_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_UNPACKER_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_UNPACKER_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_UNPACKER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/tuple.h" | 14 #include "base/tuple.h" |
| 15 | 15 |
| 16 class SkBitmap; |
| 17 |
| 18 namespace base { |
| 16 class DictionaryValue; | 19 class DictionaryValue; |
| 17 class SkBitmap; | 20 } |
| 18 | 21 |
| 19 // This class unpacks an extension. It is designed to be used in a sandboxed | 22 // This class unpacks an extension. It is designed to be used in a sandboxed |
| 20 // child process. We unpack and parse various bits of the extension, then | 23 // child process. We unpack and parse various bits of the extension, then |
| 21 // report back to the browser process, who then transcodes the pre-parsed bits | 24 // report back to the browser process, who then transcodes the pre-parsed bits |
| 22 // and writes them back out to disk for later use. | 25 // and writes them back out to disk for later use. |
| 23 class ExtensionUnpacker { | 26 class ExtensionUnpacker { |
| 24 public: | 27 public: |
| 25 typedef std::vector< Tuple2<SkBitmap, FilePath> > DecodedImages; | 28 typedef std::vector< Tuple2<SkBitmap, FilePath> > DecodedImages; |
| 26 | 29 |
| 27 explicit ExtensionUnpacker(const FilePath& extension_path); | 30 explicit ExtensionUnpacker(const FilePath& extension_path); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 44 // Read the decoded images back from the file we saved them to. | 47 // Read the decoded images back from the file we saved them to. |
| 45 // |extension_path| is the path to the extension we unpacked that wrote the | 48 // |extension_path| is the path to the extension we unpacked that wrote the |
| 46 // data. Returns true on success. | 49 // data. Returns true on success. |
| 47 static bool ReadImagesFromFile(const FilePath& extension_path, | 50 static bool ReadImagesFromFile(const FilePath& extension_path, |
| 48 DecodedImages* images); | 51 DecodedImages* images); |
| 49 | 52 |
| 50 // Read the decoded message catalogs back from the file we saved them to. | 53 // Read the decoded message catalogs back from the file we saved them to. |
| 51 // |extension_path| is the path to the extension we unpacked that wrote the | 54 // |extension_path| is the path to the extension we unpacked that wrote the |
| 52 // data. Returns true on success. | 55 // data. Returns true on success. |
| 53 static bool ReadMessageCatalogsFromFile(const FilePath& extension_path, | 56 static bool ReadMessageCatalogsFromFile(const FilePath& extension_path, |
| 54 DictionaryValue* catalogs); | 57 base::DictionaryValue* catalogs); |
| 55 | 58 |
| 56 const std::string& error_message() { return error_message_; } | 59 const std::string& error_message() { return error_message_; } |
| 57 DictionaryValue* parsed_manifest() { | 60 base::DictionaryValue* parsed_manifest() { |
| 58 return parsed_manifest_.get(); | 61 return parsed_manifest_.get(); |
| 59 } | 62 } |
| 60 const DecodedImages& decoded_images() { return decoded_images_; } | 63 const DecodedImages& decoded_images() { return decoded_images_; } |
| 61 DictionaryValue* parsed_catalogs() { return parsed_catalogs_.get(); } | 64 base::DictionaryValue* parsed_catalogs() { return parsed_catalogs_.get(); } |
| 62 | 65 |
| 63 private: | 66 private: |
| 64 // Parse the manifest.json file inside the extension (not in the header). | 67 // Parse the manifest.json file inside the extension (not in the header). |
| 65 // Caller takes ownership of return value. | 68 // Caller takes ownership of return value. |
| 66 DictionaryValue* ReadManifest(); | 69 base::DictionaryValue* ReadManifest(); |
| 67 | 70 |
| 68 // Parse all _locales/*/messages.json files inside the extension. | 71 // Parse all _locales/*/messages.json files inside the extension. |
| 69 bool ReadAllMessageCatalogs(const std::string& default_locale); | 72 bool ReadAllMessageCatalogs(const std::string& default_locale); |
| 70 | 73 |
| 71 // Decodes the image at the given path and puts it in our list of decoded | 74 // Decodes the image at the given path and puts it in our list of decoded |
| 72 // images. | 75 // images. |
| 73 bool AddDecodedImage(const FilePath& path); | 76 bool AddDecodedImage(const FilePath& path); |
| 74 | 77 |
| 75 // Parses the catalog at the given path and puts it in our list of parsed | 78 // Parses the catalog at the given path and puts it in our list of parsed |
| 76 // catalogs. | 79 // catalogs. |
| 77 bool ReadMessageCatalog(const FilePath& message_path); | 80 bool ReadMessageCatalog(const FilePath& message_path); |
| 78 | 81 |
| 79 // Set the error message. | 82 // Set the error message. |
| 80 void SetError(const std::string& error); | 83 void SetError(const std::string& error); |
| 81 | 84 |
| 82 // The extension to unpack. | 85 // The extension to unpack. |
| 83 FilePath extension_path_; | 86 FilePath extension_path_; |
| 84 | 87 |
| 85 // The place we unpacked the extension to. | 88 // The place we unpacked the extension to. |
| 86 FilePath temp_install_dir_; | 89 FilePath temp_install_dir_; |
| 87 | 90 |
| 88 // The parsed version of the manifest JSON contained in the extension. | 91 // The parsed version of the manifest JSON contained in the extension. |
| 89 scoped_ptr<DictionaryValue> parsed_manifest_; | 92 scoped_ptr<base::DictionaryValue> parsed_manifest_; |
| 90 | 93 |
| 91 // A list of decoded images and the paths where those images came from. Paths | 94 // A list of decoded images and the paths where those images came from. Paths |
| 92 // are relative to the manifest file. | 95 // are relative to the manifest file. |
| 93 DecodedImages decoded_images_; | 96 DecodedImages decoded_images_; |
| 94 | 97 |
| 95 // Dictionary of relative paths and catalogs per path. Paths are in the form | 98 // Dictionary of relative paths and catalogs per path. Paths are in the form |
| 96 // of _locales/locale, without messages.json base part. | 99 // of _locales/locale, without messages.json base part. |
| 97 scoped_ptr<DictionaryValue> parsed_catalogs_; | 100 scoped_ptr<base::DictionaryValue> parsed_catalogs_; |
| 98 | 101 |
| 99 // The last error message that was set. Empty if there were no errors. | 102 // The last error message that was set. Empty if there were no errors. |
| 100 std::string error_message_; | 103 std::string error_message_; |
| 101 | 104 |
| 102 DISALLOW_COPY_AND_ASSIGN(ExtensionUnpacker); | 105 DISALLOW_COPY_AND_ASSIGN(ExtensionUnpacker); |
| 103 }; | 106 }; |
| 104 | 107 |
| 105 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_UNPACKER_H_ | 108 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_UNPACKER_H_ |
| OLD | NEW |