Allow overlapping sync and async startup requests
[chromium-blink-merge.git] / chrome / utility / extensions / unpacker.h
blob53e866b5760b35bfc5505dcc514232392c73631d
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_
8 #include <string>
9 #include <vector>
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "extensions/common/manifest.h"
15 class SkBitmap;
17 namespace base {
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.
27 class Unpacker {
28 public:
29 Unpacker(const base::FilePath& extension_path,
30 const std::string& extension_id,
31 Manifest::Location location,
32 int creation_flags);
33 ~Unpacker();
35 // Install the extension file at |extension_path|. Returns true on success.
36 // Otherwise, error_message will contain a string explaining what went wrong.
37 bool Run();
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
41 // success.
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
46 // success.
47 bool DumpMessageCatalogsToFile();
49 const 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(); }
55 private:
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
64 // images.
65 bool AddDecodedImage(const base::FilePath& path);
67 // Parses the catalog at the given path and puts it in our list of parsed
68 // catalogs.
69 bool ReadMessageCatalog(const base::FilePath& message_path);
71 // Set the error message.
72 void SetError(const std::string& error);
73 void SetUTF16Error(const 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.
85 int creation_flags_;
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.
95 struct InternalData;
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 string16 error_message_;
105 DISALLOW_COPY_AND_ASSIGN(Unpacker);
108 } // namespace extensions
110 #endif // CHROME_UTILITY_EXTENSIONS_UNPACKER_H_