| 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/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/file_util_proxy.h" | 12 #include "base/file_util_proxy.h" |
| 13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
| 14 #include "base/memory/scoped_handle.h" | 14 #include "base/memory/scoped_handle.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. | 18 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. |
| 19 #include "chrome/browser/extensions/crx_file.h" | 19 #include "chrome/browser/extensions/crx_file.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/chrome_utility_messages.h" | 23 #include "chrome/common/chrome_utility_messages.h" |
| 24 #include "chrome/common/extensions/extension_manifest_constants.h" | 24 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 25 #include "chrome/common/extensions/extension_file_util.h" | 25 #include "chrome/common/extensions/extension_file_util.h" |
| 26 #include "chrome/common/extensions/extension_l10n_util.h" | 26 #include "chrome/common/extensions/extension_l10n_util.h" |
| 27 #include "chrome/common/extensions/extension_unpacker.h" | 27 #include "chrome/common/extensions/unpacker.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/utility_process_host.h" | 29 #include "content/public/browser/utility_process_host.h" |
| 30 #include "crypto/signature_verifier.h" | 30 #include "crypto/signature_verifier.h" |
| 31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/codec/png_codec.h" |
| 35 | 35 |
| 36 using content::BrowserThread; | 36 using content::BrowserThread; |
| 37 using content::UtilityProcessHost; | 37 using content::UtilityProcessHost; |
| 38 using extensions::Extension; | |
| 39 | 38 |
| 40 // The following macro makes histograms that record the length of paths | 39 // The following macro makes histograms that record the length of paths |
| 41 // in this file much easier to read. | 40 // in this file much easier to read. |
| 42 // Windows has a short max path length. If the path length to a | 41 // Windows has a short max path length. If the path length to a |
| 43 // file being unpacked from a CRX exceeds the max length, we might | 42 // file being unpacked from a CRX exceeds the max length, we might |
| 44 // fail to install. To see if this is happening, see how long the | 43 // fail to install. To see if this is happening, see how long the |
| 45 // path to the temp unpack directory is. See crbug.com/69693 . | 44 // path to the temp unpack directory is. See crbug.com/69693 . |
| 46 #define PATH_LENGTH_HISTOGRAM(name, path) \ | 45 #define PATH_LENGTH_HISTOGRAM(name, path) \ |
| 47 UMA_HISTOGRAM_CUSTOM_COUNTS(name, path.value().length(), 0, 500, 100) | 46 UMA_HISTOGRAM_CUSTOM_COUNTS(name, path.value().length(), 0, 500, 100) |
| 48 | 47 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 link_free_crx_path); | 265 link_free_crx_path); |
| 267 | 266 |
| 268 BrowserThread::PostTask( | 267 BrowserThread::PostTask( |
| 269 BrowserThread::IO, FROM_HERE, | 268 BrowserThread::IO, FROM_HERE, |
| 270 base::Bind( | 269 base::Bind( |
| 271 &SandboxedUnpacker::StartProcessOnIOThread, | 270 &SandboxedUnpacker::StartProcessOnIOThread, |
| 272 this, | 271 this, |
| 273 link_free_crx_path)); | 272 link_free_crx_path)); |
| 274 } else { | 273 } else { |
| 275 // Otherwise, unpack the extension in this process. | 274 // Otherwise, unpack the extension in this process. |
| 276 ExtensionUnpacker unpacker( | 275 Unpacker unpacker(temp_crx_path, extension_id_, location_, creation_flags_); |
| 277 temp_crx_path, extension_id_, location_, creation_flags_); | |
| 278 if (unpacker.Run() && unpacker.DumpImagesToFile() && | 276 if (unpacker.Run() && unpacker.DumpImagesToFile() && |
| 279 unpacker.DumpMessageCatalogsToFile()) { | 277 unpacker.DumpMessageCatalogsToFile()) { |
| 280 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); | 278 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); |
| 281 } else { | 279 } else { |
| 282 OnUnpackExtensionFailed(unpacker.error_message()); | 280 OnUnpackExtensionFailed(unpacker.error_message()); |
| 283 } | 281 } |
| 284 } | 282 } |
| 285 } | 283 } |
| 286 | 284 |
| 287 SandboxedUnpacker::~SandboxedUnpacker() { | 285 SandboxedUnpacker::~SandboxedUnpacker() { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 l10n_util::GetStringFUTF16( | 609 l10n_util::GetStringFUTF16( |
| 612 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 610 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 613 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); | 611 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); |
| 614 return NULL; | 612 return NULL; |
| 615 } | 613 } |
| 616 | 614 |
| 617 return final_manifest.release(); | 615 return final_manifest.release(); |
| 618 } | 616 } |
| 619 | 617 |
| 620 bool SandboxedUnpacker::RewriteImageFiles() { | 618 bool SandboxedUnpacker::RewriteImageFiles() { |
| 621 ExtensionUnpacker::DecodedImages images; | 619 Unpacker::DecodedImages images; |
| 622 if (!ExtensionUnpacker::ReadImagesFromFile(temp_dir_.path(), &images)) { | 620 if (!Unpacker::ReadImagesFromFile(temp_dir_.path(), &images)) { |
| 623 // Couldn't read image data from disk. | 621 // Couldn't read image data from disk. |
| 624 ReportFailure( | 622 ReportFailure( |
| 625 COULD_NOT_READ_IMAGE_DATA_FROM_DISK, | 623 COULD_NOT_READ_IMAGE_DATA_FROM_DISK, |
| 626 l10n_util::GetStringFUTF16( | 624 l10n_util::GetStringFUTF16( |
| 627 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 625 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 628 ASCIIToUTF16("COULD_NOT_READ_IMAGE_DATA_FROM_DISK"))); | 626 ASCIIToUTF16("COULD_NOT_READ_IMAGE_DATA_FROM_DISK"))); |
| 629 return false; | 627 return false; |
| 630 } | 628 } |
| 631 | 629 |
| 632 // Delete any images that may be used by the browser. We're going to write | 630 // Delete any images that may be used by the browser. We're going to write |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 ASCIIToUTF16("ERROR_SAVING_THEME_IMAGE"))); | 705 ASCIIToUTF16("ERROR_SAVING_THEME_IMAGE"))); |
| 708 return false; | 706 return false; |
| 709 } | 707 } |
| 710 } | 708 } |
| 711 | 709 |
| 712 return true; | 710 return true; |
| 713 } | 711 } |
| 714 | 712 |
| 715 bool SandboxedUnpacker::RewriteCatalogFiles() { | 713 bool SandboxedUnpacker::RewriteCatalogFiles() { |
| 716 DictionaryValue catalogs; | 714 DictionaryValue catalogs; |
| 717 if (!ExtensionUnpacker::ReadMessageCatalogsFromFile(temp_dir_.path(), | 715 if (!Unpacker::ReadMessageCatalogsFromFile(temp_dir_.path(), &catalogs)) { |
| 718 &catalogs)) { | |
| 719 // Could not read catalog data from disk. | 716 // Could not read catalog data from disk. |
| 720 ReportFailure( | 717 ReportFailure( |
| 721 COULD_NOT_READ_CATALOG_DATA_FROM_DISK, | 718 COULD_NOT_READ_CATALOG_DATA_FROM_DISK, |
| 722 l10n_util::GetStringFUTF16( | 719 l10n_util::GetStringFUTF16( |
| 723 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 720 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 724 ASCIIToUTF16("COULD_NOT_READ_CATALOG_DATA_FROM_DISK"))); | 721 ASCIIToUTF16("COULD_NOT_READ_CATALOG_DATA_FROM_DISK"))); |
| 725 return false; | 722 return false; |
| 726 } | 723 } |
| 727 | 724 |
| 728 // Write our parsed catalogs back to disk. | 725 // Write our parsed catalogs back to disk. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 776 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 780 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); | 777 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); |
| 781 return false; | 778 return false; |
| 782 } | 779 } |
| 783 } | 780 } |
| 784 | 781 |
| 785 return true; | 782 return true; |
| 786 } | 783 } |
| 787 | 784 |
| 788 } // namespace extensions | 785 } // namespace extensions |
| OLD | NEW |