Commit fdb038bb authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[iOS] Add basic settings toggle for leak detection

This change ads a basic toggle in Settings > Passwords that can be used
to turn password leak detection on or off.

This CL doesn't include customizing the toggle based on sign in state.

Bug: 986322
Change-Id: Ia407ef70424de3e8ad1d506ee689d286ac7cb81c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1821920
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703326}
parent 5538429b
......@@ -1345,6 +1345,9 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_SAVE_PASSWORDS" desc="Title for the switch item in Settings that can be toggled to enable or disable saving passwords. [Length: 15em] [iOS only]">
Save Passwords
</message>
<message name="IDS_IOS_LEAK_CHECK_SWITCH" desc="Title for the switch toggling whether Chrome should check that entered credentials have been part of a leak.">
Check password safety
</message>
<message name="IDS_IOS_PASSWORDS" desc="Title for the view in Settings for managing saved passwords. [Length: 15em] [iOS only]">
Passwords
</message>
......
......@@ -20,6 +20,7 @@
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h"
......@@ -77,6 +78,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeLinkHeader = kItemTypeEnumZero,
ItemTypeHeader,
ItemTypeSavePasswordsSwitch,
ItemTypePasswordLeakCheckSwitch,
ItemTypeSavedPassword, // This is a repeated item type.
ItemTypeBlacklisted, // This is a repeated item type.
ItemTypeExportPasswordsButton,
......@@ -161,10 +163,16 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
// The observable boolean that binds to the password manager setting state.
// Saved passwords are only on if the password manager is enabled.
PrefBackedBoolean* passwordManagerEnabled_;
// The observable boolean that binds to the password leak check settings
// state.
PrefBackedBoolean* passwordLeakCheckEnabled_;
// The header for save passwords switch section.
TableViewLinkHeaderFooterItem* manageAccountLinkItem_;
// The item related to the switch for the password manager setting.
SettingsSwitchItem* savePasswordsItem_;
// The item related to the switch for the automatic password leak detection
// setting.
SettingsSwitchItem* leakCheckItem_;
// The item related to the button for exporting passwords.
TableViewTextItem* exportPasswordsItem_;
// The interface for getting and manipulating a user's saved passwords.
......@@ -243,6 +251,14 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
initWithPrefService:browserState_->GetPrefs()
prefName:password_manager::prefs::kCredentialsEnableService];
[passwordManagerEnabled_ setObserver:self];
if (base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection)) {
passwordLeakCheckEnabled_ = [[PrefBackedBoolean alloc]
initWithPrefService:browserState_->GetPrefs()
prefName:password_manager::prefs::
kPasswordLeakDetectionEnabled];
[passwordLeakCheckEnabled_ setObserver:self];
}
[self getLoginsFromPasswordStore];
[self updateUIForEditState];
[self updateExportPasswordsButton];
......@@ -322,10 +338,12 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
[super setEditing:editing animated:animated];
if (editing) {
[self setSavePasswordsSwitchItemEnabled:NO];
[self setLeakCheckSwitchItemEnabled:NO];
[self setExportPasswordsButtonEnabled:NO];
[self setSearchBarEnabled:NO];
} else {
[self setSavePasswordsSwitchItemEnabled:YES];
[self setLeakCheckSwitchItemEnabled:YES];
if (exportReady_) {
[self setExportPasswordsButtonEnabled:YES];
}
......@@ -346,6 +364,12 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
savePasswordsItem_ = [self savePasswordsItem];
[model addItem:savePasswordsItem_
toSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch];
if (base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection)) {
leakCheckItem_ = [self leakCheckItem];
[model addItem:leakCheckItem_
toSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch];
}
manageAccountLinkItem_ = [self manageAccountLinkItem];
[model setHeader:manageAccountLinkItem_
forSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch];
......@@ -434,6 +458,15 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
return savePasswordsItem;
}
- (SettingsSwitchItem*)leakCheckItem {
SettingsSwitchItem* leakCheckItem =
[[SettingsSwitchItem alloc] initWithType:ItemTypePasswordLeakCheckSwitch];
leakCheckItem.text = l10n_util::GetNSString(IDS_IOS_LEAK_CHECK_SWITCH);
leakCheckItem.on = [passwordLeakCheckEnabled_ value];
leakCheckItem.accessibilityIdentifier = @"leakCheckItem_switch";
return leakCheckItem;
}
- (TableViewTextItem*)exportPasswordsItem {
TableViewTextItem* exportPasswordsItem =
[[TableViewTextItem alloc] initWithType:ItemTypeExportPasswordsButton];
......@@ -472,16 +505,30 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
#pragma mark - BooleanObserver
- (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
DCHECK_EQ(observableBoolean, passwordManagerEnabled_);
// Update the item.
savePasswordsItem_.on = [passwordManagerEnabled_ value];
// Update the cell if it's not removed by presenting search controller.
if ([self.tableViewModel
hasItemForItemType:ItemTypeSavePasswordsSwitch
sectionIdentifier:SectionIdentifierSavePasswordsSwitch]) {
[self reconfigureCellsForItems:@[ savePasswordsItem_ ]];
if (observableBoolean == passwordManagerEnabled_) {
// Update the item.
savePasswordsItem_.on = [passwordManagerEnabled_ value];
// Update the cell if it's not removed by presenting search controller.
if ([self.tableViewModel
hasItemForItemType:ItemTypeSavePasswordsSwitch
sectionIdentifier:SectionIdentifierSavePasswordsSwitch]) {
[self reconfigureCellsForItems:@[ savePasswordsItem_ ]];
}
} else if (observableBoolean == passwordLeakCheckEnabled_) {
DCHECK(base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection));
// Update the item.
leakCheckItem_.on = [passwordLeakCheckEnabled_ value];
// Update the cell if it's not removed by presenting search controller.
if ([self.tableViewModel
hasItemForItemType:ItemTypePasswordLeakCheckSwitch
sectionIdentifier:SectionIdentifierSavePasswordsSwitch]) {
[self reconfigureCellsForItems:@[ leakCheckItem_ ]];
}
} else {
NOTREACHED();
}
}
......@@ -495,6 +542,14 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
savePasswordsItem_.on = [passwordManagerEnabled_ value];
}
- (void)passwordLeakCheckSwitchChanged:(UISwitch*)switchView {
// Update the setting.
[passwordLeakCheckEnabled_ setValue:switchView.on];
// Update the item.
leakCheckItem_.on = [passwordLeakCheckEnabled_ value];
}
#pragma mark - SavePasswordsConsumerDelegate
- (void)onGetPasswordStoreResults:
......@@ -585,6 +640,11 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
withRowAnimation:UITableViewRowAnimationTop];
[model addItem:savePasswordsItem_
toSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch];
if (base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection)) {
[model addItem:leakCheckItem_
toSectionWithIdentifier:SectionIdentifierSavePasswordsSwitch];
}
[self.tableView
insertRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:0
inSection:0] ]
......@@ -910,6 +970,7 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
case ItemTypeLinkHeader:
case ItemTypeHeader:
case ItemTypeSavePasswordsSwitch:
case ItemTypePasswordLeakCheckSwitch:
break;
case ItemTypeSavedPassword: {
DCHECK_EQ(SectionIdentifierSavedPasswords,
......@@ -989,6 +1050,17 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
forControlEvents:UIControlEventValueChanged];
break;
}
case ItemTypePasswordLeakCheckSwitch: {
DCHECK(base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection));
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[switchCell.switchView
addTarget:self
action:@selector(passwordLeakCheckSwitchChanged:)
forControlEvents:UIControlEventValueChanged];
break;
}
}
return cell;
}
......@@ -1170,6 +1242,15 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
[self reconfigureCellsForItems:@[ savePasswordsItem_ ]];
}
// Sets the leak check switch item's enabled status to |enabled| and
// reconfigures the corresponding cell.
- (void)setLeakCheckSwitchItemEnabled:(BOOL)enabled {
if (!base::FeatureList::IsEnabled(password_manager::features::kLeakDetection))
return;
[leakCheckItem_ setEnabled:enabled];
[self reconfigureCellsForItems:@[ leakCheckItem_ ]];
}
// Enables/disables search bar.
- (void)setSearchBarEnabled:(BOOL)enabled {
if (enabled) {
......
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