diff options
Diffstat (limited to 'chrome/browser/extensions/extension_shelf.cc')
-rw-r--r-- | chrome/browser/extensions/extension_shelf.cc | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/chrome/browser/extensions/extension_shelf.cc b/chrome/browser/extensions/extension_shelf.cc index 17623b6..445f181e 100644 --- a/chrome/browser/extensions/extension_shelf.cc +++ b/chrome/browser/extensions/extension_shelf.cc @@ -145,11 +145,11 @@ ExtensionShelf::ExtensionShelf(Browser* browser) handle_visible_(false), current_handle_view_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)) { - // Watch extensions loaded notification. - NotificationService* ns = NotificationService::current(); - Source<Profile> ns_source(browser->profile()->GetOriginalProfile()); - ns->AddObserver(this, NotificationType::EXTENSIONS_LOADED, - NotificationService::AllSources()); + // Watch extensions loaded and unloaded notifications. + registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, + NotificationService::AllSources()); // Add any already-loaded extensions now, since we missed the notification for // those. @@ -162,12 +162,6 @@ ExtensionShelf::ExtensionShelf(Browser* browser) } } -ExtensionShelf::~ExtensionShelf() { - NotificationService* ns = NotificationService::current(); - ns->RemoveObserver(this, NotificationType::EXTENSIONS_LOADED, - NotificationService::AllSources()); -} - BrowserBubble* ExtensionShelf::GetHandle() { if (!handle_.get() && HasExtensionViews() && current_handle_view_) { ExtensionShelfHandle* handle_view = new ExtensionShelfHandle(this); @@ -271,6 +265,11 @@ void ExtensionShelf::Observe(NotificationType type, AddExtensionViews(extensions); break; } + case NotificationType::EXTENSION_UNLOADED: { + Extension* extension = Details<Extension>(details).ptr(); + RemoveExtensionViews(extension); + break; + } default: DCHECK(false) << "Unhandled notification of type: " << type.value; break; @@ -306,6 +305,28 @@ bool ExtensionShelf::AddExtensionViews(const ExtensionList* extensions) { return added_toolstrip; } +bool ExtensionShelf::RemoveExtensionViews(Extension* extension) { + if (!HasExtensionViews()) + return false; + + bool removed_toolstrip = false; + int count = GetChildViewCount(); + for (int i = count - 1; i >= 0; --i) { + ExtensionView* view = static_cast<ExtensionView*>(GetChildViewAt(i)); + if (view->host()->extension()->id() == extension->id()) { + RemoveChildView(view); + delete view; + removed_toolstrip = true; + } + } + + if (removed_toolstrip) { + SchedulePaint(); + PreferredSizeChanged(); + } + return removed_toolstrip; +} + bool ExtensionShelf::HasExtensionViews() { return GetChildViewCount() > 0; } |