sandboxed_extension_unpacker.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/extensions/sandboxed_extension_unpacker.h" 6 7#include <set> 8 9#include "base/base64.h" 10#include "base/crypto/signature_verifier.h" 11#include "base/file_util.h" 12#include "base/file_util_proxy.h" 13#include "base/message_loop.h" 14#include "base/metrics/histogram.h" 15#include "base/path_service.h" 16#include "base/scoped_handle.h" 17#include "base/task.h" 18#include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. 19#include "chrome/browser/browser_thread.h" 20#include "chrome/browser/extensions/extension_service.h" 21#include "chrome/browser/renderer_host/resource_dispatcher_host.h" 22#include "chrome/common/chrome_paths.h" 23#include "chrome/common/chrome_switches.h" 24#include "chrome/common/extensions/extension.h" 25#include "chrome/common/extensions/extension_constants.h" 26#include "chrome/common/extensions/extension_file_util.h" 27#include "chrome/common/extensions/extension_l10n_util.h" 28#include "chrome/common/extensions/extension_unpacker.h" 29#include "chrome/common/json_value_serializer.h" 30#include "grit/generated_resources.h" 31#include "third_party/skia/include/core/SkBitmap.h" 32#include "ui/base/l10n/l10n_util.h" 33#include "ui/gfx/codec/png_codec.h" 34 35const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; 36 37SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( 38 const FilePath& crx_path, 39 ResourceDispatcherHost* rdh, 40 SandboxedExtensionUnpackerClient* client) 41 : crx_path_(crx_path), 42 thread_identifier_(BrowserThread::ID_COUNT), 43 rdh_(rdh), client_(client), got_response_(false) { 44} 45 46bool SandboxedExtensionUnpacker::CreateTempDirectory() { 47 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); 48 49 FilePath user_data_temp_dir = extension_file_util::GetUserDataTempDir(); 50 if (user_data_temp_dir.empty()) { 51 ReportFailure( 52 COULD_NOT_GET_TEMP_DIRECTORY, 53 l10n_util::GetStringFUTF8( 54 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 55 ASCIIToUTF16("COULD_NOT_GET_TEMP_DIRECTORY"))); 56 return false; 57 } 58 59 if (!temp_dir_.CreateUniqueTempDirUnderPath(user_data_temp_dir)) { 60 ReportFailure( 61 COULD_NOT_CREATE_TEMP_DIRECTORY, 62 l10n_util::GetStringFUTF8( 63 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 64 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); 65 return false; 66 } 67 68 return true; 69} 70 71void SandboxedExtensionUnpacker::Start() { 72 // We assume that we are started on the thread that the client wants us to do 73 // file IO on. 74 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); 75 76 if (!CreateTempDirectory()) 77 return; // ReportFailure() already called. 78 79 // Initialize the path that will eventually contain the unpacked extension. 80 extension_root_ = temp_dir_.path().AppendASCII( 81 extension_filenames::kTempExtensionName); 82 83 // Extract the public key and validate the package. 84 if (!ValidateSignature()) 85 return; // ValidateSignature() already reported the error. 86 87 // Copy the crx file into our working directory. 88 FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); 89 if (!file_util::CopyFile(crx_path_, temp_crx_path)) { 90 // Failed to copy extension file to temporary directory. 91 ReportFailure( 92 FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY, 93 l10n_util::GetStringFUTF8( 94 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 95 ASCIIToUTF16("FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY"))); 96 return; 97 } 98 99 // If we are supposed to use a subprocess, kick off the subprocess. 100 // 101 // TODO(asargent) we shouldn't need to do this branch here - instead 102 // UtilityProcessHost should handle it for us. (http://crbug.com/19192) 103 bool use_utility_process = rdh_ && 104 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); 105 if (use_utility_process) { 106 // The utility process will have access to the directory passed to 107 // SandboxedExtensionUnpacker. That directory should not contain a 108 // symlink or NTFS reparse point. When the path is used, following 109 // the link/reparse point will cause file system access outside the 110 // sandbox path, and the sandbox will deny the operation. 111 FilePath link_free_crx_path; 112 if (!file_util::NormalizeFilePath(temp_crx_path, &link_free_crx_path)) { 113 LOG(ERROR) << "Could not get the normalized path of " 114 << temp_crx_path.value(); 115 ReportFailure( 116 COULD_NOT_GET_SANDBOX_FRIENDLY_PATH, 117 l10n_util::GetStringUTF8(IDS_EXTENSION_UNPACK_FAILED)); 118 return; 119 } 120 121 BrowserThread::PostTask( 122 BrowserThread::IO, FROM_HERE, 123 NewRunnableMethod( 124 this, 125 &SandboxedExtensionUnpacker::StartProcessOnIOThread, 126 link_free_crx_path)); 127 } else { 128 // Otherwise, unpack the extension in this process. 129 ExtensionUnpacker unpacker(temp_crx_path); 130 if (unpacker.Run() && unpacker.DumpImagesToFile() && 131 unpacker.DumpMessageCatalogsToFile()) { 132 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); 133 } else { 134 OnUnpackExtensionFailed(unpacker.error_message()); 135 } 136 } 137} 138 139SandboxedExtensionUnpacker::~SandboxedExtensionUnpacker() { 140 base::FileUtilProxy::Delete( 141 BrowserThread::GetMessageLoopProxyForThread(thread_identifier_), 142 temp_dir_.Take(), 143 true, 144 NULL); 145} 146 147void SandboxedExtensionUnpacker::StartProcessOnIOThread( 148 const FilePath& temp_crx_path) { 149 UtilityProcessHost* host = new UtilityProcessHost( 150 rdh_, this, thread_identifier_); 151 host->StartExtensionUnpacker(temp_crx_path); 152} 153 154void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( 155 const DictionaryValue& manifest) { 156 // Skip check for unittests. 157 if (thread_identifier_ != BrowserThread::ID_COUNT) 158 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); 159 got_response_ = true; 160 161 scoped_ptr<DictionaryValue> final_manifest(RewriteManifestFile(manifest)); 162 if (!final_manifest.get()) 163 return; 164 165 // Create an extension object that refers to the temporary location the 166 // extension was unpacked to. We use this until the extension is finally 167 // installed. For example, the install UI shows images from inside the 168 // extension. 169 170 // Localize manifest now, so confirm UI gets correct extension name. 171 std::string error; 172 if (!extension_l10n_util::LocalizeExtension(extension_root_, 173 final_manifest.get(), 174 &error)) { 175 ReportFailure( 176 COULD_NOT_LOCALIZE_EXTENSION, 177 l10n_util::GetStringFUTF8( 178 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, 179 ASCIIToUTF16(error))); 180 return; 181 } 182 183 extension_ = Extension::Create( 184 extension_root_, Extension::INTERNAL, *final_manifest, true, &error); 185 186 if (!extension_.get()) { 187 ReportFailure( 188 INVALID_MANIFEST, 189 std::string("Manifest is invalid: ") + error); 190 return; 191 } 192 193 if (!RewriteImageFiles()) 194 return; 195 196 if (!RewriteCatalogFiles()) 197 return; 198 199 ReportSuccess(); 200} 201 202void SandboxedExtensionUnpacker::OnUnpackExtensionFailed( 203 const std::string& error) { 204 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); 205 got_response_ = true; 206 ReportFailure( 207 UNPACKER_CLIENT_FAILED, 208 l10n_util::GetStringFUTF8( 209 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, 210 ASCIIToUTF16(error))); 211} 212 213void SandboxedExtensionUnpacker::OnProcessCrashed(int exit_code) { 214 // Don't report crashes if they happen after we got a response. 215 if (got_response_) 216 return; 217 218 // Utility process crashed while trying to install. 219 ReportFailure( 220 UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL, 221 l10n_util::GetStringFUTF8( 222 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 223 ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); 224} 225 226bool SandboxedExtensionUnpacker::ValidateSignature() { 227 ScopedStdioHandle file(file_util::OpenFile(crx_path_, "rb")); 228 if (!file.get()) { 229 // Could not open crx file for reading 230 ReportFailure( 231 CRX_FILE_NOT_READABLE, 232 l10n_util::GetStringFUTF8( 233 IDS_EXTENSION_PACKAGE_ERROR_CODE, 234 ASCIIToUTF16("CRX_FILE_NOT_READABLE"))); 235 return false; 236 } 237 238 // Read and verify the header. 239 ExtensionHeader header; 240 size_t len; 241 242 // TODO(erikkay): Yuck. I'm not a big fan of this kind of code, but it 243 // appears that we don't have any endian/alignment aware serialization 244 // code in the code base. So for now, this assumes that we're running 245 // on a little endian machine with 4 byte alignment. 246 len = fread(&header, 1, sizeof(ExtensionHeader), 247 file.get()); 248 if (len < sizeof(ExtensionHeader)) { 249 // Invalid crx header 250 ReportFailure( 251 CRX_HEADER_INVALID, 252 l10n_util::GetStringFUTF8( 253 IDS_EXTENSION_PACKAGE_ERROR_CODE, 254 ASCIIToUTF16("CRX_HEADER_INVALID"))); 255 return false; 256 } 257 if (strncmp(kExtensionHeaderMagic, header.magic, 258 sizeof(header.magic))) { 259 // Bad magic number 260 ReportFailure( 261 CRX_MAGIC_NUMBER_INVALID, 262 l10n_util::GetStringFUTF8( 263 IDS_EXTENSION_PACKAGE_ERROR_CODE, 264 ASCIIToUTF16("CRX_MAGIC_NUMBER_INVALID"))); 265 return false; 266 } 267 if (header.version != kCurrentVersion) { 268 // Bad version numer 269 ReportFailure(CRX_VERSION_NUMBER_INVALID, 270 l10n_util::GetStringFUTF8( 271 IDS_EXTENSION_PACKAGE_ERROR_CODE, 272 ASCIIToUTF16("CRX_VERSION_NUMBER_INVALID"))); 273 return false; 274 } 275 if (header.key_size > kMaxPublicKeySize || 276 header.signature_size > kMaxSignatureSize) { 277 // Excessively large key or signature 278 ReportFailure( 279 CRX_EXCESSIVELY_LARGE_KEY_OR_SIGNATURE, 280 l10n_util::GetStringFUTF8( 281 IDS_EXTENSION_PACKAGE_ERROR_CODE, 282 ASCIIToUTF16("CRX_EXCESSIVELY_LARGE_KEY_OR_SIGNATURE"))); 283 return false; 284 } 285 if (header.key_size == 0) { 286 // Key length is zero 287 ReportFailure( 288 CRX_ZERO_KEY_LENGTH, 289 l10n_util::GetStringFUTF8( 290 IDS_EXTENSION_PACKAGE_ERROR_CODE, 291 ASCIIToUTF16("CRX_ZERO_KEY_LENGTH"))); 292 return false; 293 } 294 if (header.signature_size == 0) { 295 // Signature length is zero 296 ReportFailure( 297 CRX_ZERO_SIGNATURE_LENGTH, 298 l10n_util::GetStringFUTF8( 299 IDS_EXTENSION_PACKAGE_ERROR_CODE, 300 ASCIIToUTF16("CRX_ZERO_SIGNATURE_LENGTH"))); 301 return false; 302 } 303 304 std::vector<uint8> key; 305 key.resize(header.key_size); 306 len = fread(&key.front(), sizeof(uint8), header.key_size, file.get()); 307 if (len < header.key_size) { 308 // Invalid public key 309 ReportFailure( 310 CRX_PUBLIC_KEY_INVALID, 311 l10n_util::GetStringFUTF8( 312 IDS_EXTENSION_PACKAGE_ERROR_CODE, 313 ASCIIToUTF16("CRX_PUBLIC_KEY_INVALID"))); 314 return false; 315 } 316 317 std::vector<uint8> signature; 318 signature.resize(header.signature_size); 319 len = fread(&signature.front(), sizeof(uint8), header.signature_size, 320 file.get()); 321 if (len < header.signature_size) { 322 // Invalid signature 323 ReportFailure( 324 CRX_SIGNATURE_INVALID, 325 l10n_util::GetStringFUTF8( 326 IDS_EXTENSION_PACKAGE_ERROR_CODE, 327 ASCIIToUTF16("CRX_SIGNATURE_INVALID"))); 328 return false; 329 } 330 331 base::SignatureVerifier verifier; 332 if (!verifier.VerifyInit(extension_misc::kSignatureAlgorithm, 333 sizeof(extension_misc::kSignatureAlgorithm), 334 &signature.front(), 335 signature.size(), 336 &key.front(), 337 key.size())) { 338 // Signature verification initialization failed. This is most likely 339 // caused by a public key in the wrong format (should encode algorithm). 340 ReportFailure( 341 CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED, 342 l10n_util::GetStringFUTF8( 343 IDS_EXTENSION_PACKAGE_ERROR_CODE, 344 ASCIIToUTF16("CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED"))); 345 return false; 346 } 347 348 unsigned char buf[1 << 12]; 349 while ((len = fread(buf, 1, sizeof(buf), file.get())) > 0) 350 verifier.VerifyUpdate(buf, len); 351 352 if (!verifier.VerifyFinal()) { 353 // Signature verification failed 354 ReportFailure( 355 CRX_SIGNATURE_VERIFICATION_FAILED, 356 l10n_util::GetStringFUTF8( 357 IDS_EXTENSION_PACKAGE_ERROR_CODE, 358 ASCIIToUTF16("CRX_SIGNATURE_VERIFICATION_FAILED"))); 359 return false; 360 } 361 362 base::Base64Encode(std::string(reinterpret_cast<char*>(&key.front()), 363 key.size()), &public_key_); 364 return true; 365} 366 367void SandboxedExtensionUnpacker::ReportFailure(FailureReason reason, 368 const std::string& error) { 369 UMA_HISTOGRAM_COUNTS("Extensions.SandboxUnpackFailure", 1); 370 UMA_HISTOGRAM_ENUMERATION("Extensions.SandboxUnpackFailureReason", 371 reason, NUM_FAILURE_REASONS); 372 373 client_->OnUnpackFailure(error); 374} 375 376void SandboxedExtensionUnpacker::ReportSuccess() { 377 UMA_HISTOGRAM_COUNTS("Extensions.SandboxUnpackSuccess", 1); 378 379 // Client takes ownership of temporary directory and extension. 380 client_->OnUnpackSuccess(temp_dir_.Take(), extension_root_, extension_); 381 extension_ = NULL; 382} 383 384DictionaryValue* SandboxedExtensionUnpacker::RewriteManifestFile( 385 const DictionaryValue& manifest) { 386 // Add the public key extracted earlier to the parsed manifest and overwrite 387 // the original manifest. We do this to ensure the manifest doesn't contain an 388 // exploitable bug that could be used to compromise the browser. 389 scoped_ptr<DictionaryValue> final_manifest(manifest.DeepCopy()); 390 final_manifest->SetString(extension_manifest_keys::kPublicKey, public_key_); 391 392 std::string manifest_json; 393 JSONStringValueSerializer serializer(&manifest_json); 394 serializer.set_pretty_print(true); 395 if (!serializer.Serialize(*final_manifest)) { 396 // Error serializing manifest.json. 397 ReportFailure( 398 ERROR_SERIALIZING_MANIFEST_JSON, 399 l10n_util::GetStringFUTF8( 400 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 401 ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON"))); 402 return NULL; 403 } 404 405 FilePath manifest_path = 406 extension_root_.Append(Extension::kManifestFilename); 407 if (!file_util::WriteFile(manifest_path, 408 manifest_json.data(), manifest_json.size())) { 409 // Error saving manifest.json. 410 ReportFailure( 411 ERROR_SAVING_MANIFEST_JSON, 412 l10n_util::GetStringFUTF8( 413 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 414 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); 415 return NULL; 416 } 417 418 return final_manifest.release(); 419} 420 421bool SandboxedExtensionUnpacker::RewriteImageFiles() { 422 ExtensionUnpacker::DecodedImages images; 423 if (!ExtensionUnpacker::ReadImagesFromFile(temp_dir_.path(), &images)) { 424 // Couldn't read image data from disk. 425 ReportFailure( 426 COULD_NOT_READ_IMAGE_DATA_FROM_DISK, 427 l10n_util::GetStringFUTF8( 428 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 429 ASCIIToUTF16("COULD_NOT_READ_IMAGE_DATA_FROM_DISK"))); 430 return false; 431 } 432 433 // Delete any images that may be used by the browser. We're going to write 434 // out our own versions of the parsed images, and we want to make sure the 435 // originals are gone for good. 436 std::set<FilePath> image_paths = extension_->GetBrowserImages(); 437 if (image_paths.size() != images.size()) { 438 // Decoded images don't match what's in the manifest. 439 ReportFailure( 440 DECODED_IMAGES_DO_NOT_MATCH_THE_MANIFEST, 441 l10n_util::GetStringFUTF8( 442 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 443 ASCIIToUTF16("DECODED_IMAGES_DO_NOT_MATCH_THE_MANIFEST"))); 444 return false; 445 } 446 447 for (std::set<FilePath>::iterator it = image_paths.begin(); 448 it != image_paths.end(); ++it) { 449 FilePath path = *it; 450 if (path.IsAbsolute() || path.ReferencesParent()) { 451 // Invalid path for browser image. 452 ReportFailure( 453 INVALID_PATH_FOR_BROWSER_IMAGE, 454 l10n_util::GetStringFUTF8( 455 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 456 ASCIIToUTF16("INVALID_PATH_FOR_BROWSER_IMAGE"))); 457 return false; 458 } 459 if (!file_util::Delete(extension_root_.Append(path), false)) { 460 // Error removing old image file. 461 ReportFailure( 462 ERROR_REMOVING_OLD_IMAGE_FILE, 463 l10n_util::GetStringFUTF8( 464 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 465 ASCIIToUTF16("ERROR_REMOVING_OLD_IMAGE_FILE"))); 466 return false; 467 } 468 } 469 470 // Write our parsed images back to disk as well. 471 for (size_t i = 0; i < images.size(); ++i) { 472 const SkBitmap& image = images[i].a; 473 FilePath path_suffix = images[i].b; 474 if (path_suffix.IsAbsolute() || path_suffix.ReferencesParent()) { 475 // Invalid path for bitmap image. 476 ReportFailure( 477 INVALID_PATH_FOR_BITMAP_IMAGE, 478 l10n_util::GetStringFUTF8( 479 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 480 ASCIIToUTF16("INVALID_PATH_FOR_BITMAP_IMAGE"))); 481 return false; 482 } 483 FilePath path = extension_root_.Append(path_suffix); 484 485 std::vector<unsigned char> image_data; 486 // TODO(mpcomplete): It's lame that we're encoding all images as PNG, even 487 // though they may originally be .jpg, etc. Figure something out. 488 // http://code.google.com/p/chromium/issues/detail?id=12459 489 if (!gfx::PNGCodec::EncodeBGRASkBitmap(image, false, &image_data)) { 490 // Error re-encoding theme image. 491 ReportFailure( 492 ERROR_RE_ENCODING_THEME_IMAGE, 493 l10n_util::GetStringFUTF8( 494 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 495 ASCIIToUTF16("ERROR_RE_ENCODING_THEME_IMAGE"))); 496 return false; 497 } 498 499 // Note: we're overwriting existing files that the utility process wrote, 500 // so we can be sure the directory exists. 501 const char* image_data_ptr = reinterpret_cast<const char*>(&image_data[0]); 502 if (!file_util::WriteFile(path, image_data_ptr, image_data.size())) { 503 // Error saving theme image. 504 ReportFailure( 505 ERROR_SAVING_THEME_IMAGE, 506 l10n_util::GetStringFUTF8( 507 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 508 ASCIIToUTF16("ERROR_SAVING_THEME_IMAGE"))); 509 return false; 510 } 511 } 512 513 return true; 514} 515 516bool SandboxedExtensionUnpacker::RewriteCatalogFiles() { 517 DictionaryValue catalogs; 518 if (!ExtensionUnpacker::ReadMessageCatalogsFromFile(temp_dir_.path(), 519 &catalogs)) { 520 // Could not read catalog data from disk. 521 ReportFailure( 522 COULD_NOT_READ_CATALOG_DATA_FROM_DISK, 523 l10n_util::GetStringFUTF8( 524 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 525 ASCIIToUTF16("COULD_NOT_READ_CATALOG_DATA_FROM_DISK"))); 526 return false; 527 } 528 529 // Write our parsed catalogs back to disk. 530 for (DictionaryValue::key_iterator key_it = catalogs.begin_keys(); 531 key_it != catalogs.end_keys(); ++key_it) { 532 DictionaryValue* catalog; 533 if (!catalogs.GetDictionaryWithoutPathExpansion(*key_it, &catalog)) { 534 // Invalid catalog data. 535 ReportFailure( 536 INVALID_CATALOG_DATA, 537 l10n_util::GetStringFUTF8( 538 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 539 ASCIIToUTF16("INVALID_CATALOG_DATA"))); 540 return false; 541 } 542 543 // TODO(viettrungluu): Fix the |FilePath::FromWStringHack(UTF8ToWide())| 544 // hack and remove the corresponding #include. 545 FilePath relative_path = FilePath::FromWStringHack(UTF8ToWide(*key_it)); 546 relative_path = relative_path.Append(Extension::kMessagesFilename); 547 if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) { 548 // Invalid path for catalog. 549 ReportFailure( 550 INVALID_PATH_FOR_CATALOG, 551 l10n_util::GetStringFUTF8( 552 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 553 ASCIIToUTF16("INVALID_PATH_FOR_CATALOG"))); 554 return false; 555 } 556 FilePath path = extension_root_.Append(relative_path); 557 558 std::string catalog_json; 559 JSONStringValueSerializer serializer(&catalog_json); 560 serializer.set_pretty_print(true); 561 if (!serializer.Serialize(*catalog)) { 562 // Error serializing catalog. 563 ReportFailure( 564 ERROR_SERIALIZING_CATALOG, 565 l10n_util::GetStringFUTF8( 566 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 567 ASCIIToUTF16("ERROR_SERIALIZING_CATALOG"))); 568 return false; 569 } 570 571 // Note: we're overwriting existing files that the utility process read, 572 // so we can be sure the directory exists. 573 if (!file_util::WriteFile(path, 574 catalog_json.c_str(), 575 catalog_json.size())) { 576 // Error saving catalog. 577 ReportFailure( 578 ERROR_SAVING_CATALOG, 579 l10n_util::GetStringFUTF8( 580 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 581 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); 582 return false; 583 } 584 } 585 586 return true; 587} 588