Don't preload rarely seen large images
[chromium-blink-merge.git] / extensions / utility / unpacker.h
blob7e5a7e47c75347b94e3aeac8e482c7c5f98a4040
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 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.
27 class Unpacker {
28 public:
29 Unpacker(const base::FilePath& working_dir,
30 const base::FilePath& extension_dir,
31 const std::string& extension_id,
32 Manifest::Location location,
33 int creation_flags);
34 ~Unpacker();
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.
40 bool Run();
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(); }
46 private:
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
49 // success.
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
54 // success.
55 bool DumpMessageCatalogsToFile();
57 // Parse the manifest.json file inside the extension (not in the header).
58 // Caller takes ownership of return value.
59 base::DictionaryValue* ReadManifest();
61 // Parse all _locales/*/messages.json files inside the extension.
62 bool ReadAllMessageCatalogs(const std::string& default_locale);
64 // Decodes the image at the given path and puts it in our list of decoded
65 // images.
66 bool AddDecodedImage(const base::FilePath& path);
68 // Parses the catalog at the given path and puts it in our list of parsed
69 // catalogs.
70 bool ReadMessageCatalog(const base::FilePath& message_path);
72 // Set the error message.
73 void SetError(const std::string& error);
74 void SetUTF16Error(const base::string16& error);
76 // The directory to do work in.
77 base::FilePath working_dir_;
79 // The directory where the extension source lives.
80 base::FilePath extension_dir_;
82 // The extension ID if known.
83 std::string extension_id_;
85 // The location to use for the created extension.
86 Manifest::Location location_;
88 // The creation flags to use with the created extension.
89 int creation_flags_;
91 // The parsed version of the manifest JSON contained in the extension.
92 scoped_ptr<base::DictionaryValue> parsed_manifest_;
94 // A list of decoded images and the paths where those images came from. Paths
95 // are relative to the manifest file.
96 struct InternalData;
97 scoped_ptr<InternalData> internal_data_;
99 // Dictionary of relative paths and catalogs per path. Paths are in the form
100 // of _locales/locale, without messages.json base part.
101 scoped_ptr<base::DictionaryValue> parsed_catalogs_;
103 // The last error message that was set. Empty if there were no errors.
104 base::string16 error_message_;
106 DISALLOW_COPY_AND_ASSIGN(Unpacker);
109 } // namespace extensions
111 #endif // EXTENSIONS_UTILITY_UNPACKER_H_