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

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

Issue 21443002: Add NOTIFICATION_EXTENSION_REMOVED for Extensions removed from ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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) 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/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/extensions/extension_install_prompt.h" 17 #include "chrome/browser/extensions/extension_install_prompt.h"
19 #include "chrome/browser/extensions/extension_install_ui.h" 18 #include "chrome/browser/extensions/extension_install_ui.h"
20 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 20 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
22 #include "chrome/browser/extensions/image_loader.h" 21 #include "chrome/browser/extensions/image_loader.h"
23 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/global_error/global_error.h" 24 #include "chrome/browser/ui/global_error/global_error.h"
26 #include "chrome/browser/ui/global_error/global_error_service.h" 25 #include "chrome/browser/ui/global_error/global_error_service.h"
27 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 26 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
30 #include "chrome/common/extensions/extension_icon_set.h" 29 #include "chrome/common/extensions/extension_icon_set.h"
31 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" 30 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
32 #include "chrome/common/extensions/permissions/permission_set.h" 31 #include "chrome/common/extensions/permissions/permission_set.h"
33 #include "content/public/browser/notification_details.h"
34 #include "content/public/browser/notification_observer.h"
35 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/notification_source.h"
37 #include "grit/chromium_strings.h" 32 #include "grit/chromium_strings.h"
38 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
39 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
40 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/gfx/image/image.h" 36 #include "ui/gfx/image/image.h"
42 #include "ui/gfx/image/image_skia_operations.h" 37 #include "ui/gfx/image/image_skia_operations.h"
43 #include "ui/gfx/size.h" 38 #include "ui/gfx/size.h"
44 39
45 using extensions::Extension; 40 using extensions::Extension;
46 41
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 "Extensions.Permissions_ReEnableAbort"; 122 "Extensions.Permissions_ReEnableAbort";
128 ExtensionService::RecordPermissionMessagesHistogram( 123 ExtensionService::RecordPermissionMessagesHistogram(
129 extension_, histogram_name.c_str()); 124 extension_, histogram_name.c_str());
130 125
131 // Do nothing. The extension will remain disabled. 126 // Do nothing. The extension will remain disabled.
132 Release(); 127 Release();
133 } 128 }
134 129
135 // ExtensionDisabledGlobalError ----------------------------------------------- 130 // ExtensionDisabledGlobalError -----------------------------------------------
136 131
137 class ExtensionDisabledGlobalError : public GlobalError, 132 class ExtensionDisabledGlobalError
138 public content::NotificationObserver, 133 : public GlobalError,
139 public ExtensionUninstallDialog::Delegate { 134 public ExtensionService::DisabledExtensionObserver,
135 public ExtensionUninstallDialog::Delegate {
140 public: 136 public:
141 ExtensionDisabledGlobalError(ExtensionService* service, 137 ExtensionDisabledGlobalError(ExtensionService* service,
142 const Extension* extension, 138 const Extension* extension,
143 const gfx::Image& icon); 139 const gfx::Image& icon);
144 virtual ~ExtensionDisabledGlobalError(); 140 virtual ~ExtensionDisabledGlobalError();
145 141
146 // GlobalError implementation. 142 // GlobalError implementation.
147 virtual Severity GetSeverity() OVERRIDE; 143 virtual Severity GetSeverity() OVERRIDE;
148 virtual bool HasMenuItem() OVERRIDE; 144 virtual bool HasMenuItem() OVERRIDE;
149 virtual int MenuItemCommandID() OVERRIDE; 145 virtual int MenuItemCommandID() OVERRIDE;
150 virtual string16 MenuItemLabel() OVERRIDE; 146 virtual string16 MenuItemLabel() OVERRIDE;
151 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; 147 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE;
152 virtual bool HasBubbleView() OVERRIDE; 148 virtual bool HasBubbleView() OVERRIDE;
153 virtual gfx::Image GetBubbleViewIcon() OVERRIDE; 149 virtual gfx::Image GetBubbleViewIcon() OVERRIDE;
154 virtual string16 GetBubbleViewTitle() OVERRIDE; 150 virtual string16 GetBubbleViewTitle() OVERRIDE;
155 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE; 151 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE;
156 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; 152 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE;
157 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; 153 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE;
158 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; 154 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE;
159 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; 155 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE;
160 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; 156 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE;
161 157
162 // ExtensionUninstallDialog::Delegate implementation. 158 // ExtensionUninstallDialog::Delegate implementation.
163 virtual void ExtensionUninstallAccepted() OVERRIDE; 159 virtual void ExtensionUninstallAccepted() OVERRIDE;
164 virtual void ExtensionUninstallCanceled() OVERRIDE; 160 virtual void ExtensionUninstallCanceled() OVERRIDE;
165 161
166 // content::NotificationObserver implementation. 162 // ExtensionService::DisabledExtensionObserver implementation.
167 virtual void Observe(int type, 163 virtual void OnDisabledExtensionRemoved(const Extension* extension,
168 const content::NotificationSource& source, 164 bool was_enabled) OVERRIDE;
169 const content::NotificationDetails& details) OVERRIDE;
170 165
171 private: 166 private:
172 ExtensionService* service_; 167 ExtensionService* service_;
173 const Extension* extension_; 168 const Extension* extension_;
174 gfx::Image icon_; 169 gfx::Image icon_;
175 170
176 // How the user responded to the error; used for metrics. 171 // How the user responded to the error; used for metrics.
177 enum UserResponse { 172 enum UserResponse {
178 IGNORED, 173 IGNORED,
179 REENABLE, 174 REENABLE,
180 UNINSTALL, 175 UNINSTALL,
181 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY 176 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY
182 }; 177 };
183 UserResponse user_response_; 178 UserResponse user_response_;
184 179
185 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_; 180 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_;
186 181
187 // Menu command ID assigned for this extension's error. 182 // Menu command ID assigned for this extension's error.
188 int menu_command_id_; 183 int menu_command_id_;
189
190 content::NotificationRegistrar registrar_;
191 }; 184 };
192 185
193 // TODO(yoz): create error at startup for disabled extensions. 186 // TODO(yoz): create error at startup for disabled extensions.
194 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( 187 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError(
195 ExtensionService* service, 188 ExtensionService* service,
196 const Extension* extension, 189 const Extension* extension,
197 const gfx::Image& icon) 190 const gfx::Image& icon)
198 : service_(service), 191 : service_(service),
199 extension_(extension), 192 extension_(extension),
200 icon_(icon), 193 icon_(icon),
201 user_response_(IGNORED), 194 user_response_(IGNORED),
202 menu_command_id_(GetMenuCommandID()) { 195 menu_command_id_(GetMenuCommandID()) {
203 if (icon_.IsEmpty()) { 196 if (icon_.IsEmpty()) {
204 icon_ = gfx::Image( 197 icon_ = gfx::Image(
205 gfx::ImageSkiaOperations::CreateResizedImage( 198 gfx::ImageSkiaOperations::CreateResizedImage(
206 extension_->is_app() ? 199 extension_->is_app() ?
207 extensions::IconsInfo::GetDefaultAppIcon() : 200 extensions::IconsInfo::GetDefaultAppIcon() :
208 extensions::IconsInfo::GetDefaultExtensionIcon(), 201 extensions::IconsInfo::GetDefaultExtensionIcon(),
209 skia::ImageOperations::RESIZE_BEST, 202 skia::ImageOperations::RESIZE_BEST,
210 gfx::Size(kIconSize, kIconSize))); 203 gfx::Size(kIconSize, kIconSize)));
211 } 204 }
212 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 205 service_->AddDisabledExtensionObserver(this);
213 content::Source<Profile>(service->profile()));
214 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
215 content::Source<Profile>(service->profile()));
216 } 206 }
217 207
218 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { 208 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() {
219 ReleaseMenuCommandID(menu_command_id_); 209 ReleaseMenuCommandID(menu_command_id_);
220 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse", 210 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse",
221 user_response_, 211 user_response_,
222 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); 212 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY);
213 service_->RemoveDisabledExtensionObserver(this);
223 } 214 }
224 215
225 GlobalError::Severity ExtensionDisabledGlobalError::GetSeverity() { 216 GlobalError::Severity ExtensionDisabledGlobalError::GetSeverity() {
226 return SEVERITY_LOW; 217 return SEVERITY_LOW;
227 } 218 }
228 219
229 bool ExtensionDisabledGlobalError::HasMenuItem() { 220 bool ExtensionDisabledGlobalError::HasMenuItem() {
230 return true; 221 return true;
231 } 222 }
232 223
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 298 }
308 299
309 void ExtensionDisabledGlobalError::ExtensionUninstallAccepted() { 300 void ExtensionDisabledGlobalError::ExtensionUninstallAccepted() {
310 service_->UninstallExtension(extension_->id(), false, NULL); 301 service_->UninstallExtension(extension_->id(), false, NULL);
311 } 302 }
312 303
313 void ExtensionDisabledGlobalError::ExtensionUninstallCanceled() { 304 void ExtensionDisabledGlobalError::ExtensionUninstallCanceled() {
314 // Nothing happens, and the error is still there. 305 // Nothing happens, and the error is still there.
315 } 306 }
316 307
317 void ExtensionDisabledGlobalError::Observe( 308 void ExtensionDisabledGlobalError::OnDisabledExtensionRemoved(
318 int type, 309 const Extension* extension, bool was_enabled) {
319 const content::NotificationSource& source,
320 const content::NotificationDetails& details) {
321 const Extension* extension = NULL;
322 // The error is invalidated if the extension has been reloaded 310 // The error is invalidated if the extension has been reloaded
323 // or unloaded. 311 // or unloaded.
324 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { 312 if (extension != extension_)
325 extension = content::Details<const Extension>(details).ptr(); 313 return;
326 } else { 314 GlobalErrorServiceFactory::GetForProfile(service_->profile())->
327 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); 315 RemoveGlobalError(this);
328 extensions::UnloadedExtensionInfo* info =
329 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
330 extension = info->extension;
331 }
332 if (extension == extension_) {
333 GlobalErrorServiceFactory::GetForProfile(service_->profile())->
334 RemoveGlobalError(this);
335 316
336 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) 317 if (was_enabled)
337 user_response_ = REENABLE; 318 user_response_ = REENABLE;
338 else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) 319 else
339 user_response_ = UNINSTALL; 320 user_response_ = UNINSTALL;
340 delete this; 321 delete this;
341 }
342 } 322 }
343 323
344 // Globals -------------------------------------------------------------------- 324 // Globals --------------------------------------------------------------------
345 325
346 namespace extensions { 326 namespace extensions {
347 327
348 void AddExtensionDisabledErrorWithIcon(base::WeakPtr<ExtensionService> service, 328 void AddExtensionDisabledErrorWithIcon(base::WeakPtr<ExtensionService> service,
349 const std::string& extension_id, 329 const std::string& extension_id,
350 const gfx::Image& icon) { 330 const gfx::Image& icon) {
351 if (!service.get()) 331 if (!service.get())
(...skipping 20 matching lines...) Expand all
372 void ShowExtensionDisabledDialog(ExtensionService* service, 352 void ShowExtensionDisabledDialog(ExtensionService* service,
373 content::WebContents* web_contents, 353 content::WebContents* web_contents,
374 const Extension* extension) { 354 const Extension* extension) {
375 scoped_ptr<ExtensionInstallPrompt> install_ui( 355 scoped_ptr<ExtensionInstallPrompt> install_ui(
376 new ExtensionInstallPrompt(web_contents)); 356 new ExtensionInstallPrompt(web_contents));
377 // This object manages its own lifetime. 357 // This object manages its own lifetime.
378 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension); 358 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension);
379 } 359 }
380 360
381 } // namespace extensions 361 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service.h » ('j') | chrome/browser/extensions/extension_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698