Skip to content

Commit

Permalink
Fixes Tor avatar menu after c78 bump.
Browse files Browse the repository at this point in the history
Also, removed no longer used override in chromium_src's profiles_state.cc.

Fixes brave/brave-browser#6451
  • Loading branch information
mkarolin committed Oct 12, 2019
1 parent 442f247 commit 7a25f04
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 27 deletions.
6 changes: 6 additions & 0 deletions browser/ui/views/profiles/brave_avatar_toolbar_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h"

void BraveAvatarToolbarButton::SetText(const base::string16& text) {
// We only want the icon for Tor profile.
AvatarToolbarButton::SetText(brave::IsTorProfile(profile_) ? base::string16()
: text);
}

gfx::ImageSkia BraveAvatarToolbarButton::GetAvatarIcon(
const gfx::Image& gaia_image) const {
if (brave::IsTorProfile(profile_)) {
Expand Down
3 changes: 3 additions & 0 deletions browser/ui/views/profiles/brave_avatar_toolbar_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class BraveAvatarToolbarButton : public AvatarToolbarButton {
public:
using AvatarToolbarButton::AvatarToolbarButton;

// views::LabelButton:
void SetText(const base::string16& text) override;

private:
gfx::ImageSkia GetAvatarIcon(const gfx::Image& gaia_image) const override;
DISALLOW_COPY_AND_ASSIGN(BraveAvatarToolbarButton);
Expand Down
36 changes: 36 additions & 0 deletions browser/ui/views/profiles/brave_incognito_menu_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,50 @@
#include <memory>
#include <utility>

#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/ui/views/profiles/brave_profile_menu_view_helper.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/hover_button.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/button/button.h"

void BraveIncognitoMenuView::BuildMenu() {
if (!brave::IsTorProfile(browser()->profile())) {
IncognitoMenuView::BuildMenu();
return;
}

ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
const SkColor icon_color = provider->GetTypographyProvider().GetColor(
*this, views::style::CONTEXT_LABEL, views::style::STYLE_PRIMARY);
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_TOR_PROFILE_NAME),
base::string16(), base::RepeatingClosure());

AddMenuGroup();
exit_button_ = CreateAndAddButton(
gfx::CreateVectorIcon(kCloseAllIcon, 16, gfx::kChromeIconGrey),
l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_TOR),
base::BindRepeating(&IncognitoMenuView::OnExitButtonClicked,
base::Unretained(this)));
return;

SetIdentityInfo(
gfx::Image(gfx::CreateVectorIcon(kIncognitoProfileIcon, icon_color)),
l10n_util::GetStringUTF16(IDS_TOR_PROFILE_NAME), base::string16());
}

void BraveIncognitoMenuView::AddTorButton() {
if (brave::ShouldShowTorProfileButton(browser()->profile())) {
tor_profile_button_ = CreateAndAddButton(
Expand Down
11 changes: 7 additions & 4 deletions browser/ui/views/profiles/brave_incognito_menu_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
#include "chrome/browser/ui/views/profiles/incognito_menu_view.h"

class BraveIncognitoMenuView : public IncognitoMenuView {
private:
friend class IncognitoMenuView;

public:
using IncognitoMenuView::IncognitoMenuView;
~BraveIncognitoMenuView() override = default;

void AddTorButton();
// ProfileMenuViewBase:
void BuildMenu() override;

private:
friend class IncognitoMenuView;

void AddTorButton();
void OnTorProfileButtonClicked();

views::Button* tor_profile_button_ = nullptr;
Expand Down
17 changes: 0 additions & 17 deletions chromium_src/chrome/browser/profiles/profiles_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
#include "brave/browser/profiles/brave_profile_manager.h"
#include "brave/browser/profiles/profile_util.h"
#include "ui/gfx/text_elider.h"
#define GetAvatarButtonTextForProfile GetAvatarButtonTextForProfile_ChromiumImpl
#define GetAvatarNameForProfile GetAvatarNameForProfile_ChromiumImpl
#include "../../../../../../chrome/browser/profiles/profiles_state.cc"
#undef GetAvatarNameForProfile
#undef GetAvatarButtonTextForProfile

namespace profiles {

Expand All @@ -20,21 +18,6 @@ base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path) {
return l10n_util::GetStringUTF16(IDS_TOR_PROFILE_NAME);
return GetAvatarNameForProfile_ChromiumImpl(profile_path);
}

#if !defined(OS_CHROMEOS)
base::string16 GetAvatarButtonTextForProfile(Profile* profile) {
const int kMaxCharactersToDisplay = 15;
base::string16 name = GetAvatarNameForProfile(profile->GetPath());
name = gfx::TruncateString(name,
kMaxCharactersToDisplay,
gfx::CHARACTER_BREAK);
if (profile->IsLegacySupervised()) {
name = l10n_util::GetStringFUTF16(
IDS_LEGACY_SUPERVISED_USER_NEW_AVATAR_LABEL, name);
}
return name;
}
#endif // !defined(OS_CHROMEOS)
#endif // !defined(OS_ANDROID)

} // namespace profiles
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
diff --git a/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc b/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
index 982a8b33c30266413e2cd0ea0944d7c835b81ceb..950e5b0ffcef94d52934579a9b2ea331159be55e 100644
index 982a8b33c30266413e2cd0ea0944d7c835b81ceb..bf5cdc8224ffa6ce4496a4246fdce1f1834fb66a 100644
--- a/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
+++ b/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
@@ -343,6 +343,7 @@ base::string16 AvatarToolbarButton::GetAvatarTooltipText() const {
if (IsIncognito())
return l10n_util::GetStringUTF16(IDS_AVATAR_BUTTON_INCOGNITO_TOOLTIP);
@@ -340,6 +340,7 @@ bool AvatarToolbarButton::ShouldShowGenericIcon() const {
}

base::string16 AvatarToolbarButton::GetAvatarTooltipText() const {
+ GET_AVATAR_TOOLTIP_TEXT_
if (profile_->IsGuestSession())
return l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME);
if (IsIncognito())
return l10n_util::GetStringUTF16(IDS_AVATAR_BUTTON_INCOGNITO_TOOLTIP);

0 comments on commit 7a25f04

Please sign in to comment.