Commit 91e7625f authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Passwords] Add checkbox to save to remote store

With this CL, the PasswordPendingView shows an additional checkbox in
test and debug builds. When the checkbox is selected/unselected, it
changes the store inside the pending_form_ of the
ManagePasswordsBubbleModel. So far, this field is unused (since
pending_form_ is a copy and only username and password are passed to
the delegate).

To see the checkbox:
* Build with is_debug=true or check_always_on=true
* set the flag \#passwords-account-storage-saving-ui
(or check out the screenshots in the linked bug)

Bug: 1018701
Change-Id: Ie26931fb375677cffb5de3c0b5dff3b0a1544375
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1926587Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717685}
parent 00ac7340
......@@ -39,6 +39,8 @@ namespace metrics_util = password_manager::metrics_util;
namespace {
using Store = autofill::PasswordForm::Store;
void CleanStatisticsForSite(Profile* profile, const GURL& origin) {
DCHECK(profile);
password_manager::PasswordStore* password_store =
......@@ -389,6 +391,13 @@ void ManagePasswordsBubbleModel::OnSkipSignInClicked() {
password_manager::prefs::kWasSignInPasswordPromoClicked, true);
}
#if defined(PASSWORD_STORE_SELECT_ENABLED)
void ManagePasswordsBubbleModel::OnToggleAccountStore(bool is_checked) {
pending_password_.in_store =
is_checked ? Store::kAccountStore : Store::kProfileStore;
}
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
Profile* ManagePasswordsBubbleModel::GetProfile() const {
content::WebContents* web_contents = GetWebContents();
if (!web_contents)
......@@ -475,6 +484,12 @@ bool ManagePasswordsBubbleModel::RevealPasswords() {
return reveal_immediately;
}
#if defined(PASSWORD_STORE_SELECT_ENABLED)
bool ManagePasswordsBubbleModel::IsUsingAccountStore() {
return pending_password_.in_store == Store::kAccountStore;
}
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
void ManagePasswordsBubbleModel::UpdatePendingStateTitle() {
PasswordTitleType type =
state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE
......
......@@ -90,6 +90,11 @@ class ManagePasswordsBubbleModel {
// clicked.
void OnSkipSignInClicked();
#if defined(PASSWORD_STORE_SELECT_ENABLED)
// Called by the view when the account store checkbox is toggled.
void OnToggleAccountStore(bool is_checked);
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
password_manager::ui::State state() const { return state_; }
const base::string16& title() const { return title_; }
......@@ -155,6 +160,11 @@ class ManagePasswordsBubbleModel {
// re-authentication is successful.
bool RevealPasswords();
#if defined(PASSWORD_STORE_SELECT_ENABLED)
// Returns true iff the password account store is used.
bool IsUsingAccountStore();
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
private:
class InteractionKeeper;
// Updates |title_| for the PENDING_PASSWORD_STATE.
......
......@@ -40,6 +40,12 @@
#include "ui/views/view.h"
#include "ui/views/window/dialog_client_view.h"
#if defined(PASSWORD_STORE_SELECT_ENABLED)
#include "base/feature_list.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "ui/views/controls/button/checkbox.h"
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
namespace {
enum PasswordPendingViewColumnSetType {
......@@ -216,6 +222,28 @@ std::unique_ptr<views::View> CreateHeaderImage(int image_id) {
return image_view;
}
#if defined(PASSWORD_STORE_SELECT_ENABLED)
views::Checkbox* MaybeAppendAccountCheckboxRow(
views::GridLayout* layout,
bool uses_account_store,
int height,
views::ButtonListener* listener) {
if (!base::FeatureList::IsEnabled(
password_manager::features::kEnablePasswordsAccountStorageSavingUi)) {
return nullptr;
}
auto account_store_checkbox = std::make_unique<views::Checkbox>(
base::ASCIIToUTF16("Store passwords in account store?"), listener);
account_store_checkbox->SetChecked(uses_account_store);
BuildColumnSet(layout, DOUBLE_VIEW_COLUMN_SET_PASSWORD);
layout->StartRow(views::GridLayout::kFixedSize,
DOUBLE_VIEW_COLUMN_SET_PASSWORD);
return layout->AddView(std::move(account_store_checkbox), 1, 1,
views::GridLayout::FILL, views::GridLayout::FILL, 0,
height);
}
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
} // namespace
PasswordPendingView::PasswordPendingView(content::WebContents* web_contents,
......@@ -271,6 +299,11 @@ PasswordPendingView::PasswordPendingView(content::WebContents* web_contents,
BuildCredentialRows(layout, std::move(username_dropdown),
std::move(password_dropdown),
std::move(password_view_button));
#if defined(PASSWORD_STORE_SELECT_ENABLED)
account_store_checkbox_ = MaybeAppendAccountCheckboxRow(
layout, model()->IsUsingAccountStore(),
password_dropdown_->GetPreferredSize().height(), this);
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
}
}
......@@ -310,6 +343,13 @@ bool PasswordPendingView::Close() {
void PasswordPendingView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
#if defined(PASSWORD_STORE_SELECT_ENABLED)
DCHECK(sender);
if (sender == account_store_checkbox_) {
model()->OnToggleAccountStore(account_store_checkbox_->GetChecked());
return;
}
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
DCHECK(sender == password_view_button_);
TogglePasswordVisibility();
}
......@@ -446,6 +486,9 @@ void PasswordPendingView::ReplaceWithPromo() {
username_dropdown_ = nullptr;
password_dropdown_ = nullptr;
password_view_button_ = nullptr;
#if defined(PASSWORD_STORE_SELECT_ENABLED)
account_store_checkbox_ = nullptr;
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
SetLayoutManager(std::make_unique<views::FillLayout>());
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, views::TEXT));
......
......@@ -13,6 +13,10 @@
namespace views {
class EditableCombobox;
class ToggleImageButton;
#if defined(PASSWORD_STORE_SELECT_ENABLED)
class Checkbox;
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
} // namespace views
class PasswordSignInPromoView;
......@@ -77,6 +81,10 @@ class PasswordPendingView : public PasswordBubbleViewBase,
// The view for the password value.
views::EditableCombobox* password_dropdown_;
#if defined(PASSWORD_STORE_SELECT_ENABLED)
views::Checkbox* account_store_checkbox_ = nullptr;
#endif // defined(PASSWORD_STORE_SELECT_ENABLED)
bool are_passwords_revealed_;
DISALLOW_COPY_AND_ASSIGN(PasswordPendingView);
......
......@@ -29,6 +29,16 @@ config("password_reuse_detection_config") {
}
}
# Support the store select for debug builds only.
password_store_select_supported = is_debug
config("password_store_select_config") {
defines = []
if (password_store_select_supported) {
defines += [ "PASSWORD_STORE_SELECT_ENABLED" ]
}
}
jumbo_static_library("browser") {
sources = [
"android_affiliation/affiliated_match_helper.cc",
......@@ -217,7 +227,10 @@ jumbo_static_library("browser") {
"votes_uploader.h",
]
all_dependent_configs = [ ":password_reuse_detection_config" ]
all_dependent_configs = [
":password_reuse_detection_config",
":password_store_select_config",
]
if (password_reuse_detection_support) {
sources += [
......
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