| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/utility_process_host.h" | 14 #include "content/browser/utility_process_host.h" |
| 15 | 15 |
| 16 class DictionaryValue; | |
| 17 class Extension; | 16 class Extension; |
| 18 class ResourceDispatcherHost; | 17 class ResourceDispatcherHost; |
| 19 | 18 |
| 19 namespace base { |
| 20 class DictionaryValue; |
| 21 } |
| 22 |
| 20 class SandboxedExtensionUnpackerClient | 23 class SandboxedExtensionUnpackerClient |
| 21 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> { | 24 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> { |
| 22 public: | 25 public: |
| 23 // temp_dir - A temporary directory containing the results of the extension | 26 // temp_dir - A temporary directory containing the results of the extension |
| 24 // unpacking. The client is responsible for deleting this directory. | 27 // unpacking. The client is responsible for deleting this directory. |
| 25 // | 28 // |
| 26 // extension_root - The path to the extension root inside of temp_dir. | 29 // extension_root - The path to the extension root inside of temp_dir. |
| 27 // | 30 // |
| 28 // original_manifest - The parsed but unmodified version of the manifest, | 31 // original_manifest - The parsed but unmodified version of the manifest, |
| 29 // with no modifications such as localization, etc. | 32 // with no modifications such as localization, etc. |
| 30 // | 33 // |
| 31 // extension - The extension that was unpacked. The client is responsible | 34 // extension - The extension that was unpacked. The client is responsible |
| 32 // for deleting this memory. | 35 // for deleting this memory. |
| 33 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 36 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
| 34 const FilePath& extension_root, | 37 const FilePath& extension_root, |
| 35 const DictionaryValue* original_manifest, | 38 const base::DictionaryValue* original_manifest, |
| 36 const Extension* extension) = 0; | 39 const Extension* extension) = 0; |
| 37 virtual void OnUnpackFailure(const std::string& error) = 0; | 40 virtual void OnUnpackFailure(const std::string& error) = 0; |
| 38 | 41 |
| 39 protected: | 42 protected: |
| 40 friend class base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient>; | 43 friend class base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient>; |
| 41 | 44 |
| 42 virtual ~SandboxedExtensionUnpackerClient() {} | 45 virtual ~SandboxedExtensionUnpackerClient() {} |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 // SandboxedExtensionUnpacker unpacks extensions from the CRX format into a | 48 // SandboxedExtensionUnpacker unpacks extensions from the CRX format into a |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 bool ValidateSignature(); | 188 bool ValidateSignature(); |
| 186 | 189 |
| 187 // Starts the utility process that unpacks our extension. | 190 // Starts the utility process that unpacks our extension. |
| 188 void StartProcessOnIOThread(const FilePath& temp_crx_path); | 191 void StartProcessOnIOThread(const FilePath& temp_crx_path); |
| 189 | 192 |
| 190 // UtilityProcessHost::Client | 193 // UtilityProcessHost::Client |
| 191 virtual bool OnMessageReceived(const IPC::Message& message); | 194 virtual bool OnMessageReceived(const IPC::Message& message); |
| 192 virtual void OnProcessCrashed(int exit_code); | 195 virtual void OnProcessCrashed(int exit_code); |
| 193 | 196 |
| 194 // IPC message handlers. | 197 // IPC message handlers. |
| 195 void OnUnpackExtensionSucceeded(const DictionaryValue& manifest); | 198 void OnUnpackExtensionSucceeded(const base::DictionaryValue& manifest); |
| 196 void OnUnpackExtensionFailed(const std::string& error_message); | 199 void OnUnpackExtensionFailed(const std::string& error_message); |
| 197 | 200 |
| 198 void ReportFailure(FailureReason reason, const std::string& message); | 201 void ReportFailure(FailureReason reason, const std::string& message); |
| 199 void ReportSuccess(const DictionaryValue& original_manifest); | 202 void ReportSuccess(const base::DictionaryValue& original_manifest); |
| 200 | 203 |
| 201 // Overwrites original manifest with safe result from utility process. | 204 // Overwrites original manifest with safe result from utility process. |
| 202 // Returns NULL on error. Caller owns the returned object. | 205 // Returns NULL on error. Caller owns the returned object. |
| 203 DictionaryValue* RewriteManifestFile(const DictionaryValue& manifest); | 206 base::DictionaryValue* RewriteManifestFile( |
| 207 const base::DictionaryValue& manifest); |
| 204 | 208 |
| 205 // Overwrites original files with safe results from utility process. | 209 // Overwrites original files with safe results from utility process. |
| 206 // Reports error and returns false if it fails. | 210 // Reports error and returns false if it fails. |
| 207 bool RewriteImageFiles(); | 211 bool RewriteImageFiles(); |
| 208 bool RewriteCatalogFiles(); | 212 bool RewriteCatalogFiles(); |
| 209 | 213 |
| 210 // The path to the CRX to unpack. | 214 // The path to the CRX to unpack. |
| 211 FilePath crx_path_; | 215 FilePath crx_path_; |
| 212 | 216 |
| 213 // Our client's thread. This is the thread we respond on. | 217 // Our client's thread. This is the thread we respond on. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 232 bool got_response_; | 236 bool got_response_; |
| 233 | 237 |
| 234 // The public key that was extracted from the CRX header. | 238 // The public key that was extracted from the CRX header. |
| 235 std::string public_key_; | 239 std::string public_key_; |
| 236 | 240 |
| 237 // Time at which unpacking started. Used to compute the time unpacking takes. | 241 // Time at which unpacking started. Used to compute the time unpacking takes. |
| 238 base::TimeTicks unpack_start_time_; | 242 base::TimeTicks unpack_start_time_; |
| 239 }; | 243 }; |
| 240 | 244 |
| 241 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ | 245 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ |
| OLD | NEW |