Index: chrome/browser/extensions/sandboxed_extension_unpacker.cc |
=================================================================== |
--- chrome/browser/extensions/sandboxed_extension_unpacker.cc (revision 66672) |
+++ chrome/browser/extensions/sandboxed_extension_unpacker.cc (working copy) |
@@ -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" |
@@ -26,6 +27,7 @@ |
#include "chrome/common/json_value_serializer.h" |
#include "gfx/codec/png_codec.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
+#include "grit/generated_resources.h" |
const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; |
@@ -46,7 +48,10 @@ |
// 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 @@ |
// 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 @@ |
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 @@ |
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,10 @@ |
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() { |
@@ -186,13 +185,19 @@ |
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 +212,47 @@ |
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 +260,10 @@ |
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 +272,10 @@ |
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 +286,11 @@ |
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 +299,10 @@ |
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 +334,10 @@ |
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 +345,10 @@ |
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 +358,10 @@ |
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 +370,10 @@ |
// 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 +381,17 @@ |
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 +401,10 @@ |
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 +414,10 @@ |
// 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 +425,10 @@ |
// 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 +440,10 @@ |
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 +452,10 @@ |
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 +464,10 @@ |
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 +476,10 @@ |
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 +488,10 @@ |
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; |
} |
} |