| 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 "base/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
| 9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sessions/session_tab_helper.h" | 12 #include "chrome/browser/sessions/session_tab_helper.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 15 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 18 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 18 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 19 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 20 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 20 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 21 #include "chrome/common/pref_names.h" |
| 21 #include "components/crx_file/id_util.h" | 22 #include "components/crx_file/id_util.h" |
| 23 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 23 #include "extensions/browser/runtime_data.h" | 25 #include "extensions/browser/runtime_data.h" |
| 24 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/feature_switch.h" | 27 #include "extensions/common/feature_switch.h" |
| 26 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // static | 442 // static |
| 441 int ToolbarActionsBar::IconWidth(bool include_padding) { | 443 int ToolbarActionsBar::IconWidth(bool include_padding) { |
| 442 return GetIconDimension(WIDTH) + (include_padding ? kItemSpacing : 0); | 444 return GetIconDimension(WIDTH) + (include_padding ? kItemSpacing : 0); |
| 443 } | 445 } |
| 444 | 446 |
| 445 // static | 447 // static |
| 446 int ToolbarActionsBar::IconHeight() { | 448 int ToolbarActionsBar::IconHeight() { |
| 447 return GetIconDimension(HEIGHT); | 449 return GetIconDimension(HEIGHT); |
| 448 } | 450 } |
| 449 | 451 |
| 452 // static |
| 453 void ToolbarActionsBar::RegisterProfilePrefs( |
| 454 user_prefs::PrefRegistrySyncable* registry) { |
| 455 registry->RegisterBooleanPref( |
| 456 prefs::kToolbarIconSurfacingBubbleAcknowledged, |
| 457 false, |
| 458 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 459 registry->RegisterInt64Pref( |
| 460 prefs::kToolbarIconSurfacingBubbleLastShowTime, |
| 461 0, |
| 462 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 463 } |
| 464 |
| 450 gfx::Size ToolbarActionsBar::GetPreferredSize() const { | 465 gfx::Size ToolbarActionsBar::GetPreferredSize() const { |
| 451 int icon_count = GetIconCount(); | 466 int icon_count = GetIconCount(); |
| 452 if (in_overflow_mode()) { | 467 if (in_overflow_mode()) { |
| 453 // In overflow, we always have a preferred size of a full row (even if we | 468 // In overflow, we always have a preferred size of a full row (even if we |
| 454 // don't use it), and always of at least one row. The parent may decide to | 469 // don't use it), and always of at least one row. The parent may decide to |
| 455 // show us even when empty, e.g. as a drag target for dragging in icons from | 470 // show us even when empty, e.g. as a drag target for dragging in icons from |
| 456 // the main container. | 471 // the main container. |
| 457 int row_count = ((std::max(0, icon_count - 1)) / | 472 int row_count = ((std::max(0, icon_count - 1)) / |
| 458 platform_settings_.icons_per_overflow_menu_row) + 1; | 473 platform_settings_.icons_per_overflow_menu_row) + 1; |
| 459 return gfx::Size( | 474 return gfx::Size( |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 else if (drag_type == DRAG_TO_MAIN) | 695 else if (drag_type == DRAG_TO_MAIN) |
| 681 delta = 1; | 696 delta = 1; |
| 682 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), | 697 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), |
| 683 dropped_index); | 698 dropped_index); |
| 684 if (delta) | 699 if (delta) |
| 685 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); | 700 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); |
| 686 } | 701 } |
| 687 } | 702 } |
| 688 | 703 |
| 689 bool ToolbarActionsBar::ShouldShowInfoBubble() { | 704 bool ToolbarActionsBar::ShouldShowInfoBubble() { |
| 690 return false; | 705 // If the redesign isn't running, or the user has already acknowledged it, |
| 706 // we don't show the bubble. |
| 707 PrefService* prefs = browser_->profile()->GetPrefs(); |
| 708 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled() || |
| 709 (prefs->HasPrefPath(prefs::kToolbarIconSurfacingBubbleAcknowledged) && |
| 710 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged))) |
| 711 return false; |
| 712 |
| 713 // We don't show more than once per day. |
| 714 if (prefs->HasPrefPath(prefs::kToolbarIconSurfacingBubbleLastShowTime)) { |
| 715 base::Time last_shown_time = base::Time::FromInternalValue( |
| 716 prefs->GetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime)); |
| 717 if (base::Time::Now() - last_shown_time < base::TimeDelta::FromDays(1)) |
| 718 return false; |
| 719 } |
| 720 |
| 721 if (!model_->RedesignIsShowingNewIcons()) { |
| 722 // We only show the bubble if there are any new icons present - otherwise, |
| 723 // the user won't see anything different, so we treat it as acknowledged. |
| 724 OnToolbarActionsBarBubbleClosed( |
| 725 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED); |
| 726 return false; |
| 727 } |
| 728 |
| 729 return true; |
| 691 } | 730 } |
| 692 | 731 |
| 693 void ToolbarActionsBar::OnToolbarExtensionAdded( | 732 void ToolbarActionsBar::OnToolbarExtensionAdded( |
| 694 const extensions::Extension* extension, | 733 const extensions::Extension* extension, |
| 695 int index) { | 734 int index) { |
| 696 DCHECK(GetActionForId(extension->id()) == nullptr) << | 735 DCHECK(GetActionForId(extension->id()) == nullptr) << |
| 697 "Asked to add a toolbar action view for an extension that already exists"; | 736 "Asked to add a toolbar action view for an extension that already exists"; |
| 698 | 737 |
| 699 toolbar_actions_.insert( | 738 toolbar_actions_.insert( |
| 700 toolbar_actions_.begin() + index, | 739 toolbar_actions_.begin() + index, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 tracked_objects::ScopedTracker tracking_profile( | 891 tracked_objects::ScopedTracker tracking_profile( |
| 853 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 892 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 854 "ToolbarActionsBar::OnToolbarModelInitialized")); | 893 "ToolbarActionsBar::OnToolbarModelInitialized")); |
| 855 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 894 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 856 } | 895 } |
| 857 | 896 |
| 858 Browser* ToolbarActionsBar::GetBrowser() { | 897 Browser* ToolbarActionsBar::GetBrowser() { |
| 859 return browser_; | 898 return browser_; |
| 860 } | 899 } |
| 861 | 900 |
| 901 void ToolbarActionsBar::OnToolbarActionsBarBubbleShown() { |
| 902 // Record the last time the bubble was shown. |
| 903 browser_->profile()->GetPrefs()->SetInt64( |
| 904 prefs::kToolbarIconSurfacingBubbleLastShowTime, |
| 905 base::Time::Now().ToInternalValue()); |
| 906 } |
| 907 |
| 862 void ToolbarActionsBar::OnToolbarActionsBarBubbleClosed(CloseAction action) { | 908 void ToolbarActionsBar::OnToolbarActionsBarBubbleClosed(CloseAction action) { |
| 909 if (action == ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED) { |
| 910 PrefService* prefs = browser_->profile()->GetPrefs(); |
| 911 prefs->SetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged, true); |
| 912 // Once the bubble is acknowledged, we no longer need to store the last |
| 913 // show time. |
| 914 if (prefs->HasPrefPath(prefs::kToolbarIconSurfacingBubbleLastShowTime)) |
| 915 prefs->ClearPref(prefs::kToolbarIconSurfacingBubbleLastShowTime); |
| 916 } |
| 863 } | 917 } |
| 864 | 918 |
| 865 void ToolbarActionsBar::ReorderActions() { | 919 void ToolbarActionsBar::ReorderActions() { |
| 866 if (toolbar_actions_.empty()) | 920 if (toolbar_actions_.empty()) |
| 867 return; | 921 return; |
| 868 | 922 |
| 869 // First, reset the order to that of the model. | 923 // First, reset the order to that of the model. |
| 870 auto compare = [](ToolbarActionViewController* const& action, | 924 auto compare = [](ToolbarActionViewController* const& action, |
| 871 const scoped_refptr<const extensions::Extension>& ext) { | 925 const scoped_refptr<const extensions::Extension>& ext) { |
| 872 return action->GetId() == ext->id(); | 926 return action->GetId() == ext->id(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 for (ToolbarActionViewController* action : toolbar_actions_) { | 977 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 924 if (action->GetId() == id) | 978 if (action->GetId() == id) |
| 925 return action; | 979 return action; |
| 926 } | 980 } |
| 927 return nullptr; | 981 return nullptr; |
| 928 } | 982 } |
| 929 | 983 |
| 930 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 984 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 931 return browser_->tab_strip_model()->GetActiveWebContents(); | 985 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 932 } | 986 } |
| OLD | NEW |