Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / utility / unpacker.h
blob240172e0ad729c4d1ef3dedc382c0e63345a78cd
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_
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 base::string16& error_message() { return error_message_; }
50 base::DictionaryValue* parsed_manifest() { return parsed_manifest_.get(); }
51 base::DictionaryValue* parsed_catalogs() { return parsed_catalogs_.get(); }
53 private:
54 // Parse the manifest.json file inside the extension (not in the header).
55 // Caller takes ownership of return value.
56 base::DictionaryValue* ReadManifest();
58 // Parse all _locales/*/messages.json files inside the extension.
59 bool ReadAllMessageCatalogs(const std::string& default_locale);
61 // Decodes the image at the given path and puts it in our list of decoded
62 // images.
63 bool AddDecodedImage(const base::FilePath& path);
65 // Parses the catalog at the given path and puts it in our list of parsed
66 // catalogs.
67 bool ReadMessageCatalog(const base::FilePath& message_path);
69 // Set the error message.
70 void SetError(const std::string& error);
71 void SetUTF16Error(const base::string16& error);
73 // The extension to unpack.
74 base::FilePath extension_path_;
76 // The extension ID if known.
77 std::string extension_id_;
79 // The location to use for the created extension.
80 Manifest::Location location_;
82 // The creation flags to use with the created extension.
83 int creation_flags_;
85 // The place we unpacked the extension to.
86 base::FilePath temp_install_dir_;
88 // The parsed version of the manifest JSON contained in the extension.
89 scoped_ptr<base::DictionaryValue> parsed_manifest_;
91 // A list of decoded images and the paths where those images came from. Paths
92 // are relative to the manifest file.
93 struct InternalData;
94 scoped_ptr<InternalData> internal_data_;
96 // Dictionary of relative paths and catalogs per path. Paths are in the form
97 // of _locales/locale, without messages.json base part.
98 scoped_ptr<base::DictionaryValue> parsed_catalogs_;
100 // The last error message that was set. Empty if there were no errors.
101 base::string16 error_message_;
103 DISALLOW_COPY_AND_ASSIGN(Unpacker);
106 } // namespace extensions
108 #endif // EXTENSIONS_UTILITY_UNPACKER_H_