| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return false; | 125 return false; |
| 126 | 126 |
| 127 base::FilePath temp_file; | 127 base::FilePath temp_file; |
| 128 if (!base::CreateTemporaryFileInDir(*temp_dir, &temp_file)) { | 128 if (!base::CreateTemporaryFileInDir(*temp_dir, &temp_file)) { |
| 129 LOG(ERROR) << temp_dir->value() << " is not writable"; | 129 LOG(ERROR) << temp_dir->value() << " is not writable"; |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 // NormalizeFilePath requires a non-empty file, so write some data. | 132 // NormalizeFilePath requires a non-empty file, so write some data. |
| 133 // If you change the exit points of this function please make sure all | 133 // If you change the exit points of this function please make sure all |
| 134 // exit points delete this temp file! | 134 // exit points delete this temp file! |
| 135 if (file_util::WriteFile(temp_file, ".", 1) != 1) | 135 if (base::WriteFile(temp_file, ".", 1) != 1) |
| 136 return false; | 136 return false; |
| 137 | 137 |
| 138 base::FilePath normalized_temp_file; | 138 base::FilePath normalized_temp_file; |
| 139 bool normalized = base::NormalizeFilePath(temp_file, &normalized_temp_file); | 139 bool normalized = base::NormalizeFilePath(temp_file, &normalized_temp_file); |
| 140 if (!normalized) { | 140 if (!normalized) { |
| 141 // If |temp_file| contains a link, the sandbox will block al file system | 141 // If |temp_file| contains a link, the sandbox will block al file system |
| 142 // operations, and the install will fail. | 142 // operations, and the install will fail. |
| 143 LOG(ERROR) << temp_dir->value() << " seem to be on remote drive."; | 143 LOG(ERROR) << temp_dir->value() << " seem to be on remote drive."; |
| 144 } else { | 144 } else { |
| 145 *temp_dir = normalized_temp_file.DirName(); | 145 *temp_dir = normalized_temp_file.DirName(); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 ERROR_SERIALIZING_MANIFEST_JSON, | 622 ERROR_SERIALIZING_MANIFEST_JSON, |
| 623 l10n_util::GetStringFUTF16( | 623 l10n_util::GetStringFUTF16( |
| 624 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 624 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 625 ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON"))); | 625 ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON"))); |
| 626 return NULL; | 626 return NULL; |
| 627 } | 627 } |
| 628 | 628 |
| 629 base::FilePath manifest_path = | 629 base::FilePath manifest_path = |
| 630 extension_root_.Append(kManifestFilename); | 630 extension_root_.Append(kManifestFilename); |
| 631 int size = base::checked_cast<int>(manifest_json.size()); | 631 int size = base::checked_cast<int>(manifest_json.size()); |
| 632 if (file_util::WriteFile(manifest_path, manifest_json.data(), size) != size) { | 632 if (base::WriteFile(manifest_path, manifest_json.data(), size) != size) { |
| 633 // Error saving manifest.json. | 633 // Error saving manifest.json. |
| 634 ReportFailure( | 634 ReportFailure( |
| 635 ERROR_SAVING_MANIFEST_JSON, | 635 ERROR_SAVING_MANIFEST_JSON, |
| 636 l10n_util::GetStringFUTF16( | 636 l10n_util::GetStringFUTF16( |
| 637 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 637 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 638 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); | 638 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); |
| 639 return NULL; | 639 return NULL; |
| 640 } | 640 } |
| 641 | 641 |
| 642 return final_manifest.release(); | 642 return final_manifest.release(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 l10n_util::GetStringFUTF16( | 735 l10n_util::GetStringFUTF16( |
| 736 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 736 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 737 ASCIIToUTF16("ERROR_RE_ENCODING_THEME_IMAGE"))); | 737 ASCIIToUTF16("ERROR_RE_ENCODING_THEME_IMAGE"))); |
| 738 return false; | 738 return false; |
| 739 } | 739 } |
| 740 | 740 |
| 741 // Note: we're overwriting existing files that the utility process wrote, | 741 // Note: we're overwriting existing files that the utility process wrote, |
| 742 // so we can be sure the directory exists. | 742 // so we can be sure the directory exists. |
| 743 const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); | 743 const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); |
| 744 int size = base::checked_cast<int>(image_data.size()); | 744 int size = base::checked_cast<int>(image_data.size()); |
| 745 if (file_util::WriteFile(path, image_data_ptr, size) != size) { | 745 if (base::WriteFile(path, image_data_ptr, size) != size) { |
| 746 // Error saving theme image. | 746 // Error saving theme image. |
| 747 ReportFailure( | 747 ReportFailure( |
| 748 ERROR_SAVING_THEME_IMAGE, | 748 ERROR_SAVING_THEME_IMAGE, |
| 749 l10n_util::GetStringFUTF16( | 749 l10n_util::GetStringFUTF16( |
| 750 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 750 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 751 ASCIIToUTF16("ERROR_SAVING_THEME_IMAGE"))); | 751 ASCIIToUTF16("ERROR_SAVING_THEME_IMAGE"))); |
| 752 return false; | 752 return false; |
| 753 } | 753 } |
| 754 } | 754 } |
| 755 | 755 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 ERROR_SERIALIZING_CATALOG, | 804 ERROR_SERIALIZING_CATALOG, |
| 805 l10n_util::GetStringFUTF16( | 805 l10n_util::GetStringFUTF16( |
| 806 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 806 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 807 ASCIIToUTF16("ERROR_SERIALIZING_CATALOG"))); | 807 ASCIIToUTF16("ERROR_SERIALIZING_CATALOG"))); |
| 808 return false; | 808 return false; |
| 809 } | 809 } |
| 810 | 810 |
| 811 // Note: we're overwriting existing files that the utility process read, | 811 // Note: we're overwriting existing files that the utility process read, |
| 812 // so we can be sure the directory exists. | 812 // so we can be sure the directory exists. |
| 813 int size = base::checked_cast<int>(catalog_json.size()); | 813 int size = base::checked_cast<int>(catalog_json.size()); |
| 814 if (file_util::WriteFile(path, catalog_json.c_str(), size) != size) { | 814 if (base::WriteFile(path, catalog_json.c_str(), size) != size) { |
| 815 // Error saving catalog. | 815 // Error saving catalog. |
| 816 ReportFailure( | 816 ReportFailure( |
| 817 ERROR_SAVING_CATALOG, | 817 ERROR_SAVING_CATALOG, |
| 818 l10n_util::GetStringFUTF16( | 818 l10n_util::GetStringFUTF16( |
| 819 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 819 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 820 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); | 820 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); |
| 821 return false; | 821 return false; |
| 822 } | 822 } |
| 823 } | 823 } |
| 824 | 824 |
| 825 return true; | 825 return true; |
| 826 } | 826 } |
| 827 | 827 |
| 828 void SandboxedUnpacker::Cleanup() { | 828 void SandboxedUnpacker::Cleanup() { |
| 829 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 829 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 830 if (!temp_dir_.Delete()) { | 830 if (!temp_dir_.Delete()) { |
| 831 LOG(WARNING) << "Can not delete temp directory at " | 831 LOG(WARNING) << "Can not delete temp directory at " |
| 832 << temp_dir_.path().value(); | 832 << temp_dir_.path().value(); |
| 833 } | 833 } |
| 834 } | 834 } |
| 835 | 835 |
| 836 } // namespace extensions | 836 } // namespace extensions |
| OLD | NEW |