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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h"
6 6 #include "base/message_loop.h"
7 #include <string> 7 #include "base/memory/ref_counted.h"
8
9 #include "base/compiler_specific.h"
10 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/extensions/extension_disabled_ui.h"
11 #include "chrome/browser/extensions/extension_install_ui.h" 11 #include "chrome/browser/extensions/extension_install_ui.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/infobars/infobar_tab_helper.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/global_error_service.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/global_error_service_factory.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/extensions/extension_file_util.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_resource.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
23 #include "content/public/browser/web_contents.h" 21 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
25 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
26 24
27 // ExtensionDisabledDialogDelegate -------------------------------------------- 25 // ExtensionDisabledDialogDelegate --------------------------------------------
28 26
29 class ExtensionDisabledDialogDelegate 27 class ExtensionDisabledDialogDelegate
30 : public ExtensionInstallUI::Delegate, 28 : public ExtensionInstallUI::Delegate,
31 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> { 29 public base::RefCountedThreadSafe<ExtensionDisabledDialogDelegate> {
32 public: 30 public:
33 ExtensionDisabledDialogDelegate(Profile* profile, 31 ExtensionDisabledDialogDelegate(Profile* profile,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 std::string histogram_name = user_initiated ? 71 std::string histogram_name = user_initiated ?
74 "Extensions.Permissions_ReEnableCancel" : 72 "Extensions.Permissions_ReEnableCancel" :
75 "Extensions.Permissions_ReEnableAbort"; 73 "Extensions.Permissions_ReEnableAbort";
76 ExtensionService::RecordPermissionMessagesHistogram( 74 ExtensionService::RecordPermissionMessagesHistogram(
77 extension_, histogram_name.c_str()); 75 extension_, histogram_name.c_str());
78 76
79 // Do nothing. The extension will remain disabled. 77 // Do nothing. The extension will remain disabled.
80 Release(); 78 Release();
81 } 79 }
82 80
81 // ExtensionDisabledGlobalError -----------------------------------------------
83 82
84 // ExtensionDisabledInfobarDelegate ------------------------------------------- 83 // TODO(yoz): create error at startup for disabled extensions.
85 84 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError(
86 class ExtensionDisabledInfobarDelegate : public ConfirmInfoBarDelegate,
87 public content::NotificationObserver {
88 public:
89 ExtensionDisabledInfobarDelegate(InfoBarTabHelper* infobar_helper,
90 ExtensionService* service,
91 const Extension* extension);
92
93 private:
94 virtual ~ExtensionDisabledInfobarDelegate();
95
96 // ConfirmInfoBarDelegate:
97 virtual string16 GetMessageText() const OVERRIDE;
98 virtual int GetButtons() const OVERRIDE;
99 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
100 virtual bool Accept() OVERRIDE;
101
102 // content::NotificationObserver:
103 virtual void Observe(int type,
104 const content::NotificationSource& source,
105 const content::NotificationDetails& details) OVERRIDE;
106
107 content::NotificationRegistrar registrar_;
108 ExtensionService* service_;
109 const Extension* extension_;
110 };
111
112 ExtensionDisabledInfobarDelegate::ExtensionDisabledInfobarDelegate(
113 InfoBarTabHelper* infobar_helper,
114 ExtensionService* service, 85 ExtensionService* service,
115 const Extension* extension) 86 const Extension* extension)
116 : ConfirmInfoBarDelegate(infobar_helper), 87 : service_(service),
117 service_(service),
118 extension_(extension) { 88 extension_(extension) {
119 // The user might re-enable the extension in other ways, so watch for that.
120 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 89 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
121 content::Source<Profile>(service->profile())); 90 content::Source<Profile>(service->profile()));
122 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 91 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
123 content::Source<Profile>(service->profile())); 92 content::Source<Profile>(service->profile()));
124 } 93 }
125 94
126 ExtensionDisabledInfobarDelegate::~ExtensionDisabledInfobarDelegate() { 95 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() {
127 } 96 }
128 97
129 string16 ExtensionDisabledInfobarDelegate::GetMessageText() const { 98 bool ExtensionDisabledGlobalError::HasBadge() {
99 return true;
100 }
101
102 bool ExtensionDisabledGlobalError::HasMenuItem() {
103 return true;
104 }
105
106 int ExtensionDisabledGlobalError::MenuItemCommandID() {
107 return IDC_EXTENSION_DISABLED_ERROR;
108 }
109
110 string16 ExtensionDisabledGlobalError::MenuItemLabel() {
111 // TODO(yoz): this is too awkward.
112 return l10n_util::GetStringUTF16(IDS_EXTENSION_DISABLED_ERROR_MENU_LABEL);
113 }
114
115 void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) {
116 MessageLoop::current()->PostTask(FROM_HERE,
117 base::Bind(&ExtensionDisabledGlobalError::ShowBubbleView,
118 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.
119 browser));
120 }
121
122 bool ExtensionDisabledGlobalError::HasBubbleView() {
123 return true;
124 }
125
126 string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() {
127 // TODO(yoz): Should this include the extension name?
128 return l10n_util::GetStringUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE);
129 }
130
131 string16 ExtensionDisabledGlobalError::GetBubbleViewMessage() {
130 return l10n_util::GetStringFUTF16(extension_->is_app() ? 132 return l10n_util::GetStringFUTF16(extension_->is_app() ?
131 IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL, 133 IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL,
132 UTF8ToUTF16(extension_->name())); 134 UTF8ToUTF16(extension_->name()));
133 } 135 }
134 136
135 int ExtensionDisabledInfobarDelegate::GetButtons() const { 137 string16 ExtensionDisabledGlobalError::GetBubbleViewAcceptButtonLabel() {
136 return BUTTON_OK; 138 return l10n_util::GetStringUTF16(
139 IDS_EXTENSION_DISABLED_ERROR_ENABLE_BUTTON);
137 } 140 }
138 141
139 string16 ExtensionDisabledInfobarDelegate::GetButtonLabel( 142 string16 ExtensionDisabledGlobalError::GetBubbleViewCancelButtonLabel() {
140 InfoBarButton button) const { 143 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL);
141 DCHECK_EQ(BUTTON_OK, button);
142 return l10n_util::GetStringUTF16(
143 IDS_EXTENSION_DISABLED_INFOBAR_ENABLE_BUTTON);
144 } 144 }
145 145
146 bool ExtensionDisabledInfobarDelegate::Accept() { 146 void ExtensionDisabledGlobalError::OnBubbleViewDidClose(Browser* browser) {
147 // This object manages its own lifetime. 147 }
148
149 void ExtensionDisabledGlobalError::BubbleViewAcceptButtonPressed(
150 Browser* browser) {
148 new ExtensionDisabledDialogDelegate(service_->profile(), service_, 151 new ExtensionDisabledDialogDelegate(service_->profile(), service_,
149 extension_); 152 extension_);
150 return true;
151 } 153 }
152 154
153 void ExtensionDisabledInfobarDelegate::Observe( 155 void ExtensionDisabledGlobalError::BubbleViewCancelButtonPressed(
156 Browser* browser) {
157 uninstall_dialog_.reset(
158 ExtensionUninstallDialog::Create(service_->profile(), this));
159 uninstall_dialog_->ConfirmUninstall(extension_);
160 }
161
162 void ExtensionDisabledGlobalError::ExtensionUninstallAccepted() {
163 service_->UninstallExtension(extension_->id(), false, NULL);
164 }
165
166 void ExtensionDisabledGlobalError::ExtensionUninstallCanceled() {
167 // Nothing happens, and the error is still there.
168 }
169
170 void ExtensionDisabledGlobalError::Observe(
154 int type, 171 int type,
155 const content::NotificationSource& source, 172 const content::NotificationSource& source,
156 const content::NotificationDetails& details) { 173 const content::NotificationDetails& details) {
157 // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us getting
158 // deleted.
159 const Extension* extension = NULL; 174 const Extension* extension = NULL;
175 // The error is invalidated if the extension has been reloaded
176 // or unloaded.
160 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { 177 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
161 extension = content::Details<const Extension>(details).ptr(); 178 extension = content::Details<const Extension>(details).ptr();
162 } else { 179 } else {
163 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); 180 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type);
164 UnloadedExtensionInfo* info = 181 UnloadedExtensionInfo* info =
165 content::Details<UnloadedExtensionInfo>(details).ptr(); 182 content::Details<UnloadedExtensionInfo>(details).ptr();
166 extension = info->extension; 183 extension = info->extension;
167 } 184 }
168 if (extension == extension_) 185 if (extension == extension_) {
169 RemoveSelf(); 186 GlobalErrorServiceFactory::GetForProfile(service_->profile())->
187 RemoveGlobalError(this);
188 delete this;
189 }
170 } 190 }
171 191
192 // Globals --------------------------------------------------------------------
172 193
173 // Globals -------------------------------------------------------------------- 194 namespace extensions {
174 195
175 void ShowExtensionDisabledUI(ExtensionService* service, 196 void ShowExtensionDisabledUI(ExtensionService* service,
176 Profile* profile, 197 Profile* profile,
177 const Extension* extension) { 198 const Extension* extension) {
178 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 199 GlobalErrorServiceFactory::GetForProfile(service->profile())->
179 if (!browser) 200 AddGlobalError(new ExtensionDisabledGlobalError(service, extension));
180 return;
181
182 TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper();
183 if (!tab_contents)
184 return;
185
186 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
187 infobar_helper->AddInfoBar(
188 new ExtensionDisabledInfobarDelegate(infobar_helper, service, extension));
189 } 201 }
190 202
191 void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, 203 void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile,
192 const Extension* extension) { 204 const Extension* extension) {
193 // This object manages its own lifetime. 205 // This object manages its own lifetime.
194 new ExtensionDisabledDialogDelegate(profile, service, extension); 206 new ExtensionDisabledDialogDelegate(profile, service, extension);
195 } 207 }
208
209 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698