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

Unified Diff: chrome/browser/gtk/browser_actions_toolbar_gtk.cc

Issue 462026: Extensions: create a simple model for the browser action buttons toolstrip an... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/gtk/browser_actions_toolbar_gtk.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/gtk/browser_actions_toolbar_gtk.cc
===================================================================
--- chrome/browser/gtk/browser_actions_toolbar_gtk.cc (revision 33989)
+++ chrome/browser/gtk/browser_actions_toolbar_gtk.cc (working copy)
@@ -203,18 +203,20 @@
BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser)
: browser_(browser),
profile_(browser->profile()),
+ model_(NULL),
hbox_(gtk_hbox_new(FALSE, kBrowserActionButtonPadding)) {
- registrar_.Add(this, NotificationType::EXTENSION_LOADED,
- Source<Profile>(profile_));
- registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
- Source<Profile>(profile_));
- registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
- Source<Profile>(profile_));
-
- CreateAllButtons();
+ ExtensionsService* extension_service = profile_->GetExtensionsService();
+ // The |extension_service| can be NULL in Incognito.
+ if (extension_service) {
+ model_ = extension_service->toolbar_model();
+ model_->AddObserver(this);
+ CreateAllButtons();
+ }
}
BrowserActionsToolbarGtk::~BrowserActionsToolbarGtk() {
+ if (model_)
+ model_->RemoveObserver(this);
hbox_.Destroy();
}
@@ -233,38 +235,14 @@
}
}
-void BrowserActionsToolbarGtk::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- Extension* extension = Details<Extension>(details).ptr();
-
- if (type == NotificationType::EXTENSION_LOADED) {
- CreateButtonForExtension(extension);
- } else if (type == NotificationType::EXTENSION_UNLOADED ||
- type == NotificationType::EXTENSION_UNLOADED_DISABLED) {
- RemoveButtonForExtension(extension);
- } else {
- NOTREACHED() << "Received unexpected notification";
- }
-}
-
void BrowserActionsToolbarGtk::CreateAllButtons() {
- ExtensionsService* extension_service = profile_->GetExtensionsService();
- if (!extension_service) // The |extension_service| can be NULL in Incognito.
- return;
-
- for (size_t i = 0; i < extension_service->extensions()->size(); ++i) {
- Extension* extension = extension_service->GetExtensionById(
- extension_service->extensions()->at(i)->id(), false);
- CreateButtonForExtension(extension);
+ for (ExtensionList::iterator iter = model_->begin();
+ iter != model_->end(); ++iter) {
+ CreateButtonForExtension(*iter);
}
}
void BrowserActionsToolbarGtk::CreateButtonForExtension(Extension* extension) {
- // Only show extensions with browser actions.
- if (!extension->browser_action())
- return;
-
RemoveButtonForExtension(extension);
linked_ptr<BrowserActionButton> button(
new BrowserActionButton(this, extension));
@@ -286,3 +264,13 @@
else
gtk_widget_show(widget());
}
+
+void BrowserActionsToolbarGtk::ExtensionAdded(Extension* extension,
+ int index) {
+ // TODO(estade): respect |index|.
+ CreateButtonForExtension(extension);
+}
+
+void BrowserActionsToolbarGtk::ExtensionRemoved(Extension* extension) {
+ RemoveButtonForExtension(extension);
+}
« no previous file with comments | « chrome/browser/gtk/browser_actions_toolbar_gtk.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698