OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/extension_toolbar_model.h" | 5 #include "chrome/browser/extensions/extension_toolbar_model.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_browser_event_router.h" | 7 #include "chrome/browser/extensions/extension_browser_event_router.h" |
8 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_switch_utils.h" | |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 | 24 |
24 using extensions::Extension; | 25 using extensions::Extension; |
25 using extensions::ExtensionList; | 26 using extensions::ExtensionList; |
26 | 27 |
27 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) | 28 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) |
28 : service_(service), | 29 : service_(service), |
(...skipping 25 matching lines...) Expand all Loading... | |
54 observers_.RemoveObserver(observer); | 55 observers_.RemoveObserver(observer); |
55 } | 56 } |
56 | 57 |
57 void ExtensionToolbarModel::MoveBrowserAction(const Extension* extension, | 58 void ExtensionToolbarModel::MoveBrowserAction(const Extension* extension, |
58 int index) { | 59 int index) { |
59 ExtensionList::iterator pos = std::find(begin(), end(), extension); | 60 ExtensionList::iterator pos = std::find(begin(), end(), extension); |
60 if (pos == end()) { | 61 if (pos == end()) { |
61 NOTREACHED(); | 62 NOTREACHED(); |
62 return; | 63 return; |
63 } | 64 } |
64 toolitems_.erase(pos); | 65 toolbar_items_.erase(pos); |
65 | 66 |
66 int i = 0; | 67 int i = 0; |
67 bool inserted = false; | 68 bool inserted = false; |
68 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter, ++i) { | 69 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter, ++i) { |
69 if (i == index) { | 70 if (i == index) { |
70 toolitems_.insert(iter, make_scoped_refptr(extension)); | 71 toolbar_items_.insert(iter, make_scoped_refptr(extension)); |
71 inserted = true; | 72 inserted = true; |
72 break; | 73 break; |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 if (!inserted) { | 77 if (!inserted) { |
77 DCHECK_EQ(index, static_cast<int>(toolitems_.size())); | 78 DCHECK_EQ(index, static_cast<int>(toolbar_items_.size())); |
78 index = toolitems_.size(); | 79 index = toolbar_items_.size(); |
79 | 80 |
80 toolitems_.push_back(make_scoped_refptr(extension)); | 81 toolbar_items_.push_back(make_scoped_refptr(extension)); |
81 } | 82 } |
82 | 83 |
83 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); | 84 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
84 | 85 |
85 UpdatePrefs(); | 86 UpdatePrefs(); |
86 } | 87 } |
87 | 88 |
88 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( | 89 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
89 const Extension* extension, | 90 const Extension* extension, |
90 Browser* browser, | 91 Browser* browser, |
(...skipping 29 matching lines...) Expand all Loading... | |
120 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 121 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
121 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; | 122 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; |
122 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); | 123 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); |
123 } | 124 } |
124 | 125 |
125 void ExtensionToolbarModel::Observe( | 126 void ExtensionToolbarModel::Observe( |
126 int type, | 127 int type, |
127 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
128 const content::NotificationDetails& details) { | 129 const content::NotificationDetails& details) { |
129 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { | 130 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { |
130 InitializeExtensionList(); | 131 InitializeExtensionLists(); |
131 return; | 132 return; |
132 } | 133 } |
133 | 134 |
134 if (!service_->is_ready()) | 135 if (!service_->is_ready()) |
135 return; | 136 return; |
136 | 137 |
137 const Extension* extension = NULL; | 138 const Extension* extension = NULL; |
138 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 139 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
139 extension = content::Details<extensions::UnloadedExtensionInfo>( | 140 extension = content::Details<extensions::UnloadedExtensionInfo>( |
140 details)->extension; | 141 details)->extension; |
141 } else { | 142 } else { |
142 extension = content::Details<const Extension>(details).ptr(); | 143 extension = content::Details<const Extension>(details).ptr(); |
143 } | 144 } |
145 bool found_in_toolbar = FindInExtensionList(extension, toolbar_items_); | |
msw
2012/07/24 23:41:55
nit: Instead of using two bools here, use a single
yefimt
2012/07/25 21:09:21
I believe it is much more readable as it is. Using
msw
2012/07/25 23:02:03
I disagree, it'd be: RemoveExtension(extension, co
yefimt
2012/07/31 00:10:11
Done.
| |
146 bool found_in_action_box_menu = | |
147 FindInExtensionList(extension, action_box_menu_items_); | |
144 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 148 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
145 // We don't want to add the same extension twice. It may have already been | 149 // We don't want to add the same extension twice. It may have already been |
146 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | 150 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user |
147 // hides the browser action and then disables and enables the extension. | 151 // hides the browser action and then disables and enables the extension. |
148 for (size_t i = 0; i < toolitems_.size(); i++) { | 152 if (found_in_toolbar || found_in_action_box_menu) |
149 if (toolitems_[i].get() == extension) | 153 return; // Already exists. |
msw
2012/07/24 23:41:55
nit: remoove inline comment, it's explained well a
yefimt
2012/07/25 21:09:21
Done.
| |
150 return; // Already exists. | 154 if (extensions::switch_utils::IsActionBoxEnabled()) |
151 } | 155 AddExtension(extension, &action_box_menu_items_); |
152 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) | 156 else |
153 AddExtension(extension); | 157 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
msw
2012/07/24 23:41:55
nit: fit on line above as "else if"
yefimt
2012/07/25 21:09:21
Done.
| |
158 AddExtension(extension, &toolbar_items_); | |
154 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 159 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
155 RemoveExtension(extension); | 160 if (found_in_toolbar) |
161 RemoveExtension(extension, &toolbar_items_); | |
162 if (found_in_action_box_menu) | |
163 RemoveExtension(extension, &action_box_menu_items_); | |
156 } else if ( | 164 } else if ( |
157 type == | 165 type == |
158 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { | 166 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { |
159 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) | 167 if (extensions::switch_utils::IsActionBoxEnabled()) { |
160 AddExtension(extension); | 168 // TODO: Implement this when implementing drag & drop for action box menu. |
msw
2012/07/24 23:41:55
nit: use TODO(ldap): format.
yefimt
2012/07/25 21:09:21
Done.
| |
161 else | 169 } else { |
162 RemoveExtension(extension); | 170 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
171 AddExtension(extension, &toolbar_items_); | |
172 else | |
173 RemoveExtension(extension, &toolbar_items_); | |
174 } | |
163 } else { | 175 } else { |
164 NOTREACHED() << "Received unexpected notification"; | 176 NOTREACHED() << "Received unexpected notification"; |
165 } | 177 } |
166 } | 178 } |
167 | 179 |
168 void ExtensionToolbarModel::AddExtension(const Extension* extension) { | 180 void ExtensionToolbarModel::AddExtension(const Extension* extension, |
181 ExtensionList* result_list) { | |
msw
2012/07/24 23:41:55
nit: Name |list| instead of |result_list| and simi
yefimt
2012/07/25 21:09:21
Done.
| |
169 // We only care about extensions with browser actions. | 182 // We only care about extensions with browser actions. |
170 if (!extension->browser_action()) | 183 if (!extension->browser_action()) |
171 return; | 184 return; |
172 | 185 |
173 if (extension->id() == last_extension_removed_ && | 186 if (extension->id() == last_extension_removed_ && |
174 last_extension_removed_index_ < toolitems_.size()) { | 187 last_extension_removed_index_ < result_list->size()) { |
175 toolitems_.insert(begin() + last_extension_removed_index_, | 188 result_list->insert(result_list->begin() + last_extension_removed_index_, |
176 make_scoped_refptr(extension)); | 189 make_scoped_refptr(extension)); |
177 FOR_EACH_OBSERVER(Observer, observers_, | 190 FOR_EACH_OBSERVER(Observer, observers_, |
178 BrowserActionAdded(extension, last_extension_removed_index_)); | 191 BrowserActionAdded(extension, last_extension_removed_index_)); |
179 } else { | 192 } else { |
180 toolitems_.push_back(make_scoped_refptr(extension)); | 193 result_list->push_back(make_scoped_refptr(extension)); |
181 FOR_EACH_OBSERVER(Observer, observers_, | 194 FOR_EACH_OBSERVER(Observer, observers_, |
182 BrowserActionAdded(extension, toolitems_.size() - 1)); | 195 BrowserActionAdded(extension, result_list->size() - 1)); |
183 } | 196 } |
184 | 197 |
185 last_extension_removed_ = ""; | 198 last_extension_removed_ = ""; |
186 last_extension_removed_index_ = -1; | 199 last_extension_removed_index_ = -1; |
187 | 200 |
188 UpdatePrefs(); | 201 UpdatePrefs(); |
189 } | 202 } |
190 | 203 |
191 void ExtensionToolbarModel::RemoveExtension(const Extension* extension) { | 204 void ExtensionToolbarModel::RemoveExtension(const Extension* extension, |
192 ExtensionList::iterator pos = std::find(begin(), end(), extension); | 205 ExtensionList* result_list) { |
206 ExtensionList::iterator pos = | |
207 std::find(result_list->begin(), result_list->end(), extension); | |
193 if (pos == end()) { | 208 if (pos == end()) { |
194 return; | 209 return; |
195 } | 210 } |
196 | 211 |
197 last_extension_removed_ = extension->id(); | 212 last_extension_removed_ = extension->id(); |
198 last_extension_removed_index_ = pos - begin(); | 213 last_extension_removed_index_ = pos - result_list->begin(); |
199 | 214 |
200 toolitems_.erase(pos); | 215 result_list->erase(pos); |
201 FOR_EACH_OBSERVER(Observer, observers_, | 216 FOR_EACH_OBSERVER(Observer, observers_, |
202 BrowserActionRemoved(extension)); | 217 BrowserActionRemoved(extension)); |
203 | 218 |
204 UpdatePrefs(); | 219 UpdatePrefs(); |
205 } | 220 } |
206 | 221 |
207 // Combine the currently enabled extensions that have browser actions (which | 222 // Combine the currently enabled extensions that have browser actions (which |
208 // we get from the ExtensionService) with the ordering we get from the | 223 // we get from the ExtensionService) with the ordering we get from the |
209 // pref service. For robustness we use a somewhat inefficient process: | 224 // pref service. For robustness we use a somewhat inefficient process: |
210 // 1. Create a vector of extensions sorted by their pref values. This vector may | 225 // 1. Create a vector of extensions sorted by their pref values. This vector may |
211 // have holes. | 226 // have holes. |
212 // 2. Create a vector of extensions that did not have a pref value. | 227 // 2. Create a vector of extensions that did not have a pref value. |
213 // 3. Remove holes from the sorted vector and append the unsorted vector. | 228 // 3. Remove holes from the sorted vector and append the unsorted vector. |
214 void ExtensionToolbarModel::InitializeExtensionList() { | 229 void ExtensionToolbarModel::InitializeExtensionLists() { |
215 DCHECK(service_->is_ready()); | 230 DCHECK(service_->is_ready()); |
216 | 231 |
217 std::vector<std::string> pref_order = service_->extension_prefs()-> | 232 if (extensions::switch_utils::IsActionBoxEnabled()) |
218 GetToolbarOrder(); | 233 PopulateForActionBoxMode(); |
234 else | |
235 PopulateForNonActionBoxMode(); | |
236 | |
237 UpdatePrefs(); | |
238 | |
239 extensions_initialized_ = true; | |
240 FOR_EACH_OBSERVER(Observer, observers_, ModelLoaded()); | |
241 } | |
242 | |
243 void ExtensionToolbarModel::PopulateForActionBoxMode() { | |
244 const extensions::ExtensionPrefs::ExtensionIdSet toolbar_order = | |
245 service_->extension_prefs()->GetToolbarOrder(); | |
246 extensions::ExtensionPrefs::ExtensionIdSet action_box_order = | |
247 service_->extension_prefs()->GetActionBoxOrder(); | |
248 | |
249 // Add all browser actions not already in the toolbar or action box | |
250 // to the action box. | |
msw
2012/07/24 23:41:55
nit: explain why the prefs list might miss some ex
yefimt
2012/07/25 21:09:21
I dont think I can, it could be hundreds of reason
msw
2012/07/25 23:02:03
Fair enough, consider at least adding "The prefs l
yefimt
2012/07/31 00:10:11
Done.
| |
251 for (ExtensionSet::const_iterator iter = service_->extensions()->begin(); | |
252 iter != service_->extensions()->end(); ++iter) { | |
253 const Extension* extension = *iter; | |
254 if (!extension->browser_action()) | |
255 continue; | |
256 | |
257 extensions::ExtensionPrefs::ExtensionIdSet::const_iterator toolbar_pos = | |
msw
2012/07/24 23:41:55
nit: continue early if it's in the first list, don
yefimt
2012/07/25 21:09:21
Done.
| |
258 std::find(toolbar_order.begin(), toolbar_order.end(), extension->id()); | |
259 extensions::ExtensionPrefs::ExtensionIdSet::const_iterator action_box_pos = | |
260 std::find(action_box_order.begin(), action_box_order.end(), | |
261 extension->id()); | |
262 if ((toolbar_pos == toolbar_order.end()) && | |
263 (action_box_pos == action_box_order.end())) | |
264 action_box_order.push_back(extension->id()); | |
265 } | |
266 | |
267 FillExtensionList(action_box_order, &action_box_menu_items_); | |
268 FillExtensionList(toolbar_order, &toolbar_items_); | |
269 | |
270 // Inform observers. | |
msw
2012/07/24 23:41:55
nit: Can this be built-in by calling AddExtension
yefimt
2012/07/25 21:09:21
Done.
| |
271 for (size_t i = 0; i < action_box_menu_items_.size(); i++) | |
272 FOR_EACH_OBSERVER(Observer, observers_, | |
273 BrowserActionAdded(action_box_menu_items_[i], i)); | |
274 for (size_t i = 0; i < toolbar_items_.size(); i++) | |
275 FOR_EACH_OBSERVER(Observer, observers_, | |
276 BrowserActionAdded(toolbar_items_[i], i)); | |
277 } | |
278 | |
279 void ExtensionToolbarModel::PopulateForNonActionBoxMode() { | |
280 const extensions::ExtensionPrefs::ExtensionIdSet pref_order = | |
281 service_->extension_prefs()->GetToolbarOrder(); | |
219 // Items that have a pref for their position. | 282 // Items that have a pref for their position. |
220 ExtensionList sorted; | 283 ExtensionList sorted; |
221 sorted.resize(pref_order.size(), NULL); | 284 sorted.resize(pref_order.size(), NULL); |
222 // The items that don't have a pref for their position. | 285 // The items that don't have a pref for their position. |
223 ExtensionList unsorted; | 286 ExtensionList unsorted; |
224 | 287 |
225 // Create the lists. | 288 // Create the lists. |
226 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); | 289 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); |
227 it != service_->extensions()->end(); ++it) { | 290 it != service_->extensions()->end(); ++it) { |
228 const Extension* extension = *it; | 291 const Extension* extension = *it; |
229 if (!extension->browser_action()) | 292 if (!extension->browser_action()) |
230 continue; | 293 continue; |
231 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) | 294 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
232 continue; | 295 continue; |
233 | 296 |
234 std::vector<std::string>::iterator pos = | 297 AddToProperList(extension, pref_order, &sorted, &unsorted); |
235 std::find(pref_order.begin(), pref_order.end(), extension->id()); | |
236 if (pos != pref_order.end()) { | |
237 int index = std::distance(pref_order.begin(), pos); | |
238 sorted[index] = extension; | |
239 } else { | |
240 unsorted.push_back(make_scoped_refptr(extension)); | |
241 } | |
242 } | 298 } |
243 | 299 |
244 // Merge the lists. | 300 // Merge the lists. |
245 toolitems_.reserve(sorted.size() + unsorted.size()); | 301 toolbar_items_.clear(); |
246 for (ExtensionList::iterator iter = sorted.begin(); | 302 toolbar_items_.reserve(sorted.size() + unsorted.size()); |
303 for (ExtensionList::const_iterator iter = sorted.begin(); | |
msw
2012/07/24 23:41:55
nit: use toolbar_items_.insert for |sorted| (like
yefimt
2012/07/25 21:09:21
Some could be NULL and need to be excluded
msw
2012/07/25 23:02:03
Good point! Sorry.
| |
247 iter != sorted.end(); ++iter) { | 304 iter != sorted.end(); ++iter) { |
248 if (*iter != NULL) | 305 if (*iter != NULL) |
249 toolitems_.push_back(*iter); | 306 toolbar_items_.push_back(*iter); |
250 } | 307 } |
251 toolitems_.insert(toolitems_.end(), unsorted.begin(), unsorted.end()); | 308 toolbar_items_.insert(toolbar_items_.end(), unsorted.begin(), |
309 unsorted.end()); | |
252 | 310 |
253 // Inform observers. | 311 // Inform observers. |
254 for (size_t i = 0; i < toolitems_.size(); i++) { | 312 for (size_t i = 0; i < toolbar_items_.size(); i++) { |
255 FOR_EACH_OBSERVER(Observer, observers_, | 313 FOR_EACH_OBSERVER(Observer, observers_, |
256 BrowserActionAdded(toolitems_[i], i)); | 314 BrowserActionAdded(toolbar_items_[i], i)); |
257 } | 315 } |
316 } | |
258 | 317 |
259 UpdatePrefs(); | 318 void ExtensionToolbarModel::AddToProperList(const Extension* extension, |
msw
2012/07/24 23:41:55
nit: I think if args don't fit aligned to inside t
msw
2012/07/24 23:41:55
nit: make this a file-local function in an anon na
yefimt
2012/07/25 21:09:21
I removed it at all, it was used in one place only
| |
319 const extensions::ExtensionPrefs::ExtensionIdSet& order, | |
320 ExtensionList* sorted, | |
321 ExtensionList* unsorted) { | |
322 DCHECK_EQ(order.size(), sorted->size()); | |
323 extensions::ExtensionPrefs::ExtensionIdSet::const_iterator pos = | |
324 std::find(order.begin(), order.end(), extension->id()); | |
325 if (pos != order.end()) | |
326 (*sorted)[pos - order.begin()] = extension; | |
327 else | |
328 unsorted->push_back(make_scoped_refptr(extension)); | |
329 } | |
260 | 330 |
261 extensions_initialized_ = true; | 331 void ExtensionToolbarModel::FillExtensionList( |
262 FOR_EACH_OBSERVER(Observer, observers_, ModelLoaded()); | 332 const extensions::ExtensionPrefs::ExtensionIdSet& order, |
333 ExtensionList* result_list) { | |
334 result_list->clear(); | |
335 result_list->reserve(order.size()); | |
336 for (size_t i = 0; i < order.size(); ++i) { | |
337 const extensions::Extension* extension = | |
msw
2012/07/24 23:41:55
nit: declare a single non-const Extension* outside
yefimt
2012/07/25 21:09:21
GetExtensionById() returns const Extension*, so it
msw
2012/07/25 23:02:03
Fair enough!
| |
338 service_->GetExtensionById(order[i], false); | |
339 if (!extension) | |
msw
2012/07/24 23:41:55
nit: invert NULL check and just perform the single
yefimt
2012/07/25 21:09:21
Done.
| |
340 continue; | |
341 result_list->push_back(extension); | |
msw
2012/07/24 23:41:55
nit: Call AddExtension here instead, and remove th
yefimt
2012/07/25 21:09:21
Done.
| |
342 } | |
263 } | 343 } |
264 | 344 |
345 bool ExtensionToolbarModel::FindInExtensionList( | |
msw
2012/07/24 23:41:55
nit: make this a file-local function in an anon na
yefimt
2012/07/25 21:09:21
Done.
| |
346 const Extension* extension, | |
347 const extensions::ExtensionList& extension_list) { | |
348 for (size_t i = 0; i < extension_list.size(); i++) { | |
349 if (extension_list[i].get() == extension) | |
350 return true; | |
351 } | |
352 return false; | |
353 } | |
354 | |
355 | |
265 void ExtensionToolbarModel::UpdatePrefs() { | 356 void ExtensionToolbarModel::UpdatePrefs() { |
266 if (!service_->extension_prefs()) | 357 if (!service_->extension_prefs()) |
267 return; | 358 return; |
268 | 359 |
269 std::vector<std::string> ids; | 360 extensions::ExtensionPrefs::ExtensionIdSet toolbar_ids; |
270 ids.reserve(toolitems_.size()); | 361 toolbar_ids.reserve(toolbar_items_.size()); |
271 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter) | 362 for (size_t i = 0; i < toolbar_items_.size(); ++i) |
272 ids.push_back((*iter)->id()); | 363 toolbar_ids.push_back(toolbar_items_[i]->id()); |
273 service_->extension_prefs()->SetToolbarOrder(ids); | 364 service_->extension_prefs()->SetToolbarOrder(toolbar_ids); |
274 } | |
275 | 365 |
276 const Extension* ExtensionToolbarModel::GetExtensionByIndex(int index) const { | 366 extensions::ExtensionPrefs::ExtensionIdSet action_box_ids; |
277 return toolitems_[index]; | 367 action_box_ids.reserve(action_box_menu_items_.size()); |
368 for (size_t i = 0; i < action_box_menu_items_.size(); ++i) | |
369 action_box_ids.push_back(action_box_menu_items_[i]->id()); | |
370 service_->extension_prefs()->SetActionBoxOrder(action_box_ids); | |
278 } | 371 } |
279 | 372 |
280 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { | 373 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { |
281 int original_index = 0, i = 0; | 374 int original_index = 0, i = 0; |
282 for (ExtensionList::iterator iter = begin(); iter != end(); | 375 for (ExtensionList::iterator iter = begin(); iter != end(); |
283 ++iter, ++original_index) { | 376 ++iter, ++original_index) { |
284 if (service_->IsIncognitoEnabled((*iter)->id())) { | 377 if (service_->IsIncognitoEnabled((*iter)->id())) { |
285 if (incognito_index == i) | 378 if (incognito_index == i) |
286 break; | 379 break; |
287 ++i; | 380 ++i; |
288 } | 381 } |
289 } | 382 } |
290 return original_index; | 383 return original_index; |
291 } | 384 } |
292 | 385 |
293 int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) { | 386 int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) { |
294 int incognito_index = 0, i = 0; | 387 int incognito_index = 0, i = 0; |
295 for (ExtensionList::iterator iter = begin(); iter != end(); | 388 for (ExtensionList::iterator iter = begin(); iter != end(); |
296 ++iter, ++i) { | 389 ++iter, ++i) { |
297 if (original_index == i) | 390 if (original_index == i) |
298 break; | 391 break; |
299 if (service_->IsIncognitoEnabled((*iter)->id())) | 392 if (service_->IsIncognitoEnabled((*iter)->id())) |
300 ++incognito_index; | 393 ++incognito_index; |
301 } | 394 } |
302 return incognito_index; | 395 return incognito_index; |
303 } | 396 } |
OLD | NEW |