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 EXTENSIONS_UTILITY_UNPACKER_H_
6 #define EXTENSIONS_UTILITY_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 parse various bits of the extension, then report back to
25 // the browser process, who then transcodes the pre-parsed bits and writes them
26 // back out to disk for later use.
29 Unpacker(const base::FilePath
& working_dir
,
30 const base::FilePath
& extension_dir
,
31 const std::string
& extension_id
,
32 Manifest::Location location
,
36 // Runs the processing steps for the extension. On success, this returns true
37 // and the decoded images will be in a file at
38 // |working_dir|/kDecodedImagesFilename and the decoded messages will be in a
39 // file at |working_dir|/kDecodedMessageCatalogsFilename.
42 const base::string16
& error_message() { return error_message_
; }
43 base::DictionaryValue
* parsed_manifest() { return parsed_manifest_
.get(); }
44 base::DictionaryValue
* parsed_catalogs() { return parsed_catalogs_
.get(); }
47 // Write the decoded images to kDecodedImagesFilename. We do this instead
48 // of sending them over IPC, since they are so large. Returns true on
50 bool DumpImagesToFile();
52 // Write the decoded messages to kDecodedMessageCatalogsFilename. We do this
53 // instead of sending them over IPC, since they are so large. Returns true on
55 bool DumpMessageCatalogsToFile();
57 // Parse the manifest.json file inside the extension (not in the header).
58 scoped_ptr
<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 directory to do work in.
76 base::FilePath working_dir_
;
78 // The directory where the extension source lives.
79 base::FilePath extension_dir_
;
81 // The extension ID if known.
82 std::string extension_id_
;
84 // The location to use for the created extension.
85 Manifest::Location location_
;
87 // The creation flags to use with the created extension.
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 // EXTENSIONS_UTILITY_UNPACKER_H_