| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ |
| 6 #define CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ | 6 #define CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/linked_ptr.h" | 11 #include "base/linked_ptr.h" |
| 12 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 12 #include "chrome/common/notification_observer.h" | 13 #include "chrome/common/notification_observer.h" |
| 13 #include "chrome/common/notification_registrar.h" | 14 #include "chrome/common/notification_registrar.h" |
| 14 #include "chrome/common/owned_widget_gtk.h" | 15 #include "chrome/common/owned_widget_gtk.h" |
| 15 | 16 |
| 16 class Browser; | 17 class Browser; |
| 17 class BrowserActionButton; | 18 class BrowserActionButton; |
| 18 class Extension; | 19 class Extension; |
| 19 class Profile; | 20 class Profile; |
| 20 | 21 |
| 21 typedef struct _GtkWidget GtkWidget; | 22 typedef struct _GtkWidget GtkWidget; |
| 22 | 23 |
| 23 class BrowserActionsToolbarGtk : public NotificationObserver { | 24 class BrowserActionsToolbarGtk : public ExtensionToolbarModel::Observer { |
| 24 public: | 25 public: |
| 25 explicit BrowserActionsToolbarGtk(Browser* browser); | 26 explicit BrowserActionsToolbarGtk(Browser* browser); |
| 26 ~BrowserActionsToolbarGtk(); | 27 ~BrowserActionsToolbarGtk(); |
| 27 | 28 |
| 28 GtkWidget* widget() { return hbox_.get(); } | 29 GtkWidget* widget() { return hbox_.get(); } |
| 29 | 30 |
| 30 int button_count() { return extension_button_map_.size(); } | 31 int button_count() { return extension_button_map_.size(); } |
| 31 | 32 |
| 32 Browser* browser() { return browser_; } | 33 Browser* browser() { return browser_; } |
| 33 | 34 |
| 34 // Returns the currently selected tab ID, or -1 if there is none. | 35 // Returns the currently selected tab ID, or -1 if there is none. |
| 35 int GetCurrentTabId(); | 36 int GetCurrentTabId(); |
| 36 | 37 |
| 37 // Update the display of all buttons. | 38 // Update the display of all buttons. |
| 38 void Update(); | 39 void Update(); |
| 39 | 40 |
| 40 // NotificationObserver implementation. | |
| 41 void Observe(NotificationType type, | |
| 42 const NotificationSource& source, | |
| 43 const NotificationDetails& details); | |
| 44 | |
| 45 private: | 41 private: |
| 46 // Query the extensions service for all extensions with browser actions, | 42 // Query the extensions service for all extensions with browser actions, |
| 47 // and create the UI for them. | 43 // and create the UI for them. |
| 48 void CreateAllButtons(); | 44 void CreateAllButtons(); |
| 49 | 45 |
| 50 // Create the UI for a single browser action. This will stick the button | 46 // Create the UI for a single browser action. This will stick the button |
| 51 // at the end of the toolbar. | 47 // at the end of the toolbar. |
| 52 // TODO(estade): is this OK, or does it need to place it in a specific | 48 // TODO(estade): is this OK, or does it need to place it in a specific |
| 53 // location on the toolbar? | 49 // location on the toolbar? |
| 54 void CreateButtonForExtension(Extension* extension); | 50 void CreateButtonForExtension(Extension* extension); |
| 55 | 51 |
| 56 // Delete resources associated with UI for a browser action. | 52 // Delete resources associated with UI for a browser action. |
| 57 void RemoveButtonForExtension(Extension* extension); | 53 void RemoveButtonForExtension(Extension* extension); |
| 58 | 54 |
| 59 // Change the visibility of widget() based on whether we have any buttons | 55 // Change the visibility of widget() based on whether we have any buttons |
| 60 // to show. | 56 // to show. |
| 61 void UpdateVisibility(); | 57 void UpdateVisibility(); |
| 62 | 58 |
| 59 // ExtensionToolbarModel::Observer implementation. |
| 60 virtual void ExtensionAdded(Extension* extension, int index); |
| 61 virtual void ExtensionRemoved(Extension* extension); |
| 62 |
| 63 Browser* browser_; | 63 Browser* browser_; |
| 64 | 64 |
| 65 Profile* profile_; | 65 Profile* profile_; |
| 66 | 66 |
| 67 ExtensionToolbarModel* model_; |
| 68 |
| 67 OwnedWidgetGtk hbox_; | 69 OwnedWidgetGtk hbox_; |
| 68 | 70 |
| 69 NotificationRegistrar registrar_; | |
| 70 | |
| 71 // Map from extension ID to BrowserActionButton, which is a wrapper for | 71 // Map from extension ID to BrowserActionButton, which is a wrapper for |
| 72 // a chrome button and related functionality. There should be one entry | 72 // a chrome button and related functionality. There should be one entry |
| 73 // for every extension that has a browser action. | 73 // for every extension that has a browser action. |
| 74 typedef std::map<std::string, linked_ptr<BrowserActionButton> > | 74 typedef std::map<std::string, linked_ptr<BrowserActionButton> > |
| 75 ExtensionButtonMap; | 75 ExtensionButtonMap; |
| 76 ExtensionButtonMap extension_button_map_; | 76 ExtensionButtonMap extension_button_map_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(BrowserActionsToolbarGtk); | 78 DISALLOW_COPY_AND_ASSIGN(BrowserActionsToolbarGtk); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 #endif // CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ | 81 #endif // CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ |
| OLD | NEW |