| OLD | NEW |
| 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 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 5 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/crypto/signature_verifier.h" | 9 #include "base/crypto/signature_verifier.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/common/json_value_serializer.h" | 21 #include "chrome/common/json_value_serializer.h" |
| 22 #include "net/base/base64.h" | 22 #include "net/base/base64.h" |
| 23 | 23 |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 | 25 |
| 26 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; | 26 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; |
| 27 | 27 |
| 28 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( | 28 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( |
| 29 const FilePath& crx_path, ResourceDispatcherHost* rdh, | 29 const FilePath& crx_path, ResourceDispatcherHost* rdh, |
| 30 SandboxedExtensionUnpackerClient* client) | 30 SandboxedExtensionUnpackerClient* client) |
| 31 : crx_path_(crx_path), client_loop_(MessageLoop::current()), rdh_(rdh), | 31 : crx_path_(crx_path), file_loop_(NULL), rdh_(rdh), client_(client), |
| 32 client_(client), got_response_(false) { | 32 got_response_(false) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void SandboxedExtensionUnpacker::Start() { | 35 void SandboxedExtensionUnpacker::Start() { |
| 36 // We assume that we are started on the thread that the client wants us to do |
| 37 // file IO on. |
| 38 file_loop_ = MessageLoop::current(); |
| 39 |
| 36 // Create a temporary directory to work in. | 40 // Create a temporary directory to work in. |
| 37 if (!temp_dir_.CreateUniqueTempDir()) { | 41 if (!temp_dir_.CreateUniqueTempDir()) { |
| 38 ReportFailure("Could not create temporary directory."); | 42 ReportFailure("Could not create temporary directory."); |
| 39 return; | 43 return; |
| 40 } | 44 } |
| 41 | 45 |
| 42 // Initialize the path that will eventually contain the unpacked extension. | 46 // Initialize the path that will eventually contain the unpacked extension. |
| 43 extension_root_ = temp_dir_.path().AppendASCII("TEMP_INSTALL"); | 47 extension_root_ = temp_dir_.path().AppendASCII("TEMP_INSTALL"); |
| 44 | 48 |
| 45 // Extract the public key and validate the package. | 49 // Extract the public key and validate the package. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 ExtensionUnpacker unpacker(temp_crx_path); | 69 ExtensionUnpacker unpacker(temp_crx_path); |
| 66 if (unpacker.Run() && unpacker.DumpImagesToFile()) | 70 if (unpacker.Run() && unpacker.DumpImagesToFile()) |
| 67 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); | 71 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); |
| 68 else | 72 else |
| 69 OnUnpackExtensionFailed(unpacker.error_message()); | 73 OnUnpackExtensionFailed(unpacker.error_message()); |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 | 76 |
| 73 void SandboxedExtensionUnpacker::StartProcessOnIOThread( | 77 void SandboxedExtensionUnpacker::StartProcessOnIOThread( |
| 74 const FilePath& temp_crx_path) { | 78 const FilePath& temp_crx_path) { |
| 75 UtilityProcessHost* host = new UtilityProcessHost(rdh_, this, | 79 UtilityProcessHost* host = new UtilityProcessHost(rdh_, this, file_loop_); |
| 76 MessageLoop::current()); | |
| 77 host->StartExtensionUnpacker(temp_crx_path); | 80 host->StartExtensionUnpacker(temp_crx_path); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( | 83 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( |
| 81 const DictionaryValue& manifest) { | 84 const DictionaryValue& manifest) { |
| 85 DCHECK(file_loop_ == MessageLoop::current()); |
| 82 got_response_ = true; | 86 got_response_ = true; |
| 83 | 87 |
| 84 ExtensionUnpacker::DecodedImages images; | 88 ExtensionUnpacker::DecodedImages images; |
| 85 if (!ExtensionUnpacker::ReadImagesFromFile(temp_dir_.path(), &images)) { | 89 if (!ExtensionUnpacker::ReadImagesFromFile(temp_dir_.path(), &images)) { |
| 86 ReportFailure("Couldn't read image data from disk."); | 90 ReportFailure("Couldn't read image data from disk."); |
| 87 return; | 91 return; |
| 88 } | 92 } |
| 89 | 93 |
| 90 // Add the public key extracted earlier to the parsed manifest and overwrite | 94 // Add the public key extracted earlier to the parsed manifest and overwrite |
| 91 // the original manifest. We do this to ensure the manifest doesn't contain an | 95 // the original manifest. We do this to ensure the manifest doesn't contain an |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 ReportFailure("Error saving theme image."); | 161 ReportFailure("Error saving theme image."); |
| 158 return; | 162 return; |
| 159 } | 163 } |
| 160 } | 164 } |
| 161 | 165 |
| 162 ReportSuccess(); | 166 ReportSuccess(); |
| 163 } | 167 } |
| 164 | 168 |
| 165 void SandboxedExtensionUnpacker::OnUnpackExtensionFailed( | 169 void SandboxedExtensionUnpacker::OnUnpackExtensionFailed( |
| 166 const std::string& error) { | 170 const std::string& error) { |
| 171 DCHECK(file_loop_ == MessageLoop::current()); |
| 167 got_response_ = true; | 172 got_response_ = true; |
| 168 ReportFailure(error); | 173 ReportFailure(error); |
| 169 } | 174 } |
| 170 | 175 |
| 171 void SandboxedExtensionUnpacker::OnProcessCrashed() { | 176 void SandboxedExtensionUnpacker::OnProcessCrashed() { |
| 172 // Don't report crashes if they happen after we got a response. | 177 // Don't report crashes if they happen after we got a response. |
| 173 if (got_response_) | 178 if (got_response_) |
| 174 return; | 179 return; |
| 175 | 180 |
| 176 ReportFailure("Utility process crashed while trying to install."); | 181 ReportFailure("Utility process crashed while trying to install."); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 272 |
| 268 void SandboxedExtensionUnpacker::ReportFailure(const std::string& error) { | 273 void SandboxedExtensionUnpacker::ReportFailure(const std::string& error) { |
| 269 client_->OnUnpackFailure(error); | 274 client_->OnUnpackFailure(error); |
| 270 } | 275 } |
| 271 | 276 |
| 272 void SandboxedExtensionUnpacker::ReportSuccess() { | 277 void SandboxedExtensionUnpacker::ReportSuccess() { |
| 273 // Client takes ownership of temporary directory and extension. | 278 // Client takes ownership of temporary directory and extension. |
| 274 client_->OnUnpackSuccess(temp_dir_.Take(), extension_root_, | 279 client_->OnUnpackSuccess(temp_dir_.Take(), extension_root_, |
| 275 extension_.release()); | 280 extension_.release()); |
| 276 } | 281 } |
| OLD | NEW |