| 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" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 << "remote drives or read-only. Installation can not complete!"; | 171 << "remote drives or read-only. Installation can not complete!"; |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace | 175 } // namespace |
| 176 | 176 |
| 177 namespace extensions { | 177 namespace extensions { |
| 178 | 178 |
| 179 SandboxedUnpacker::SandboxedUnpacker( | 179 SandboxedUnpacker::SandboxedUnpacker( |
| 180 const base::FilePath& crx_path, | 180 const base::FilePath& crx_path, |
| 181 bool run_out_of_process, | |
| 182 Manifest::Location location, | 181 Manifest::Location location, |
| 183 int creation_flags, | 182 int creation_flags, |
| 184 const base::FilePath& extensions_dir, | 183 const base::FilePath& extensions_dir, |
| 185 base::SequencedTaskRunner* unpacker_io_task_runner, | 184 base::SequencedTaskRunner* unpacker_io_task_runner, |
| 186 SandboxedUnpackerClient* client) | 185 SandboxedUnpackerClient* client) |
| 187 : crx_path_(crx_path), | 186 : crx_path_(crx_path), |
| 188 run_out_of_process_(run_out_of_process), | |
| 189 client_(client), | 187 client_(client), |
| 190 extensions_dir_(extensions_dir), | 188 extensions_dir_(extensions_dir), |
| 191 got_response_(false), | 189 got_response_(false), |
| 192 location_(location), | 190 location_(location), |
| 193 creation_flags_(creation_flags), | 191 creation_flags_(creation_flags), |
| 194 unpacker_io_task_runner_(unpacker_io_task_runner) { | 192 unpacker_io_task_runner_(unpacker_io_task_runner) { |
| 195 } | 193 } |
| 196 | 194 |
| 197 bool SandboxedUnpacker::CreateTempDirectory() { | 195 bool SandboxedUnpacker::CreateTempDirectory() { |
| 198 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 196 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 if (!file_util::CopyFile(crx_path_, temp_crx_path)) { | 247 if (!file_util::CopyFile(crx_path_, temp_crx_path)) { |
| 250 // Failed to copy extension file to temporary directory. | 248 // Failed to copy extension file to temporary directory. |
| 251 ReportFailure( | 249 ReportFailure( |
| 252 FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY, | 250 FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY, |
| 253 l10n_util::GetStringFUTF16( | 251 l10n_util::GetStringFUTF16( |
| 254 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 252 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
| 255 ASCIIToUTF16("FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY"))); | 253 ASCIIToUTF16("FAILED_TO_COPY_EXTENSION_FILE_TO_TEMP_DIRECTORY"))); |
| 256 return; | 254 return; |
| 257 } | 255 } |
| 258 | 256 |
| 259 // If we are supposed to use a subprocess, kick off the subprocess. | 257 // The utility process will have access to the directory passed to |
| 260 // | 258 // SandboxedUnpacker. That directory should not contain a symlink or NTFS |
| 261 // TODO(asargent) we shouldn't need to do this branch here - instead | 259 // reparse point. When the path is used, following the link/reparse point |
| 262 // UtilityProcessHost should handle it for us. (http://crbug.com/19192) | 260 // will cause file system access outside the sandbox path, and the sandbox |
| 263 bool use_utility_process = run_out_of_process_ && | 261 // will deny the operation. |
| 264 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); | 262 base::FilePath link_free_crx_path; |
| 265 if (use_utility_process) { | 263 if (!file_util::NormalizeFilePath(temp_crx_path, &link_free_crx_path)) { |
| 266 // The utility process will have access to the directory passed to | 264 LOG(ERROR) << "Could not get the normalized path of " |
| 267 // SandboxedUnpacker. That directory should not contain a symlink or NTFS | 265 << temp_crx_path.value(); |
| 268 // reparse point. When the path is used, following the link/reparse point | 266 ReportFailure( |
| 269 // will cause file system access outside the sandbox path, and the sandbox | 267 COULD_NOT_GET_SANDBOX_FRIENDLY_PATH, |
| 270 // will deny the operation. | 268 l10n_util::GetStringUTF16(IDS_EXTENSION_UNPACK_FAILED)); |
| 271 base::FilePath link_free_crx_path; | 269 return; |
| 272 if (!file_util::NormalizeFilePath(temp_crx_path, &link_free_crx_path)) { | 270 } |
| 273 LOG(ERROR) << "Could not get the normalized path of " | 271 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackLinkFreeCrxPathLength", |
| 274 << temp_crx_path.value(); | 272 link_free_crx_path); |
| 275 ReportFailure( | |
| 276 COULD_NOT_GET_SANDBOX_FRIENDLY_PATH, | |
| 277 l10n_util::GetStringUTF16(IDS_EXTENSION_UNPACK_FAILED)); | |
| 278 return; | |
| 279 } | |
| 280 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackLinkFreeCrxPathLength", | |
| 281 link_free_crx_path); | |
| 282 | 273 |
| 283 BrowserThread::PostTask( | 274 BrowserThread::PostTask( |
| 284 BrowserThread::IO, FROM_HERE, | 275 BrowserThread::IO, FROM_HERE, |
| 285 base::Bind( | 276 base::Bind( |
| 286 &SandboxedUnpacker::StartProcessOnIOThread, | 277 &SandboxedUnpacker::StartProcessOnIOThread, |
| 287 this, | 278 this, |
| 288 link_free_crx_path)); | 279 link_free_crx_path)); |
| 289 } else { | |
| 290 // Otherwise, unpack the extension in this process. | |
| 291 Unpacker unpacker(temp_crx_path, extension_id_, location_, creation_flags_); | |
| 292 if (unpacker.Run() && unpacker.DumpImagesToFile() && | |
| 293 unpacker.DumpMessageCatalogsToFile()) { | |
| 294 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); | |
| 295 } else { | |
| 296 OnUnpackExtensionFailed(unpacker.error_message()); | |
| 297 } | |
| 298 } | |
| 299 } | 280 } |
| 300 | 281 |
| 301 SandboxedUnpacker::~SandboxedUnpacker() { | 282 SandboxedUnpacker::~SandboxedUnpacker() { |
| 302 } | 283 } |
| 303 | 284 |
| 304 bool SandboxedUnpacker::OnMessageReceived(const IPC::Message& message) { | 285 bool SandboxedUnpacker::OnMessageReceived(const IPC::Message& message) { |
| 305 bool handled = true; | 286 bool handled = true; |
| 306 IPC_BEGIN_MESSAGE_MAP(SandboxedUnpacker, message) | 287 IPC_BEGIN_MESSAGE_MAP(SandboxedUnpacker, message) |
| 307 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnpackExtension_Succeeded, | 288 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnpackExtension_Succeeded, |
| 308 OnUnpackExtensionSucceeded) | 289 OnUnpackExtensionSucceeded) |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 773 |
| 793 void SandboxedUnpacker::Cleanup() { | 774 void SandboxedUnpacker::Cleanup() { |
| 794 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 775 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
| 795 if (!temp_dir_.Delete()) { | 776 if (!temp_dir_.Delete()) { |
| 796 LOG(WARNING) << "Can not delete temp directory at " | 777 LOG(WARNING) << "Can not delete temp directory at " |
| 797 << temp_dir_.path().value(); | 778 << temp_dir_.path().value(); |
| 798 } | 779 } |
| 799 } | 780 } |
| 800 | 781 |
| 801 } // namespace extensions | 782 } // namespace extensions |
| OLD | NEW |