| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // Utility process crashed while trying to install. | 321 // Utility process crashed while trying to install. |
| 322 ReportFailure( | 322 ReportFailure( |
| 323 UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL, | 323 UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL, |
| 324 l10n_util::GetStringFUTF16( | 324 l10n_util::GetStringFUTF16( |
| 325 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 325 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 326 ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); | 326 ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void SandboxedUnpacker::StartProcessOnIOThread( | 329 void SandboxedUnpacker::StartProcessOnIOThread( |
| 330 const base::FilePath& temp_crx_path) { | 330 const base::FilePath& temp_crx_path) { |
| 331 UtilityProcessHost* host = UtilityProcessHost::Create( | 331 UtilityProcessHost* host = |
| 332 this, unpacker_io_task_runner_); | 332 UtilityProcessHost::Create(this, unpacker_io_task_runner_.get()); |
| 333 // Grant the subprocess access to the entire subdir the extension file is | 333 // Grant the subprocess access to the entire subdir the extension file is |
| 334 // in, so that it can unpack to that dir. | 334 // in, so that it can unpack to that dir. |
| 335 host->SetExposedDir(temp_crx_path.DirName()); | 335 host->SetExposedDir(temp_crx_path.DirName()); |
| 336 host->Send( | 336 host->Send( |
| 337 new ChromeUtilityMsg_UnpackExtension( | 337 new ChromeUtilityMsg_UnpackExtension( |
| 338 temp_crx_path, extension_id_, location_, creation_flags_)); | 338 temp_crx_path, extension_id_, location_, creation_flags_)); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void SandboxedUnpacker::OnUnpackExtensionSucceeded( | 341 void SandboxedUnpacker::OnUnpackExtensionSucceeded( |
| 342 const DictionaryValue& manifest) { | 342 const DictionaryValue& manifest) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 368 return; | 368 return; |
| 369 } | 369 } |
| 370 | 370 |
| 371 extension_ = Extension::Create( | 371 extension_ = Extension::Create( |
| 372 extension_root_, | 372 extension_root_, |
| 373 location_, | 373 location_, |
| 374 *final_manifest, | 374 *final_manifest, |
| 375 Extension::REQUIRE_KEY | creation_flags_, | 375 Extension::REQUIRE_KEY | creation_flags_, |
| 376 &utf8_error); | 376 &utf8_error); |
| 377 | 377 |
| 378 | 378 if (!extension_.get()) { |
| 379 if (!extension_) { | 379 ReportFailure(INVALID_MANIFEST, |
| 380 ReportFailure( | 380 ASCIIToUTF16("Manifest is invalid: " + utf8_error)); |
| 381 INVALID_MANIFEST, | |
| 382 ASCIIToUTF16("Manifest is invalid: " + utf8_error)); | |
| 383 return; | 381 return; |
| 384 } | 382 } |
| 385 | 383 |
| 386 if (!RewriteImageFiles()) | 384 if (!RewriteImageFiles()) |
| 387 return; | 385 return; |
| 388 | 386 |
| 389 if (!RewriteCatalogFiles()) | 387 if (!RewriteCatalogFiles()) |
| 390 return; | 388 return; |
| 391 | 389 |
| 392 ReportSuccess(manifest); | 390 ReportSuccess(manifest); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } | 573 } |
| 576 | 574 |
| 577 void SandboxedUnpacker::ReportSuccess( | 575 void SandboxedUnpacker::ReportSuccess( |
| 578 const DictionaryValue& original_manifest) { | 576 const DictionaryValue& original_manifest) { |
| 579 UMA_HISTOGRAM_COUNTS("Extensions.SandboxUnpackSuccess", 1); | 577 UMA_HISTOGRAM_COUNTS("Extensions.SandboxUnpackSuccess", 1); |
| 580 | 578 |
| 581 RecordSuccessfulUnpackTimeHistograms( | 579 RecordSuccessfulUnpackTimeHistograms( |
| 582 crx_path_, base::TimeTicks::Now() - unpack_start_time_); | 580 crx_path_, base::TimeTicks::Now() - unpack_start_time_); |
| 583 | 581 |
| 584 // Client takes ownership of temporary directory and extension. | 582 // Client takes ownership of temporary directory and extension. |
| 585 client_->OnUnpackSuccess(temp_dir_.Take(), | 583 client_->OnUnpackSuccess( |
| 586 extension_root_, | 584 temp_dir_.Take(), extension_root_, &original_manifest, extension_.get()); |
| 587 &original_manifest, | |
| 588 extension_); | |
| 589 extension_ = NULL; | 585 extension_ = NULL; |
| 590 } | 586 } |
| 591 | 587 |
| 592 DictionaryValue* SandboxedUnpacker::RewriteManifestFile( | 588 DictionaryValue* SandboxedUnpacker::RewriteManifestFile( |
| 593 const DictionaryValue& manifest) { | 589 const DictionaryValue& manifest) { |
| 594 // Add the public key extracted earlier to the parsed manifest and overwrite | 590 // Add the public key extracted earlier to the parsed manifest and overwrite |
| 595 // the original manifest. We do this to ensure the manifest doesn't contain an | 591 // the original manifest. We do this to ensure the manifest doesn't contain an |
| 596 // exploitable bug that could be used to compromise the browser. | 592 // exploitable bug that could be used to compromise the browser. |
| 597 scoped_ptr<DictionaryValue> final_manifest(manifest.DeepCopy()); | 593 scoped_ptr<DictionaryValue> final_manifest(manifest.DeepCopy()); |
| 598 final_manifest->SetString(extension_manifest_keys::kPublicKey, public_key_); | 594 final_manifest->SetString(extension_manifest_keys::kPublicKey, public_key_); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 l10n_util::GetStringFUTF16( | 631 l10n_util::GetStringFUTF16( |
| 636 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 632 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 637 ASCIIToUTF16("COULD_NOT_READ_IMAGE_DATA_FROM_DISK"))); | 633 ASCIIToUTF16("COULD_NOT_READ_IMAGE_DATA_FROM_DISK"))); |
| 638 return false; | 634 return false; |
| 639 } | 635 } |
| 640 | 636 |
| 641 // Delete any images that may be used by the browser. We're going to write | 637 // Delete any images that may be used by the browser. We're going to write |
| 642 // out our own versions of the parsed images, and we want to make sure the | 638 // out our own versions of the parsed images, and we want to make sure the |
| 643 // originals are gone for good. | 639 // originals are gone for good. |
| 644 std::set<base::FilePath> image_paths = | 640 std::set<base::FilePath> image_paths = |
| 645 extension_file_util::GetBrowserImagePaths(extension_); | 641 extension_file_util::GetBrowserImagePaths(extension_.get()); |
| 646 if (image_paths.size() != images.size()) { | 642 if (image_paths.size() != images.size()) { |
| 647 // Decoded images don't match what's in the manifest. | 643 // Decoded images don't match what's in the manifest. |
| 648 ReportFailure( | 644 ReportFailure( |
| 649 DECODED_IMAGES_DO_NOT_MATCH_THE_MANIFEST, | 645 DECODED_IMAGES_DO_NOT_MATCH_THE_MANIFEST, |
| 650 l10n_util::GetStringFUTF16( | 646 l10n_util::GetStringFUTF16( |
| 651 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 647 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 652 ASCIIToUTF16("DECODED_IMAGES_DO_NOT_MATCH_THE_MANIFEST"))); | 648 ASCIIToUTF16("DECODED_IMAGES_DO_NOT_MATCH_THE_MANIFEST"))); |
| 653 return false; | 649 return false; |
| 654 } | 650 } |
| 655 | 651 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 | 792 |
| 797 void SandboxedUnpacker::Cleanup() { | 793 void SandboxedUnpacker::Cleanup() { |
| 798 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 794 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 799 if (!temp_dir_.Delete()) { | 795 if (!temp_dir_.Delete()) { |
| 800 LOG(WARNING) << "Can not delete temp directory at " | 796 LOG(WARNING) << "Can not delete temp directory at " |
| 801 << temp_dir_.path().value(); | 797 << temp_dir_.path().value(); |
| 802 } | 798 } |
| 803 } | 799 } |
| 804 | 800 |
| 805 } // namespace extensions | 801 } // namespace extensions |
| OLD | NEW |