| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/unpacked_installer.h" | 5 #include "chrome/browser/extensions/unpacked_installer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 123 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 124 } | 124 } |
| 125 | 125 |
| 126 UnpackedInstaller::~UnpackedInstaller() { | 126 UnpackedInstaller::~UnpackedInstaller() { |
| 127 } | 127 } |
| 128 | 128 |
| 129 void UnpackedInstaller::Load(const base::FilePath& path_in) { | 129 void UnpackedInstaller::Load(const base::FilePath& path_in) { |
| 130 DCHECK(extension_path_.empty()); | 130 DCHECK(extension_path_.empty()); |
| 131 extension_path_ = path_in; | 131 extension_path_ = path_in; |
| 132 BrowserThread::PostTask( | 132 BrowserThread::PostTask( |
| 133 BrowserThread::FILE, | 133 BrowserThread::FILE, FROM_HERE, |
| 134 FROM_HERE, | 134 base::BindOnce(&UnpackedInstaller::GetAbsolutePath, this)); |
| 135 base::Bind(&UnpackedInstaller::GetAbsolutePath, this)); | |
| 136 } | 135 } |
| 137 | 136 |
| 138 bool UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, | 137 bool UnpackedInstaller::LoadFromCommandLine(const base::FilePath& path_in, |
| 139 std::string* extension_id, | 138 std::string* extension_id, |
| 140 bool only_allow_apps) { | 139 bool only_allow_apps) { |
| 141 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 142 DCHECK(extension_path_.empty()); | 141 DCHECK(extension_path_.empty()); |
| 143 | 142 |
| 144 if (!service_weak_.get()) | 143 if (!service_weak_.get()) |
| 145 return false; | 144 return false; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 301 } |
| 303 | 302 |
| 304 void UnpackedInstaller::GetAbsolutePath() { | 303 void UnpackedInstaller::GetAbsolutePath() { |
| 305 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 304 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 306 | 305 |
| 307 extension_path_ = base::MakeAbsoluteFilePath(extension_path_); | 306 extension_path_ = base::MakeAbsoluteFilePath(extension_path_); |
| 308 | 307 |
| 309 std::string error; | 308 std::string error; |
| 310 if (!file_util::CheckForIllegalFilenames(extension_path_, &error)) { | 309 if (!file_util::CheckForIllegalFilenames(extension_path_, &error)) { |
| 311 BrowserThread::PostTask( | 310 BrowserThread::PostTask( |
| 312 BrowserThread::UI, | 311 BrowserThread::UI, FROM_HERE, |
| 313 FROM_HERE, | 312 base::BindOnce(&UnpackedInstaller::ReportExtensionLoadError, this, |
| 314 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); | 313 error)); |
| 315 return; | 314 return; |
| 316 } | 315 } |
| 317 BrowserThread::PostTask( | 316 BrowserThread::PostTask( |
| 318 BrowserThread::UI, FROM_HERE, | 317 BrowserThread::UI, FROM_HERE, |
| 319 base::Bind(&UnpackedInstaller::CheckExtensionFileAccess, this)); | 318 base::BindOnce(&UnpackedInstaller::CheckExtensionFileAccess, this)); |
| 320 } | 319 } |
| 321 | 320 |
| 322 void UnpackedInstaller::CheckExtensionFileAccess() { | 321 void UnpackedInstaller::CheckExtensionFileAccess() { |
| 323 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 322 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 324 if (!service_weak_.get()) | 323 if (!service_weak_.get()) |
| 325 return; | 324 return; |
| 326 | 325 |
| 327 if (!IsLoadingUnpackedAllowed()) { | 326 if (!IsLoadingUnpackedAllowed()) { |
| 328 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); | 327 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); |
| 329 return; | 328 return; |
| 330 } | 329 } |
| 331 | 330 |
| 332 BrowserThread::PostTask( | 331 BrowserThread::PostTask( |
| 333 BrowserThread::FILE, | 332 BrowserThread::FILE, FROM_HERE, |
| 334 FROM_HERE, | 333 base::BindOnce(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); |
| 335 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); | |
| 336 } | 334 } |
| 337 | 335 |
| 338 void UnpackedInstaller::LoadWithFileAccess(int flags) { | 336 void UnpackedInstaller::LoadWithFileAccess(int flags) { |
| 339 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 337 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 340 | 338 |
| 341 std::string error; | 339 std::string error; |
| 342 extension_ = file_util::LoadExtension(extension_path_, Manifest::UNPACKED, | 340 extension_ = file_util::LoadExtension(extension_path_, Manifest::UNPACKED, |
| 343 flags, &error); | 341 flags, &error); |
| 344 | 342 |
| 345 if (!extension() || | 343 if (!extension() || |
| 346 !extension_l10n_util::ValidateExtensionLocales( | 344 !extension_l10n_util::ValidateExtensionLocales( |
| 347 extension_path_, extension()->manifest()->value(), &error)) { | 345 extension_path_, extension()->manifest()->value(), &error)) { |
| 348 BrowserThread::PostTask( | 346 BrowserThread::PostTask( |
| 349 BrowserThread::UI, | 347 BrowserThread::UI, FROM_HERE, |
| 350 FROM_HERE, | 348 base::BindOnce(&UnpackedInstaller::ReportExtensionLoadError, this, |
| 351 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); | 349 error)); |
| 352 return; | 350 return; |
| 353 } | 351 } |
| 354 | 352 |
| 355 BrowserThread::PostTask( | 353 BrowserThread::PostTask( |
| 356 BrowserThread::UI, | 354 BrowserThread::UI, FROM_HERE, |
| 357 FROM_HERE, | 355 base::BindOnce(&UnpackedInstaller::ShowInstallPrompt, this)); |
| 358 base::Bind(&UnpackedInstaller::ShowInstallPrompt, this)); | |
| 359 } | 356 } |
| 360 | 357 |
| 361 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) { | 358 void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) { |
| 362 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 359 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 363 | 360 |
| 364 if (service_weak_.get()) { | 361 if (service_weak_.get()) { |
| 365 ExtensionErrorReporter::GetInstance()->ReportLoadError( | 362 ExtensionErrorReporter::GetInstance()->ReportLoadError( |
| 366 extension_path_, | 363 extension_path_, |
| 367 error, | 364 error, |
| 368 service_weak_->profile(), | 365 service_weak_->profile(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 390 service_weak_->OnExtensionInstalled( | 387 service_weak_->OnExtensionInstalled( |
| 391 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); | 388 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); |
| 392 | 389 |
| 393 if (!callback_.is_null()) { | 390 if (!callback_.is_null()) { |
| 394 callback_.Run(extension(), extension_path_, std::string()); | 391 callback_.Run(extension(), extension_path_, std::string()); |
| 395 callback_.Reset(); | 392 callback_.Reset(); |
| 396 } | 393 } |
| 397 } | 394 } |
| 398 | 395 |
| 399 } // namespace extensions | 396 } // namespace extensions |
| OLD | NEW |