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

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

Issue 9718008: Replace extension disabled infobar with a global error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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_ui.cc
diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_ui.cc
similarity index 54%
rename from chrome/browser/extensions/extension_disabled_infobar_delegate.cc
rename to chrome/browser/extensions/extension_disabled_ui.cc
index a090e95ad7195041726e31bdc9c284c1bbdc42d5..e59a43e8d94cf62f51c2c3b9da0f638c1705800b 100644
--- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_disabled_ui.cc
@@ -1,26 +1,24 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
-#include "chrome/browser/extensions/extension_disabled_infobar_delegate.h"
-
-#include <string>
-
-#include "base/compiler_specific.h"
+#include "base/bind.h"
+#include "base/message_loop.h"
+#include "base/memory/ref_counted.h"
#include "base/utf_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/extensions/extension_disabled_ui.h"
#include "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/infobars/infobar_tab_helper.h"
-#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/global_error_service.h"
+#include "chrome/browser/ui/global_error_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/extensions/extension_file_util.h"
-#include "chrome/common/extensions/extension_resource.h"
-#include "content/public/browser/notification_registrar.h"
+#include "chrome/common/extensions/extension.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
-#include "content/public/browser/web_contents.h"
+#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -80,83 +78,102 @@ void ExtensionDisabledDialogDelegate::InstallUIAbort(bool user_initiated) {
Release();
}
+// ExtensionDisabledGlobalError -----------------------------------------------
-// ExtensionDisabledInfobarDelegate -------------------------------------------
-
-class ExtensionDisabledInfobarDelegate : public ConfirmInfoBarDelegate,
- public content::NotificationObserver {
- public:
- ExtensionDisabledInfobarDelegate(InfoBarTabHelper* infobar_helper,
- ExtensionService* service,
- const Extension* extension);
-
- private:
- virtual ~ExtensionDisabledInfobarDelegate();
-
- // ConfirmInfoBarDelegate:
- virtual string16 GetMessageText() const OVERRIDE;
- virtual int GetButtons() const OVERRIDE;
- virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
- virtual bool Accept() OVERRIDE;
-
- // content::NotificationObserver:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
- content::NotificationRegistrar registrar_;
- ExtensionService* service_;
- const Extension* extension_;
-};
-
-ExtensionDisabledInfobarDelegate::ExtensionDisabledInfobarDelegate(
- InfoBarTabHelper* infobar_helper,
+// TODO(yoz): create error at startup for disabled extensions.
+ExtensionDisabledGlobalError::ExtensionDisabledGlobalError(
ExtensionService* service,
const Extension* extension)
- : ConfirmInfoBarDelegate(infobar_helper),
- service_(service),
+ : service_(service),
extension_(extension) {
- // The user might re-enable the extension in other ways, so watch for that.
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
content::Source<Profile>(service->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(service->profile()));
}
-ExtensionDisabledInfobarDelegate::~ExtensionDisabledInfobarDelegate() {
+ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() {
+}
+
+bool ExtensionDisabledGlobalError::HasBadge() {
+ return true;
+}
+
+bool ExtensionDisabledGlobalError::HasMenuItem() {
+ return true;
+}
+
+int ExtensionDisabledGlobalError::MenuItemCommandID() {
+ return IDC_EXTENSION_DISABLED_ERROR;
}
-string16 ExtensionDisabledInfobarDelegate::GetMessageText() const {
+string16 ExtensionDisabledGlobalError::MenuItemLabel() {
+ // TODO(yoz): this is too awkward.
+ return l10n_util::GetStringUTF16(IDS_EXTENSION_DISABLED_ERROR_MENU_LABEL);
+}
+
+void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(&ExtensionDisabledGlobalError::ShowBubbleView,
+ base::Unretained(this),
sail 2012/03/16 22:21:43 can you use a weak ptr instead?
Yoyo Zhou 2012/03/20 07:04:08 It looks like I don't need to PostTask after all.
+ browser));
+}
+
+bool ExtensionDisabledGlobalError::HasBubbleView() {
+ return true;
+}
+
+string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() {
+ // TODO(yoz): Should this include the extension name?
+ return l10n_util::GetStringUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE);
+}
+
+string16 ExtensionDisabledGlobalError::GetBubbleViewMessage() {
return l10n_util::GetStringFUTF16(extension_->is_app() ?
- IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL,
+ IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL,
UTF8ToUTF16(extension_->name()));
}
-int ExtensionDisabledInfobarDelegate::GetButtons() const {
- return BUTTON_OK;
+string16 ExtensionDisabledGlobalError::GetBubbleViewAcceptButtonLabel() {
+ return l10n_util::GetStringUTF16(
+ IDS_EXTENSION_DISABLED_ERROR_ENABLE_BUTTON);
+}
+
+string16 ExtensionDisabledGlobalError::GetBubbleViewCancelButtonLabel() {
+ return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL);
}
-string16 ExtensionDisabledInfobarDelegate::GetButtonLabel(
- InfoBarButton button) const {
- DCHECK_EQ(BUTTON_OK, button);
- return l10n_util::GetStringUTF16(
- IDS_EXTENSION_DISABLED_INFOBAR_ENABLE_BUTTON);
+void ExtensionDisabledGlobalError::OnBubbleViewDidClose(Browser* browser) {
}
-bool ExtensionDisabledInfobarDelegate::Accept() {
- // This object manages its own lifetime.
+void ExtensionDisabledGlobalError::BubbleViewAcceptButtonPressed(
+ Browser* browser) {
new ExtensionDisabledDialogDelegate(service_->profile(), service_,
extension_);
- return true;
}
-void ExtensionDisabledInfobarDelegate::Observe(
+void ExtensionDisabledGlobalError::BubbleViewCancelButtonPressed(
+ Browser* browser) {
+ uninstall_dialog_.reset(
+ ExtensionUninstallDialog::Create(service_->profile(), this));
+ uninstall_dialog_->ConfirmUninstall(extension_);
+}
+
+void ExtensionDisabledGlobalError::ExtensionUninstallAccepted() {
+ service_->UninstallExtension(extension_->id(), false, NULL);
+}
+
+void ExtensionDisabledGlobalError::ExtensionUninstallCanceled() {
+ // Nothing happens, and the error is still there.
+}
+
+void ExtensionDisabledGlobalError::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us getting
- // deleted.
const Extension* extension = NULL;
+ // The error is invalidated if the extension has been reloaded
+ // or unloaded.
if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
extension = content::Details<const Extension>(details).ptr();
} else {
@@ -165,27 +182,22 @@ void ExtensionDisabledInfobarDelegate::Observe(
content::Details<UnloadedExtensionInfo>(details).ptr();
extension = info->extension;
}
- if (extension == extension_)
- RemoveSelf();
+ if (extension == extension_) {
+ GlobalErrorServiceFactory::GetForProfile(service_->profile())->
+ RemoveGlobalError(this);
+ delete this;
+ }
}
-
// Globals --------------------------------------------------------------------
+namespace extensions {
+
void ShowExtensionDisabledUI(ExtensionService* service,
Profile* profile,
const Extension* extension) {
- Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
- if (!browser)
- return;
-
- TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper();
- if (!tab_contents)
- return;
-
- InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
- infobar_helper->AddInfoBar(
- new ExtensionDisabledInfobarDelegate(infobar_helper, service, extension));
+ GlobalErrorServiceFactory::GetForProfile(service->profile())->
+ AddGlobalError(new ExtensionDisabledGlobalError(service, extension));
}
void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile,
@@ -193,3 +205,5 @@ void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile,
// This object manages its own lifetime.
new ExtensionDisabledDialogDelegate(profile, service, extension);
}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698