| 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 "extensions/browser/sandboxed_unpacker.h" | 5 #include "extensions/browser/sandboxed_unpacker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 location_(location), | 228 location_(location), |
| 229 creation_flags_(creation_flags), | 229 creation_flags_(creation_flags), |
| 230 unpacker_io_task_runner_(unpacker_io_task_runner) { | 230 unpacker_io_task_runner_(unpacker_io_task_runner) { |
| 231 // Tracking for crbug.com/692069. The location must be valid. If it's invalid, | 231 // Tracking for crbug.com/692069. The location must be valid. If it's invalid, |
| 232 // the utility process kills itself for a bad IPC. | 232 // the utility process kills itself for a bad IPC. |
| 233 CHECK_GT(location, Manifest::INVALID_LOCATION); | 233 CHECK_GT(location, Manifest::INVALID_LOCATION); |
| 234 CHECK_LT(location, Manifest::NUM_LOCATIONS); | 234 CHECK_LT(location, Manifest::NUM_LOCATIONS); |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool SandboxedUnpacker::CreateTempDirectory() { | 237 bool SandboxedUnpacker::CreateTempDirectory() { |
| 238 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 238 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
| 239 | 239 |
| 240 base::FilePath temp_dir; | 240 base::FilePath temp_dir; |
| 241 if (!FindWritableTempLocation(extensions_dir_, &temp_dir)) { | 241 if (!FindWritableTempLocation(extensions_dir_, &temp_dir)) { |
| 242 ReportFailure(COULD_NOT_GET_TEMP_DIRECTORY, | 242 ReportFailure(COULD_NOT_GET_TEMP_DIRECTORY, |
| 243 l10n_util::GetStringFUTF16( | 243 l10n_util::GetStringFUTF16( |
| 244 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 244 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 245 ASCIIToUTF16("COULD_NOT_GET_TEMP_DIRECTORY"))); | 245 ASCIIToUTF16("COULD_NOT_GET_TEMP_DIRECTORY"))); |
| 246 return false; | 246 return false; |
| 247 } | 247 } |
| 248 | 248 |
| 249 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_dir)) { | 249 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_dir)) { |
| 250 ReportFailure(COULD_NOT_CREATE_TEMP_DIRECTORY, | 250 ReportFailure(COULD_NOT_CREATE_TEMP_DIRECTORY, |
| 251 l10n_util::GetStringFUTF16( | 251 l10n_util::GetStringFUTF16( |
| 252 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 252 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 253 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); | 253 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); |
| 254 return false; | 254 return false; |
| 255 } | 255 } |
| 256 | 256 |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 void SandboxedUnpacker::StartWithCrx(const CRXFileInfo& crx_info) { | 260 void SandboxedUnpacker::StartWithCrx(const CRXFileInfo& crx_info) { |
| 261 // We assume that we are started on the thread that the client wants us | 261 // We assume that we are started on the thread that the client wants us |
| 262 // to do file IO on. | 262 // to do file IO on. |
| 263 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 263 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
| 264 | 264 |
| 265 crx_unpack_start_time_ = base::TimeTicks::Now(); | 265 crx_unpack_start_time_ = base::TimeTicks::Now(); |
| 266 std::string expected_hash; | 266 std::string expected_hash; |
| 267 if (!crx_info.expected_hash.empty() && | 267 if (!crx_info.expected_hash.empty() && |
| 268 base::CommandLine::ForCurrentProcess()->HasSwitch( | 268 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 269 extensions::switches::kEnableCrxHashCheck)) { | 269 extensions::switches::kEnableCrxHashCheck)) { |
| 270 expected_hash = base::ToLowerASCII(crx_info.expected_hash); | 270 expected_hash = base::ToLowerASCII(crx_info.expected_hash); |
| 271 } | 271 } |
| 272 | 272 |
| 273 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", | 273 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 return; | 440 return; |
| 441 } | 441 } |
| 442 | 442 |
| 443 unpacker_io_task_runner_->PostTask( | 443 unpacker_io_task_runner_->PostTask( |
| 444 FROM_HERE, base::Bind(&SandboxedUnpacker::UnpackExtensionSucceeded, this, | 444 FROM_HERE, base::Bind(&SandboxedUnpacker::UnpackExtensionSucceeded, this, |
| 445 base::Passed(&manifest))); | 445 base::Passed(&manifest))); |
| 446 } | 446 } |
| 447 | 447 |
| 448 void SandboxedUnpacker::UnpackExtensionSucceeded( | 448 void SandboxedUnpacker::UnpackExtensionSucceeded( |
| 449 std::unique_ptr<base::DictionaryValue> manifest) { | 449 std::unique_ptr<base::DictionaryValue> manifest) { |
| 450 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 450 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
| 451 | 451 |
| 452 std::unique_ptr<base::DictionaryValue> final_manifest( | 452 std::unique_ptr<base::DictionaryValue> final_manifest( |
| 453 RewriteManifestFile(*manifest)); | 453 RewriteManifestFile(*manifest)); |
| 454 if (!final_manifest) | 454 if (!final_manifest) |
| 455 return; | 455 return; |
| 456 | 456 |
| 457 // Create an extension object that refers to the temporary location the | 457 // Create an extension object that refers to the temporary location the |
| 458 // extension was unpacked to. We use this until the extension is finally | 458 // extension was unpacked to. We use this until the extension is finally |
| 459 // installed. For example, the install UI shows images from inside the | 459 // installed. For example, the install UI shows images from inside the |
| 460 // extension. | 460 // extension. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 487 if (!RewriteImageFiles(&install_icon)) | 487 if (!RewriteImageFiles(&install_icon)) |
| 488 return; | 488 return; |
| 489 | 489 |
| 490 if (!RewriteCatalogFiles()) | 490 if (!RewriteCatalogFiles()) |
| 491 return; | 491 return; |
| 492 | 492 |
| 493 ReportSuccess(std::move(manifest), install_icon); | 493 ReportSuccess(std::move(manifest), install_icon); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void SandboxedUnpacker::UnpackExtensionFailed(const base::string16& error) { | 496 void SandboxedUnpacker::UnpackExtensionFailed(const base::string16& error) { |
| 497 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 497 CHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
| 498 | 498 |
| 499 ReportFailure( | 499 ReportFailure( |
| 500 UNPACKER_CLIENT_FAILED, | 500 UNPACKER_CLIENT_FAILED, |
| 501 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, error)); | 501 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, error)); |
| 502 } | 502 } |
| 503 | 503 |
| 504 base::string16 SandboxedUnpacker::FailureReasonToString16( | 504 base::string16 SandboxedUnpacker::FailureReasonToString16( |
| 505 FailureReason reason) { | 505 FailureReason reason) { |
| 506 switch (reason) { | 506 switch (reason) { |
| 507 case COULD_NOT_GET_TEMP_DIRECTORY: | 507 case COULD_NOT_GET_TEMP_DIRECTORY: |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 898 l10n_util::GetStringFUTF16(IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 899 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); | 899 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); |
| 900 return false; | 900 return false; |
| 901 } | 901 } |
| 902 } | 902 } |
| 903 | 903 |
| 904 return true; | 904 return true; |
| 905 } | 905 } |
| 906 | 906 |
| 907 void SandboxedUnpacker::Cleanup() { | 907 void SandboxedUnpacker::Cleanup() { |
| 908 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 908 DCHECK(unpacker_io_task_runner_->RunsTasksInCurrentSequence()); |
| 909 if (!temp_dir_.Delete()) { | 909 if (!temp_dir_.Delete()) { |
| 910 LOG(WARNING) << "Can not delete temp directory at " | 910 LOG(WARNING) << "Can not delete temp directory at " |
| 911 << temp_dir_.GetPath().value(); | 911 << temp_dir_.GetPath().value(); |
| 912 } | 912 } |
| 913 } | 913 } |
| 914 | 914 |
| 915 } // namespace extensions | 915 } // namespace extensions |
| OLD | NEW |