| 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, | 63 ExtensionDisabledInfobarDelegate(TabContents* tab_contents, |
| 64 ExtensionService* service, | 64 ExtensionService* service, |
| 65 const Extension* extension) | 65 const Extension* extension) |
| 66 : ConfirmInfoBarDelegate(tab_contents), | 66 : ConfirmInfoBarDelegate(tab_contents), |
| 67 tab_contents_(tab_contents), | 67 tab_contents_(tab_contents), |
| 68 service_(service), | 68 service_(service), |
| 69 extension_(extension) { | 69 extension_(extension) { |
| 70 // The user might re-enable the extension in other ways, so watch for that. | 70 // The user might re-enable the extension in other ways, so watch for that. |
| 71 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 71 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 72 Source<Profile>(service->profile())); | 72 Source<Profile>(service->profile())); |
| 73 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, | 73 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 74 Source<Profile>(service->profile())); | 74 Source<Profile>(service->profile())); |
| 75 } | 75 } |
| 76 virtual ~ExtensionDisabledInfobarDelegate() { | 76 virtual ~ExtensionDisabledInfobarDelegate() { |
| 77 } | 77 } |
| 78 virtual string16 GetMessageText() const { | 78 virtual string16 GetMessageText() const { |
| 79 return l10n_util::GetStringFUTF16(extension_->is_app() ? | 79 return l10n_util::GetStringFUTF16(extension_->is_app() ? |
| 80 IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL, | 80 IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL, |
| 81 UTF8ToUTF16(extension_->name())); | 81 UTF8ToUTF16(extension_->name())); |
| 82 } | 82 } |
| 83 virtual SkBitmap* GetIcon() const { | 83 virtual SkBitmap* GetIcon() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 99 } | 99 } |
| 100 virtual void InfoBarClosed() { | 100 virtual void InfoBarClosed() { |
| 101 delete this; | 101 delete this; |
| 102 } | 102 } |
| 103 | 103 |
| 104 virtual void Observe(NotificationType type, | 104 virtual void Observe(NotificationType type, |
| 105 const NotificationSource& source, | 105 const NotificationSource& source, |
| 106 const NotificationDetails& details) { | 106 const NotificationDetails& details) { |
| 107 // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us | 107 // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us |
| 108 // getting deleted. | 108 // getting deleted. |
| 109 const Extension* extension = NULL; |
| 109 switch (type.value) { | 110 switch (type.value) { |
| 110 case NotificationType::EXTENSION_LOADED: | 111 case NotificationType::EXTENSION_LOADED: |
| 111 case NotificationType::EXTENSION_UNLOADED_DISABLED: { | 112 extension = Details<const Extension>(details).ptr(); |
| 112 const Extension* extension = Details<const Extension>(details).ptr(); | 113 break; |
| 113 if (extension == extension_) | 114 case NotificationType::EXTENSION_UNLOADED: { |
| 114 tab_contents_->RemoveInfoBar(this); | 115 UnloadedExtensionInfo* info = |
| 116 Details<UnloadedExtensionInfo>(details).ptr(); |
| 117 if (info->reason == UnloadedExtensionInfo::DISABLE) |
| 118 extension = info->extension; |
| 115 break; | 119 break; |
| 116 } | 120 } |
| 117 default: | 121 default: |
| 118 NOTREACHED(); | 122 NOTREACHED(); |
| 123 return; |
| 119 } | 124 } |
| 125 if (extension == extension_) |
| 126 tab_contents_->RemoveInfoBar(this); |
| 120 } | 127 } |
| 121 | 128 |
| 122 private: | 129 private: |
| 123 NotificationRegistrar registrar_; | 130 NotificationRegistrar registrar_; |
| 124 TabContents* tab_contents_; | 131 TabContents* tab_contents_; |
| 125 ExtensionService* service_; | 132 ExtensionService* service_; |
| 126 const Extension* extension_; | 133 const Extension* extension_; |
| 127 }; | 134 }; |
| 128 | 135 |
| 129 void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile, | 136 void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile, |
| 130 const Extension* extension) { | 137 const Extension* extension) { |
| 131 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 138 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 132 if (!browser) | 139 if (!browser) |
| 133 return; | 140 return; |
| 134 | 141 |
| 135 TabContents* tab_contents = browser->GetSelectedTabContents(); | 142 TabContents* tab_contents = browser->GetSelectedTabContents(); |
| 136 if (!tab_contents) | 143 if (!tab_contents) |
| 137 return; | 144 return; |
| 138 | 145 |
| 139 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( | 146 tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( |
| 140 tab_contents, service, extension)); | 147 tab_contents, service, extension)); |
| 141 } | 148 } |
| 142 | 149 |
| 143 void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, | 150 void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, |
| 144 const Extension* extension) { | 151 const Extension* extension) { |
| 145 // This object manages its own lifetime. | 152 // This object manages its own lifetime. |
| 146 new ExtensionDisabledDialogDelegate(profile, service, extension); | 153 new ExtensionDisabledDialogDelegate(profile, service, extension); |
| 147 } | 154 } |
| OLD | NEW |