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

Side by Side Diff: chrome/browser/extensions/extension_disabled_ui.cc

Issue 15745022: Add custom icon support to GlobalError. Show extension icon in permissions increase bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no icon ok Created 7 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_error_ui_default.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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_ui.h" 5 #include "chrome/browser/extensions/extension_disabled_ui.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/extensions/extension_install_prompt.h" 17 #include "chrome/browser/extensions/extension_install_prompt.h"
18 #include "chrome/browser/extensions/extension_install_ui.h" 18 #include "chrome/browser/extensions/extension_install_ui.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 20 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
21 #include "chrome/browser/extensions/image_loader.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/global_error/global_error.h" 24 #include "chrome/browser/ui/global_error/global_error.h"
24 #include "chrome/browser/ui/global_error/global_error_service.h" 25 #include "chrome/browser/ui/global_error/global_error_service.h"
25 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 26 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/extensions/extension.h" 29 #include "chrome/common/extensions/extension.h"
30 #include "chrome/common/extensions/extension_icon_set.h"
31 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
29 #include "chrome/common/extensions/permissions/permission_set.h" 32 #include "chrome/common/extensions/permissions/permission_set.h"
30 #include "content/public/browser/notification_details.h" 33 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_observer.h" 34 #include "content/public/browser/notification_observer.h"
32 #include "content/public/browser/notification_registrar.h" 35 #include "content/public/browser/notification_registrar.h"
33 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
34 #include "grit/chromium_strings.h" 37 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
36 #include "grit/theme_resources.h" 39 #include "grit/theme_resources.h"
37 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/gfx/image/image.h"
42 #include "ui/gfx/image/image_skia_operations.h"
43 #include "ui/gfx/size.h"
38 44
39 using extensions::Extension; 45 using extensions::Extension;
40 46
41 namespace { 47 namespace {
42 48
49 static int kIconSize = extension_misc::EXTENSION_ICON_SMALL;
Matt Perry 2013/05/28 22:50:40 nit: const int
Yoyo Zhou 2013/05/28 22:56:44 Oops, done.
50
43 static base::LazyInstance< 51 static base::LazyInstance<
44 std::bitset<IDC_EXTENSION_DISABLED_LAST - 52 std::bitset<IDC_EXTENSION_DISABLED_LAST -
45 IDC_EXTENSION_DISABLED_FIRST + 1> > 53 IDC_EXTENSION_DISABLED_FIRST + 1> >
46 menu_command_ids = LAZY_INSTANCE_INITIALIZER; 54 menu_command_ids = LAZY_INSTANCE_INITIALIZER;
47 55
48 // Get an available menu ID. 56 // Get an available menu ID.
49 int GetMenuCommandID() { 57 int GetMenuCommandID() {
50 int id; 58 int id;
51 for (id = IDC_EXTENSION_DISABLED_FIRST; 59 for (id = IDC_EXTENSION_DISABLED_FIRST;
52 id <= IDC_EXTENSION_DISABLED_LAST; ++id) { 60 id <= IDC_EXTENSION_DISABLED_LAST; ++id) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 Release(); 132 Release();
125 } 133 }
126 134
127 // ExtensionDisabledGlobalError ----------------------------------------------- 135 // ExtensionDisabledGlobalError -----------------------------------------------
128 136
129 class ExtensionDisabledGlobalError : public GlobalError, 137 class ExtensionDisabledGlobalError : public GlobalError,
130 public content::NotificationObserver, 138 public content::NotificationObserver,
131 public ExtensionUninstallDialog::Delegate { 139 public ExtensionUninstallDialog::Delegate {
132 public: 140 public:
133 ExtensionDisabledGlobalError(ExtensionService* service, 141 ExtensionDisabledGlobalError(ExtensionService* service,
134 const Extension* extension); 142 const Extension* extension,
143 const gfx::Image& icon);
135 virtual ~ExtensionDisabledGlobalError(); 144 virtual ~ExtensionDisabledGlobalError();
136 145
137 // GlobalError implementation. 146 // GlobalError implementation.
138 virtual Severity GetSeverity() OVERRIDE; 147 virtual Severity GetSeverity() OVERRIDE;
139 virtual bool HasMenuItem() OVERRIDE; 148 virtual bool HasMenuItem() OVERRIDE;
140 virtual int MenuItemCommandID() OVERRIDE; 149 virtual int MenuItemCommandID() OVERRIDE;
141 virtual string16 MenuItemLabel() OVERRIDE; 150 virtual string16 MenuItemLabel() OVERRIDE;
142 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; 151 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE;
143 virtual bool HasBubbleView() OVERRIDE; 152 virtual bool HasBubbleView() OVERRIDE;
153 virtual gfx::Image GetBubbleViewIcon() OVERRIDE;
144 virtual string16 GetBubbleViewTitle() OVERRIDE; 154 virtual string16 GetBubbleViewTitle() OVERRIDE;
145 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE; 155 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE;
146 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; 156 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE;
147 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; 157 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE;
148 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; 158 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE;
149 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; 159 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE;
150 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; 160 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE;
151 161
152 // ExtensionUninstallDialog::Delegate implementation. 162 // ExtensionUninstallDialog::Delegate implementation.
153 virtual void ExtensionUninstallAccepted() OVERRIDE; 163 virtual void ExtensionUninstallAccepted() OVERRIDE;
154 virtual void ExtensionUninstallCanceled() OVERRIDE; 164 virtual void ExtensionUninstallCanceled() OVERRIDE;
155 165
156 // content::NotificationObserver implementation. 166 // content::NotificationObserver implementation.
157 virtual void Observe(int type, 167 virtual void Observe(int type,
158 const content::NotificationSource& source, 168 const content::NotificationSource& source,
159 const content::NotificationDetails& details) OVERRIDE; 169 const content::NotificationDetails& details) OVERRIDE;
160 170
161 private: 171 private:
162 ExtensionService* service_; 172 ExtensionService* service_;
163 const Extension* extension_; 173 const Extension* extension_;
174 gfx::Image icon_;
164 175
165 // How the user responded to the error; used for metrics. 176 // How the user responded to the error; used for metrics.
166 enum UserResponse { 177 enum UserResponse {
167 IGNORED, 178 IGNORED,
168 REENABLE, 179 REENABLE,
169 UNINSTALL, 180 UNINSTALL,
170 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY 181 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY
171 }; 182 };
172 UserResponse user_response_; 183 UserResponse user_response_;
173 184
174 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_; 185 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_;
175 186
176 // Menu command ID assigned for this extension's error. 187 // Menu command ID assigned for this extension's error.
177 int menu_command_id_; 188 int menu_command_id_;
178 189
179 content::NotificationRegistrar registrar_; 190 content::NotificationRegistrar registrar_;
180 }; 191 };
181 192
182 // TODO(yoz): create error at startup for disabled extensions. 193 // TODO(yoz): create error at startup for disabled extensions.
183 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( 194 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError(
184 ExtensionService* service, 195 ExtensionService* service,
185 const Extension* extension) 196 const Extension* extension,
197 const gfx::Image& icon)
186 : service_(service), 198 : service_(service),
187 extension_(extension), 199 extension_(extension),
200 icon_(icon),
188 user_response_(IGNORED), 201 user_response_(IGNORED),
189 menu_command_id_(GetMenuCommandID()) { 202 menu_command_id_(GetMenuCommandID()) {
203 if (icon_.IsEmpty()) {
204 icon_ = gfx::Image(
205 gfx::ImageSkiaOperations::CreateResizedImage(
206 extension_->is_app() ?
207 extensions::IconsInfo::GetDefaultAppIcon() :
208 extensions::IconsInfo::GetDefaultExtensionIcon(),
209 skia::ImageOperations::RESIZE_BEST,
210 gfx::Size(kIconSize, kIconSize)));
211 }
190 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 212 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
191 content::Source<Profile>(service->profile())); 213 content::Source<Profile>(service->profile()));
192 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 214 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
193 content::Source<Profile>(service->profile())); 215 content::Source<Profile>(service->profile()));
194 } 216 }
195 217
196 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { 218 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() {
197 ReleaseMenuCommandID(menu_command_id_); 219 ReleaseMenuCommandID(menu_command_id_);
198 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse", 220 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse",
199 user_response_, 221 user_response_,
(...skipping 18 matching lines...) Expand all
218 } 240 }
219 241
220 void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) { 242 void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) {
221 ShowBubbleView(browser); 243 ShowBubbleView(browser);
222 } 244 }
223 245
224 bool ExtensionDisabledGlobalError::HasBubbleView() { 246 bool ExtensionDisabledGlobalError::HasBubbleView() {
225 return true; 247 return true;
226 } 248 }
227 249
250 gfx::Image ExtensionDisabledGlobalError::GetBubbleViewIcon() {
251 return icon_;
252 }
253
228 string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() { 254 string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() {
229 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, 255 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE,
230 UTF8ToUTF16(extension_->name())); 256 UTF8ToUTF16(extension_->name()));
231 } 257 }
232 258
233 std::vector<string16> ExtensionDisabledGlobalError::GetBubbleViewMessages() { 259 std::vector<string16> ExtensionDisabledGlobalError::GetBubbleViewMessages() {
234 std::vector<string16> messages; 260 std::vector<string16> messages;
235 messages.push_back(l10n_util::GetStringFUTF16( 261 messages.push_back(l10n_util::GetStringFUTF16(
236 extension_->is_app() ? 262 extension_->is_app() ?
237 IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL, 263 IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) 338 else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED)
313 user_response_ = UNINSTALL; 339 user_response_ = UNINSTALL;
314 delete this; 340 delete this;
315 } 341 }
316 } 342 }
317 343
318 // Globals -------------------------------------------------------------------- 344 // Globals --------------------------------------------------------------------
319 345
320 namespace extensions { 346 namespace extensions {
321 347
348 void AddExtensionDisabledErrorWithIcon(base::WeakPtr<ExtensionService> service,
349 const std::string& extension_id,
350 const gfx::Image& icon) {
351 if (!service.get())
352 return;
353 const Extension* extension = service->GetInstalledExtension(extension_id);
354 if (extension) {
355 GlobalErrorServiceFactory::GetForProfile(service->profile())->
356 AddGlobalError(new ExtensionDisabledGlobalError(
357 service, extension, icon));
358 }
359 }
360
322 void AddExtensionDisabledError(ExtensionService* service, 361 void AddExtensionDisabledError(ExtensionService* service,
323 const Extension* extension) { 362 const Extension* extension) {
324 GlobalErrorServiceFactory::GetForProfile(service->profile())-> 363 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource(
325 AddGlobalError(new ExtensionDisabledGlobalError(service, extension)); 364 extension, kIconSize, ExtensionIconSet::MATCH_BIGGER);
365 gfx::Size size(kIconSize, kIconSize);
366 ImageLoader::Get(service->profile())->LoadImageAsync(
367 extension, image, size,
368 base::Bind(&AddExtensionDisabledErrorWithIcon,
369 service->AsWeakPtr(), extension->id()));
326 } 370 }
327 371
328 void ShowExtensionDisabledDialog(ExtensionService* service, 372 void ShowExtensionDisabledDialog(ExtensionService* service,
329 content::WebContents* web_contents, 373 content::WebContents* web_contents,
330 const Extension* extension) { 374 const Extension* extension) {
331 scoped_ptr<ExtensionInstallPrompt> install_ui( 375 scoped_ptr<ExtensionInstallPrompt> install_ui(
332 new ExtensionInstallPrompt(web_contents)); 376 new ExtensionInstallPrompt(web_contents));
333 // This object manages its own lifetime. 377 // This object manages its own lifetime.
334 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension); 378 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension);
335 } 379 }
336 380
337 } // namespace extensions 381 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_error_ui_default.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698