| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extension_disabled_infobar_delegate.h" | 5 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
| 9 #include "chrome/browser/extensions/extension_install_ui.h" | 9 #include "chrome/browser/extensions/extension_install_ui.h" |
| 10 #include "chrome/browser/extensions/extensions_service.h" | 10 #include "chrome/browser/extensions/extensions_service.h" |
| 11 #include "chrome/browser/tab_contents/infobar_delegate.h" | 11 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/common/extensions/extension_file_util.h" | 14 #include "chrome/common/extensions/extension_file_util.h" |
| 15 #include "chrome/common/extensions/extension_resource.h" | 15 #include "chrome/common/extensions/extension_resource.h" |
| 16 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
| 17 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 | 19 |
| 20 class ExtensionDisabledDialogDelegate | 20 class ExtensionDisabledDialogDelegate |
| 21 : public ExtensionInstallUI::Delegate, | 21 : public ExtensionInstallUI::Delegate, |
| 22 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { | 22 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { |
| 23 public: | 23 public: |
| 24 ExtensionDisabledDialogDelegate(Profile* profile, | 24 ExtensionDisabledDialogDelegate(Profile* profile, |
| 25 ExtensionsService* service, | 25 ExtensionsService* service, |
| 26 Extension* extension) | 26 Extension* extension) |
| 27 : profile_(profile), service_(service), extension_(extension) { | 27 : service_(service), extension_(extension) { |
| 28 AddRef(); // Balanced in Proceed or Abort. | 28 AddRef(); // Balanced in Proceed or Abort. |
| 29 | 29 |
| 30 // Do this now because we can't touch extension on the file loop. | 30 install_ui_.reset(new ExtensionInstallUI(profile)); |
| 31 install_icon_resource_ = | 31 install_ui_->ConfirmInstall(this, extension_); |
| 32 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); | |
| 33 | |
| 34 ChromeThread::PostTask( | |
| 35 ChromeThread::FILE, FROM_HERE, | |
| 36 NewRunnableMethod(this, &ExtensionDisabledDialogDelegate::Start)); | |
| 37 } | 32 } |
| 38 | 33 |
| 39 // ExtensionInstallUI::Delegate | 34 // ExtensionInstallUI::Delegate |
| 40 virtual void InstallUIProceed(bool create_app_shortcut) { | 35 virtual void InstallUIProceed(bool create_app_shortcut) { |
| 41 ExtensionPrefs* prefs = service_->extension_prefs(); | 36 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 42 prefs->SetShowInstallWarningOnEnable(extension_, false); | 37 prefs->SetShowInstallWarningOnEnable(extension_, false); |
| 43 service_->EnableExtension(extension_->id()); | 38 service_->EnableExtension(extension_->id()); |
| 44 Release(); | 39 Release(); |
| 45 } | 40 } |
| 46 virtual void InstallUIAbort() { | 41 virtual void InstallUIAbort() { |
| 47 // Do nothing. The extension will remain disabled. | 42 // Do nothing. The extension will remain disabled. |
| 48 Release(); | 43 Release(); |
| 49 } | 44 } |
| 50 | 45 |
| 51 private: | 46 private: |
| 52 friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; | 47 friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; |
| 53 | 48 |
| 54 virtual ~ExtensionDisabledDialogDelegate() {} | 49 virtual ~ExtensionDisabledDialogDelegate() {} |
| 55 | 50 |
| 56 void Start() { | 51 // The UI for showing the install dialog when enabling. |
| 57 // We start on the file thread so we can decode the install icon. | 52 scoped_ptr<ExtensionInstallUI> install_ui_; |
| 58 FilePath install_icon_path = install_icon_resource_.GetFilePath(); | |
| 59 Extension::DecodeIconFromPath( | |
| 60 install_icon_path, Extension::EXTENSION_ICON_LARGE, &install_icon_); | |
| 61 // Then we display the UI on the UI thread. | |
| 62 ChromeThread::PostTask( | |
| 63 ChromeThread::UI, FROM_HERE, | |
| 64 NewRunnableMethod( | |
| 65 this, &ExtensionDisabledDialogDelegate::ConfirmInstall)); | |
| 66 } | |
| 67 | 53 |
| 68 void ConfirmInstall() { | |
| 69 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 70 ExtensionInstallUI ui(profile_); | |
| 71 ui.ConfirmInstall(this, extension_, install_icon_.get()); | |
| 72 } | |
| 73 | |
| 74 Profile* profile_; | |
| 75 ExtensionsService* service_; | 54 ExtensionsService* service_; |
| 76 Extension* extension_; | 55 Extension* extension_; |
| 77 ExtensionResource install_icon_resource_; | |
| 78 scoped_ptr<SkBitmap> install_icon_; | |
| 79 }; | 56 }; |
| 80 | 57 |
| 81 class ExtensionDisabledInfobarDelegate | 58 class ExtensionDisabledInfobarDelegate |
| 82 : public ConfirmInfoBarDelegate, | 59 : public ConfirmInfoBarDelegate, |
| 83 public NotificationObserver { | 60 public NotificationObserver { |
| 84 public: | 61 public: |
| 85 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, | 62 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, |
| 86 ExtensionsService* service, | 63 ExtensionsService* service, |
| 87 Extension* extension) | 64 Extension* extension) |
| 88 : ConfirmInfoBarDelegate(tab_contents), | 65 : ConfirmInfoBarDelegate(tab_contents), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 135 |
| 159 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( | 136 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( |
| 160 tab_contents, service, extension)); | 137 tab_contents, service, extension)); |
| 161 } | 138 } |
| 162 | 139 |
| 163 void ShowExtensionDisabledDialog(ExtensionsService* service, Profile* profile, | 140 void ShowExtensionDisabledDialog(ExtensionsService* service, Profile* profile, |
| 164 Extension* extension) { | 141 Extension* extension) { |
| 165 // This object manages its own lifetime. | 142 // This object manages its own lifetime. |
| 166 new ExtensionDisabledDialogDelegate(profile, service, extension); | 143 new ExtensionDisabledDialogDelegate(profile, service, extension); |
| 167 } | 144 } |
| OLD | NEW |