| 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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/file_util_proxy.h" | 11 #include "base/file_util_proxy.h" |
| 12 #include "base/memory/scoped_handle.h" | 12 #include "base/memory/scoped_handle.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. | 17 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. |
| 18 #include "crypto/signature_verifier.h" | 18 #include "crypto/signature_verifier.h" |
| 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/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/extensions/extension_file_util.h" | 25 #include "chrome/common/extensions/extension_file_util.h" |
| 25 #include "chrome/common/extensions/extension_l10n_util.h" | 26 #include "chrome/common/extensions/extension_l10n_util.h" |
| 26 #include "chrome/common/extensions/extension_unpacker.h" | 27 #include "chrome/common/extensions/extension_unpacker.h" |
| 27 #include "content/browser/browser_thread.h" | 28 #include "content/browser/browser_thread.h" |
| 28 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 29 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 29 #include "content/common/json_value_serializer.h" | 30 #include "content/common/json_value_serializer.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 223 } |
| 223 | 224 |
| 224 SandboxedExtensionUnpacker::~SandboxedExtensionUnpacker() { | 225 SandboxedExtensionUnpacker::~SandboxedExtensionUnpacker() { |
| 225 base::FileUtilProxy::Delete( | 226 base::FileUtilProxy::Delete( |
| 226 BrowserThread::GetMessageLoopProxyForThread(thread_identifier_), | 227 BrowserThread::GetMessageLoopProxyForThread(thread_identifier_), |
| 227 temp_dir_.Take(), | 228 temp_dir_.Take(), |
| 228 true, | 229 true, |
| 229 NULL); | 230 NULL); |
| 230 } | 231 } |
| 231 | 232 |
| 233 bool SandboxedExtensionUnpacker::OnMessageReceived( |
| 234 const IPC::Message& message) { |
| 235 bool handled = true; |
| 236 IPC_BEGIN_MESSAGE_MAP(SandboxedExtensionUnpacker, message) |
| 237 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Succeeded, |
| 238 OnUnpackExtensionSucceeded) |
| 239 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Failed, |
| 240 OnUnpackExtensionFailed) |
| 241 IPC_MESSAGE_UNHANDLED(handled = false) |
| 242 IPC_END_MESSAGE_MAP_EX() |
| 243 return handled; |
| 244 } |
| 245 |
| 246 void SandboxedExtensionUnpacker::OnProcessCrashed(int exit_code) { |
| 247 // Don't report crashes if they happen after we got a response. |
| 248 if (got_response_) |
| 249 return; |
| 250 |
| 251 // Utility process crashed while trying to install. |
| 252 ReportFailure( |
| 253 UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL, |
| 254 l10n_util::GetStringFUTF8( |
| 255 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 256 ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); |
| 257 } |
| 258 |
| 232 void SandboxedExtensionUnpacker::StartProcessOnIOThread( | 259 void SandboxedExtensionUnpacker::StartProcessOnIOThread( |
| 233 const FilePath& temp_crx_path) { | 260 const FilePath& temp_crx_path) { |
| 234 UtilityProcessHost* host = new UtilityProcessHost(this, thread_identifier_); | 261 UtilityProcessHost* host = new UtilityProcessHost(this, thread_identifier_); |
| 235 host->StartExtensionUnpacker(temp_crx_path); | 262 // Grant the subprocess access to the entire subdir the extension file is |
| 263 // in, so that it can unpack to that dir. |
| 264 host->set_exposed_dir(temp_crx_path.DirName()); |
| 265 host->Send(new UtilityMsg_UnpackExtension(temp_crx_path)); |
| 236 } | 266 } |
| 237 | 267 |
| 238 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( | 268 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( |
| 239 const DictionaryValue& manifest) { | 269 const DictionaryValue& manifest) { |
| 240 // Skip check for unittests. | 270 // Skip check for unittests. |
| 241 if (thread_identifier_ != BrowserThread::ID_COUNT) | 271 if (thread_identifier_ != BrowserThread::ID_COUNT) |
| 242 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); | 272 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); |
| 243 got_response_ = true; | 273 got_response_ = true; |
| 244 | 274 |
| 245 scoped_ptr<DictionaryValue> final_manifest(RewriteManifestFile(manifest)); | 275 scoped_ptr<DictionaryValue> final_manifest(RewriteManifestFile(manifest)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 const std::string& error) { | 321 const std::string& error) { |
| 292 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); | 322 CHECK(BrowserThread::CurrentlyOn(thread_identifier_)); |
| 293 got_response_ = true; | 323 got_response_ = true; |
| 294 ReportFailure( | 324 ReportFailure( |
| 295 UNPACKER_CLIENT_FAILED, | 325 UNPACKER_CLIENT_FAILED, |
| 296 l10n_util::GetStringFUTF8( | 326 l10n_util::GetStringFUTF8( |
| 297 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, | 327 IDS_EXTENSION_PACKAGE_ERROR_MESSAGE, |
| 298 ASCIIToUTF16(error))); | 328 ASCIIToUTF16(error))); |
| 299 } | 329 } |
| 300 | 330 |
| 301 void SandboxedExtensionUnpacker::OnProcessCrashed(int exit_code) { | |
| 302 // Don't report crashes if they happen after we got a response. | |
| 303 if (got_response_) | |
| 304 return; | |
| 305 | |
| 306 // Utility process crashed while trying to install. | |
| 307 ReportFailure( | |
| 308 UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL, | |
| 309 l10n_util::GetStringFUTF8( | |
| 310 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | |
| 311 ASCIIToUTF16("UTILITY_PROCESS_CRASHED_WHILE_TRYING_TO_INSTALL"))); | |
| 312 } | |
| 313 | |
| 314 bool SandboxedExtensionUnpacker::ValidateSignature() { | 331 bool SandboxedExtensionUnpacker::ValidateSignature() { |
| 315 ScopedStdioHandle file(file_util::OpenFile(crx_path_, "rb")); | 332 ScopedStdioHandle file(file_util::OpenFile(crx_path_, "rb")); |
| 316 | 333 |
| 317 if (!file.get()) { | 334 if (!file.get()) { |
| 318 // Could not open crx file for reading. | 335 // Could not open crx file for reading. |
| 319 #if defined (OS_WIN) | 336 #if defined (OS_WIN) |
| 320 // On windows, get the error code. | 337 // On windows, get the error code. |
| 321 uint32 error_code = ::GetLastError(); | 338 uint32 error_code = ::GetLastError(); |
| 322 // TODO(skerner): Use this histogram to understand why so many | 339 // TODO(skerner): Use this histogram to understand why so many |
| 323 // windows users hit this error. crbug.com/69693 | 340 // windows users hit this error. crbug.com/69693 |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 ERROR_SAVING_CATALOG, | 709 ERROR_SAVING_CATALOG, |
| 693 l10n_util::GetStringFUTF8( | 710 l10n_util::GetStringFUTF8( |
| 694 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 711 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 695 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); | 712 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); |
| 696 return false; | 713 return false; |
| 697 } | 714 } |
| 698 } | 715 } |
| 699 | 716 |
| 700 return true; | 717 return true; |
| 701 } | 718 } |
| OLD | NEW |