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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_util_proxy.h" | 13 #include "base/files/file_util_proxy.h" |
14 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
15 #include "base/memory/scoped_handle.h" | 15 #include "base/memory/scoped_handle.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/numerics/safe_conversions.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/safe_numerics.h" | |
20 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/chrome_utility_messages.h" | 26 #include "chrome/common/chrome_utility_messages.h" |
27 #include "chrome/common/extensions/extension_file_util.h" | 27 #include "chrome/common/extensions/extension_file_util.h" |
28 #include "chrome/common/extensions/extension_l10n_util.h" | 28 #include "chrome/common/extensions/extension_l10n_util.h" |
29 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 29 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 ReportFailure( | 621 ReportFailure( |
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_numeric_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 (file_util::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 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 ERROR_RE_ENCODING_THEME_IMAGE, | 734 ERROR_RE_ENCODING_THEME_IMAGE, |
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_numeric_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 (file_util::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 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 ReportFailure( | 803 ReportFailure( |
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_numeric_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 (file_util::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 |