| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_extension_unpacker.h" | 5 #include "chrome/browser/extensions/sandboxed_extension_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_value_serializer.h" | 13 #include "base/json/json_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/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/chrome_utility_messages.h" | 22 #include "chrome/common/chrome_utility_messages.h" |
| 23 #include "chrome/common/extensions/extension.h" | |
| 24 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 25 #include "chrome/common/extensions/extension_file_util.h" | 24 #include "chrome/common/extensions/extension_file_util.h" |
| 26 #include "chrome/common/extensions/extension_l10n_util.h" | 25 #include "chrome/common/extensions/extension_l10n_util.h" |
| 27 #include "chrome/common/extensions/extension_unpacker.h" | 26 #include "chrome/common/extensions/extension_unpacker.h" |
| 28 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 27 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 29 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 30 #include "crypto/signature_verifier.h" | 29 #include "crypto/signature_verifier.h" |
| 31 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 32 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 UNPACK_RATE_HISTOGRAM( | 104 UNPACK_RATE_HISTOGRAM( |
| 106 "Extensions.SandboxUnpackRateOver10mB", unpack_rate_kb_per_s); | 105 "Extensions.SandboxUnpackRateOver10mB", unpack_rate_kb_per_s); |
| 107 } | 106 } |
| 108 } | 107 } |
| 109 | 108 |
| 110 } // namespace | 109 } // namespace |
| 111 | 110 |
| 112 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( | 111 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( |
| 113 const FilePath& crx_path, | 112 const FilePath& crx_path, |
| 114 ResourceDispatcherHost* rdh, | 113 ResourceDispatcherHost* rdh, |
| 114 Extension::Location location, |
| 115 int creation_flags, | 115 int creation_flags, |
| 116 SandboxedExtensionUnpackerClient* client) | 116 SandboxedExtensionUnpackerClient* client) |
| 117 : crx_path_(crx_path), | 117 : crx_path_(crx_path), |
| 118 thread_identifier_(BrowserThread::ID_COUNT), | 118 thread_identifier_(BrowserThread::ID_COUNT), |
| 119 rdh_(rdh), client_(client), got_response_(false), | 119 rdh_(rdh), client_(client), got_response_(false), |
| 120 creation_flags_(creation_flags) { | 120 location_(location), creation_flags_(creation_flags) { |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool SandboxedExtensionUnpacker::CreateTempDirectory() { | 123 bool SandboxedExtensionUnpacker::CreateTempDirectory() { |
| 124 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); | 124 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); |
| 125 | 125 |
| 126 FilePath user_data_temp_dir = extension_file_util::GetUserDataTempDir(); | 126 FilePath user_data_temp_dir = extension_file_util::GetUserDataTempDir(); |
| 127 if (user_data_temp_dir.empty()) { | 127 if (user_data_temp_dir.empty()) { |
| 128 ReportFailure( | 128 ReportFailure( |
| 129 COULD_NOT_GET_TEMP_DIRECTORY, | 129 COULD_NOT_GET_TEMP_DIRECTORY, |
| 130 l10n_util::GetStringFUTF8( | 130 l10n_util::GetStringFUTF8( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 link_free_crx_path); | 207 link_free_crx_path); |
| 208 | 208 |
| 209 BrowserThread::PostTask( | 209 BrowserThread::PostTask( |
| 210 BrowserThread::IO, FROM_HERE, | 210 BrowserThread::IO, FROM_HERE, |
| 211 base::Bind( | 211 base::Bind( |
| 212 &SandboxedExtensionUnpacker::StartProcessOnIOThread, | 212 &SandboxedExtensionUnpacker::StartProcessOnIOThread, |
| 213 this, | 213 this, |
| 214 link_free_crx_path)); | 214 link_free_crx_path)); |
| 215 } else { | 215 } else { |
| 216 // Otherwise, unpack the extension in this process. | 216 // Otherwise, unpack the extension in this process. |
| 217 ExtensionUnpacker unpacker(temp_crx_path); | 217 ExtensionUnpacker unpacker(temp_crx_path, location_, creation_flags_); |
| 218 if (unpacker.Run() && unpacker.DumpImagesToFile() && | 218 if (unpacker.Run() && unpacker.DumpImagesToFile() && |
| 219 unpacker.DumpMessageCatalogsToFile()) { | 219 unpacker.DumpMessageCatalogsToFile()) { |
| 220 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); | 220 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); |
| 221 } else { | 221 } else { |
| 222 OnUnpackExtensionFailed(unpacker.error_message()); | 222 OnUnpackExtensionFailed(unpacker.error_message()); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 SandboxedExtensionUnpacker::~SandboxedExtensionUnpacker() { | 227 SandboxedExtensionUnpacker::~SandboxedExtensionUnpacker() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 255 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 255 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 256 ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); | 256 ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void SandboxedExtensionUnpacker::StartProcessOnIOThread( | 259 void SandboxedExtensionUnpacker::StartProcessOnIOThread( |
| 260 const FilePath& temp_crx_path) { | 260 const FilePath& temp_crx_path) { |
| 261 UtilityProcessHost* host = new UtilityProcessHost(this, thread_identifier_); | 261 UtilityProcessHost* host = new UtilityProcessHost(this, thread_identifier_); |
| 262 // Grant the subprocess access to the entire subdir the extension file is | 262 // Grant the subprocess access to the entire subdir the extension file is |
| 263 // in, so that it can unpack to that dir. | 263 // in, so that it can unpack to that dir. |
| 264 host->set_exposed_dir(temp_crx_path.DirName()); | 264 host->set_exposed_dir(temp_crx_path.DirName()); |
| 265 host->Send(new ChromeUtilityMsg_UnpackExtension(temp_crx_path)); | 265 host->Send( |
| 266 new ChromeUtilityMsg_UnpackExtension( |
| 267 temp_crx_path, location_, creation_flags_)); |
| 266 } | 268 } |
| 267 | 269 |
| 268 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( | 270 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( |
| 269 const DictionaryValue& manifest) { | 271 const DictionaryValue& manifest) { |
| 270 // Skip check for unittests. | 272 // Skip check for unittests. |
| 271 if (thread_identifier_ != BrowserThread::ID_COUNT) | 273 if (thread_identifier_ != BrowserThread::ID_COUNT) |
| 272 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); | 274 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); |
| 273 got_response_ = true; | 275 got_response_ = true; |
| 274 | 276 |
| 275 scoped_ptr<DictionaryValue> final_manifest(RewriteManifestFile(manifest)); | 277 scoped_ptr<DictionaryValue> final_manifest(RewriteManifestFile(manifest)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 289 ReportFailure( | 291 ReportFailure( |
| 290 COULD_NOT_LOCALIZE_EXTENSION, | 292 COULD_NOT_LOCALIZE_EXTENSION, |
| 291 l10n_util::GetStringFUTF8( | 293 l10n_util::GetStringFUTF8( |
| 292 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, | 294 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, |
| 293 ASCIIToUTF16(error))); | 295 ASCIIToUTF16(error))); |
| 294 return; | 296 return; |
| 295 } | 297 } |
| 296 | 298 |
| 297 extension_ = Extension::Create( | 299 extension_ = Extension::Create( |
| 298 extension_root_, | 300 extension_root_, |
| 299 Extension::INTERNAL, | 301 location_, |
| 300 *final_manifest, | 302 *final_manifest, |
| 301 Extension::REQUIRE_KEY | creation_flags_, | 303 Extension::REQUIRE_KEY | creation_flags_, |
| 302 &error); | 304 &error); |
| 303 | 305 |
| 304 if (!extension_.get()) { | 306 if (!extension_.get()) { |
| 305 ReportFailure( | 307 ReportFailure( |
| 306 INVALID_MANIFEST, | 308 INVALID_MANIFEST, |
| 307 std::string("Manifest is invalid: ") + error); | 309 std::string("Manifest is invalid: ") + error); |
| 308 return; | 310 return; |
| 309 } | 311 } |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 ERROR_SAVING_CATALOG, | 711 ERROR_SAVING_CATALOG, |
| 710 l10n_util::GetStringFUTF8( | 712 l10n_util::GetStringFUTF8( |
| 711 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 713 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 712 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); | 714 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); |
| 713 return false; | 715 return false; |
| 714 } | 716 } |
| 715 } | 717 } |
| 716 | 718 |
| 717 return true; | 719 return true; |
| 718 } | 720 } |
| OLD | NEW |