Commit 0668472e authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[profile-menu] Implement incognito menu

The incognito menu code is moved into ProfileMenuView
because there is a lot of shared code with regular and
guest mode. This also removes special casing during the
bubble creation.

Screenshot:
https://drive.google.com/file/d/1JeyIWItOqCnQ7dJAWI_q0eD0zkaFPIPr/view?usp=sharing

Flag: profile-menu-revamp

Bug: 995720
Change-Id: Id2778759dbe83a342cb8a0261f74d3ece4572d29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819444
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698930}
parent 480313d9
......@@ -49,36 +49,26 @@ void IncognitoMenuView::BuildMenu() {
const SkColor icon_color = provider->GetTypographyProvider().GetColor(
*this, views::style::CONTEXT_LABEL, views::style::STYLE_PRIMARY);
if (!base::FeatureList::IsEnabled(features::kProfileMenuRevamp)) {
auto incognito_icon = std::make_unique<views::ImageView>();
incognito_icon->SetImage(
gfx::CreateVectorIcon(kIncognitoProfileIcon, icon_color));
auto incognito_icon = std::make_unique<views::ImageView>();
incognito_icon->SetImage(
gfx::CreateVectorIcon(kIncognitoProfileIcon, icon_color));
AddMenuGroup(false /* add_separator */);
CreateAndAddTitleCard(
std::move(incognito_icon),
l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_TITLE),
incognito_window_count > 1
? l10n_util::GetPluralStringFUTF16(
IDS_INCOGNITO_WINDOW_COUNT_MESSAGE, incognito_window_count)
: base::string16(),
base::RepeatingClosure());
AddMenuGroup();
exit_button_ = CreateAndAddButton(
gfx::CreateVectorIcon(kCloseAllIcon, 16, gfx::kChromeIconGrey),
l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_CLOSE_BUTTON),
base::BindRepeating(&IncognitoMenuView::OnExitButtonClicked,
base::Unretained(this)));
return;
}
SetIdentityInfo(
gfx::Image(gfx::CreateVectorIcon(kIncognitoProfileIcon, icon_color)),
AddMenuGroup(false /* add_separator */);
CreateAndAddTitleCard(
std::move(incognito_icon),
l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_TITLE),
incognito_window_count > 1
? l10n_util::GetPluralStringFUTF16(IDS_INCOGNITO_WINDOW_COUNT_MESSAGE,
incognito_window_count)
: base::string16());
: base::string16(),
base::RepeatingClosure());
AddMenuGroup();
exit_button_ = CreateAndAddButton(
gfx::CreateVectorIcon(kCloseAllIcon, 16, gfx::kChromeIconGrey),
l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_CLOSE_BUTTON),
base::BindRepeating(&IncognitoMenuView::OnExitButtonClicked,
base::Unretained(this)));
}
base::string16 IncognitoMenuView::GetAccessibleWindowTitle() const {
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/sync/sync_promo_ui.h"
......@@ -171,15 +172,18 @@ void ProfileMenuView::BuildMenu() {
}
Profile* profile = browser()->profile();
if (profile->IsGuestSession()) {
BuildGuestIdentity();
} else {
DCHECK(profile->IsRegularProfile());
if (profile->IsRegularProfile()) {
BuildIdentity();
BuildSyncInfo();
BuildAccountFeatureButtons();
BuildAutofillButtons();
BuildProfileFeatureButtons();
} else if (profile->IsIncognitoProfile()) {
BuildIncognitoIdentity();
BuildAutofillButtons();
} else {
DCHECK(profile->IsGuestSession());
BuildGuestIdentity();
}
BuildProfileHeading();
......@@ -425,6 +429,19 @@ void ProfileMenuView::BuildGuestIdentity() {
l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME));
}
void ProfileMenuView::BuildIncognitoIdentity() {
int incognito_window_count =
BrowserList::GetIncognitoSessionsActiveForProfile(browser()->profile());
SetIdentityInfo(
gfx::Image(ImageForMenu(kIncognitoProfileIcon)),
l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_TITLE),
incognito_window_count > 1
? l10n_util::GetPluralStringFUTF16(IDS_INCOGNITO_WINDOW_COUNT_MESSAGE,
incognito_window_count)
: base::string16());
}
void ProfileMenuView::BuildAutofillButtons() {
AddShortcutFeatureButton(
ImageForMenu(kKeyIcon, kShortcutIconToImageRatio),
......
......@@ -102,6 +102,7 @@ class ProfileMenuView : public ProfileMenuViewBase, public AvatarMenuObserver {
// Helper methods for building the menu.
void BuildIdentity();
void BuildGuestIdentity();
void BuildIncognitoIdentity();
void BuildAutofillButtons();
void BuildSyncInfo();
void BuildAccountFeatureButtons();
......
......@@ -158,17 +158,30 @@ void ProfileMenuViewBase::ShowBubble(
base::RecordAction(base::UserMetricsAction("ProfileMenu_Opened"));
ProfileMenuViewBase* bubble;
if (view_mode == profiles::BUBBLE_VIEW_MODE_INCOGNITO) {
if (base::FeatureList::IsEnabled(features::kProfileMenuRevamp)) {
#if !defined(OS_CHROMEOS)
// On Desktop, all modes(regular, guest, incognito) are handled within
// ProfileMenuView.
bubble = new ProfileMenuView(anchor_button, browser, access_point);
#else
// On ChromeOS, only the incognito menu is implemented.
DCHECK(browser->profile()->IsIncognitoProfile());
bubble = new IncognitoMenuView(anchor_button, browser);
#endif
} else {
DCHECK_EQ(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, view_mode);
if (view_mode == profiles::BUBBLE_VIEW_MODE_INCOGNITO) {
DCHECK(browser->profile()->IsIncognitoProfile());
bubble = new IncognitoMenuView(anchor_button, browser);
} else {
DCHECK_EQ(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, view_mode);
#if !defined(OS_CHROMEOS)
bubble = new ProfileMenuView(anchor_button, browser, access_point);
bubble = new ProfileMenuView(anchor_button, browser, access_point);
#else
NOTREACHED();
return;
NOTREACHED();
return;
#endif
}
}
views::BubbleDialogDelegateView::CreateBubble(bubble)->Show();
......
......@@ -884,3 +884,43 @@ INSTANTIATE_TEST_SUITE_P(
size_t(0),
base::size(
ProfileMenuClickTest_GuestProfile::kOrderedActionableItems)));
class ProfileMenuClickTest_IncognitoProfile : public ProfileMenuClickTest {
public:
// List of actionable items in the correct order as they appear in the menu.
// If a new button is added to the menu, it should also be added to this list.
static constexpr ProfileMenuView::ActionableItem kOrderedActionableItems[4] =
{ProfileMenuView::ActionableItem::kPasswordsButton,
ProfileMenuView::ActionableItem::kCreditCardsButton,
ProfileMenuView::ActionableItem::kAddressesButton,
// The first button is added again to finish the cycle and test that
// there are no other buttons at the end.
ProfileMenuView::ActionableItem::kPasswordsButton};
ProfileMenuClickTest_IncognitoProfile() = default;
ProfileMenuView::ActionableItem GetExpectedActionableItemAtIndex(
size_t index) override {
return kOrderedActionableItems[index];
}
DISALLOW_COPY_AND_ASSIGN(ProfileMenuClickTest_IncognitoProfile);
};
// static
constexpr ProfileMenuView::ActionableItem
ProfileMenuClickTest_IncognitoProfile::kOrderedActionableItems[];
IN_PROC_BROWSER_TEST_P(ProfileMenuClickTest_IncognitoProfile, SetupAndRunTest) {
SetTargetBrowser(CreateIncognitoBrowser(browser()->profile()));
RunTest();
}
INSTANTIATE_TEST_SUITE_P(
,
ProfileMenuClickTest_IncognitoProfile,
::testing::Range(
size_t(0),
base::size(
ProfileMenuClickTest_IncognitoProfile::kOrderedActionableItems)));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment