| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "chrome/browser/extensions/extension_action_manager.h" | 8 #include "chrome/browser/extensions/extension_action_manager.h" |
| 9 #include "chrome/browser/extensions/extension_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/sessions/session_tab_helper.h" | 11 #include "chrome/browser/sessions/session_tab_helper.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 14 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 16 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 17 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 17 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 18 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 18 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 browser_, | 683 browser_, |
| 683 extensions::ExtensionActionManager::Get(browser_->profile())-> | 684 extensions::ExtensionActionManager::Get(browser_->profile())-> |
| 684 GetExtensionAction(*extension))); | 685 GetExtensionAction(*extension))); |
| 685 | 686 |
| 686 delegate_->AddViewForAction(toolbar_actions_[index], index); | 687 delegate_->AddViewForAction(toolbar_actions_[index], index); |
| 687 | 688 |
| 688 // If we are still initializing the container, don't bother animating. | 689 // If we are still initializing the container, don't bother animating. |
| 689 if (!model_->extensions_initialized()) | 690 if (!model_->extensions_initialized()) |
| 690 return; | 691 return; |
| 691 | 692 |
| 692 // If this is just an upgrade, then don't worry about resizing. | 693 // We may need to resize (e.g. to show the new icon, or the chevron). We don't |
| 693 if (extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> | 694 // need to check if the extension is upgrading here, because ResizeDelegate() |
| 694 IsBeingUpgraded(extension->id())) { | 695 // checks to see if the container is already the proper size, and because |
| 695 delegate_->Redraw(false); | 696 // if the action is newly incognito enabled, even though it's a reload, it's |
| 696 } else { | 697 // a new extension to this toolbar. |
| 697 // We may need to resize (e.g. to show the new icon, or the chevron). | 698 // We suppress the chevron during animation because, if we're expanding to |
| 698 // We suppress the chevron during animation because, if we're expanding to | 699 // show a new icon, we don't want to have the chevron visible only for the |
| 699 // show a new icon, we don't want to have the chevron visible only for the | 700 // duration of the animation. |
| 700 // duration of the animation. | 701 ResizeDelegate(gfx::Tween::LINEAR, true); |
| 701 ResizeDelegate(gfx::Tween::LINEAR, true); | |
| 702 } | |
| 703 } | 702 } |
| 704 | 703 |
| 705 void ToolbarActionsBar::ToolbarExtensionRemoved( | 704 void ToolbarActionsBar::ToolbarExtensionRemoved( |
| 706 const extensions::Extension* extension) { | 705 const extensions::Extension* extension) { |
| 707 ToolbarActions::iterator iter = toolbar_actions_.begin(); | 706 ToolbarActions::iterator iter = toolbar_actions_.begin(); |
| 708 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) | 707 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) |
| 709 ++iter; | 708 ++iter; |
| 710 | 709 |
| 711 if (iter == toolbar_actions_.end()) | 710 if (iter == toolbar_actions_.end()) |
| 712 return; | 711 return; |
| 713 | 712 |
| 714 delegate_->RemoveViewForAction(*iter); | 713 delegate_->RemoveViewForAction(*iter); |
| 715 if (tab_order_helper_) | 714 if (tab_order_helper_) |
| 716 tab_order_helper_->ActionRemoved(*iter); | 715 tab_order_helper_->ActionRemoved(*iter); |
| 717 toolbar_actions_.erase(iter); | 716 toolbar_actions_.erase(iter); |
| 718 | 717 |
| 719 // If the extension is being upgraded we don't want the bar to shrink | 718 // If the extension is being upgraded we don't want the bar to shrink |
| 720 // because the icon is just going to get re-added to the same location. | 719 // because the icon is just going to get re-added to the same location. |
| 720 // There is an exception if this is an off-the-record profile, and the |
| 721 // extension is no longer incognito-enabled. |
| 721 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> | 722 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> |
| 722 IsBeingUpgraded(extension->id())) { | 723 IsBeingUpgraded(extension->id()) || |
| 724 (browser_->profile()->IsOffTheRecord() && |
| 725 !extensions::util::IsIncognitoEnabled(extension->id(), |
| 726 browser_->profile()))) { |
| 723 if (toolbar_actions_.size() > model_->visible_icon_count()) { | 727 if (toolbar_actions_.size() > model_->visible_icon_count()) { |
| 724 // If we have more icons than we can show, then we must not be changing | 728 // If we have more icons than we can show, then we must not be changing |
| 725 // the container size (since we either removed an icon from the main | 729 // the container size (since we either removed an icon from the main |
| 726 // area and one from the overflow list will have shifted in, or we | 730 // area and one from the overflow list will have shifted in, or we |
| 727 // removed an entry directly from the overflow list). | 731 // removed an entry directly from the overflow list). |
| 728 delegate_->Redraw(false); | 732 delegate_->Redraw(false); |
| 729 } else { | 733 } else { |
| 730 delegate_->SetChevronVisibility(false); | 734 delegate_->SetChevronVisibility(false); |
| 731 // Either we went from overflow to no-overflow, or we shrunk the no- | 735 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 732 // overflow container by 1. Either way the size changed, so animate. | 736 // overflow container by 1. Either way the size changed, so animate. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 for (ToolbarActionViewController* action : toolbar_actions_) { | 864 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 861 if (action->GetId() == id) | 865 if (action->GetId() == id) |
| 862 return action; | 866 return action; |
| 863 } | 867 } |
| 864 return nullptr; | 868 return nullptr; |
| 865 } | 869 } |
| 866 | 870 |
| 867 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 871 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 868 return browser_->tab_strip_model()->GetActiveWebContents(); | 872 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 869 } | 873 } |
| OLD | NEW |