Chromium Code Reviews| 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_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 | 49 |
| 50 // The model representing the toolstrips on an ExtensionShelf. The order of | 50 // The model representing the toolstrips on an ExtensionShelf. The order of |
| 51 // the toolstrips is common across all of the models for a given Profile, | 51 // the toolstrips is common across all of the models for a given Profile, |
| 52 // but there are multiple models. Each model contains the hosts/views which | 52 // but there are multiple models. Each model contains the hosts/views which |
| 53 // are specific to a Browser. | 53 // are specific to a Browser. |
| 54 class ExtensionShelfModel : public NotificationObserver { | 54 class ExtensionShelfModel : public NotificationObserver { |
| 55 public: | 55 public: |
| 56 ExtensionShelfModel(Browser* browser); | 56 ExtensionShelfModel(Browser* browser); |
| 57 virtual ~ExtensionShelfModel(); | 57 virtual ~ExtensionShelfModel(); |
| 58 | 58 |
| 59 struct ToolstripItem { | |
| 60 ExtensionHost* host; | |
| 61 Extension::ToolstripInfo info; | |
| 62 void* data; | |
| 63 }; | |
| 64 | |
| 59 // Add and remove observers to changes within this ExtensionShelfModel. | 65 // Add and remove observers to changes within this ExtensionShelfModel. |
| 60 void AddObserver(ExtensionShelfModelObserver* observer); | 66 void AddObserver(ExtensionShelfModelObserver* observer); |
| 61 void RemoveObserver(ExtensionShelfModelObserver* observer); | 67 void RemoveObserver(ExtensionShelfModelObserver* observer); |
| 62 | 68 |
| 63 // The number of toolstrips in the model. | 69 // The number of toolstrips in the model. |
| 64 int count() const { return static_cast<int>(toolstrips_.size()); } | 70 int count() const { return static_cast<int>(toolstrips_.size()); } |
| 65 bool empty() const { return toolstrips_.empty(); } | 71 bool empty() const { return toolstrips_.empty(); } |
| 66 | 72 |
| 67 // Add |toolstrip| to the end of the shelf. | 73 // Add |toolstrip| to the end of the shelf. |
| 68 void AppendToolstrip(ExtensionHost* toolstrip); | 74 void AppendToolstrip(const ToolstripItem& toolstrip); |
| 69 | 75 |
| 70 // Insert |toolstrip| and |data| at |index|. | 76 // Insert |toolstrip| and |data| at |index|. |
| 71 void InsertToolstripAt(int index, ExtensionHost* toolstrip, void* data); | 77 void InsertToolstripAt(int index, const ToolstripItem& toolstrip); |
| 72 | 78 |
| 73 // Remove the toolstrip at |index|. | 79 // Remove the toolstrip at |index|. |
| 74 void RemoveToolstripAt(int index); | 80 void RemoveToolstripAt(int index); |
| 75 | 81 |
| 76 // Move the toolstrip at |index| to |to_index|. | 82 // Move the toolstrip at |index| to |to_index|. |
| 77 void MoveToolstripAt(int index, int to_index); | 83 void MoveToolstripAt(int index, int to_index); |
| 78 | 84 |
| 79 // Lookup the index of |toolstrip|. Returns -1 if not present. | 85 // Lookup the index of |toolstrip|. Returns -1 if not present. |
| 80 int IndexOfToolstrip(ExtensionHost* toolstrip); | 86 int IndexOfToolstrip(ExtensionHost* toolstrip); |
|
Matt Perry
2009/07/24 23:11:11
IndexOfExtension?
Erik does not do reviews
2009/07/26 00:34:46
No. An extension can have multiple toolstrips.
Matt Perry
2009/07/27 17:41:50
Then what good is this method?
Actually, after a
| |
| 81 | 87 |
| 82 // Return the toolstrip at |index|. Returns NULL if index is out of range. | 88 // Return the toolstrip at |index|. |
| 83 ExtensionHost* ToolstripAt(int index); | 89 ExtensionHost* ToolstripAt(int index); |
| 84 | 90 |
| 91 // Return the ToolstripInfo at |index|. | |
| 92 Extension::ToolstripInfo* ToolstripInfoAt(int index); | |
| 93 | |
| 85 // Get/Set some arbitrary data associated with a particular toolstrip. | 94 // Get/Set some arbitrary data associated with a particular toolstrip. |
| 86 void SetToolstripDataAt(int index, void* data); | 95 void SetToolstripDataAt(int index, void* data); |
| 87 void* ToolstripDataAt(int index); | 96 void* ToolstripDataAt(int index); |
| 88 | 97 |
| 89 // NotificationObserver | 98 // NotificationObserver |
| 90 virtual void Observe(NotificationType type, | 99 virtual void Observe(NotificationType type, |
| 91 const NotificationSource& source, | 100 const NotificationSource& source, |
| 92 const NotificationDetails& details); | 101 const NotificationDetails& details); |
| 93 | 102 |
| 94 private: | 103 private: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 110 // The browser that this model is attached to. | 119 // The browser that this model is attached to. |
| 111 Browser* browser_; | 120 Browser* browser_; |
| 112 | 121 |
| 113 // The preferences that this model uses. | 122 // The preferences that this model uses. |
| 114 ExtensionPrefs* prefs_; | 123 ExtensionPrefs* prefs_; |
| 115 | 124 |
| 116 // Manages our notification registrations. | 125 // Manages our notification registrations. |
| 117 NotificationRegistrar registrar_; | 126 NotificationRegistrar registrar_; |
| 118 | 127 |
| 119 // The Toolstrips loaded in this model. The model owns these objects. | 128 // The Toolstrips loaded in this model. The model owns these objects. |
| 120 typedef std::pair<ExtensionHost*, void*> ToolstripItem; | |
| 121 typedef std::vector<ToolstripItem> ExtensionToolstrips; | 129 typedef std::vector<ToolstripItem> ExtensionToolstrips; |
| 122 ExtensionToolstrips toolstrips_; | 130 ExtensionToolstrips toolstrips_; |
| 123 | 131 |
| 124 // Our observers. | 132 // Our observers. |
| 125 typedef ObserverList<ExtensionShelfModelObserver> | 133 typedef ObserverList<ExtensionShelfModelObserver> |
| 126 ExtensionShelfModelObservers; | 134 ExtensionShelfModelObservers; |
| 127 ExtensionShelfModelObservers observers_; | 135 ExtensionShelfModelObservers observers_; |
| 128 | 136 |
| 129 // Whether the model has received an EXTENSIONS_READY notification. | 137 // Whether the model has received an EXTENSIONS_READY notification. |
| 130 bool ready_; | 138 bool ready_; |
| 131 | 139 |
| 132 DISALLOW_COPY_AND_ASSIGN(ExtensionShelfModel); | 140 DISALLOW_COPY_AND_ASSIGN(ExtensionShelfModel); |
| 133 }; | 141 }; |
| 134 | 142 |
| 135 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ | 143 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ |
| OLD | NEW |