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

Side by Side Diff: chrome/browser/extensions/external_install_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/external_install_ui.h" 5 #include "chrome/browser/extensions/external_install_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/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.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/host_desktop.h" 27 #include "chrome/browser/ui/host_desktop.h"
29 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
30 #include "chrome/common/extensions/extension_constants.h" 29 #include "chrome/common/extensions/extension_constants.h"
31 #include "chrome/common/extensions/manifest_url_handler.h" 30 #include "chrome/common/extensions/manifest_url_handler.h"
32 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_observer.h"
34 #include "content/public/browser/notification_registrar.h"
35 #include "content/public/browser/notification_source.h"
36 #include "grit/chromium_strings.h" 31 #include "grit/chromium_strings.h"
37 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
38 #include "grit/theme_resources.h" 33 #include "grit/theme_resources.h"
39 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/gfx/image/image.h" 35 #include "ui/gfx/image/image.h"
41 #include "ui/gfx/image/image_skia_operations.h" 36 #include "ui/gfx/image/image_skia_operations.h"
42 #include "ui/gfx/size.h" 37 #include "ui/gfx/size.h"
43 38
44 namespace extensions { 39 namespace extensions {
45 40
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // The UI for showing the install dialog when enabling. 78 // The UI for showing the install dialog when enabling.
84 scoped_ptr<ExtensionInstallPrompt> install_ui_; 79 scoped_ptr<ExtensionInstallPrompt> install_ui_;
85 80
86 Browser* browser_; 81 Browser* browser_;
87 base::WeakPtr<ExtensionService> service_weak_; 82 base::WeakPtr<ExtensionService> service_weak_;
88 const std::string extension_id_; 83 const std::string extension_id_;
89 }; 84 };
90 85
91 // Only shows a menu item, no bubble. Clicking the menu item shows 86 // Only shows a menu item, no bubble. Clicking the menu item shows
92 // an external install dialog. 87 // an external install dialog.
93 class ExternalInstallMenuAlert : public GlobalError, 88 class ExternalInstallMenuAlert
94 public content::NotificationObserver { 89 : public GlobalError,
90 public ExtensionService::DisabledExtensionObserver {
95 public: 91 public:
96 ExternalInstallMenuAlert(ExtensionService* service, 92 ExternalInstallMenuAlert(ExtensionService* service,
97 const Extension* extension); 93 const Extension* extension);
98 virtual ~ExternalInstallMenuAlert(); 94 virtual ~ExternalInstallMenuAlert();
99 95
100 const Extension* extension() const { return extension_; } 96 const Extension* extension() const { return extension_; }
101 97
102 // GlobalError implementation. 98 // GlobalError implementation.
103 virtual Severity GetSeverity() OVERRIDE; 99 virtual Severity GetSeverity() OVERRIDE;
104 virtual bool HasMenuItem() OVERRIDE; 100 virtual bool HasMenuItem() OVERRIDE;
105 virtual int MenuItemCommandID() OVERRIDE; 101 virtual int MenuItemCommandID() OVERRIDE;
106 virtual string16 MenuItemLabel() OVERRIDE; 102 virtual string16 MenuItemLabel() OVERRIDE;
107 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; 103 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE;
108 virtual bool HasBubbleView() OVERRIDE; 104 virtual bool HasBubbleView() OVERRIDE;
109 virtual string16 GetBubbleViewTitle() OVERRIDE; 105 virtual string16 GetBubbleViewTitle() OVERRIDE;
110 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE; 106 virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE;
111 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; 107 virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE;
112 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; 108 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE;
113 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; 109 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE;
114 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; 110 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE;
115 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; 111 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE;
116 112
117 // content::NotificationObserver implementation. 113 // ExtensionService::DisabledExtensionObserver implementation.
118 virtual void Observe(int type, 114 virtual void OnDisabledExtensionRemoved(const Extension* extension,
119 const content::NotificationSource& source, 115 bool was_enabled) OVERRIDE;
120 const content::NotificationDetails& details) OVERRIDE;
121 116
122 protected: 117 protected:
123 ExtensionService* service_; 118 ExtensionService* service_;
124 const Extension* extension_; 119 const Extension* extension_;
125 content::NotificationRegistrar registrar_;
126 }; 120 };
127 121
128 // Shows a menu item and a global error bubble, replacing the install dialog. 122 // Shows a menu item and a global error bubble, replacing the install dialog.
129 class ExternalInstallGlobalError : public ExternalInstallMenuAlert { 123 class ExternalInstallGlobalError : public ExternalInstallMenuAlert {
130 public: 124 public:
131 ExternalInstallGlobalError(ExtensionService* service, 125 ExternalInstallGlobalError(ExtensionService* service,
132 const Extension* extension, 126 const Extension* extension,
133 ExternalInstallDialogDelegate* delegate, 127 ExternalInstallDialogDelegate* delegate,
134 const ExtensionInstallPrompt::Prompt& prompt); 128 const ExtensionInstallPrompt::Prompt& prompt);
135 virtual ~ExternalInstallGlobalError(); 129 virtual ~ExternalInstallGlobalError();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 Release(); 229 Release();
236 } 230 }
237 231
238 // ExternalInstallMenuAlert ------------------------------------------------- 232 // ExternalInstallMenuAlert -------------------------------------------------
239 233
240 ExternalInstallMenuAlert::ExternalInstallMenuAlert( 234 ExternalInstallMenuAlert::ExternalInstallMenuAlert(
241 ExtensionService* service, 235 ExtensionService* service,
242 const Extension* extension) 236 const Extension* extension)
243 : service_(service), 237 : service_(service),
244 extension_(extension) { 238 extension_(extension) {
245 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 239 service_->AddDisabledExtensionObserver(this);
246 content::Source<Profile>(service->profile()));
247 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
248 content::Source<Profile>(service->profile()));
249 } 240 }
250 241
251 ExternalInstallMenuAlert::~ExternalInstallMenuAlert() { 242 ExternalInstallMenuAlert::~ExternalInstallMenuAlert() {
243 service_->RemoveDisabledExtensionObserver(this);
252 } 244 }
253 245
254 GlobalError::Severity ExternalInstallMenuAlert::GetSeverity() { 246 GlobalError::Severity ExternalInstallMenuAlert::GetSeverity() {
255 return SEVERITY_LOW; 247 return SEVERITY_LOW;
256 } 248 }
257 249
258 bool ExternalInstallMenuAlert::HasMenuItem() { 250 bool ExternalInstallMenuAlert::HasMenuItem() {
259 return true; 251 return true;
260 } 252 }
261 253
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void ExternalInstallMenuAlert::BubbleViewAcceptButtonPressed( 296 void ExternalInstallMenuAlert::BubbleViewAcceptButtonPressed(
305 Browser* browser) { 297 Browser* browser) {
306 NOTREACHED(); 298 NOTREACHED();
307 } 299 }
308 300
309 void ExternalInstallMenuAlert::BubbleViewCancelButtonPressed( 301 void ExternalInstallMenuAlert::BubbleViewCancelButtonPressed(
310 Browser* browser) { 302 Browser* browser) {
311 NOTREACHED(); 303 NOTREACHED();
312 } 304 }
313 305
314 void ExternalInstallMenuAlert::Observe( 306 void ExternalInstallMenuAlert::OnDisabledExtensionRemoved(
315 int type, 307 const Extension* extension, bool was_enabled) {
316 const content::NotificationSource& source,
317 const content::NotificationDetails& details) {
318 const Extension* extension = NULL;
319 // The error is invalidated if the extension has been reloaded or unloaded. 308 // The error is invalidated if the extension has been reloaded or unloaded.
320 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { 309 if (extension != extension_)
321 extension = content::Details<const Extension>(details).ptr(); 310 return;
322 } else { 311 GlobalErrorService* error_service =
323 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); 312 GlobalErrorServiceFactory::GetForProfile(service_->profile());
324 extensions::UnloadedExtensionInfo* info = 313 error_service->RemoveGlobalError(this);
325 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); 314 service_->AcknowledgeExternalExtension(extension_->id());
326 extension = info->extension; 315 delete this;
327 }
328 if (extension == extension_) {
329 GlobalErrorService* error_service =
330 GlobalErrorServiceFactory::GetForProfile(service_->profile());
331 error_service->RemoveGlobalError(this);
332 service_->AcknowledgeExternalExtension(extension_->id());
333 delete this;
334 }
335 } 316 }
336 317
337 // ExternalInstallGlobalError ----------------------------------------------- 318 // ExternalInstallGlobalError -----------------------------------------------
338 319
339 ExternalInstallGlobalError::ExternalInstallGlobalError( 320 ExternalInstallGlobalError::ExternalInstallGlobalError(
340 ExtensionService* service, 321 ExtensionService* service,
341 const Extension* extension, 322 const Extension* extension,
342 ExternalInstallDialogDelegate* delegate, 323 ExternalInstallDialogDelegate* delegate,
343 const ExtensionInstallPrompt::Prompt& prompt) 324 const ExtensionInstallPrompt::Prompt& prompt)
344 : ExternalInstallMenuAlert(service, extension), 325 : ExternalInstallMenuAlert(service, extension),
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 440
460 bool HasExternalInstallBubble(ExtensionService* service) { 441 bool HasExternalInstallBubble(ExtensionService* service) {
461 GlobalErrorService* error_service = 442 GlobalErrorService* error_service =
462 GlobalErrorServiceFactory::GetForProfile(service->profile()); 443 GlobalErrorServiceFactory::GetForProfile(service->profile());
463 GlobalError* error = error_service->GetGlobalErrorByMenuItemCommandID( 444 GlobalError* error = error_service->GetGlobalErrorByMenuItemCommandID(
464 kMenuCommandId); 445 kMenuCommandId);
465 return error && error->HasBubbleView(); 446 return error && error->HasBubbleView();
466 } 447 }
467 448
468 } // namespace extensions 449 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698