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