summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/browser_actions_toolbar_gtk.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-07 22:34:31 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-07 22:34:31 +0000
commite0360f2cca48cf72be469c936783c10d037af292 (patch)
treeb0fcb4f5a8de7a177af436df6bbfc7a87b6ab2d0 /chrome/browser/gtk/browser_actions_toolbar_gtk.cc
parentf891c9df37709735c6f188e163f57e6ee12cf25c (diff)
downloadchromium_src-e0360f2cca48cf72be469c936783c10d037af292.zip
chromium_src-e0360f2cca48cf72be469c936783c10d037af292.tar.gz
chromium_src-e0360f2cca48cf72be469c936783c10d037af292.tar.bz2
Extensions: create a simple model for the browser action buttons toolstrip and use it on Linux.
TODO: persist the order of buttons TODO: use the model on windows, mac TODO: let the view change the order of buttons My plan for persisting the order is just to write/read a simple text file to/from disk, one extension id per line. Similar to the bookmark model, except that is structured data (because they try to hold more information). BUG=26990 Review URL: http://codereview.chromium.org/462026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/browser_actions_toolbar_gtk.cc')
-rw-r--r--chrome/browser/gtk/browser_actions_toolbar_gtk.cc58
1 files changed, 23 insertions, 35 deletions
diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc
index 4399923..91ea423 100644
--- a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc
@@ -203,18 +203,20 @@ class BrowserActionButton : public NotificationObserver,
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::Update() {
}
}
-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 @@ void BrowserActionsToolbarGtk::UpdateVisibility() {
else
gtk_widget_show(widget());
}
+
+void BrowserActionsToolbarGtk::BrowserActionAdded(Extension* extension,
+ int index) {
+ // TODO(estade): respect |index|.
+ CreateButtonForExtension(extension);
+}
+
+void BrowserActionsToolbarGtk::BrowserActionRemoved(Extension* extension) {
+ RemoveButtonForExtension(extension);
+}