OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/utility_process_host_client.h" | 16 #include "content/public/browser/utility_process_host_client.h" |
17 | 17 |
18 class Extension; | |
19 | |
20 namespace base { | 18 namespace base { |
21 class DictionaryValue; | 19 class DictionaryValue; |
22 } | 20 } |
23 | 21 |
24 class SandboxedExtensionUnpackerClient | 22 class SandboxedExtensionUnpackerClient |
25 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> { | 23 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> { |
26 public: | 24 public: |
27 // temp_dir - A temporary directory containing the results of the extension | 25 // temp_dir - A temporary directory containing the results of the extension |
28 // unpacking. The client is responsible for deleting this directory. | 26 // unpacking. The client is responsible for deleting this directory. |
29 // | 27 // |
30 // extension_root - The path to the extension root inside of temp_dir. | 28 // extension_root - The path to the extension root inside of temp_dir. |
31 // | 29 // |
32 // original_manifest - The parsed but unmodified version of the manifest, | 30 // original_manifest - The parsed but unmodified version of the manifest, |
33 // with no modifications such as localization, etc. | 31 // with no modifications such as localization, etc. |
34 // | 32 // |
35 // extension - The extension that was unpacked. The client is responsible | 33 // extension - The extension that was unpacked. The client is responsible |
36 // for deleting this memory. | 34 // for deleting this memory. |
37 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 35 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
38 const FilePath& extension_root, | 36 const FilePath& extension_root, |
39 const base::DictionaryValue* original_manifest, | 37 const base::DictionaryValue* original_manifest, |
40 const Extension* extension) = 0; | 38 const extensions::Extension* extension) = 0; |
41 virtual void OnUnpackFailure(const string16& error) = 0; | 39 virtual void OnUnpackFailure(const string16& error) = 0; |
42 | 40 |
43 protected: | 41 protected: |
44 friend class base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient>; | 42 friend class base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient>; |
45 | 43 |
46 virtual ~SandboxedExtensionUnpackerClient() {} | 44 virtual ~SandboxedExtensionUnpackerClient() {} |
47 }; | 45 }; |
48 | 46 |
49 // SandboxedExtensionUnpacker unpacks extensions from the CRX format into a | 47 // SandboxedExtensionUnpacker unpacks extensions from the CRX format into a |
50 // directory. This is done in a sandboxed subprocess to protect the browser | 48 // directory. This is done in a sandboxed subprocess to protect the browser |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 static const char kExtensionHeaderMagic[]; | 93 static const char kExtensionHeaderMagic[]; |
96 | 94 |
97 // The current version of the crx format. | 95 // The current version of the crx format. |
98 static const uint32 kCurrentVersion = 2; | 96 static const uint32 kCurrentVersion = 2; |
99 | 97 |
100 // Unpacks the extension in |crx_path| into a temporary directory and calls | 98 // Unpacks the extension in |crx_path| into a temporary directory and calls |
101 // |client| with the result. If |run_out_of_process| is provided, unpacking | 99 // |client| with the result. If |run_out_of_process| is provided, unpacking |
102 // is done in a sandboxed subprocess. Otherwise, it is done in-process. | 100 // is done in a sandboxed subprocess. Otherwise, it is done in-process. |
103 SandboxedExtensionUnpacker(const FilePath& crx_path, | 101 SandboxedExtensionUnpacker(const FilePath& crx_path, |
104 bool run_out_of_process, | 102 bool run_out_of_process, |
105 Extension::Location location, | 103 extensions::Extension::Location location, |
106 int creation_flags, | 104 int creation_flags, |
107 SandboxedExtensionUnpackerClient* client); | 105 SandboxedExtensionUnpackerClient* client); |
108 | 106 |
109 // Start unpacking the extension. The client is called with the results. | 107 // Start unpacking the extension. The client is called with the results. |
110 void Start(); | 108 void Start(); |
111 | 109 |
112 private: | 110 private: |
113 class ProcessHostClient; | 111 class ProcessHostClient; |
114 | 112 |
115 // Enumerate all the ways unpacking can fail. Calls to ReportFailure() | 113 // Enumerate all the ways unpacking can fail. Calls to ReportFailure() |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // Our client. | 224 // Our client. |
227 scoped_refptr<SandboxedExtensionUnpackerClient> client_; | 225 scoped_refptr<SandboxedExtensionUnpackerClient> client_; |
228 | 226 |
229 // A temporary directory to use for unpacking. | 227 // A temporary directory to use for unpacking. |
230 ScopedTempDir temp_dir_; | 228 ScopedTempDir temp_dir_; |
231 | 229 |
232 // The root directory of the unpacked extension. This is a child of temp_dir_. | 230 // The root directory of the unpacked extension. This is a child of temp_dir_. |
233 FilePath extension_root_; | 231 FilePath extension_root_; |
234 | 232 |
235 // Represents the extension we're unpacking. | 233 // Represents the extension we're unpacking. |
236 scoped_refptr<Extension> extension_; | 234 scoped_refptr<extensions::Extension> extension_; |
237 | 235 |
238 // Whether we've received a response from the utility process yet. | 236 // Whether we've received a response from the utility process yet. |
239 bool got_response_; | 237 bool got_response_; |
240 | 238 |
241 // The public key that was extracted from the CRX header. | 239 // The public key that was extracted from the CRX header. |
242 std::string public_key_; | 240 std::string public_key_; |
243 | 241 |
244 // The extension's ID. This will be calculated from the public key in the crx | 242 // The extension's ID. This will be calculated from the public key in the crx |
245 // header. | 243 // header. |
246 std::string extension_id_; | 244 std::string extension_id_; |
247 | 245 |
248 // Time at which unpacking started. Used to compute the time unpacking takes. | 246 // Time at which unpacking started. Used to compute the time unpacking takes. |
249 base::TimeTicks unpack_start_time_; | 247 base::TimeTicks unpack_start_time_; |
250 | 248 |
251 // Location to use for the unpacked extension. | 249 // Location to use for the unpacked extension. |
252 Extension::Location location_; | 250 extensions::Extension::Location location_; |
253 | 251 |
254 // Creation flags to use for the extension. These flags will be used | 252 // Creation flags to use for the extension. These flags will be used |
255 // when calling Extenion::Create() by the crx installer. | 253 // when calling Extenion::Create() by the crx installer. |
256 int creation_flags_; | 254 int creation_flags_; |
257 }; | 255 }; |
258 | 256 |
259 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ | 257 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ |
OLD | NEW |