Commit f7e2be4a authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

Add b4p badges to the credential manager account chooser UI

CredentialsItemView now supports setting an optional right-aligned
G-logo icon to disguish account store forms from profile store
ones.

The icon is set in the AccountChooserDialogView for credentials
read from the account store. If the user has not opted in to b4p,
no forms will satisfy this, so there's no need explicitly check
the opted-in state of the user to guarantee that no badges will
be shown for non opted-in users.

Account chooser with badges:
https://screenshot.googleplex.com/JMiryuMoec8

Bug: 1060134
Change-Id: Id0a27324ad7955dae366a3e6efa8102c1145633f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116211
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758817}
parent f9755ae5
......@@ -4,7 +4,9 @@
#include "chrome/browser/ui/views/passwords/account_chooser_dialog_view.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
......@@ -54,6 +56,7 @@ views::ScrollView* CreateCredentialsView(
CredentialsItemView* credential_view =
new CredentialsItemView(button_listener, titles.first, titles.second,
form.get(), loader_factory);
credential_view->SetStoreIndicatorIcon(form->in_store);
ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get();
gfx::Insets insets =
layout_provider->GetInsetsMetric(views::INSETS_DIALOG_SUBSECTION);
......
......@@ -4,17 +4,22 @@
#include "chrome/browser/ui/views/passwords/credentials_item_view.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/grit/theme_resources.h"
#include "components/autofill/core/common/password_form.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/border.h"
#include "ui/views/bubble/tooltip_icon.h"
#include "ui/views/controls/image_view.h"
......@@ -64,6 +69,9 @@ CredentialsItemView::CredentialsItemView(
views::BoxLayout::Orientation::kHorizontal));
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
layout->set_between_child_spacing(
ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_RELATED_LABEL_HORIZONTAL));
// Create an image-view for the avatar. Make sure it ignores events so that
// the parent can receive the events instead.
auto image_view = std::make_unique<CircularImageView>();
......@@ -94,12 +102,6 @@ CredentialsItemView::CredentialsItemView(
views::BoxLayout::Orientation::kVertical));
text_layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kStart);
text_container->SetProperty(
views::kMarginsKey,
gfx::Insets(0,
ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_RELATED_LABEL_HORIZONTAL),
0, 0));
layout->SetFlexForView(text_container, 1);
}
......@@ -133,6 +135,24 @@ CredentialsItemView::CredentialsItemView(
CredentialsItemView::~CredentialsItemView() = default;
void CredentialsItemView::SetStoreIndicatorIcon(
autofill::PasswordForm::Store store) {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (store == autofill::PasswordForm::Store::kAccountStore &&
!store_indicator_icon_view_) {
store_indicator_icon_view_ =
AddChildView(std::make_unique<views::ImageView>());
store_indicator_icon_view_->set_can_process_events_within_subtree(false);
store_indicator_icon_view_->SetImage(
gfx::CreateVectorIcon(kGoogleGLogoIcon, gfx::kPlaceholderColor));
} else if (store == autofill::PasswordForm::Store::kProfileStore &&
store_indicator_icon_view_) {
RemoveChildView(store_indicator_icon_view_);
store_indicator_icon_view_ = nullptr;
}
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
}
void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) {
image_view_->SetImage(ScaleImageForAccountAvatar(image));
}
......
......@@ -7,14 +7,13 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "build/branding_buildflags.h"
#include "build/buildflag.h"
#include "chrome/browser/ui/passwords/account_avatar_fetcher.h"
#include "components/autofill/core/common/password_form.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/style/typography.h"
namespace autofill {
struct PasswordForm;
}
namespace gfx {
class ImageSkia;
}
......@@ -44,6 +43,10 @@ class CredentialsItemView : public AccountAvatarFetcherDelegate,
int lower_text_style = views::style::STYLE_SECONDARY);
~CredentialsItemView() override;
// If |store| is kAccountStore and the build is official, adds a G logo icon
// to the view. If |store| is kProfileStore, removes any existing icon.
void SetStoreIndicatorIcon(autofill::PasswordForm::Store store);
const autofill::PasswordForm* form() const { return form_; }
// AccountAvatarFetcherDelegate:
......@@ -58,6 +61,13 @@ class CredentialsItemView : public AccountAvatarFetcherDelegate,
const autofill::PasswordForm* form_;
views::ImageView* image_view_;
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Optional right-aligned icon to distinguish account store credentials and
// profile store ones.
views::ImageView* store_indicator_icon_view_ = nullptr;
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
views::Label* upper_label_ = nullptr;
views::Label* lower_label_ = nullptr;
views::ImageView* info_icon_ = nullptr;
......
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