diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-22 01:18:33 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-22 01:18:33 +0000 |
commit | 19a7337c99cef4cacf34698d8c2cb70601de4c57 (patch) | |
tree | 960004f6d2d9804619126b7e0924568aaa91071b /chrome/browser | |
parent | 85f0a4eb2fee288901fded8ca2267e4960390fd1 (diff) | |
download | chromium_src-19a7337c99cef4cacf34698d8c2cb70601de4c57.zip chromium_src-19a7337c99cef4cacf34698d8c2cb70601de4c57.tar.gz chromium_src-19a7337c99cef4cacf34698d8c2cb70601de4c57.tar.bz2 |
Move more extensions hard coded error messages to .grd file.
BUG=51398
TEST=trybots
Original Review: http://codereview.chromium.org/4953002/
Signed-off-by: Lauri Oherd <lauri.oherd@gmail.com>
Reviewed-by: Aaron Boodman <aa@chromium.org>
Review URL: http://codereview.chromium.org/6088002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/extensions/sandboxed_extension_unpacker.cc | 169 |
1 files changed, 122 insertions, 47 deletions
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc index fcd569b..9d7e45b 100644 --- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc +++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc @@ -6,6 +6,7 @@ #include <set> +#include "app/l10n_util.h" #include "base/base64.h" #include "base/crypto/signature_verifier.h" #include "base/file_util.h" @@ -25,6 +26,7 @@ #include "chrome/common/extensions/extension_unpacker.h" #include "chrome/common/json_value_serializer.h" #include "gfx/codec/png_codec.h" +#include "grit/generated_resources.h" #include "third_party/skia/include/core/SkBitmap.h" const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; @@ -46,7 +48,10 @@ void SandboxedExtensionUnpacker::Start() { // Create a temporary directory to work in. if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path_)) { - ReportFailure("Could not create temporary directory."); + // Could not create temporary directory. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); return; } @@ -61,7 +66,10 @@ void SandboxedExtensionUnpacker::Start() { // Copy the crx file into our working directory. FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); if (!file_util::CopyFile(crx_path_, temp_crx_path)) { - ReportFailure("Failed to copy extension file to temporary directory."); + // Failed to copy extension file to temporary directory. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY"))); return; } @@ -81,21 +89,7 @@ void SandboxedExtensionUnpacker::Start() { if (!file_util::NormalizeFilePath(temp_crx_path, &link_free_crx_path)) { LOG(ERROR) << "Could not get the normalized path of " << temp_crx_path.value(); -#if defined (OS_WIN) - // On windows, it is possible to mount a disk without the root of that - // disk having a drive letter. The sandbox does not support this. - // See crbug/49530 . - ReportFailure( - "Can not unpack extension. To safely unpack an extension, " - "there must be a path to your profile directory that starts " - "with a drive letter and does not contain a junction, mount " - "point, or symlink. No such path exists for your profile."); -#else - ReportFailure( - "Can not unpack extension. To safely unpack an extension, " - "there must be a path to your profile directory that does " - "not contain a symlink. No such path exists for your profile."); -#endif + ReportFailure(l10n_util::GetStringUTF8(IDS_EXTENSION_UNPACK_FAILED)); return; } @@ -153,7 +147,9 @@ void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( if (!extension_l10n_util::LocalizeExtension(extension_root_, final_manifest.get(), &error)) { - ReportFailure(error); + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, + ASCIIToUTF16(error))); return; } @@ -178,7 +174,9 @@ void SandboxedExtensionUnpacker::OnUnpackExtensionFailed( const std::string& error) { DCHECK(BrowserThread::CurrentlyOn(thread_identifier_)); got_response_ = true; - ReportFailure(error); + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, + ASCIIToUTF16(error))); } void SandboxedExtensionUnpacker::OnProcessCrashed(int exit_code) { @@ -186,13 +184,19 @@ void SandboxedExtensionUnpacker::OnProcessCrashed(int exit_code) { if (got_response_) return; - ReportFailure("Utility process crashed while trying to install."); + // Utility process crashed while trying to install. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); } bool SandboxedExtensionUnpacker::ValidateSignature() { ScopedStdioHandle file(file_util::OpenFile(crx_path_, "rb")); if (!file.get()) { - ReportFailure("Could not open crx file for reading"); + // Could not open crx file for reading + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_FILE_NOT_READABLE"))); return false; } @@ -207,29 +211,47 @@ bool SandboxedExtensionUnpacker::ValidateSignature() { len = fread(&header, 1, sizeof(ExtensionHeader), file.get()); if (len < sizeof(ExtensionHeader)) { - ReportFailure("Invalid crx header"); + // Invalid crx header + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_HEADER_INVALID"))); return false; } if (strncmp(kExtensionHeaderMagic, header.magic, sizeof(header.magic))) { - ReportFailure("Bad magic number"); + // Bad magic number + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_MAGIC_NUMBER_INVALID"))); return false; } if (header.version != kCurrentVersion) { - ReportFailure("Bad version number"); + // Bad version numer + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_VERSION_NUMBER_INVALID"))); return false; } if (header.key_size > kMaxPublicKeySize || header.signature_size > kMaxSignatureSize) { - ReportFailure("Excessively large key or signature"); + // Excessively large key or signature + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_EXCESSIVELY_LARGE_KEY_OR_SIGNATURE"))); return false; } if (header.key_size == 0) { - ReportFailure("Key length is zero"); + // Key length is zero + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_ZERO_KEY_LENGTH"))); return false; } if (header.signature_size == 0) { - ReportFailure("Signature length is zero"); + // Signature length is zero + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_ZERO_SIGNATURE_LENGTH"))); return false; } @@ -237,7 +259,10 @@ bool SandboxedExtensionUnpacker::ValidateSignature() { key.resize(header.key_size); len = fread(&key.front(), sizeof(uint8), header.key_size, file.get()); if (len < header.key_size) { - ReportFailure("Invalid public key"); + // Invalid public key + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_PUBLIC_KEY_INVALID"))); return false; } @@ -246,7 +271,10 @@ bool SandboxedExtensionUnpacker::ValidateSignature() { len = fread(&signature.front(), sizeof(uint8), header.signature_size, file.get()); if (len < header.signature_size) { - ReportFailure("Invalid signature"); + // Invalid signature + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_SIGNATURE_INVALID"))); return false; } @@ -257,9 +285,11 @@ bool SandboxedExtensionUnpacker::ValidateSignature() { signature.size(), &key.front(), key.size())) { - ReportFailure("Signature verification initialization failed. " - "This is most likely caused by a public key in " - "the wrong format (should encode algorithm)."); + // Signature verification initialization failed. This is most likely + // caused by a public key in the wrong format (should encode algorithm). + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED"))); return false; } @@ -268,7 +298,10 @@ bool SandboxedExtensionUnpacker::ValidateSignature() { verifier.VerifyUpdate(buf, len); if (!verifier.VerifyFinal()) { - ReportFailure("Signature verification failed"); + // Signature verification failed + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_ERROR_CODE, + ASCIIToUTF16("CRX_SIGNATURE_VERIFICATION_FAILED"))); return false; } @@ -300,7 +333,10 @@ DictionaryValue* SandboxedExtensionUnpacker::RewriteManifestFile( JSONStringValueSerializer serializer(&manifest_json); serializer.set_pretty_print(true); if (!serializer.Serialize(*final_manifest)) { - ReportFailure("Error serializing manifest.json."); + // Error serializing manifest.json. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON"))); return NULL; } @@ -308,7 +344,10 @@ DictionaryValue* SandboxedExtensionUnpacker::RewriteManifestFile( extension_root_.Append(Extension::kManifestFilename); if (!file_util::WriteFile(manifest_path, manifest_json.data(), manifest_json.size())) { - ReportFailure("Error saving manifest.json."); + // Error saving manifest.json. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); return NULL; } @@ -318,7 +357,10 @@ DictionaryValue* SandboxedExtensionUnpacker::RewriteManifestFile( bool SandboxedExtensionUnpacker::RewriteImageFiles() { ExtensionUnpacker::DecodedImages images; if (!ExtensionUnpacker::ReadImagesFromFile(temp_dir_.path(), &images)) { - ReportFailure("Couldn't read image data from disk."); + // Couldn't read image data from disk. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("COULD_NOT_READ_IMAGE_DATA_FROM_DISK"))); return false; } @@ -327,7 +369,10 @@ bool SandboxedExtensionUnpacker::RewriteImageFiles() { // originals are gone for good. std::set<FilePath> image_paths = extension_->GetBrowserImages(); if (image_paths.size() != images.size()) { - ReportFailure("Decoded images don't match what's in the manifest."); + // Decoded images don't match what's in the manifest. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("DECODED_IMAGES_DO_NOT_MATCH_THE_MANIFEST"))); return false; } @@ -335,11 +380,17 @@ bool SandboxedExtensionUnpacker::RewriteImageFiles() { it != image_paths.end(); ++it) { FilePath path = *it; if (path.IsAbsolute() || path.ReferencesParent()) { - ReportFailure("Invalid path for browser image."); + // Invalid path for browser image. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("INVALID_PATH_FOR_BROWSER_IMAGE"))); return false; } if (!file_util::Delete(extension_root_.Append(path), false)) { - ReportFailure("Error removing old image file."); + // Error removing old image file. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("ERROR_REMOVING_OLD_IMAGE_FILE"))); return false; } } @@ -349,7 +400,10 @@ bool SandboxedExtensionUnpacker::RewriteImageFiles() { const SkBitmap& image = images[i].a; FilePath path_suffix = images[i].b; if (path_suffix.IsAbsolute() || path_suffix.ReferencesParent()) { - ReportFailure("Invalid path for bitmap image."); + // Invalid path for bitmap image. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("INVALID_PATH_FOR_BITMAP_IMAGE"))); return false; } FilePath path = extension_root_.Append(path_suffix); @@ -359,7 +413,10 @@ bool SandboxedExtensionUnpacker::RewriteImageFiles() { // though they may originally be .jpg, etc. Figure something out. // http://code.google.com/p/chromium/issues/detail?id=12459 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &image_data)) { - ReportFailure("Error re-encoding theme image."); + // Error re-encoding theme image. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("ERROR_RE_ENCODING_THEME_IMAGE"))); return false; } @@ -367,7 +424,10 @@ bool SandboxedExtensionUnpacker::RewriteImageFiles() { // so we can be sure the directory exists. const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); if (!file_util::WriteFile(path, image_data_ptr, image_data.size())) { - ReportFailure("Error saving theme image."); + // Error saving theme image. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("ERROR_SAVING_THEME_IMAGE"))); return false; } } @@ -379,7 +439,10 @@ bool SandboxedExtensionUnpacker::RewriteCatalogFiles() { DictionaryValue catalogs; if (!ExtensionUnpacker::ReadMessageCatalogsFromFile(temp_dir_.path(), &catalogs)) { - ReportFailure("Could not read catalog data from disk."); + // Could not read catalog data from disk. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("COULD_NOT_READ_CATALOG_DATA_FROM_DISK"))); return false; } @@ -388,7 +451,10 @@ bool SandboxedExtensionUnpacker::RewriteCatalogFiles() { key_it != catalogs.end_keys(); ++key_it) { DictionaryValue* catalog; if (!catalogs.GetDictionaryWithoutPathExpansion(*key_it, &catalog)) { - ReportFailure("Invalid catalog data."); + // Invalid catalog data. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("INVALID_CATALOG_DATA"))); return false; } @@ -397,7 +463,10 @@ bool SandboxedExtensionUnpacker::RewriteCatalogFiles() { FilePath relative_path = FilePath::FromWStringHack(UTF8ToWide(*key_it)); relative_path = relative_path.Append(Extension::kMessagesFilename); if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) { - ReportFailure("Invalid path for catalog."); + // Invalid path for catalog. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("INVALID_PATH_FOR_CATALOG"))); return false; } FilePath path = extension_root_.Append(relative_path); @@ -406,7 +475,10 @@ bool SandboxedExtensionUnpacker::RewriteCatalogFiles() { JSONStringValueSerializer serializer(&catalog_json); serializer.set_pretty_print(true); if (!serializer.Serialize(*catalog)) { - ReportFailure("Error serializing catalog."); + // Error serializing catalog. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("ERROR_SERIALIZING_CATALOG"))); return false; } @@ -415,7 +487,10 @@ bool SandboxedExtensionUnpacker::RewriteCatalogFiles() { if (!file_util::WriteFile(path, catalog_json.c_str(), catalog_json.size())) { - ReportFailure("Error saving catalog."); + // Error saving catalog. + ReportFailure(l10n_util::GetStringFUTF8( + IDS_EXTENSION_PACKAGE_INSTALL_ERROR, + ASCIIToUTF16("ERROR_SAVING_CATALOG"))); return false; } } |