Chromium Code Reviews| 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 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 5 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 const base::FilePath& crx_path, | 216 const base::FilePath& crx_path, |
| 217 Manifest::Location location, | 217 Manifest::Location location, |
| 218 int creation_flags, | 218 int creation_flags, |
| 219 const base::FilePath& extensions_dir, | 219 const base::FilePath& extensions_dir, |
| 220 base::SequencedTaskRunner* unpacker_io_task_runner, | 220 base::SequencedTaskRunner* unpacker_io_task_runner, |
| 221 SandboxedUnpackerClient* client) | 221 SandboxedUnpackerClient* client) |
| 222 : crx_path_(crx_path), | 222 : crx_path_(crx_path), |
| 223 client_(client), | 223 client_(client), |
| 224 extensions_dir_(extensions_dir), | 224 extensions_dir_(extensions_dir), |
| 225 got_response_(false), | 225 got_response_(false), |
| 226 is_zipfile_(false), | |
| 226 location_(location), | 227 location_(location), |
| 227 creation_flags_(creation_flags), | 228 creation_flags_(creation_flags), |
| 228 unpacker_io_task_runner_(unpacker_io_task_runner) { | 229 unpacker_io_task_runner_(unpacker_io_task_runner) { |
| 229 } | 230 } |
| 230 | 231 |
| 231 bool SandboxedUnpacker::CreateTempDirectory() { | 232 bool SandboxedUnpacker::CreateTempDirectory() { |
| 232 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 233 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 233 | 234 |
| 234 base::FilePath temp_dir; | 235 base::FilePath temp_dir; |
| 235 if (!FindWritableTempLocation(extensions_dir_, &temp_dir)) { | 236 if (!FindWritableTempLocation(extensions_dir_, &temp_dir)) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 253 return true; | 254 return true; |
| 254 } | 255 } |
| 255 | 256 |
| 256 void SandboxedUnpacker::Start() { | 257 void SandboxedUnpacker::Start() { |
| 257 // We assume that we are started on the thread that the client wants us to do | 258 // We assume that we are started on the thread that the client wants us to do |
| 258 // file IO on. | 259 // file IO on. |
| 259 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 260 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 260 | 261 |
| 261 unpack_start_time_ = base::TimeTicks::Now(); | 262 unpack_start_time_ = base::TimeTicks::Now(); |
| 262 | 263 |
| 264 if (crx_path_.Extension() == ".zip") | |
| 265 is_zipfile_ = true; | |
|
meacer
2014/07/28 23:01:05
Cleaner?
is_zipfile_ = crx_path_.Extension() == "
elijahtaylor1
2014/07/31 17:29:55
removed code
| |
| 266 | |
| 263 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", | 267 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", |
| 264 crx_path_); | 268 crx_path_); |
| 265 if (!CreateTempDirectory()) | 269 if (!CreateTempDirectory()) |
| 266 return; // ReportFailure() already called. | 270 return; // ReportFailure() already called. |
| 267 | 271 |
| 268 // Initialize the path that will eventually contain the unpacked extension. | 272 // Initialize the path that will eventually contain the unpacked extension. |
| 269 extension_root_ = temp_dir_.path().AppendASCII(kTempExtensionName); | 273 extension_root_ = temp_dir_.path().AppendASCII(kTempExtensionName); |
| 270 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength", | 274 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength", |
| 271 extension_root_); | 275 extension_root_); |
| 272 | 276 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 host->Send( | 358 host->Send( |
| 355 new ChromeUtilityMsg_UnpackExtension( | 359 new ChromeUtilityMsg_UnpackExtension( |
| 356 temp_crx_path, extension_id_, location_, creation_flags_)); | 360 temp_crx_path, extension_id_, location_, creation_flags_)); |
| 357 } | 361 } |
| 358 | 362 |
| 359 void SandboxedUnpacker::OnUnpackExtensionSucceeded( | 363 void SandboxedUnpacker::OnUnpackExtensionSucceeded( |
| 360 const base::DictionaryValue& manifest) { | 364 const base::DictionaryValue& manifest) { |
| 361 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 365 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 362 got_response_ = true; | 366 got_response_ = true; |
| 363 | 367 |
| 368 if (is_zipfile_) { | |
| 369 ReportSuccess(manifest, SkBitmap()); | |
| 370 return; | |
| 371 } | |
| 372 | |
| 364 scoped_ptr<base::DictionaryValue> final_manifest( | 373 scoped_ptr<base::DictionaryValue> final_manifest( |
| 365 RewriteManifestFile(manifest)); | 374 RewriteManifestFile(manifest)); |
| 366 if (!final_manifest) | 375 if (!final_manifest) |
| 367 return; | 376 return; |
| 368 | 377 |
| 369 // Create an extension object that refers to the temporary location the | 378 // Create an extension object that refers to the temporary location the |
| 370 // extension was unpacked to. We use this until the extension is finally | 379 // extension was unpacked to. We use this until the extension is finally |
| 371 // installed. For example, the install UI shows images from inside the | 380 // installed. For example, the install UI shows images from inside the |
| 372 // extension. | 381 // extension. |
| 373 | 382 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 423 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 415 got_response_ = true; | 424 got_response_ = true; |
| 416 ReportFailure( | 425 ReportFailure( |
| 417 UNPACKER_CLIENT_FAILED, | 426 UNPACKER_CLIENT_FAILED, |
| 418 l10n_util::GetStringFUTF16( | 427 l10n_util::GetStringFUTF16( |
| 419 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, | 428 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, |
| 420 error)); | 429 error)); |
| 421 } | 430 } |
| 422 | 431 |
| 423 bool SandboxedUnpacker::ValidateSignature() { | 432 bool SandboxedUnpacker::ValidateSignature() { |
| 433 if (is_zipfile_) | |
| 434 return true; | |
| 435 | |
| 424 base::ScopedFILE file(base::OpenFile(crx_path_, "rb")); | 436 base::ScopedFILE file(base::OpenFile(crx_path_, "rb")); |
| 425 | 437 |
| 426 if (!file.get()) { | 438 if (!file.get()) { |
| 427 // Could not open crx file for reading. | 439 // Could not open crx file for reading. |
| 428 #if defined (OS_WIN) | 440 #if defined (OS_WIN) |
| 429 // On windows, get the error code. | 441 // On windows, get the error code. |
| 430 uint32 error_code = ::GetLastError(); | 442 uint32 error_code = ::GetLastError(); |
| 431 // TODO(skerner): Use this histogram to understand why so many | 443 // TODO(skerner): Use this histogram to understand why so many |
| 432 // windows users hit this error. crbug.com/69693 | 444 // windows users hit this error. crbug.com/69693 |
| 433 | 445 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 | 841 |
| 830 void SandboxedUnpacker::Cleanup() { | 842 void SandboxedUnpacker::Cleanup() { |
| 831 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 843 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 832 if (!temp_dir_.Delete()) { | 844 if (!temp_dir_.Delete()) { |
| 833 LOG(WARNING) << "Can not delete temp directory at " | 845 LOG(WARNING) << "Can not delete temp directory at " |
| 834 << temp_dir_.path().value(); | 846 << temp_dir_.path().value(); |
| 835 } | 847 } |
| 836 } | 848 } |
| 837 | 849 |
| 838 } // namespace extensions | 850 } // namespace extensions |
| OLD | NEW |