Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: chrome/browser/extensions/extension_disabled_infobar_delegate.cc

Issue 6249010: Cleanup: de-inline a bunch of classes, rename and move "PluginInstaller" to "... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_disabled_infobar_delegate.cc
===================================================================
--- chrome/browser/extensions/extension_disabled_infobar_delegate.cc (revision 72158)
+++ chrome/browser/extensions/extension_disabled_infobar_delegate.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,35 +20,25 @@
#include "chrome/common/notification_source.h"
#include "grit/generated_resources.h"
+// ExtensionDisabledDialogDelegate --------------------------------------------
+
class ExtensionDisabledDialogDelegate
: public ExtensionInstallUI::Delegate,
public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> {
public:
ExtensionDisabledDialogDelegate(Profile* profile,
ExtensionService* service,
- const Extension* extension)
- : service_(service), extension_(extension) {
- AddRef(); // Balanced in Proceed or Abort.
+ const Extension* extension);
- install_ui_.reset(new ExtensionInstallUI(profile));
- install_ui_->ConfirmInstall(this, extension_);
- }
-
- // Overridden from ExtensionInstallUI::Delegate:
- virtual void InstallUIProceed() {
- service_->GrantPermissionsAndEnableExtension(extension_);
- Release();
- }
- virtual void InstallUIAbort() {
- // Do nothing. The extension will remain disabled.
- Release();
- }
-
private:
friend class base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate>;
- virtual ~ExtensionDisabledDialogDelegate() {}
+ virtual ~ExtensionDisabledDialogDelegate();
+ // ExtensionInstallUI::Delegate:
+ virtual void InstallUIProceed();
+ virtual void InstallUIAbort();
+
// The UI for showing the install dialog when enabling.
scoped_ptr<ExtensionInstallUI> install_ui_;
@@ -56,83 +46,129 @@
const Extension* extension_;
};
-class ExtensionDisabledInfobarDelegate
- : public ConfirmInfoBarDelegate,
- public NotificationObserver {
+ExtensionDisabledDialogDelegate::ExtensionDisabledDialogDelegate(
+ Profile* profile,
+ ExtensionService* service,
+ const Extension* extension)
+ : service_(service), extension_(extension) {
+ AddRef(); // Balanced in Proceed or Abort.
+
+ install_ui_.reset(new ExtensionInstallUI(profile));
+ install_ui_->ConfirmInstall(this, extension_);
+}
+
+ExtensionDisabledDialogDelegate::~ExtensionDisabledDialogDelegate() {
+}
+
+void ExtensionDisabledDialogDelegate::InstallUIProceed() {
+ service_->GrantPermissionsAndEnableExtension(extension_);
+ Release();
+}
+
+void ExtensionDisabledDialogDelegate::InstallUIAbort() {
+ // Do nothing. The extension will remain disabled.
+ Release();
+}
+
+
+// ExtensionDisabledInfobarDelegate -------------------------------------------
+
+class ExtensionDisabledInfobarDelegate : public ConfirmInfoBarDelegate,
+ public NotificationObserver {
public:
ExtensionDisabledInfobarDelegate(TabContents* tab_contents,
ExtensionService* service,
- const Extension* extension)
- : ConfirmInfoBarDelegate(tab_contents),
- tab_contents_(tab_contents),
- service_(service),
- extension_(extension) {
- // The user might re-enable the extension in other ways, so watch for that.
- registrar_.Add(this, NotificationType::EXTENSION_LOADED,
- Source<Profile>(service->profile()));
- registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
- Source<Profile>(service->profile()));
- }
- virtual ~ExtensionDisabledInfobarDelegate() {
- }
- virtual string16 GetMessageText() const {
- return l10n_util::GetStringFUTF16(extension_->is_app() ?
- IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL,
- UTF8ToUTF16(extension_->name()));
- }
- virtual SkBitmap* GetIcon() const {
- return NULL;
- }
- virtual int GetButtons() const {
- return BUTTON_OK;
- }
- virtual string16 GetButtonLabel(
- ConfirmInfoBarDelegate::InfoBarButton button) const {
- return l10n_util::GetStringUTF16(
- IDS_EXTENSION_DISABLED_INFOBAR_ENABLE_BUTTON);
- }
- virtual bool Accept() {
- // This object manages its own lifetime.
- new ExtensionDisabledDialogDelegate(tab_contents_->profile(),
- service_, extension_);
- return true;
- }
- virtual void InfoBarClosed() {
- delete this;
- }
+ const Extension* extension);
+ private:
+ virtual ~ExtensionDisabledInfobarDelegate();
+
+ // ConfirmInfoBarDelegate:
+ virtual void InfoBarClosed();
+ virtual string16 GetMessageText() const;
+ virtual int GetButtons() const;
+ virtual string16 GetButtonLabel(InfoBarButton button) const;
+ virtual bool Accept();
+
+ // NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
- const NotificationDetails& details) {
- // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us
- // getting deleted.
- const Extension* extension = NULL;
- switch (type.value) {
- case NotificationType::EXTENSION_LOADED:
- extension = Details<const Extension>(details).ptr();
- break;
- case NotificationType::EXTENSION_UNLOADED: {
- UnloadedExtensionInfo* info =
- Details<UnloadedExtensionInfo>(details).ptr();
- if (info->reason == UnloadedExtensionInfo::DISABLE)
- extension = info->extension;
- break;
- }
- default:
- NOTREACHED();
- return;
- }
- if (extension == extension_)
- tab_contents_->RemoveInfoBar(this);
- }
+ const NotificationDetails& details);
- private:
NotificationRegistrar registrar_;
TabContents* tab_contents_;
ExtensionService* service_;
const Extension* extension_;
};
+ExtensionDisabledInfobarDelegate::ExtensionDisabledInfobarDelegate(
+ TabContents* tab_contents,
+ ExtensionService* service,
+ const Extension* extension)
+ : ConfirmInfoBarDelegate(tab_contents),
+ tab_contents_(tab_contents),
+ service_(service),
+ extension_(extension) {
+ // The user might re-enable the extension in other ways, so watch for that.
+ registrar_.Add(this, NotificationType::EXTENSION_LOADED,
+ Source<Profile>(service->profile()));
+ registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
+ Source<Profile>(service->profile()));
+}
+
+ExtensionDisabledInfobarDelegate::~ExtensionDisabledInfobarDelegate() {
+}
+
+void ExtensionDisabledInfobarDelegate::InfoBarClosed() {
+ delete this;
+}
+
+string16 ExtensionDisabledInfobarDelegate::GetMessageText() const {
+ return l10n_util::GetStringFUTF16(extension_->is_app() ?
+ IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL,
+ UTF8ToUTF16(extension_->name()));
+}
+
+int ExtensionDisabledInfobarDelegate::GetButtons() const {
+ return BUTTON_OK;
+}
+
+string16 ExtensionDisabledInfobarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ DCHECK_EQ(BUTTON_OK, button);
+ return l10n_util::GetStringUTF16(
+ IDS_EXTENSION_DISABLED_INFOBAR_ENABLE_BUTTON);
+}
+
+bool ExtensionDisabledInfobarDelegate::Accept() {
+ // This object manages its own lifetime.
+ new ExtensionDisabledDialogDelegate(tab_contents_->profile(), service_,
+ extension_);
+ return true;
+}
+
+void ExtensionDisabledInfobarDelegate::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us getting
+ // deleted.
+ const Extension* extension;
+ if (type.value == NotificationType::EXTENSION_LOADED) {
+ extension = Details<const Extension>(details).ptr();
+ } else {
+ DCHECK_EQ(NotificationType::EXTENSION_UNLOADED, type.value);
+ UnloadedExtensionInfo* info = Details<UnloadedExtensionInfo>(details).ptr();
+ extension = (info->reason == UnloadedExtensionInfo::DISABLE) ?
+ info->extension : NULL;
+ }
+ if (extension == extension_)
+ tab_contents_->RemoveInfoBar(this);
+}
+
+
+// Globals --------------------------------------------------------------------
+
void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile,
const Extension* extension) {
Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
« no previous file with comments | « chrome/browser/extensions/extension_crash_recovery_browsertest.cc ('k') | chrome/browser/extensions/extension_dom_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698