| 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 "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "content/browser/utility_process_host.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/utility_process_host_client.h" |
| 16 | 17 |
| 17 class Extension; | 18 class Extension; |
| 18 class ResourceDispatcherHost; | 19 class ResourceDispatcherHost; |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class DictionaryValue; | 22 class DictionaryValue; |
| 22 } | 23 } |
| 23 | 24 |
| 24 class SandboxedExtensionUnpackerClient | 25 class SandboxedExtensionUnpackerClient |
| 25 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> { | 26 : public base::RefCountedThreadSafe<SandboxedExtensionUnpackerClient> { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // Lifetime management: | 61 // Lifetime management: |
| 61 // | 62 // |
| 62 // This class is ref-counted by each call it makes to itself on another thread, | 63 // This class is ref-counted by each call it makes to itself on another thread, |
| 63 // and by UtilityProcessHost. | 64 // and by UtilityProcessHost. |
| 64 // | 65 // |
| 65 // Additionally, we hold a reference to our own client so that it lives at least | 66 // Additionally, we hold a reference to our own client so that it lives at least |
| 66 // long enough to receive the result of unpacking. | 67 // long enough to receive the result of unpacking. |
| 67 // | 68 // |
| 68 // | 69 // |
| 69 // NOTE: This class should only be used on the file thread. | 70 // NOTE: This class should only be used on the file thread. |
| 70 class SandboxedExtensionUnpacker : public UtilityProcessHost::Client { | 71 class SandboxedExtensionUnpacker : public content::UtilityProcessHostClient { |
| 71 public: | 72 public: |
| 72 // The size of the magic character sequence at the beginning of each crx | 73 // The size of the magic character sequence at the beginning of each crx |
| 73 // file, in bytes. This should be a multiple of 4. | 74 // file, in bytes. This should be a multiple of 4. |
| 74 static const size_t kExtensionHeaderMagicSize = 4; | 75 static const size_t kExtensionHeaderMagicSize = 4; |
| 75 | 76 |
| 76 // This header is the first data at the beginning of an extension. Its | 77 // This header is the first data at the beginning of an extension. Its |
| 77 // contents are purposely 32-bit aligned so that it can just be slurped into | 78 // contents are purposely 32-bit aligned so that it can just be slurped into |
| 78 // a struct without manual parsing. | 79 // a struct without manual parsing. |
| 79 struct ExtensionHeader { | 80 struct ExtensionHeader { |
| 80 char magic[kExtensionHeaderMagicSize]; | 81 char magic[kExtensionHeaderMagicSize]; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // in ExtensionUnpacker as it is not specific to sandboxed unpacking. It was | 187 // in ExtensionUnpacker as it is not specific to sandboxed unpacking. It was |
| 187 // put here because we cannot run windows crypto code in the sandbox. But we | 188 // put here because we cannot run windows crypto code in the sandbox. But we |
| 188 // could still have this method statically on ExtensionUnpacker so that code | 189 // could still have this method statically on ExtensionUnpacker so that code |
| 189 // just for unpacking is there and code just for sandboxing of unpacking is | 190 // just for unpacking is there and code just for sandboxing of unpacking is |
| 190 // here. | 191 // here. |
| 191 bool ValidateSignature(); | 192 bool ValidateSignature(); |
| 192 | 193 |
| 193 // Starts the utility process that unpacks our extension. | 194 // Starts the utility process that unpacks our extension. |
| 194 void StartProcessOnIOThread(const FilePath& temp_crx_path); | 195 void StartProcessOnIOThread(const FilePath& temp_crx_path); |
| 195 | 196 |
| 196 // UtilityProcessHost::Client | 197 // UtilityProcessHostClient |
| 197 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 198 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 198 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 199 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
| 199 | 200 |
| 200 // IPC message handlers. | 201 // IPC message handlers. |
| 201 void OnUnpackExtensionSucceeded(const base::DictionaryValue& manifest); | 202 void OnUnpackExtensionSucceeded(const base::DictionaryValue& manifest); |
| 202 void OnUnpackExtensionFailed(const string16& error_message); | 203 void OnUnpackExtensionFailed(const string16& error_message); |
| 203 | 204 |
| 204 void ReportFailure(FailureReason reason, const string16& message); | 205 void ReportFailure(FailureReason reason, const string16& message); |
| 205 void ReportSuccess(const base::DictionaryValue& original_manifest); | 206 void ReportSuccess(const base::DictionaryValue& original_manifest); |
| 206 | 207 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 247 |
| 247 // Location to use for the unpacked extension. | 248 // Location to use for the unpacked extension. |
| 248 Extension::Location location_; | 249 Extension::Location location_; |
| 249 | 250 |
| 250 // Creation flags to use for the extension. These flags will be used | 251 // Creation flags to use for the extension. These flags will be used |
| 251 // when calling Extenion::Create() by the crx installer. | 252 // when calling Extenion::Create() by the crx installer. |
| 252 int creation_flags_; | 253 int creation_flags_; |
| 253 }; | 254 }; |
| 254 | 255 |
| 255 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ | 256 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ |
| OLD | NEW |