Chromium Code Reviews| 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/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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "chrome/browser/extensions/app_host_installer.h" | |
| 12 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 13 #include "chrome/browser/extensions/extension_install_ui.h" | 14 #include "chrome/browser/extensions/extension_install_ui.h" |
| 14 #include "chrome/browser/extensions/extension_prefs.h" | 15 #include "chrome/browser/extensions/extension_prefs.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/permissions_updater.h" | 17 #include "chrome/browser/extensions/permissions_updater.h" |
| 17 #include "chrome/browser/extensions/requirements_checker.h" | 18 #include "chrome/browser/extensions/requirements_checker.h" |
| 18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/extensions/extension_file_util.h" | 20 #include "chrome/common/extensions/extension_file_util.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "grit/generated_resources.h" | |
| 21 #include "sync/api/string_ordinal.h" | 23 #include "sync/api/string_ordinal.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | |
| 22 | 25 |
| 23 using content::BrowserThread; | 26 using content::BrowserThread; |
| 24 using extensions::Extension; | 27 using extensions::Extension; |
| 25 | 28 |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| 28 const char kUnpackedExtensionsBlacklistedError[] = | 31 const char kUnpackedExtensionsBlacklistedError[] = |
| 29 "Loading of unpacked extensions is disabled by the administrator."; | 32 "Loading of unpacked extensions is disabled by the administrator."; |
| 30 | 33 |
| 31 // Manages an ExtensionInstallPrompt for a particular extension. | 34 // Manages an ExtensionInstallPrompt for a particular extension. |
| 32 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { | 35 class SimpleExtensionLoadPrompt : public ExtensionInstallPrompt::Delegate { |
| 33 public: | 36 public: |
| 34 SimpleExtensionLoadPrompt(Profile* profile, | 37 SimpleExtensionLoadPrompt(Profile* profile, |
| 35 base::WeakPtr<ExtensionService> extension_service, | 38 base::WeakPtr<ExtensionService> extension_service, |
| 36 const Extension* extension); | 39 const Extension* extension, |
| 40 const base::Closure& callback); | |
| 37 ~SimpleExtensionLoadPrompt(); | 41 ~SimpleExtensionLoadPrompt(); |
| 38 | 42 |
| 39 void ShowPrompt(); | 43 void ShowPrompt(); |
| 40 | 44 |
| 41 // ExtensionInstallUI::Delegate | 45 // ExtensionInstallUI::Delegate |
| 42 virtual void InstallUIProceed() OVERRIDE; | 46 virtual void InstallUIProceed() OVERRIDE; |
| 43 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 47 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; |
| 44 | 48 |
| 45 private: | 49 private: |
| 46 base::WeakPtr<ExtensionService> service_weak_; | 50 base::WeakPtr<ExtensionService> service_weak_; |
| 47 scoped_ptr<ExtensionInstallPrompt> install_ui_; | 51 scoped_ptr<ExtensionInstallPrompt> install_ui_; |
| 48 scoped_refptr<const Extension> extension_; | 52 scoped_refptr<const Extension> extension_; |
| 53 base::Closure callback_; | |
| 49 }; | 54 }; |
| 50 | 55 |
| 51 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( | 56 SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( |
| 52 Profile* profile, | 57 Profile* profile, |
| 53 base::WeakPtr<ExtensionService> extension_service, | 58 base::WeakPtr<ExtensionService> extension_service, |
| 54 const Extension* extension) | 59 const Extension* extension, |
| 60 const base::Closure& callback) | |
| 55 : service_weak_(extension_service), | 61 : service_weak_(extension_service), |
| 56 extension_(extension) { | 62 extension_(extension), |
| 63 callback_(callback) { | |
| 57 install_ui_.reset( | 64 install_ui_.reset( |
| 58 ExtensionInstallUI::CreateInstallPromptWithProfile(profile)); | 65 ExtensionInstallUI::CreateInstallPromptWithProfile(profile)); |
| 59 } | 66 } |
| 60 | 67 |
| 61 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { | 68 SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { |
| 62 } | 69 } |
| 63 | 70 |
| 64 void SimpleExtensionLoadPrompt::ShowPrompt() { | 71 void SimpleExtensionLoadPrompt::ShowPrompt() { |
| 65 install_ui_->ConfirmInstall( | 72 install_ui_->ConfirmInstall( |
| 66 this, extension_, ExtensionInstallPrompt::GetDefaultShowDialogCallback()); | 73 this, extension_, ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
| 67 } | 74 } |
| 68 | 75 |
| 69 void SimpleExtensionLoadPrompt::InstallUIProceed() { | 76 void SimpleExtensionLoadPrompt::InstallUIProceed() { |
| 70 if (service_weak_.get()) { | 77 if (service_weak_.get()) { |
| 71 extensions::PermissionsUpdater perms_updater(service_weak_->profile()); | 78 callback_.Run(); |
| 72 perms_updater.GrantActivePermissions(extension_, false); | |
| 73 service_weak_->OnExtensionInstalled( | |
| 74 extension_, | |
| 75 syncer::StringOrdinal(), | |
| 76 false /* no requirement errors */); | |
| 77 } | 79 } |
| 78 delete this; | 80 delete this; |
| 79 } | 81 } |
| 80 | 82 |
| 81 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { | 83 void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { |
| 82 delete this; | 84 delete this; |
| 83 } | 85 } |
| 84 | 86 |
| 85 } // namespace | 87 } // namespace |
| 86 | 88 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 return; | 250 return; |
| 249 const ExtensionSet* disabled_extensions = | 251 const ExtensionSet* disabled_extensions = |
| 250 service_weak_->disabled_extensions(); | 252 service_weak_->disabled_extensions(); |
| 251 if (service_weak_->show_extensions_prompts() && | 253 if (service_weak_->show_extensions_prompts() && |
| 252 prompt_for_plugins_ && | 254 prompt_for_plugins_ && |
| 253 !extension_->plugins().empty() && | 255 !extension_->plugins().empty() && |
| 254 !disabled_extensions->Contains(extension_->id())) { | 256 !disabled_extensions->Contains(extension_->id())) { |
| 255 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( | 257 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
| 256 service_weak_->profile(), | 258 service_weak_->profile(), |
| 257 service_weak_, | 259 service_weak_, |
| 258 extension_); | 260 extension_, |
| 261 base::Bind(&UnpackedInstaller::BeginInstall, this)); | |
| 259 prompt->ShowPrompt(); | 262 prompt->ShowPrompt(); |
| 260 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* | 263 return; // continues in SimpleExtensionLoadPrompt::InstallPrompt* |
| 261 } | 264 } |
| 262 | 265 |
| 266 BeginInstall(); | |
| 267 } | |
| 268 | |
| 269 void UnpackedInstaller::BeginInstall() { | |
| 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 271 app_host_installer::InstallAppHostIfNecessary( | |
|
Aaron Boodman
2012/10/25 04:41:34
Same thing here - this should be done via an abstr
huangs
2012/11/01 22:55:48
Per our discussion, moving installation to AppShor
| |
| 272 *extension_, | |
| 273 base::Bind(&UnpackedInstaller::OnAppHostInstallationComplete, this)); | |
| 274 } | |
| 275 | |
| 276 void UnpackedInstaller::OnAppHostInstallationComplete(bool success) { | |
| 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 278 if (!success) { | |
| 279 UnpackedInstaller::ReportExtensionLoadError( | |
| 280 l10n_util::GetStringUTF8(IDS_EXTENSION_APP_HOST_INSTALL_ERROR)); | |
| 281 return; | |
| 282 } | |
| 283 | |
| 284 CompleteInstall(); | |
| 285 } | |
| 286 | |
| 287 void UnpackedInstaller::CompleteInstall() { | |
| 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 263 PermissionsUpdater perms_updater(service_weak_->profile()); | 289 PermissionsUpdater perms_updater(service_weak_->profile()); |
| 264 perms_updater.GrantActivePermissions(extension_, false); | 290 perms_updater.GrantActivePermissions(extension_, false); |
| 265 service_weak_->OnExtensionInstalled(extension_, | 291 service_weak_->OnExtensionInstalled(extension_, |
| 266 syncer::StringOrdinal(), | 292 syncer::StringOrdinal(), |
| 267 false /* no requirement errors */); | 293 false /* no requirement errors */); |
| 268 } | 294 } |
| 269 | 295 |
| 270 } // namespace extensions | 296 } // namespace extensions |
| OLD | NEW |