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/browser_event_router.h" | 7 #include "chrome/browser/extensions/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" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 void ExtensionToolbarModel::AddExtension(const Extension* extension, | 193 void ExtensionToolbarModel::AddExtension(const Extension* extension, |
194 ExtensionList* list) { | 194 ExtensionList* list) { |
195 // We only care about extensions with browser actions. | 195 // We only care about extensions with browser actions. |
196 if (!extension->browser_action()) | 196 if (!extension->browser_action()) |
197 return; | 197 return; |
198 | 198 |
199 if (extension->id() == last_extension_removed_ && | 199 if (extension->id() == last_extension_removed_ && |
200 last_extension_removed_index_ < list->size()) { | 200 last_extension_removed_index_ < list->size()) { |
201 list->insert(list->begin() + last_extension_removed_index_, | 201 list->insert(list->begin() + last_extension_removed_index_, |
202 make_scoped_refptr(extension)); | 202 make_scoped_refptr(extension)); |
203 FOR_EACH_OBSERVER(Observer, observers_, | 203 // TODO: figure out the right long term solution. |
204 BrowserActionAdded(extension, last_extension_removed_index_)); | 204 if (list == &toolbar_items_) { |
| 205 FOR_EACH_OBSERVER(Observer, observers_, |
| 206 BrowserActionAdded(extension, last_extension_removed_index_)); |
| 207 } |
205 } else { | 208 } else { |
206 list->push_back(make_scoped_refptr(extension)); | 209 list->push_back(make_scoped_refptr(extension)); |
207 FOR_EACH_OBSERVER(Observer, observers_, | 210 // TODO: figure out the right long term solution. |
208 BrowserActionAdded(extension, list->size() - 1)); | 211 if (list == &toolbar_items_) { |
| 212 FOR_EACH_OBSERVER(Observer, observers_, |
| 213 BrowserActionAdded(extension, list->size() - 1)); |
| 214 } |
209 } | 215 } |
210 | 216 |
211 last_extension_removed_ = ""; | 217 last_extension_removed_ = ""; |
212 last_extension_removed_index_ = -1; | 218 last_extension_removed_index_ = -1; |
213 | 219 |
214 UpdatePrefs(); | 220 UpdatePrefs(); |
215 } | 221 } |
216 | 222 |
217 void ExtensionToolbarModel::RemoveExtension(const Extension* extension, | 223 void ExtensionToolbarModel::RemoveExtension(const Extension* extension, |
218 ExtensionList* list) { | 224 ExtensionList* list) { |
219 ExtensionList::iterator pos = | 225 ExtensionList::iterator pos = |
220 std::find(list->begin(), list->end(), extension); | 226 std::find(list->begin(), list->end(), extension); |
221 if (pos == list->end()) | 227 if (pos == list->end()) |
222 return; | 228 return; |
223 | 229 |
224 last_extension_removed_ = extension->id(); | 230 last_extension_removed_ = extension->id(); |
225 last_extension_removed_index_ = pos - list->begin(); | 231 last_extension_removed_index_ = pos - list->begin(); |
226 | 232 |
227 list->erase(pos); | 233 list->erase(pos); |
228 FOR_EACH_OBSERVER(Observer, observers_, | 234 // TODO: figure out the right long term solution. |
229 BrowserActionRemoved(extension)); | 235 if (list == &toolbar_items_) { |
| 236 FOR_EACH_OBSERVER(Observer, observers_, |
| 237 BrowserActionRemoved(extension)); |
| 238 } |
230 | 239 |
231 UpdatePrefs(); | 240 UpdatePrefs(); |
232 } | 241 } |
233 | 242 |
234 extensions::ExtensionList* ExtensionToolbarModel::FindListWithExtension( | 243 extensions::ExtensionList* ExtensionToolbarModel::FindListWithExtension( |
235 const Extension* extension) { | 244 const Extension* extension) { |
236 if (IsInExtensionList(extension, toolbar_items_)) | 245 if (IsInExtensionList(extension, toolbar_items_)) |
237 return &toolbar_items_; | 246 return &toolbar_items_; |
238 return IsInExtensionList(extension, action_box_menu_items_) ? | 247 return IsInExtensionList(extension, action_box_menu_items_) ? |
239 &action_box_menu_items_ : NULL; | 248 &action_box_menu_items_ : NULL; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 for (ExtensionList::iterator iter = toolbar_items_.begin(); | 398 for (ExtensionList::iterator iter = toolbar_items_.begin(); |
390 iter != toolbar_items_.end(); | 399 iter != toolbar_items_.end(); |
391 ++iter, ++i) { | 400 ++iter, ++i) { |
392 if (original_index == i) | 401 if (original_index == i) |
393 break; | 402 break; |
394 if (service_->IsIncognitoEnabled((*iter)->id())) | 403 if (service_->IsIncognitoEnabled((*iter)->id())) |
395 ++incognito_index; | 404 ++incognito_index; |
396 } | 405 } |
397 return incognito_index; | 406 return incognito_index; |
398 } | 407 } |
OLD | NEW |