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
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_EXTENSIONS_UNPACKER_H_
6 #define CHROME_UTILITY_EXTENSIONS_UNPACKER_H_
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "extensions/common/manifest.h"
18 class DictionaryValue
;
21 namespace extensions
{
23 // This class unpacks an extension. It is designed to be used in a sandboxed
24 // child process. We unpack and parse various bits of the extension, then
25 // report back to the browser process, who then transcodes the pre-parsed bits
26 // and writes them back out to disk for later use.
29 Unpacker(const base::FilePath
& extension_path
,
30 const std::string
& extension_id
,
31 Manifest::Location location
,
35 // Install the extension file at |extension_path|. Returns true on success.
36 // Otherwise, error_message will contain a string explaining what went wrong.
39 // Write the decoded images to kDecodedImagesFilename. We do this instead
40 // of sending them over IPC, since they are so large. Returns true on
42 bool DumpImagesToFile();
44 // Write the decoded messages to kDecodedMessageCatalogsFilename. We do this
45 // instead of sending them over IPC, since they are so large. Returns true on
47 bool DumpMessageCatalogsToFile();
49 const base::string16
& error_message() { return error_message_
; }
50 base::DictionaryValue
* parsed_manifest() {
51 return parsed_manifest_
.get();
53 base::DictionaryValue
* parsed_catalogs() { return parsed_catalogs_
.get(); }
56 // Parse the manifest.json file inside the extension (not in the header).
57 // Caller takes ownership of return value.
58 base::DictionaryValue
* ReadManifest();
60 // Parse all _locales/*/messages.json files inside the extension.
61 bool ReadAllMessageCatalogs(const std::string
& default_locale
);
63 // Decodes the image at the given path and puts it in our list of decoded
65 bool AddDecodedImage(const base::FilePath
& path
);
67 // Parses the catalog at the given path and puts it in our list of parsed
69 bool ReadMessageCatalog(const base::FilePath
& message_path
);
71 // Set the error message.
72 void SetError(const std::string
& error
);
73 void SetUTF16Error(const base::string16
& error
);
75 // The extension to unpack.
76 base::FilePath extension_path_
;
78 // The extension ID if known.
79 std::string extension_id_
;
81 // The location to use for the created extension.
82 Manifest::Location location_
;
84 // The creation flags to use with the created extension.
87 // The place we unpacked the extension to.
88 base::FilePath temp_install_dir_
;
90 // The parsed version of the manifest JSON contained in the extension.
91 scoped_ptr
<base::DictionaryValue
> parsed_manifest_
;
93 // A list of decoded images and the paths where those images came from. Paths
94 // are relative to the manifest file.
96 scoped_ptr
<InternalData
> internal_data_
;
98 // Dictionary of relative paths and catalogs per path. Paths are in the form
99 // of _locales/locale, without messages.json base part.
100 scoped_ptr
<base::DictionaryValue
> parsed_catalogs_
;
102 // The last error message that was set. Empty if there were no errors.
103 base::string16 error_message_
;
105 DISALLOW_COPY_AND_ASSIGN(Unpacker
);
108 } // namespace extensions
110 #endif // CHROME_UTILITY_EXTENSIONS_UNPACKER_H_