| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 DCHECK_EQ(NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, type); | 204 DCHECK_EQ(NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, type); |
| 205 const Extension* extension = | 205 const Extension* extension = |
| 206 ExtensionRegistry::Get(profile_)->GetExtensionById( | 206 ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 207 *content::Details<const std::string>(details).ptr(), | 207 *content::Details<const std::string>(details).ptr(), |
| 208 ExtensionRegistry::EVERYTHING); | 208 ExtensionRegistry::EVERYTHING); |
| 209 | 209 |
| 210 bool visible = ExtensionActionAPI::GetBrowserActionVisibility( | 210 bool visible = ExtensionActionAPI::GetBrowserActionVisibility( |
| 211 extension_prefs_, extension->id()); | 211 extension_prefs_, extension->id()); |
| 212 // Hiding works differently with the new and old toolbars. | 212 // Hiding works differently with the new and old toolbars. |
| 213 if (include_all_extensions_) { | 213 if (include_all_extensions_) { |
| 214 // It's possible that we haven't added this extension yet, if its |
| 215 // visibility was adjusted in the course of its initialization. |
| 216 if (std::find(toolbar_items_.begin(), toolbar_items_.end(), extension) == |
| 217 toolbar_items_.end()) |
| 218 return; |
| 219 |
| 214 int new_size = 0; | 220 int new_size = 0; |
| 215 int new_index = 0; | 221 int new_index = 0; |
| 216 if (visible) { | 222 if (visible) { |
| 217 // If this action used to be hidden, we can't possibly be showing all. | 223 // If this action used to be hidden, we can't possibly be showing all. |
| 218 DCHECK_NE(-1, visible_icon_count_); | 224 DCHECK_NE(-1, visible_icon_count_); |
| 219 // Grow the bar by one and move the extension to the end of the visibles. | 225 // Grow the bar by one and move the extension to the end of the visibles. |
| 220 new_size = visible_icon_count_ + 1; | 226 new_size = visible_icon_count_ + 1; |
| 221 new_index = new_size - 1; | 227 new_index = new_size - 1; |
| 222 } else { | 228 } else { |
| 223 // If we're hiding one, we must be showing at least one. | 229 // If we're hiding one, we must be showing at least one. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 354 } |
| 349 } | 355 } |
| 350 } | 356 } |
| 351 | 357 |
| 352 void ExtensionToolbarModel::RemoveExtension(const Extension* extension) { | 358 void ExtensionToolbarModel::RemoveExtension(const Extension* extension) { |
| 353 ExtensionList::iterator pos = | 359 ExtensionList::iterator pos = |
| 354 std::find(toolbar_items_.begin(), toolbar_items_.end(), extension); | 360 std::find(toolbar_items_.begin(), toolbar_items_.end(), extension); |
| 355 if (pos == toolbar_items_.end()) | 361 if (pos == toolbar_items_.end()) |
| 356 return; | 362 return; |
| 357 | 363 |
| 364 // If our visible count is set to the current size, we need to decrement it. |
| 365 if (visible_icon_count_ == static_cast<int>(toolbar_items_.size())) |
| 366 SetVisibleIconCount(toolbar_items_.size() - 1); |
| 367 |
| 358 toolbar_items_.erase(pos); | 368 toolbar_items_.erase(pos); |
| 359 | 369 |
| 360 // If we're in highlight mode, we also have to remove the extension from | 370 // If we're in highlight mode, we also have to remove the extension from |
| 361 // the highlighted list. | 371 // the highlighted list. |
| 362 if (is_highlighting_) { | 372 if (is_highlighting_) { |
| 363 pos = std::find(highlighted_items_.begin(), | 373 pos = std::find(highlighted_items_.begin(), |
| 364 highlighted_items_.end(), | 374 highlighted_items_.end(), |
| 365 extension); | 375 extension); |
| 366 if (pos != highlighted_items_.end()) { | 376 if (pos != highlighted_items_.end()) { |
| 367 highlighted_items_.erase(pos); | 377 highlighted_items_.erase(pos); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 if (is_highlighting_) { | 682 if (is_highlighting_) { |
| 673 highlighted_items_.clear(); | 683 highlighted_items_.clear(); |
| 674 is_highlighting_ = false; | 684 is_highlighting_ = false; |
| 675 if (old_visible_icon_count_ != visible_icon_count_) | 685 if (old_visible_icon_count_ != visible_icon_count_) |
| 676 SetVisibleIconCount(old_visible_icon_count_); | 686 SetVisibleIconCount(old_visible_icon_count_); |
| 677 FOR_EACH_OBSERVER(Observer, observers_, ToolbarHighlightModeChanged(false)); | 687 FOR_EACH_OBSERVER(Observer, observers_, ToolbarHighlightModeChanged(false)); |
| 678 } | 688 } |
| 679 } | 689 } |
| 680 | 690 |
| 681 } // namespace extensions | 691 } // namespace extensions |
| OLD | NEW |