Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/browser/extensions/sandboxed_extension_unpacker.h

Issue 526012: Merge 32345 - Parse messages.json in ExtensionUnpacker (like we do for manife... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/249/src/
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_
6 #define CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/utility_process_host.h" 14 #include "chrome/browser/utility_process_host.h"
15 15
16 class Extension; 16 class Extension;
17 class MessageLoop; 17 class MessageLoop;
18 class ResourceDispatcherHost; 18 class ResourceDispatcherHost;
19 19
20 class SandboxedExtensionUnpackerClient 20 class SandboxedExtensionUnpackerClient
21 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> { 21 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> {
22 public: 22 public:
23 // temp_dir - A temporary directoy containing the results of the extension 23 // temp_dir - A temporary directory containing the results of the extension
24 // unpacking. The client is responsible for deleting this directory. 24 // unpacking. The client is responsible for deleting this directory.
25 // 25 //
26 // extension_root - The path to the extension root inside of temp_dir. 26 // extension_root - The path to the extension root inside of temp_dir.
27 // 27 //
28 // extension - The extension that was unpacked. The client is responsible 28 // extension - The extension that was unpacked. The client is responsible
29 // for deleting this memory. 29 // for deleting this memory.
30 virtual void OnUnpackSuccess(const FilePath& temp_dir, 30 virtual void OnUnpackSuccess(const FilePath& temp_dir,
31 const FilePath& extension_root, 31 const FilePath& extension_root,
32 Extension* extension) = 0; 32 Extension* extension) = 0;
33 virtual void OnUnpackFailure(const std::string& error) = 0; 33 virtual void OnUnpackFailure(const std::string& error) = 0;
34 34
35 protected: 35 protected:
36 friend class base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient>; 36 friend class base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient>;
37 37
38 virtual ~SandboxedExtensionUnpackerClient() {} 38 virtual ~SandboxedExtensionUnpackerClient() {}
39 }; 39 };
40 40
41 // SandboxedExtensionUnpacker unpacks extensions from the CRX format into a 41 // SandboxedExtensionUnpacker unpacks extensions from the CRX format into a
42 // directory. This is done in a sandboxed subprocess to protect the browser 42 // directory. This is done in a sandboxed subprocess to protect the browser
43 // process from parsing complex formats like JPEG or JSON from untrusted 43 // process from parsing complex formats like JPEG or JSON from untrusted
44 // sources. 44 // sources.
45 // 45 //
46 // Unpacking an extension using this class makes minor changes to its source, 46 // Unpacking an extension using this class makes minor changes to its source,
47 // such as transcoding all images to PNG and rewriting the manifest JSON. As 47 // such as transcoding all images to PNG, parsing all message catalogs
48 // such, it should not be used when the output is not intended to be given back 48 // and rewriting the manifest JSON. As such, it should not be used when the
49 // to the author. 49 // output is not intended to be given back to the author.
50 // 50 //
51 // 51 //
52 // Lifetime management: 52 // Lifetime management:
53 // 53 //
54 // This class is ref-counted by each call it makes to itself on another thread, 54 // This class is ref-counted by each call it makes to itself on another thread,
55 // and by UtilityProcessHost. 55 // and by UtilityProcessHost.
56 // 56 //
57 // Additionally, we hold a reference to our own client so that it lives at least 57 // Additionally, we hold a reference to our own client so that it lives at least
58 // long enough to receive the result of unpacking. 58 // long enough to receive the result of unpacking.
59 // 59 //
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 SandboxedExtensionUnpacker(const FilePath& crx_path, 95 SandboxedExtensionUnpacker(const FilePath& crx_path,
96 ResourceDispatcherHost* rdh, 96 ResourceDispatcherHost* rdh,
97 SandboxedExtensionUnpackerClient* cilent); 97 SandboxedExtensionUnpackerClient* cilent);
98 98
99 // Start unpacking the extension. The client is called with the results. 99 // Start unpacking the extension. The client is called with the results.
100 void Start(); 100 void Start();
101 101
102 private: 102 private:
103 class ProcessHostClient; 103 class ProcessHostClient;
104 friend class ProcessHostClient; 104 friend class ProcessHostClient;
105 friend class SandboxedExtensionUnpackerTest;
105 106
106 ~SandboxedExtensionUnpacker() {} 107 ~SandboxedExtensionUnpacker() {}
107 108
108 // Validates the signature of the extension and extract the key to 109 // Validates the signature of the extension and extract the key to
109 // |public_key_|. Returns true if the signature validates, false otherwise. 110 // |public_key_|. Returns true if the signature validates, false otherwise.
110 // 111 //
111 // NOTE: Having this method here is a bit ugly. This code should really live 112 // NOTE: Having this method here is a bit ugly. This code should really live
112 // in ExtensionUnpacker as it is not specific to sandboxed unpacking. It was 113 // in ExtensionUnpacker as it is not specific to sandboxed unpacking. It was
113 // put here because we cannot run windows crypto code in the sandbox. But we 114 // put here because we cannot run windows crypto code in the sandbox. But we
114 // could still have this method statically on ExtensionUnpacker so that code 115 // could still have this method statically on ExtensionUnpacker so that code
115 // just for unpacking is there and code just for sandboxing of unpacking is 116 // just for unpacking is there and code just for sandboxing of unpacking is
116 // here. 117 // here.
117 bool ValidateSignature(); 118 bool ValidateSignature();
118 119
119 // Starts the utility process that unpacks our extension. 120 // Starts the utility process that unpacks our extension.
120 void StartProcessOnIOThread(const FilePath& temp_crx_path); 121 void StartProcessOnIOThread(const FilePath& temp_crx_path);
121 122
122 // SandboxedExtensionUnpacker 123 // SandboxedExtensionUnpacker
123 void OnUnpackExtensionSucceeded(const DictionaryValue& manifest); 124 void OnUnpackExtensionSucceeded(const DictionaryValue& manifest,
125 const DictionaryValue& catalogs);
124 void OnUnpackExtensionFailed(const std::string& error_message); 126 void OnUnpackExtensionFailed(const std::string& error_message);
125 void OnProcessCrashed(); 127 void OnProcessCrashed();
126 128
127 void ReportFailure(const std::string& message); 129 void ReportFailure(const std::string& message);
128 void ReportSuccess(); 130 void ReportSuccess();
129 131
132 // Overwrites original manifest with safe result from utility process.
133 // Returns NULL on error. Caller owns the returned object.
134 DictionaryValue* RewriteManifestFile(const DictionaryValue& manifest);
135
136 // Overwrites original files with safe results from utility process.
137 // Reports error and returns false if it fails.
138 bool RewriteImageFiles();
139 bool RewriteCatalogFiles(const DictionaryValue& parsed_catalogs);
140
130 FilePath crx_path_; 141 FilePath crx_path_;
131 ChromeThread::ID thread_identifier_; 142 ChromeThread::ID thread_identifier_;
132 ResourceDispatcherHost* rdh_; 143 ResourceDispatcherHost* rdh_;
133 scoped_refptr<SandboxedExtensionUnpackerClient> client_; 144 scoped_refptr<SandboxedExtensionUnpackerClient> client_;
134 ScopedTempDir temp_dir_; 145 ScopedTempDir temp_dir_;
135 FilePath extension_root_; 146 FilePath extension_root_;
136 scoped_ptr<Extension> extension_; 147 scoped_ptr<Extension> extension_;
137 bool got_response_; 148 bool got_response_;
138 std::string public_key_; 149 std::string public_key_;
139 }; 150 };
140 151
141 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ 152 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_file_util.cc ('k') | chrome/browser/extensions/sandboxed_extension_unpacker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698