Chromium Code Reviews| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 const char kUnpackedExtensionsBlacklistedError[] = | 41 const char kUnpackedExtensionsBlacklistedError[] = |
| 42 "Loading of unpacked extensions is disabled by the administrator."; | 42 "Loading of unpacked extensions is disabled by the administrator."; |
| 43 | 43 |
| 44 const char kImportMinVersionNewer[] = | 44 const char kImportMinVersionNewer[] = |
| 45 "'import' version requested is newer than what is installed."; | 45 "'import' version requested is newer than what is installed."; |
| 46 const char kImportMissing[] = "'import' extension is not installed."; | 46 const char kImportMissing[] = "'import' extension is not installed."; |
| 47 const char kImportNotSharedModule[] = "'import' is not a shared module."; | 47 const char kImportNotSharedModule[] = "'import' is not a shared module."; |
| 48 | 48 |
| 49 // Manages an ExtensionInstallPrompt for a particular extension. | 49 // Manages an ExtensionInstallPrompt for a particular extension. |
| 50 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { | 50 class SimpleExtensionLoadPrompt { |
| 51 public: | 51 public: |
| 52 SimpleExtensionLoadPrompt(const Extension* extension, | 52 SimpleExtensionLoadPrompt(const Extension* extension, |
| 53 Profile* profile, | 53 Profile* profile, |
| 54 const base::Closure& callback); | 54 const base::Closure& callback); |
| 55 ~SimpleExtensionLoadPrompt() override; | |
| 56 | 55 |
| 57 void ShowPrompt(); | 56 void ShowPrompt(); |
| 58 | 57 |
| 59 // ExtensionInstallUI::Delegate | 58 private: |
| 60 void InstallUIProceed() override; | 59 ~SimpleExtensionLoadPrompt(); // Manages its own lifetime. |
| 61 void InstallUIAbort(bool user_initiated) override; | |
| 62 | 60 |
| 63 private: | 61 void OnInstallPromptDone(ExtensionInstallPrompt::Result result); |
| 62 | |
| 64 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 63 scoped_ptr<ExtensionInstallPrompt> install_ui_; |
| 65 scoped_refptr<const Extension> extension_; | 64 scoped_refptr<const Extension> extension_; |
| 66 base::Closure callback_; | 65 base::Closure callback_; |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(SimpleExtensionLoadPrompt); | |
|
Avi (use Gerrit)
2015/12/29 03:10:45
base/macros.h
Devlin
2016/01/04 22:59:23
Should be fine, since macros.h is included in unpa
| |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( | 70 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( |
| 70 const Extension* extension, | 71 const Extension* extension, |
| 71 Profile* profile, | 72 Profile* profile, |
| 72 const base::Closure& callback) | 73 const base::Closure& callback) |
| 73 : extension_(extension), callback_(callback) { | 74 : extension_(extension), callback_(callback) { |
| 74 scoped_ptr<extensions::ExtensionInstallUI> ui( | 75 scoped_ptr<extensions::ExtensionInstallUI> ui( |
| 75 extensions::CreateExtensionInstallUI(profile)); | 76 extensions::CreateExtensionInstallUI(profile)); |
| 76 install_ui_.reset(new ExtensionInstallPrompt( | 77 install_ui_.reset(new ExtensionInstallPrompt( |
| 77 profile, ui->GetDefaultInstallDialogParent())); | 78 profile, ui->GetDefaultInstallDialogParent())); |
| 78 } | 79 } |
| 79 | 80 |
| 80 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { | 81 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { |
| 81 } | 82 } |
| 82 | 83 |
| 83 void SimpleExtensionLoadPrompt::ShowPrompt() { | 84 void SimpleExtensionLoadPrompt::ShowPrompt() { |
| 85 // TODO(devlin): The AutoConfirm values should work from the | |
| 86 // ExtensionInstallPrompt code, so these should be unnecessary. | |
|
asargent_no_longer_on_chrome
2015/12/31 00:45:56
Do you mean we don't need to bother looking at the
Devlin
2016/01/04 22:59:23
Haven't tried it yet - tried to keep this small an
asargent_no_longer_on_chrome
2016/01/05 18:58:54
Ok
| |
| 84 switch (extensions::ScopedTestDialogAutoConfirm::GetAutoConfirmValue()) { | 87 switch (extensions::ScopedTestDialogAutoConfirm::GetAutoConfirmValue()) { |
| 85 case extensions::ScopedTestDialogAutoConfirm::NONE: | 88 case extensions::ScopedTestDialogAutoConfirm::NONE: |
| 89 // Unretained() is safe because this object manages its own lifetime. | |
| 86 install_ui_->ShowDialog( | 90 install_ui_->ShowDialog( |
| 87 this, extension_.get(), nullptr, | 91 base::Bind(&SimpleExtensionLoadPrompt::OnInstallPromptDone, |
| 92 base::Unretained(this)), | |
| 93 extension_.get(), nullptr, | |
| 88 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 94 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 89 break; | 95 break; |
| 90 case extensions::ScopedTestDialogAutoConfirm::ACCEPT: | 96 case extensions::ScopedTestDialogAutoConfirm::ACCEPT: |
| 91 InstallUIProceed(); | 97 OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED); |
| 92 break; | 98 break; |
| 93 case extensions::ScopedTestDialogAutoConfirm::CANCEL: | 99 case extensions::ScopedTestDialogAutoConfirm::CANCEL: |
| 94 InstallUIAbort(false); | 100 OnInstallPromptDone(ExtensionInstallPrompt::Result::ABORTED); |
| 95 break; | 101 break; |
| 96 } | 102 } |
| 97 } | 103 } |
| 98 | 104 |
| 99 void SimpleExtensionLoadPrompt::InstallUIProceed() { | 105 void SimpleExtensionLoadPrompt::OnInstallPromptDone( |
| 100 callback_.Run(); | 106 ExtensionInstallPrompt::Result result) { |
| 107 if (result == ExtensionInstallPrompt::Result::ACCEPTED) | |
| 108 callback_.Run(); | |
| 101 delete this; | 109 delete this; |
| 102 } | 110 } |
| 103 | 111 |
| 104 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { | |
| 105 delete this; | |
| 106 } | |
| 107 | |
| 108 } // namespace | 112 } // namespace |
| 109 | 113 |
| 110 namespace extensions { | 114 namespace extensions { |
| 111 | 115 |
| 112 // static | 116 // static |
| 113 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( | 117 scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create( |
| 114 ExtensionService* extension_service) { | 118 ExtensionService* extension_service) { |
| 115 DCHECK(extension_service); | 119 DCHECK(extension_service); |
| 116 return scoped_refptr<UnpackedInstaller>( | 120 return scoped_refptr<UnpackedInstaller>( |
| 117 new UnpackedInstaller(extension_service)); | 121 new UnpackedInstaller(extension_service)); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 service_weak_->OnExtensionInstalled( | 374 service_weak_->OnExtensionInstalled( |
| 371 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); | 375 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); |
| 372 | 376 |
| 373 if (!callback_.is_null()) { | 377 if (!callback_.is_null()) { |
| 374 callback_.Run(extension(), extension_path_, std::string()); | 378 callback_.Run(extension(), extension_path_, std::string()); |
| 375 callback_.Reset(); | 379 callback_.Reset(); |
| 376 } | 380 } |
| 377 } | 381 } |
| 378 | 382 |
| 379 } // namespace extensions | 383 } // namespace extensions |
| OLD | NEW |