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

Side by Side Diff: chrome/browser/extensions/extension_shelf_model.h

Issue 159763: Rolling back change 22245. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Created 11 years, 4 months 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "chrome/common/notification_observer.h" 12 #include "chrome/common/notification_observer.h"
13 #include "chrome/common/notification_registrar.h" 13 #include "chrome/common/notification_registrar.h"
14 #include "chrome/browser/extensions/extension_host.h" 14 #include "chrome/browser/extensions/extension_host.h"
15 #include "chrome/browser/extensions/extensions_service.h" 15 #include "chrome/browser/extensions/extensions_service.h"
16 16
17 class Browser; 17 class Browser;
18 class ExtensionPrefs; 18 class ExtensionPrefs;
19 class ExtensionShelfModelObserver; 19
20 // Objects implement this interface when they wish to be notified of changes to
21 // the ExtensionShelfModel.
22 //
23 // Register your ExtensionShelfModelObserver with the ExtensionShelfModel using
24 // Add/RemoveObserver methods.
25 class ExtensionShelfModelObserver {
26 public:
27 // A new toolstrip was inserted into ExtensionShelfModel at |index|.
28 virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index) {}
29
30 // The specified toolstrip is being removed and destroyed.
31 virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index) {}
32
33 // |toolstrip| moved from |from_index| to |to_index|.
34 virtual void ToolstripMoved(ExtensionHost* toolstrip,
35 int from_index,
36 int to_index) {}
37
38 // The specified toolstrip changed in some way (currently only size changes)
39 virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index) {}
40
41 // There are no more toolstrips in the model.
42 virtual void ExtensionShelfEmpty() {}
43
44 // The entire model may have changed.
45 virtual void ShelfModelReloaded() {}
46
47 // TODO(erikkay) - any more?
48 };
20 49
21 // The model representing the toolstrips on an ExtensionShelf. The order of 50 // The model representing the toolstrips on an ExtensionShelf. The order of
22 // 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,
23 // 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
24 // are specific to a Browser. 53 // are specific to a Browser.
25 class ExtensionShelfModel : public NotificationObserver { 54 class ExtensionShelfModel : public NotificationObserver {
26 public: 55 public:
27 ExtensionShelfModel(Browser* browser); 56 ExtensionShelfModel(Browser* browser);
28 virtual ~ExtensionShelfModel(); 57 virtual ~ExtensionShelfModel();
29 58
30 struct ToolstripItem { 59 struct ToolstripItem {
31 ExtensionHost* host; 60 ExtensionHost* host;
32 Extension::ToolstripInfo info; 61 Extension::ToolstripInfo info;
33 void* data; 62 void* data;
34 int height;
35 GURL url;
36 }; 63 };
37 64
38 typedef std::vector<ToolstripItem> ToolstripList;
39 typedef ToolstripList::iterator iterator;
40
41 // Add and remove observers to changes within this ExtensionShelfModel. 65 // Add and remove observers to changes within this ExtensionShelfModel.
42 void AddObserver(ExtensionShelfModelObserver* observer); 66 void AddObserver(ExtensionShelfModelObserver* observer);
43 void RemoveObserver(ExtensionShelfModelObserver* observer); 67 void RemoveObserver(ExtensionShelfModelObserver* observer);
44 68
45 // The number of toolstrips in the model. 69 // The number of toolstrips in the model.
46 int count() const { return static_cast<int>(toolstrips_.size()); } 70 int count() const { return static_cast<int>(toolstrips_.size()); }
47 bool empty() const { return toolstrips_.empty(); } 71 bool empty() const { return toolstrips_.empty(); }
48 72
49 // Iterators for the toolstrips in the model.
50 iterator begin() { return toolstrips_.begin(); }
51 ExtensionShelfModel::iterator end() { return toolstrips_.end(); }
52
53 // Add |toolstrip| to the end of the shelf. 73 // Add |toolstrip| to the end of the shelf.
54 void AppendToolstrip(const ToolstripItem& toolstrip); 74 void AppendToolstrip(const ToolstripItem& toolstrip);
55 75
56 // Insert |toolstrip| and |data| at |index|. 76 // Insert |toolstrip| and |data| at |index|.
57 void InsertToolstripAt(int index, const ToolstripItem& toolstrip); 77 void InsertToolstripAt(int index, const ToolstripItem& toolstrip);
58 78
59 // Remove the toolstrip at |index|. 79 // Remove the toolstrip at |index|.
60 void RemoveToolstripAt(int index); 80 void RemoveToolstripAt(int index);
61 81
62 // Move the toolstrip at |index| to |to_index|. 82 // Move the toolstrip at |index| to |to_index|.
63 void MoveToolstripAt(int index, int to_index); 83 void MoveToolstripAt(int index, int to_index);
64 84
65 // Lookup the index of |host|. Returns -1 if not present. 85 // Lookup the index of |toolstrip|. Returns -1 if not present.
66 int IndexOfHost(ExtensionHost* host); 86 int IndexOfToolstrip(ExtensionHost* toolstrip);
67 87
68 // Return the toolstrip at |index|. 88 // Return the toolstrip at |index|.
69 const ToolstripItem& ToolstripAt(int index); 89 ExtensionHost* ToolstripAt(int index);
70 90
71 // Return the ToolstripItem associated with |host| or NULL if it's not 91 // Return the ToolstripInfo at |index|.
72 // present. 92 Extension::ToolstripInfo& ToolstripInfoAt(int index);
73 ToolstripList::iterator ToolstripForHost(ExtensionHost* host);
74 93
75 // Set some arbitrary data associated with a particular toolstrip. 94 // Get/Set some arbitrary data associated with a particular toolstrip.
76 void SetToolstripDataAt(int index, void* data); 95 void SetToolstripDataAt(int index, void* data);
77 96 void* ToolstripDataAt(int index);
78 // Update the ToolstripItem for |toolstrip| to set its |url| and |height|
79 // and then call ToolstripChanged for all observers.
80 // If |url| is empty, no navigation is requested.
81 void ExpandToolstrip(iterator toolstrip, const GURL& url, int height);
82
83 // Update the ToolstripItem for |toolstrip| to set its |url| and its height
84 // to 0, and then call ToolstripChanged for all observers.
85 // If |url| is empty, no navigation is requested.
86 void CollapseToolstrip(iterator toolstrip, const GURL& url);
87 97
88 // NotificationObserver 98 // NotificationObserver
89 virtual void Observe(NotificationType type, 99 virtual void Observe(NotificationType type,
90 const NotificationSource& source, 100 const NotificationSource& source,
91 const NotificationDetails& details); 101 const NotificationDetails& details);
92 102
93 private: 103 private:
94 // Add all of the toolstrips from |extension|. 104 // Add all of the toolstrips from |extension|.
95 void AddExtension(Extension* extension); 105 void AddExtension(Extension* extension);
96 106
(...skipping 12 matching lines...) Expand all
109 // The browser that this model is attached to. 119 // The browser that this model is attached to.
110 Browser* browser_; 120 Browser* browser_;
111 121
112 // The preferences that this model uses. 122 // The preferences that this model uses.
113 ExtensionPrefs* prefs_; 123 ExtensionPrefs* prefs_;
114 124
115 // Manages our notification registrations. 125 // Manages our notification registrations.
116 NotificationRegistrar registrar_; 126 NotificationRegistrar registrar_;
117 127
118 // The Toolstrips loaded in this model. The model owns these objects. 128 // The Toolstrips loaded in this model. The model owns these objects.
119 ToolstripList toolstrips_; 129 typedef std::vector<ToolstripItem> ExtensionToolstrips;
130 ExtensionToolstrips toolstrips_;
120 131
121 // Our observers. 132 // Our observers.
122 typedef ObserverList<ExtensionShelfModelObserver> 133 typedef ObserverList<ExtensionShelfModelObserver>
123 ExtensionShelfModelObservers; 134 ExtensionShelfModelObservers;
124 ExtensionShelfModelObservers observers_; 135 ExtensionShelfModelObservers observers_;
125 136
126 // Whether the model has received an EXTENSIONS_READY notification. 137 // Whether the model has received an EXTENSIONS_READY notification.
127 bool ready_; 138 bool ready_;
128 139
129 DISALLOW_COPY_AND_ASSIGN(ExtensionShelfModel); 140 DISALLOW_COPY_AND_ASSIGN(ExtensionShelfModel);
130 }; 141 };
131 142
132 // Objects implement this interface when they wish to be notified of changes to
133 // the ExtensionShelfModel.
134 //
135 // Register your ExtensionShelfModelObserver with the ExtensionShelfModel using
136 // Add/RemoveObserver methods.
137 class ExtensionShelfModelObserver {
138 public:
139 // A new toolstrip was inserted into ExtensionShelfModel at |index|.
140 virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index) {}
141
142 // The specified toolstrip is being removed and destroyed.
143 virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index) {}
144
145 // |toolstrip| moved from |from_index| to |to_index|.
146 virtual void ToolstripMoved(ExtensionHost* toolstrip,
147 int from_index,
148 int to_index) {}
149
150 // The specified toolstrip changed in some way (currently only size changes)
151 virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip) {}
152
153 // There are no more toolstrips in the model.
154 virtual void ExtensionShelfEmpty() {}
155
156 // The entire model may have changed.
157 virtual void ShelfModelReloaded() {}
158
159 // The model is being destroyed.
160 virtual void ShelfModelDeleting() {}
161 };
162
163
164 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_ 143 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SHELF_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.cc ('k') | chrome/browser/extensions/extension_shelf_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698