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/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/callback_forward.h" | |
10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | |
13 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/extensions/extension_install_prompt.h" | 20 #include "chrome/browser/extensions/extension_install_prompt.h" |
19 #include "chrome/browser/extensions/extension_install_ui.h" | 21 #include "chrome/browser/extensions/extension_install_ui.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 23 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; | 114 virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE; |
113 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; | 115 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; |
114 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; | 116 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; |
115 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; | 117 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; |
116 | 118 |
117 // content::NotificationObserver implementation. | 119 // content::NotificationObserver implementation. |
118 virtual void Observe(int type, | 120 virtual void Observe(int type, |
119 const content::NotificationSource& source, | 121 const content::NotificationSource& source, |
120 const content::NotificationDetails& details) OVERRIDE; | 122 const content::NotificationDetails& details) OVERRIDE; |
121 | 123 |
124 // Callback to notify UI that extension has been removed. | |
125 void HandleExtensionRemoved(const Extension* extension); | |
126 | |
122 protected: | 127 protected: |
123 ExtensionService* service_; | 128 ExtensionService* service_; |
124 const Extension* extension_; | 129 const Extension* extension_; |
125 content::NotificationRegistrar registrar_; | 130 content::NotificationRegistrar registrar_; |
131 base::WeakPtrFactory<ExternalInstallMenuAlert> weak_factory_; | |
132 base::Callback<void(const Extension*)> on_removed_callback_; | |
126 }; | 133 }; |
127 | 134 |
128 // Shows a menu item and a global error bubble, replacing the install dialog. | 135 // Shows a menu item and a global error bubble, replacing the install dialog. |
129 class ExternalInstallGlobalError : public ExternalInstallMenuAlert { | 136 class ExternalInstallGlobalError : public ExternalInstallMenuAlert { |
130 public: | 137 public: |
131 ExternalInstallGlobalError(ExtensionService* service, | 138 ExternalInstallGlobalError(ExtensionService* service, |
132 const Extension* extension, | 139 const Extension* extension, |
133 ExternalInstallDialogDelegate* delegate, | 140 ExternalInstallDialogDelegate* delegate, |
134 const ExtensionInstallPrompt::Prompt& prompt); | 141 const ExtensionInstallPrompt::Prompt& prompt); |
135 virtual ~ExternalInstallGlobalError(); | 142 virtual ~ExternalInstallGlobalError(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 service_weak_->UninstallExtension(extension_id_, false, NULL); | 241 service_weak_->UninstallExtension(extension_id_, false, NULL); |
235 Release(); | 242 Release(); |
236 } | 243 } |
237 | 244 |
238 // ExternalInstallMenuAlert ------------------------------------------------- | 245 // ExternalInstallMenuAlert ------------------------------------------------- |
239 | 246 |
240 ExternalInstallMenuAlert::ExternalInstallMenuAlert( | 247 ExternalInstallMenuAlert::ExternalInstallMenuAlert( |
241 ExtensionService* service, | 248 ExtensionService* service, |
242 const Extension* extension) | 249 const Extension* extension) |
243 : service_(service), | 250 : service_(service), |
244 extension_(extension) { | 251 extension_(extension), |
252 weak_factory_(this) { | |
253 on_removed_callback_ = base::Bind( | |
254 &ExternalInstallMenuAlert::HandleExtensionRemoved, | |
255 weak_factory_.GetWeakPtr()); | |
256 service_->RegisterExtensionRemovedCallback(on_removed_callback_); | |
245 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 257 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
246 content::Source<Profile>(service->profile())); | 258 content::Source<Profile>(service->profile())); |
247 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_REMOVED, | |
248 content::Source<Profile>(service->profile())); | |
249 } | 259 } |
250 | 260 |
251 ExternalInstallMenuAlert::~ExternalInstallMenuAlert() { | 261 ExternalInstallMenuAlert::~ExternalInstallMenuAlert() { |
252 } | 262 } |
253 | 263 |
254 GlobalError::Severity ExternalInstallMenuAlert::GetSeverity() { | 264 GlobalError::Severity ExternalInstallMenuAlert::GetSeverity() { |
255 return SEVERITY_LOW; | 265 return SEVERITY_LOW; |
256 } | 266 } |
257 | 267 |
258 bool ExternalInstallMenuAlert::HasMenuItem() { | 268 bool ExternalInstallMenuAlert::HasMenuItem() { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 void ExternalInstallMenuAlert::BubbleViewCancelButtonPressed( | 319 void ExternalInstallMenuAlert::BubbleViewCancelButtonPressed( |
310 Browser* browser) { | 320 Browser* browser) { |
311 NOTREACHED(); | 321 NOTREACHED(); |
312 } | 322 } |
313 | 323 |
314 void ExternalInstallMenuAlert::Observe( | 324 void ExternalInstallMenuAlert::Observe( |
315 int type, | 325 int type, |
316 const content::NotificationSource& source, | 326 const content::NotificationSource& source, |
317 const content::NotificationDetails& details) { | 327 const content::NotificationDetails& details) { |
318 // The error is invalidated if the extension has been loaded or removed. | 328 // The error is invalidated if the extension has been loaded or removed. |
319 DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED || | 329 DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED); |
320 type == chrome::NOTIFICATION_EXTENSION_REMOVED); | |
321 const Extension* extension = content::Details<const Extension>(details).ptr(); | 330 const Extension* extension = content::Details<const Extension>(details).ptr(); |
322 if (extension != extension_) | 331 if (extension != extension_) |
323 return; | 332 return; |
324 GlobalErrorService* error_service = | 333 GlobalErrorService* error_service = |
325 GlobalErrorServiceFactory::GetForProfile(service_->profile()); | 334 GlobalErrorServiceFactory::GetForProfile(service_->profile()); |
326 error_service->RemoveGlobalError(this); | 335 error_service->RemoveGlobalError(this); |
327 service_->AcknowledgeExternalExtension(extension_->id()); | 336 service_->AcknowledgeExternalExtension(extension_->id()); |
328 delete this; | 337 delete this; |
329 } | 338 } |
330 | 339 |
340 void ExternalInstallMenuAlert::HandleExtensionRemoved( | |
341 const Extension* extension) { | |
342 if (extension != extension_) | |
343 return; | |
344 GlobalErrorService* error_service = | |
345 GlobalErrorServiceFactory::GetForProfile(service_->profile()); | |
346 error_service->RemoveGlobalError(this); | |
347 service_->AcknowledgeExternalExtension(extension_->id()); | |
348 service_->RemoveExtensionRemovedCallback(on_removed_callback_); | |
Yoyo Zhou
2013/08/22 16:50:26
Likewise.
Cait (Slow)
2013/08/26 18:01:46
Done.
| |
349 delete this; | |
350 } | |
351 | |
331 // ExternalInstallGlobalError ----------------------------------------------- | 352 // ExternalInstallGlobalError ----------------------------------------------- |
332 | 353 |
333 ExternalInstallGlobalError::ExternalInstallGlobalError( | 354 ExternalInstallGlobalError::ExternalInstallGlobalError( |
334 ExtensionService* service, | 355 ExtensionService* service, |
335 const Extension* extension, | 356 const Extension* extension, |
336 ExternalInstallDialogDelegate* delegate, | 357 ExternalInstallDialogDelegate* delegate, |
337 const ExtensionInstallPrompt::Prompt& prompt) | 358 const ExtensionInstallPrompt::Prompt& prompt) |
338 : ExternalInstallMenuAlert(service, extension), | 359 : ExternalInstallMenuAlert(service, extension), |
339 delegate_(delegate), | 360 delegate_(delegate), |
340 prompt_(&prompt) { | 361 prompt_(&prompt) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 | 474 |
454 bool HasExternalInstallBubble(ExtensionService* service) { | 475 bool HasExternalInstallBubble(ExtensionService* service) { |
455 GlobalErrorService* error_service = | 476 GlobalErrorService* error_service = |
456 GlobalErrorServiceFactory::GetForProfile(service->profile()); | 477 GlobalErrorServiceFactory::GetForProfile(service->profile()); |
457 GlobalError* error = error_service->GetGlobalErrorByMenuItemCommandID( | 478 GlobalError* error = error_service->GetGlobalErrorByMenuItemCommandID( |
458 kMenuCommandId); | 479 kMenuCommandId); |
459 return error && error->HasBubbleView(); | 480 return error && error->HasBubbleView(); |
460 } | 481 } |
461 | 482 |
462 } // namespace extensions | 483 } // namespace extensions |
OLD | NEW |