OLD | NEW |
---|---|
1 // Copyright (c) 2010 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/crypto/signature_verifier.h" | 11 #include "base/crypto/signature_verifier.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/file_util_proxy.h" | 13 #include "base/file_util_proxy.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/metrics/histogram.h" | |
16 #include "base/path_service.h" | |
15 #include "base/scoped_handle.h" | 17 #include "base/scoped_handle.h" |
16 #include "base/task.h" | 18 #include "base/task.h" |
17 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. | 19 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. |
18 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 22 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
23 #include "chrome/common/chrome_paths.h" | |
21 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
24 #include "chrome/common/extensions/extension_file_util.h" | 27 #include "chrome/common/extensions/extension_file_util.h" |
25 #include "chrome/common/extensions/extension_l10n_util.h" | 28 #include "chrome/common/extensions/extension_l10n_util.h" |
26 #include "chrome/common/extensions/extension_unpacker.h" | 29 #include "chrome/common/extensions/extension_unpacker.h" |
27 #include "chrome/common/json_value_serializer.h" | 30 #include "chrome/common/json_value_serializer.h" |
28 #include "gfx/codec/png_codec.h" | 31 #include "gfx/codec/png_codec.h" |
29 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
30 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
31 | 34 |
35 namespace { | |
36 | |
37 const int kUnpackPathKeys[] = { | |
38 // First try unpacking in the temp directory inside the user's | |
39 // profile. | |
40 chrome::DIR_USER_DATA_TEMP, | |
41 | |
42 // Fall back to system temp. System temp is less than ideal, | |
Erik does not do reviews
2011/01/14 22:34:44
I don't think this is a good idea. Much of Chrome
Sam Kerner (Chrome)
2011/01/18 19:26:45
The fall-back to /tmp serves two purposes:
* Miti
| |
43 // because moving a directory across volumes is more likly to fail: | |
44 // crbug.com/37572 . However, if we can't access a better unpack | |
45 // directory, this is better than nothing. | |
46 base::DIR_TEMP | |
47 }; | |
48 | |
49 } | |
50 | |
32 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; | 51 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; |
33 | 52 |
34 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( | 53 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( |
35 const FilePath& crx_path, | 54 const FilePath& crx_path, |
36 const FilePath& temp_path, | |
37 ResourceDispatcherHost* rdh, | 55 ResourceDispatcherHost* rdh, |
38 SandboxedExtensionUnpackerClient* client) | 56 SandboxedExtensionUnpackerClient* client) |
39 : crx_path_(crx_path), temp_path_(temp_path), | 57 : crx_path_(crx_path), |
40 thread_identifier_(BrowserThread::ID_COUNT), | 58 thread_identifier_(BrowserThread::ID_COUNT), |
41 rdh_(rdh), client_(client), got_response_(false) { | 59 rdh_(rdh), client_(client), got_response_(false) { |
42 } | 60 } |
43 | 61 |
62 bool SandboxedExtensionUnpacker::CreateTempDirectory( | |
63 const int unpack_path_keys[], size_t unpack_path_keys_size) { | |
64 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); | |
65 | |
66 FilePath temp_path; | |
67 bool found_path = false; | |
68 for (size_t i = 0; !found_path && i < unpack_path_keys_size; ++i) { | |
69 if (!PathService::Get(unpack_path_keys[i], &temp_path)) { | |
70 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackerCantGetTemp", i, 10); | |
Erik does not do reviews
2011/01/14 22:34:44
From what I can tell, the only way this can fail i
Sam Kerner (Chrome)
2011/01/18 19:26:45
I had some other theories as to why PathService::G
| |
71 continue; | |
72 } | |
73 | |
74 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path)) { | |
75 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackerCantCreateTemp", i, 10); | |
Erik does not do reviews
2011/01/14 22:34:44
simply knowing that this is failing might not be t
| |
76 continue; | |
77 } | |
78 | |
79 found_path = true; | |
80 } | |
81 | |
82 if (!found_path) { | |
83 // TODO(skerner): This should have its own string. | |
84 // Using an existing string so that the change can be merged. | |
85 ReportFailure(l10n_util::GetStringFUTF8( | |
86 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | |
87 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); | |
88 return false; | |
89 } | |
90 | |
91 return true; | |
92 } | |
93 | |
44 void SandboxedExtensionUnpacker::Start() { | 94 void SandboxedExtensionUnpacker::Start() { |
45 // We assume that we are started on the thread that the client wants us to do | 95 // We assume that we are started on the thread that the client wants us to do |
46 // file IO on. | 96 // file IO on. |
47 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); | 97 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); |
48 | 98 |
49 // Create a temporary directory to work in. | 99 if (!CreateTempDirectory(kUnpackPathKeys, arraysize(kUnpackPathKeys))) |
50 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path_)) { | 100 // ReportError() already called. |
Erik does not do reviews
2011/01/14 22:34:44
typo: ReportFailure
Sam Kerner (Chrome)
2011/01/18 19:26:45
Done.
| |
51 // Could not create temporary directory. | |
52 ReportFailure(l10n_util::GetStringFUTF8( | |
53 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | |
54 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); | |
55 return; | 101 return; |
56 } | |
57 | 102 |
58 // Initialize the path that will eventually contain the unpacked extension. | 103 // Initialize the path that will eventually contain the unpacked extension. |
59 extension_root_ = temp_dir_.path().AppendASCII( | 104 extension_root_ = temp_dir_.path().AppendASCII( |
60 extension_filenames::kTempExtensionName); | 105 extension_filenames::kTempExtensionName); |
61 | 106 |
62 // Extract the public key and validate the package. | 107 // Extract the public key and validate the package. |
63 if (!ValidateSignature()) | 108 if (!ValidateSignature()) |
64 return; // ValidateSignature() already reported the error. | 109 return; // ValidateSignature() already reported the error. |
65 | 110 |
66 // Copy the crx file into our working directory. | 111 // Copy the crx file into our working directory. |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 // Error saving catalog. | 535 // Error saving catalog. |
491 ReportFailure(l10n_util::GetStringFUTF8( | 536 ReportFailure(l10n_util::GetStringFUTF8( |
492 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 537 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
493 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); | 538 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); |
494 return false; | 539 return false; |
495 } | 540 } |
496 } | 541 } |
497 | 542 |
498 return true; | 543 return true; |
499 } | 544 } |
OLD | NEW |