| OLD | NEW |
| 1 // Copyright (c) 2010 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/extension_install_ui.h" | 11 #include "chrome/browser/extensions/extension_install_ui.h" |
| 12 #include "chrome/browser/extensions/extensions_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/tab_contents/infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/common/extensions/extension_file_util.h" | 16 #include "chrome/common/extensions/extension_file_util.h" |
| 17 #include "chrome/common/extensions/extension_resource.h" | 17 #include "chrome/common/extensions/extension_resource.h" |
| 18 #include "chrome/common/notification_registrar.h" | 18 #include "chrome/common/notification_registrar.h" |
| 19 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
| 20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 21 | 21 |
| 22 class ExtensionDisabledDialogDelegate | 22 class ExtensionDisabledDialogDelegate |
| 23 : public ExtensionInstallUI::Delegate, | 23 : public ExtensionInstallUI::Delegate, |
| 24 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { | 24 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { |
| 25 public: | 25 public: |
| 26 ExtensionDisabledDialogDelegate(Profile* profile, | 26 ExtensionDisabledDialogDelegate(Profile* profile, |
| 27 ExtensionsService* service, | 27 ExtensionService* service, |
| 28 const Extension* extension) | 28 const Extension* extension) |
| 29 : service_(service), extension_(extension) { | 29 : service_(service), extension_(extension) { |
| 30 AddRef(); // Balanced in Proceed or Abort. | 30 AddRef(); // Balanced in Proceed or Abort. |
| 31 | 31 |
| 32 install_ui_.reset(new ExtensionInstallUI(profile)); | 32 install_ui_.reset(new ExtensionInstallUI(profile)); |
| 33 install_ui_->ConfirmInstall(this, extension_); | 33 install_ui_->ConfirmInstall(this, extension_); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Overridden from ExtensionInstallUI::Delegate: | 36 // Overridden from ExtensionInstallUI::Delegate: |
| 37 virtual void InstallUIProceed() { | 37 virtual void InstallUIProceed() { |
| 38 service_->GrantPermissionsAndEnableExtension(extension_); | 38 service_->GrantPermissionsAndEnableExtension(extension_); |
| 39 Release(); | 39 Release(); |
| 40 } | 40 } |
| 41 virtual void InstallUIAbort() { | 41 virtual void InstallUIAbort() { |
| 42 // Do nothing. The extension will remain disabled. | 42 // Do nothing. The extension will remain disabled. |
| 43 Release(); | 43 Release(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; | 47 friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>; |
| 48 | 48 |
| 49 virtual ~ExtensionDisabledDialogDelegate() {} | 49 virtual ~ExtensionDisabledDialogDelegate() {} |
| 50 | 50 |
| 51 // The UI for showing the install dialog when enabling. | 51 // The UI for showing the install dialog when enabling. |
| 52 scoped_ptr<ExtensionInstallUI> install_ui_; | 52 scoped_ptr<ExtensionInstallUI> install_ui_; |
| 53 | 53 |
| 54 ExtensionsService* service_; | 54 ExtensionService* service_; |
| 55 const Extension* extension_; | 55 const Extension* extension_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 class ExtensionDisabledInfobarDelegate | 58 class ExtensionDisabledInfobarDelegate |
| 59 : public ConfirmInfoBarDelegate, | 59 : public ConfirmInfoBarDelegate, |
| 60 public NotificationObserver { | 60 public NotificationObserver { |
| 61 public: | 61 public: |
| 62 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, | 62 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, |
| 63 ExtensionsService* service, | 63 ExtensionService* service, |
| 64 const Extension* extension) | 64 const Extension* extension) |
| 65 : ConfirmInfoBarDelegate(tab_contents), | 65 : ConfirmInfoBarDelegate(tab_contents), |
| 66 tab_contents_(tab_contents), | 66 tab_contents_(tab_contents), |
| 67 service_(service), | 67 service_(service), |
| 68 extension_(extension) { | 68 extension_(extension) { |
| 69 // The user might re-enable the extension in other ways, so watch for that. | 69 // The user might re-enable the extension in other ways, so watch for that. |
| 70 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 70 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 71 Source<Profile>(service->profile())); | 71 Source<Profile>(service->profile())); |
| 72 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, | 72 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, |
| 73 Source<Profile>(service->profile())); | 73 Source<Profile>(service->profile())); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 break; | 114 break; |
| 115 } | 115 } |
| 116 default: | 116 default: |
| 117 NOTREACHED(); | 117 NOTREACHED(); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 NotificationRegistrar registrar_; | 122 NotificationRegistrar registrar_; |
| 123 TabContents* tab_contents_; | 123 TabContents* tab_contents_; |
| 124 ExtensionsService* service_; | 124 ExtensionService* service_; |
| 125 const Extension* extension_; | 125 const Extension* extension_; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 void ShowExtensionDisabledUI(ExtensionsService* service, Profile* profile, | 128 void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile, |
| 129 const Extension* extension) { | 129 const Extension* extension) { |
| 130 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 130 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 131 if (!browser) | 131 if (!browser) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 TabContents* tab_contents = browser->GetSelectedTabContents(); | 134 TabContents* tab_contents = browser->GetSelectedTabContents(); |
| 135 if (!tab_contents) | 135 if (!tab_contents) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( | 138 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( |
| 139 tab_contents, service, extension)); | 139 tab_contents, service, extension)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ShowExtensionDisabledDialog(ExtensionsService* service, Profile* profile, | 142 void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, |
| 143 const Extension* extension) { | 143 const Extension* extension) { |
| 144 // This object manages its own lifetime. | 144 // This object manages its own lifetime. |
| 145 new ExtensionDisabledDialogDelegate(profile, service, extension); | 145 new ExtensionDisabledDialogDelegate(profile, service, extension); |
| 146 } | 146 } |
| OLD | NEW |