Chromium Code Reviews| 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/extensions/extension_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" | 11 #include "chrome/browser/sessions/session_tab_helper.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 14 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 17 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 17 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 18 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 18 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 19 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 20 #include "chrome/common/pref_names.h" | |
| 20 #include "components/crx_file/id_util.h" | 21 #include "components/crx_file/id_util.h" |
| 21 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/browser/runtime_data.h" | 23 #include "extensions/browser/runtime_data.h" |
| 23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 24 #include "extensions/common/feature_switch.h" | 25 #include "extensions/common/feature_switch.h" |
| 25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 else if (drag_type == DRAG_TO_MAIN) | 661 else if (drag_type == DRAG_TO_MAIN) |
| 661 delta = 1; | 662 delta = 1; |
| 662 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), | 663 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), |
| 663 dropped_index); | 664 dropped_index); |
| 664 if (delta) | 665 if (delta) |
| 665 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); | 666 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); |
| 666 } | 667 } |
| 667 } | 668 } |
| 668 | 669 |
| 669 bool ToolbarActionsBar::ShouldShowInfoBubble() { | 670 bool ToolbarActionsBar::ShouldShowInfoBubble() { |
| 670 return false; | 671 // If the redesign isn't running, or the user has already acknowledged it, |
| 672 // we don't show the bubble. | |
| 673 PrefService* prefs = browser_->profile()->GetPrefs(); | |
| 674 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled() || | |
| 675 (prefs->HasPrefPath(prefs::kToolbarIconSurfacingBubbleAcknowledged) && | |
| 676 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged))) | |
| 677 return false; | |
| 678 | |
| 679 // We don't show more than once per day. | |
| 680 if (prefs->HasPrefPath(prefs::kToolbarIconSurfacingBubbleLastShowTime)) { | |
| 681 base::Time last_shown_time = base::Time::FromInternalValue( | |
| 682 prefs->GetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime)); | |
| 683 if (base::Time::Now() - last_shown_time < base::TimeDelta::FromDays(1)) | |
| 684 return false; | |
| 685 } | |
| 686 | |
| 687 if (!model_->RedesignIsShowingNewIcons()) { | |
| 688 // We only show the bubble if there are any new icons present - otherwise, | |
| 689 // the user won't see anything different. | |
| 690 browser_->profile()->GetPrefs()->SetBoolean( | |
| 691 prefs::kToolbarIconSurfacingBubbleAcknowledged, true); | |
| 692 return false; | |
| 693 } | |
| 694 | |
| 695 return true; | |
| 671 } | 696 } |
| 672 | 697 |
| 673 void ToolbarActionsBar::OnToolbarExtensionAdded( | 698 void ToolbarActionsBar::OnToolbarExtensionAdded( |
| 674 const extensions::Extension* extension, | 699 const extensions::Extension* extension, |
| 675 int index) { | 700 int index) { |
| 676 DCHECK(GetActionForId(extension->id()) == nullptr) << | 701 DCHECK(GetActionForId(extension->id()) == nullptr) << |
| 677 "Asked to add a toolbar action view for an extension that already exists"; | 702 "Asked to add a toolbar action view for an extension that already exists"; |
| 678 | 703 |
| 679 toolbar_actions_.insert( | 704 toolbar_actions_.insert( |
| 680 toolbar_actions_.begin() + index, | 705 toolbar_actions_.begin() + index, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 826 // We shouldn't have any actions before the model is initialized. | 851 // We shouldn't have any actions before the model is initialized. |
| 827 DCHECK(toolbar_actions_.empty()); | 852 DCHECK(toolbar_actions_.empty()); |
| 828 CreateActions(); | 853 CreateActions(); |
| 829 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 854 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 830 } | 855 } |
| 831 | 856 |
| 832 Browser* ToolbarActionsBar::GetBrowser() { | 857 Browser* ToolbarActionsBar::GetBrowser() { |
| 833 return browser_; | 858 return browser_; |
| 834 } | 859 } |
| 835 | 860 |
| 861 void ToolbarActionsBar::OnToolbarActionsBarBubbleShown() { | |
| 862 // Record the last time the bubble was shown. | |
| 863 browser_->profile()->GetPrefs()->SetInt64( | |
| 864 prefs::kToolbarIconSurfacingBubbleLastShowTime, | |
| 865 base::Time::Now().ToInternalValue()); | |
| 866 } | |
| 867 | |
| 836 void ToolbarActionsBar::OnToolbarActionsBarBubbleClosed(CloseAction action) { | 868 void ToolbarActionsBar::OnToolbarActionsBarBubbleClosed(CloseAction action) { |
| 869 if (action == ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED) { | |
| 870 browser_->profile()->GetPrefs()->SetBoolean( | |
| 871 prefs::kToolbarIconSurfacingBubbleAcknowledged, true); | |
|
Finnur
2015/03/13 10:54:53
Once you set this to true, there's no longer a nee
Devlin
2015/03/13 16:33:28
Good call; we can definitely clear the pref.
I do
| |
| 872 } | |
| 837 } | 873 } |
| 838 | 874 |
| 839 void ToolbarActionsBar::ReorderActions() { | 875 void ToolbarActionsBar::ReorderActions() { |
| 840 if (toolbar_actions_.empty()) | 876 if (toolbar_actions_.empty()) |
| 841 return; | 877 return; |
| 842 | 878 |
| 843 // First, reset the order to that of the model. | 879 // First, reset the order to that of the model. |
| 844 auto compare = [](ToolbarActionViewController* const& action, | 880 auto compare = [](ToolbarActionViewController* const& action, |
| 845 const scoped_refptr<const extensions::Extension>& ext) { | 881 const scoped_refptr<const extensions::Extension>& ext) { |
| 846 return action->GetId() == ext->id(); | 882 return action->GetId() == ext->id(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 for (ToolbarActionViewController* action : toolbar_actions_) { | 933 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 898 if (action->GetId() == id) | 934 if (action->GetId() == id) |
| 899 return action; | 935 return action; |
| 900 } | 936 } |
| 901 return nullptr; | 937 return nullptr; |
| 902 } | 938 } |
| 903 | 939 |
| 904 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 940 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 905 return browser_->tab_strip_model()->GetActiveWebContents(); | 941 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 906 } | 942 } |
| OLD | NEW |