OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_unpacker.h" | 5 #include "chrome/browser/extensions/sandboxed_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/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_util_proxy.h" | 13 #include "base/files/file_util_proxy.h" |
14 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
15 #include "base/memory/scoped_handle.h" | 15 #include "base/memory/scoped_handle.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
20 #include "base/strings/utf_string_conversions.h" // TODO(viettrungluu): delete me. | 20 #include "base/strings/utf_string_conversions.h" // TODO(viettrungluu): delete me. |
21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/chrome_utility_messages.h" | 25 #include "chrome/common/chrome_utility_messages.h" |
26 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_constants.h" | 27 // #include "chrome/common/extensions/extension_constants.h" |
Matt Perry
2013/07/19 22:29:11
remove
Yoyo Zhou
2013/07/19 22:50:03
Oops, done.
| |
28 #include "chrome/common/extensions/extension_file_util.h" | 28 #include "chrome/common/extensions/extension_file_util.h" |
29 #include "chrome/common/extensions/extension_l10n_util.h" | 29 #include "chrome/common/extensions/extension_l10n_util.h" |
30 #include "chrome/common/extensions/extension_manifest_constants.h" | 30 #include "chrome/common/extensions/extension_manifest_constants.h" |
31 #include "chrome/common/extensions/extension_manifest_constants.h" | 31 #include "chrome/common/extensions/extension_manifest_constants.h" |
32 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 32 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
33 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/utility_process_host.h" | 34 #include "content/public/browser/utility_process_host.h" |
35 #include "content/public/common/common_param_traits.h" | 35 #include "content/public/common/common_param_traits.h" |
36 #include "crypto/signature_verifier.h" | 36 #include "crypto/signature_verifier.h" |
37 #include "extensions/common/constants.h" | 37 #include "extensions/common/constants.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 << "remote drives or read-only. Installation can not complete!"; | 175 << "remote drives or read-only. Installation can not complete!"; |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 // Read the decoded images back from the file we saved them to. | 179 // Read the decoded images back from the file we saved them to. |
180 // |extension_path| is the path to the extension we unpacked that wrote the | 180 // |extension_path| is the path to the extension we unpacked that wrote the |
181 // data. Returns true on success. | 181 // data. Returns true on success. |
182 bool ReadImagesFromFile(const base::FilePath& extension_path, | 182 bool ReadImagesFromFile(const base::FilePath& extension_path, |
183 DecodedImages* images) { | 183 DecodedImages* images) { |
184 base::FilePath path = | 184 base::FilePath path = |
185 extension_path.AppendASCII(extension_filenames::kDecodedImagesFilename); | 185 extension_path.AppendASCII(kDecodedImagesFilename); |
186 std::string file_str; | 186 std::string file_str; |
187 if (!file_util::ReadFileToString(path, &file_str)) | 187 if (!file_util::ReadFileToString(path, &file_str)) |
188 return false; | 188 return false; |
189 | 189 |
190 IPC::Message pickle(file_str.data(), file_str.size()); | 190 IPC::Message pickle(file_str.data(), file_str.size()); |
191 PickleIterator iter(pickle); | 191 PickleIterator iter(pickle); |
192 return IPC::ReadParam(&pickle, &iter, images); | 192 return IPC::ReadParam(&pickle, &iter, images); |
193 } | 193 } |
194 | 194 |
195 // Read the decoded message catalogs back from the file we saved them to. | 195 // Read the decoded message catalogs back from the file we saved them to. |
196 // |extension_path| is the path to the extension we unpacked that wrote the | 196 // |extension_path| is the path to the extension we unpacked that wrote the |
197 // data. Returns true on success. | 197 // data. Returns true on success. |
198 bool ReadMessageCatalogsFromFile(const base::FilePath& extension_path, | 198 bool ReadMessageCatalogsFromFile(const base::FilePath& extension_path, |
199 base::DictionaryValue* catalogs) { | 199 base::DictionaryValue* catalogs) { |
200 base::FilePath path = extension_path.AppendASCII( | 200 base::FilePath path = extension_path.AppendASCII( |
201 extension_filenames::kDecodedMessageCatalogsFilename); | 201 kDecodedMessageCatalogsFilename); |
202 std::string file_str; | 202 std::string file_str; |
203 if (!file_util::ReadFileToString(path, &file_str)) | 203 if (!file_util::ReadFileToString(path, &file_str)) |
204 return false; | 204 return false; |
205 | 205 |
206 IPC::Message pickle(file_str.data(), file_str.size()); | 206 IPC::Message pickle(file_str.data(), file_str.size()); |
207 PickleIterator iter(pickle); | 207 PickleIterator iter(pickle); |
208 return IPC::ReadParam(&pickle, &iter, catalogs); | 208 return IPC::ReadParam(&pickle, &iter, catalogs); |
209 } | 209 } |
210 | 210 |
211 } // namespace | 211 } // namespace |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 257 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
258 | 258 |
259 unpack_start_time_ = base::TimeTicks::Now(); | 259 unpack_start_time_ = base::TimeTicks::Now(); |
260 | 260 |
261 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", | 261 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", |
262 crx_path_); | 262 crx_path_); |
263 if (!CreateTempDirectory()) | 263 if (!CreateTempDirectory()) |
264 return; // ReportFailure() already called. | 264 return; // ReportFailure() already called. |
265 | 265 |
266 // Initialize the path that will eventually contain the unpacked extension. | 266 // Initialize the path that will eventually contain the unpacked extension. |
267 extension_root_ = temp_dir_.path().AppendASCII( | 267 extension_root_ = temp_dir_.path().AppendASCII(kTempExtensionName); |
268 extension_filenames::kTempExtensionName); | |
269 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength", | 268 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength", |
270 extension_root_); | 269 extension_root_); |
271 | 270 |
272 // Extract the public key and validate the package. | 271 // Extract the public key and validate the package. |
273 if (!ValidateSignature()) | 272 if (!ValidateSignature()) |
274 return; // ValidateSignature() already reported the error. | 273 return; // ValidateSignature() already reported the error. |
275 | 274 |
276 // Copy the crx file into our working directory. | 275 // Copy the crx file into our working directory. |
277 base::FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); | 276 base::FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); |
278 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackTempCrxPathLength", | 277 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackTempCrxPathLength", |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 | 826 |
828 void SandboxedUnpacker::Cleanup() { | 827 void SandboxedUnpacker::Cleanup() { |
829 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 828 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
830 if (!temp_dir_.Delete()) { | 829 if (!temp_dir_.Delete()) { |
831 LOG(WARNING) << "Can not delete temp directory at " | 830 LOG(WARNING) << "Can not delete temp directory at " |
832 << temp_dir_.path().value(); | 831 << temp_dir_.path().value(); |
833 } | 832 } |
834 } | 833 } |
835 | 834 |
836 } // namespace extensions | 835 } // namespace extensions |
OLD | NEW |