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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_model.cc

Issue 2155293002: Show the Cast toolbar icon ephemerally when Cast is in use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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) 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/ui/toolbar/toolbar_actions_model.h" 5 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 320 }
321 321
322 return extension_action_manager_->GetBrowserAction(*extension) && 322 return extension_action_manager_->GetBrowserAction(*extension) &&
323 extension_action_api_->GetBrowserActionVisibility(extension->id()); 323 extension_action_api_->GetBrowserActionVisibility(extension->id());
324 } 324 }
325 325
326 void ToolbarActionsModel::AddExtension(const extensions::Extension* extension) { 326 void ToolbarActionsModel::AddExtension(const extensions::Extension* extension) {
327 if (!ShouldAddExtension(extension)) 327 if (!ShouldAddExtension(extension))
328 return; 328 return;
329 329
330 AddItem(ToolbarItem(extension->id(), EXTENSION_ACTION), 330 AddItem(ToolbarItem(extension->id(), EXTENSION_ACTION));
331 extensions::Manifest::IsComponentLocation(extension->location()));
332 } 331 }
333 332
334 void ToolbarActionsModel::AddItem(const ToolbarItem& item, bool is_component) { 333 void ToolbarActionsModel::AddItem(const ToolbarItem& item) {
335 // We only use AddItem() once the system is initialized. 334 // We only use AddItem() once the system is initialized.
336 DCHECK(actions_initialized_); 335 DCHECK(actions_initialized_);
337 336
338 // See if we have a last known good position for this extension. 337 // See if we have a last known good position for this extension.
339 bool is_new_extension = 338 bool is_new_extension =
340 !ContainsValue(last_known_positions_, item.id); 339 !ContainsValue(last_known_positions_, item.id);
341 340
342 // New extensions go at the right (end) of the visible extensions. Other 341 // New extensions go at the right (end) of the visible extensions. Other
343 // extensions go at their previous position. 342 // extensions go at their previous position.
344 size_t new_index = 0; 343 size_t new_index = 0;
345 if (is_new_extension) { 344 if (is_new_extension) {
346 new_index = is_component ? 0 : visible_icon_count(); 345 new_index = visible_icon_count();
347 // For the last-known position, we use the index of the extension that is 346 // For the last-known position, we use the index of the extension that is
348 // just before this extension, plus one. (Note that this isn't the same 347 // just before this extension, plus one. (Note that this isn't the same
349 // as new_index + 1, because last_known_positions_ can include disabled 348 // as new_index + 1, because last_known_positions_ can include disabled
350 // extensions.) 349 // extensions.)
351 int new_last_known_index = 350 int new_last_known_index =
352 new_index == 0 ? 0 : std::find(last_known_positions_.begin(), 351 new_index == 0 ? 0 : std::find(last_known_positions_.begin(),
353 last_known_positions_.end(), 352 last_known_positions_.end(),
354 toolbar_items_[new_index - 1].id) - 353 toolbar_items_[new_index - 1].id) -
355 last_known_positions_.begin() + 1; 354 last_known_positions_.begin() + 1;
356 // In theory, the extension before this one should always 355 // In theory, the extension before this one should always
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 bool ToolbarActionsModel::HasComponentAction( 625 bool ToolbarActionsModel::HasComponentAction(
627 const std::string& action_id) const { 626 const std::string& action_id) const {
628 DCHECK(use_redesign_); 627 DCHECK(use_redesign_);
629 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION)); 628 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION));
630 } 629 }
631 630
632 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) { 631 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) {
633 DCHECK(use_redesign_); 632 DCHECK(use_redesign_);
634 ToolbarItem component_item(action_id, COMPONENT_ACTION); 633 ToolbarItem component_item(action_id, COMPONENT_ACTION);
635 DCHECK(!HasItem(component_item)); 634 DCHECK(!HasItem(component_item));
636 AddItem(component_item, true); 635 AddItem(component_item);
637 } 636 }
638 637
639 void ToolbarActionsModel::RemoveComponentAction(const std::string& action_id) { 638 void ToolbarActionsModel::RemoveComponentAction(const std::string& action_id) {
640 DCHECK(use_redesign_); 639 DCHECK(use_redesign_);
641 ToolbarItem component_item(action_id, COMPONENT_ACTION); 640 ToolbarItem component_item(action_id, COMPONENT_ACTION);
642 DCHECK(HasItem(component_item)); 641 DCHECK(HasItem(component_item));
643 RemoveItem(component_item); 642 RemoveItem(component_item);
644 RemovePref(component_item); 643 RemovePref(component_item);
645 } 644 }
646 645
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 prefs_->GetInteger(extensions::pref_names::kToolbarSize); 837 prefs_->GetInteger(extensions::pref_names::kToolbarSize);
839 if (saved_icon_count != visible_icon_count_) 838 if (saved_icon_count != visible_icon_count_)
840 SetVisibleIconCount(saved_icon_count); 839 SetVisibleIconCount(saved_icon_count);
841 } 840 }
842 } 841 }
843 842
844 const extensions::Extension* ToolbarActionsModel::GetExtensionById( 843 const extensions::Extension* ToolbarActionsModel::GetExtensionById(
845 const std::string& id) const { 844 const std::string& id) const {
846 return extension_registry_->enabled_extensions().GetByID(id); 845 return extension_registry_->enabled_extensions().GetByID(id);
847 } 846 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698