OLD | NEW |
---|---|
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/size.h" | |
38 | 43 |
39 using extensions::Extension; | 44 using extensions::Extension; |
40 | 45 |
41 namespace { | 46 namespace { |
42 | 47 |
43 static base::LazyInstance< | 48 static base::LazyInstance< |
44 std::bitset<IDC_EXTENSION_DISABLED_LAST - | 49 std::bitset<IDC_EXTENSION_DISABLED_LAST - |
45 IDC_EXTENSION_DISABLED_FIRST + 1> > | 50 IDC_EXTENSION_DISABLED_FIRST + 1> > |
46 menu_command_ids = LAZY_INSTANCE_INITIALIZER; | 51 menu_command_ids = LAZY_INSTANCE_INITIALIZER; |
47 | 52 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 Release(); | 129 Release(); |
125 } | 130 } |
126 | 131 |
127 // ExtensionDisabledGlobalError ----------------------------------------------- | 132 // ExtensionDisabledGlobalError ----------------------------------------------- |
128 | 133 |
129 class ExtensionDisabledGlobalError : public GlobalError, | 134 class ExtensionDisabledGlobalError : public GlobalError, |
130 public content::NotificationObserver, | 135 public content::NotificationObserver, |
131 public ExtensionUninstallDialog::Delegate { | 136 public ExtensionUninstallDialog::Delegate { |
132 public: | 137 public: |
133 ExtensionDisabledGlobalError(ExtensionService* service, | 138 ExtensionDisabledGlobalError(ExtensionService* service, |
134 const Extension* extension); | 139 const Extension* extension, |
140 const gfx::Image& icon); | |
135 virtual ~ExtensionDisabledGlobalError(); | 141 virtual ~ExtensionDisabledGlobalError(); |
136 | 142 |
137 // GlobalError implementation. | 143 // GlobalError implementation. |
138 virtual Severity GetSeverity() OVERRIDE; | 144 virtual Severity GetSeverity() OVERRIDE; |
139 virtual bool HasMenuItem() OVERRIDE; | 145 virtual bool HasMenuItem() OVERRIDE; |
140 virtual int MenuItemCommandID() OVERRIDE; | 146 virtual int MenuItemCommandID() OVERRIDE; |
141 virtual string16 MenuItemLabel() OVERRIDE; | 147 virtual string16 MenuItemLabel() OVERRIDE; |
142 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; | 148 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; |
143 virtual bool HasBubbleView() OVERRIDE; | 149 virtual bool HasBubbleView() OVERRIDE; |
150 virtual gfx::Image* GetBubbleViewCustomIcon() OVERRIDE; | |
144 virtual string16 GetBubbleViewTitle() OVERRIDE; | 151 virtual string16 GetBubbleViewTitle() OVERRIDE; |
145 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE; | 152 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE; |
146 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; | 153 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; |
147 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; | 154 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; |
148 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; | 155 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; |
149 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; | 156 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; |
150 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; | 157 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; |
151 | 158 |
152 // ExtensionUninstallDialog::Delegate implementation. | 159 // ExtensionUninstallDialog::Delegate implementation. |
153 virtual void ExtensionUninstallAccepted() OVERRIDE; | 160 virtual void ExtensionUninstallAccepted() OVERRIDE; |
154 virtual void ExtensionUninstallCanceled() OVERRIDE; | 161 virtual void ExtensionUninstallCanceled() OVERRIDE; |
155 | 162 |
156 // content::NotificationObserver implementation. | 163 // content::NotificationObserver implementation. |
157 virtual void Observe(int type, | 164 virtual void Observe(int type, |
158 const content::NotificationSource& source, | 165 const content::NotificationSource& source, |
159 const content::NotificationDetails& details) OVERRIDE; | 166 const content::NotificationDetails& details) OVERRIDE; |
160 | 167 |
161 private: | 168 private: |
162 ExtensionService* service_; | 169 ExtensionService* service_; |
163 const Extension* extension_; | 170 const Extension* extension_; |
171 gfx::Image icon_; | |
164 | 172 |
165 // How the user responded to the error; used for metrics. | 173 // How the user responded to the error; used for metrics. |
166 enum UserResponse { | 174 enum UserResponse { |
167 IGNORED, | 175 IGNORED, |
168 REENABLE, | 176 REENABLE, |
169 UNINSTALL, | 177 UNINSTALL, |
170 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY | 178 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY |
171 }; | 179 }; |
172 UserResponse user_response_; | 180 UserResponse user_response_; |
173 | 181 |
174 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_; | 182 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_; |
175 | 183 |
176 // Menu command ID assigned for this extension's error. | 184 // Menu command ID assigned for this extension's error. |
177 int menu_command_id_; | 185 int menu_command_id_; |
178 | 186 |
179 content::NotificationRegistrar registrar_; | 187 content::NotificationRegistrar registrar_; |
180 }; | 188 }; |
181 | 189 |
182 // TODO(yoz): create error at startup for disabled extensions. | 190 // TODO(yoz): create error at startup for disabled extensions. |
183 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( | 191 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( |
184 ExtensionService* service, | 192 ExtensionService* service, |
185 const Extension* extension) | 193 const Extension* extension, |
194 const gfx::Image& icon) | |
186 : service_(service), | 195 : service_(service), |
187 extension_(extension), | 196 extension_(extension), |
197 icon_(icon), | |
188 user_response_(IGNORED), | 198 user_response_(IGNORED), |
189 menu_command_id_(GetMenuCommandID()) { | 199 menu_command_id_(GetMenuCommandID()) { |
190 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 200 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
191 content::Source<Profile>(service->profile())); | 201 content::Source<Profile>(service->profile())); |
192 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 202 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
193 content::Source<Profile>(service->profile())); | 203 content::Source<Profile>(service->profile())); |
194 } | 204 } |
195 | 205 |
196 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { | 206 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { |
197 ReleaseMenuCommandID(menu_command_id_); | 207 ReleaseMenuCommandID(menu_command_id_); |
(...skipping 20 matching lines...) Expand all Loading... | |
218 } | 228 } |
219 | 229 |
220 void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) { | 230 void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) { |
221 ShowBubbleView(browser); | 231 ShowBubbleView(browser); |
222 } | 232 } |
223 | 233 |
224 bool ExtensionDisabledGlobalError::HasBubbleView() { | 234 bool ExtensionDisabledGlobalError::HasBubbleView() { |
225 return true; | 235 return true; |
226 } | 236 } |
227 | 237 |
238 gfx::Image* ExtensionDisabledGlobalError::GetBubbleViewCustomIcon() { | |
239 if (icon_.IsEmpty()) | |
240 return NULL; | |
241 return &icon_; | |
242 } | |
243 | |
228 string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() { | 244 string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() { |
229 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, | 245 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, |
230 UTF8ToUTF16(extension_->name())); | 246 UTF8ToUTF16(extension_->name())); |
231 } | 247 } |
232 | 248 |
233 std::vector<string16> ExtensionDisabledGlobalError::GetBubbleViewMessages() { | 249 std::vector<string16> ExtensionDisabledGlobalError::GetBubbleViewMessages() { |
234 std::vector<string16> messages; | 250 std::vector<string16> messages; |
235 messages.push_back(l10n_util::GetStringFUTF16( | 251 messages.push_back(l10n_util::GetStringFUTF16( |
236 extension_->is_app() ? | 252 extension_->is_app() ? |
237 IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL, | 253 IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) | 328 else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) |
313 user_response_ = UNINSTALL; | 329 user_response_ = UNINSTALL; |
314 delete this; | 330 delete this; |
315 } | 331 } |
316 } | 332 } |
317 | 333 |
318 // Globals -------------------------------------------------------------------- | 334 // Globals -------------------------------------------------------------------- |
319 | 335 |
320 namespace extensions { | 336 namespace extensions { |
321 | 337 |
338 void AddExtensionDisabledErrorWithIcon(ExtensionService* service, | |
339 const Extension* extension, | |
340 const gfx::Image& icon) { | |
341 GlobalErrorServiceFactory::GetForProfile(service->profile())-> | |
342 AddGlobalError(new ExtensionDisabledGlobalError( | |
343 service, extension, icon)); | |
344 } | |
345 | |
322 void AddExtensionDisabledError(ExtensionService* service, | 346 void AddExtensionDisabledError(ExtensionService* service, |
323 const Extension* extension) { | 347 const Extension* extension) { |
324 GlobalErrorServiceFactory::GetForProfile(service->profile())-> | 348 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
325 AddGlobalError(new ExtensionDisabledGlobalError(service, extension)); | 349 extension, |
350 extension_misc::EXTENSION_ICON_SMALL, | |
351 ExtensionIconSet::MATCH_BIGGER); | |
352 gfx::Size size(extension_misc::EXTENSION_ICON_SMALL, | |
353 extension_misc::EXTENSION_ICON_SMALL); | |
354 ImageLoader::Get(service->profile())->LoadImageAsync( | |
355 extension, image, size, | |
356 base::Bind(&AddExtensionDisabledErrorWithIcon, service, extension)); | |
Matt Perry
2013/05/24 00:24:04
What happens if |service| or |extension| get delet
Yoyo Zhou
2013/05/24 00:47:11
Done.
| |
326 } | 357 } |
327 | 358 |
328 void ShowExtensionDisabledDialog(ExtensionService* service, | 359 void ShowExtensionDisabledDialog(ExtensionService* service, |
329 content::WebContents* web_contents, | 360 content::WebContents* web_contents, |
330 const Extension* extension) { | 361 const Extension* extension) { |
331 scoped_ptr<ExtensionInstallPrompt> install_ui( | 362 scoped_ptr<ExtensionInstallPrompt> install_ui( |
332 new ExtensionInstallPrompt(web_contents)); | 363 new ExtensionInstallPrompt(web_contents)); |
333 // This object manages its own lifetime. | 364 // This object manages its own lifetime. |
334 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension); | 365 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension); |
335 } | 366 } |
336 | 367 |
337 } // namespace extensions | 368 } // namespace extensions |
OLD | NEW |