| 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" | |
| 28 #include "chrome/common/extensions/extension_file_util.h" | 27 #include "chrome/common/extensions/extension_file_util.h" |
| 29 #include "chrome/common/extensions/extension_l10n_util.h" | 28 #include "chrome/common/extensions/extension_l10n_util.h" |
| 30 #include "chrome/common/extensions/extension_manifest_constants.h" | 29 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 31 #include "chrome/common/extensions/extension_manifest_constants.h" | 30 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 32 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 31 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
| 33 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/utility_process_host.h" | 33 #include "content/public/browser/utility_process_host.h" |
| 35 #include "content/public/common/common_param_traits.h" | 34 #include "content/public/common/common_param_traits.h" |
| 36 #include "crypto/signature_verifier.h" | 35 #include "crypto/signature_verifier.h" |
| 37 #include "extensions/common/constants.h" | 36 #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!"; | 174 << "remote drives or read-only. Installation can not complete!"; |
| 176 return false; | 175 return false; |
| 177 } | 176 } |
| 178 | 177 |
| 179 // Read the decoded images back from the file we saved them to. | 178 // 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 | 179 // |extension_path| is the path to the extension we unpacked that wrote the |
| 181 // data. Returns true on success. | 180 // data. Returns true on success. |
| 182 bool ReadImagesFromFile(const base::FilePath& extension_path, | 181 bool ReadImagesFromFile(const base::FilePath& extension_path, |
| 183 DecodedImages* images) { | 182 DecodedImages* images) { |
| 184 base::FilePath path = | 183 base::FilePath path = |
| 185 extension_path.AppendASCII(extension_filenames::kDecodedImagesFilename); | 184 extension_path.AppendASCII(kDecodedImagesFilename); |
| 186 std::string file_str; | 185 std::string file_str; |
| 187 if (!file_util::ReadFileToString(path, &file_str)) | 186 if (!file_util::ReadFileToString(path, &file_str)) |
| 188 return false; | 187 return false; |
| 189 | 188 |
| 190 IPC::Message pickle(file_str.data(), file_str.size()); | 189 IPC::Message pickle(file_str.data(), file_str.size()); |
| 191 PickleIterator iter(pickle); | 190 PickleIterator iter(pickle); |
| 192 return IPC::ReadParam(&pickle, &iter, images); | 191 return IPC::ReadParam(&pickle, &iter, images); |
| 193 } | 192 } |
| 194 | 193 |
| 195 // Read the decoded message catalogs back from the file we saved them to. | 194 // 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 | 195 // |extension_path| is the path to the extension we unpacked that wrote the |
| 197 // data. Returns true on success. | 196 // data. Returns true on success. |
| 198 bool ReadMessageCatalogsFromFile(const base::FilePath& extension_path, | 197 bool ReadMessageCatalogsFromFile(const base::FilePath& extension_path, |
| 199 base::DictionaryValue* catalogs) { | 198 base::DictionaryValue* catalogs) { |
| 200 base::FilePath path = extension_path.AppendASCII( | 199 base::FilePath path = extension_path.AppendASCII( |
| 201 extension_filenames::kDecodedMessageCatalogsFilename); | 200 kDecodedMessageCatalogsFilename); |
| 202 std::string file_str; | 201 std::string file_str; |
| 203 if (!file_util::ReadFileToString(path, &file_str)) | 202 if (!file_util::ReadFileToString(path, &file_str)) |
| 204 return false; | 203 return false; |
| 205 | 204 |
| 206 IPC::Message pickle(file_str.data(), file_str.size()); | 205 IPC::Message pickle(file_str.data(), file_str.size()); |
| 207 PickleIterator iter(pickle); | 206 PickleIterator iter(pickle); |
| 208 return IPC::ReadParam(&pickle, &iter, catalogs); | 207 return IPC::ReadParam(&pickle, &iter, catalogs); |
| 209 } | 208 } |
| 210 | 209 |
| 211 } // namespace | 210 } // namespace |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 256 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 258 | 257 |
| 259 unpack_start_time_ = base::TimeTicks::Now(); | 258 unpack_start_time_ = base::TimeTicks::Now(); |
| 260 | 259 |
| 261 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", | 260 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", |
| 262 crx_path_); | 261 crx_path_); |
| 263 if (!CreateTempDirectory()) | 262 if (!CreateTempDirectory()) |
| 264 return; // ReportFailure() already called. | 263 return; // ReportFailure() already called. |
| 265 | 264 |
| 266 // Initialize the path that will eventually contain the unpacked extension. | 265 // Initialize the path that will eventually contain the unpacked extension. |
| 267 extension_root_ = temp_dir_.path().AppendASCII( | 266 extension_root_ = temp_dir_.path().AppendASCII(kTempExtensionName); |
| 268 extension_filenames::kTempExtensionName); | |
| 269 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength", | 267 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength", |
| 270 extension_root_); | 268 extension_root_); |
| 271 | 269 |
| 272 // Extract the public key and validate the package. | 270 // Extract the public key and validate the package. |
| 273 if (!ValidateSignature()) | 271 if (!ValidateSignature()) |
| 274 return; // ValidateSignature() already reported the error. | 272 return; // ValidateSignature() already reported the error. |
| 275 | 273 |
| 276 // Copy the crx file into our working directory. | 274 // Copy the crx file into our working directory. |
| 277 base::FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); | 275 base::FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); |
| 278 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackTempCrxPathLength", | 276 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackTempCrxPathLength", |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 | 825 |
| 828 void SandboxedUnpacker::Cleanup() { | 826 void SandboxedUnpacker::Cleanup() { |
| 829 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 827 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 830 if (!temp_dir_.Delete()) { | 828 if (!temp_dir_.Delete()) { |
| 831 LOG(WARNING) << "Can not delete temp directory at " | 829 LOG(WARNING) << "Can not delete temp directory at " |
| 832 << temp_dir_.path().value(); | 830 << temp_dir_.path().value(); |
| 833 } | 831 } |
| 834 } | 832 } |
| 835 | 833 |
| 836 } // namespace extensions | 834 } // namespace extensions |
| OLD | NEW |