1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'chrome://resources/cr_elements/cr_link_row/cr_link_row.js';
import 'chrome://resources/cr_elements/cr_shared_style.css.js';
import 'chrome://resources/cr_elements/cr_button/cr_button.js';
import 'chrome://resources/cr_elements/cr_dialog/cr_dialog.js';
import 'chrome://resources/cr_elements/cr_icon/cr_icon.js';
import './shared_style.css.js';
import type {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.js';
import type {CrDialogElement} from 'chrome://resources/cr_elements/cr_dialog/cr_dialog.js';
import type {CrToastElement} from 'chrome://resources/cr_elements/cr_toast/cr_toast.js';
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
import {PluralStringProxyImpl} from 'chrome://resources/js/plural_string_proxy.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {getTemplate} from './full_data_reset.html.js';
import {PasswordManagerImpl} from './password_manager_proxy.js';
export interface FullDataResetElement {
$: {
confirmationDialogTitle: HTMLElement,
deleteAllButton: CrButtonElement,
cancelButton: CrButtonElement,
confirmButton: CrButtonElement,
dialog: CrDialogElement,
successToast: CrToastElement,
};
}
const FullDataResetElementBase = I18nMixin(PolymerElement);
export class FullDataResetElement extends FullDataResetElementBase {
static get is() {
return 'full-data-reset';
}
static get template() {
return getTemplate();
}
static get properties() {
return {
isSyncingPasswords: {
type: Boolean,
value: false,
},
isAccountStoreUser: {
type: Boolean,
value: false,
},
passwordsCount_: {
type: String,
value: '',
},
passkeysCount_: {
type: String,
value: '',
},
passwordsCountDetails_: {
type: String,
value: '',
},
passkeysCountDetails_: {
type: String,
value: '',
},
};
}
declare isSyncingPasswords: boolean;
declare isAccountStoreUser: boolean;
declare private passwordsCount_: string;
declare private passkeysCount_: string;
declare private passwordsCountDetails_: string;
declare private passkeysCountDetails_: string;
private async updateCounters_(credentials:
chrome.passwordsPrivate.PasswordUiEntry[]) {
let numPasswords = 0;
let numPasskeys = 0;
const passwordSites = new Set<string>();
const passkeySites = new Set<string>();
for (const credential of credentials) {
if (credential.isPasskey) {
numPasskeys++;
credential.affiliatedDomains.forEach(
domain => passkeySites.add(domain.name));
} else {
numPasswords++;
credential.affiliatedDomains.forEach(
domain => passwordSites.add(domain.name));
}
}
const [
passwordCountString,
passkeysCountString,
passwordDetails,
passkeysDetails,
] = await Promise.all([
this.getFormattedCountString('fullResetPasswordsCounter', numPasswords),
this.getFormattedCountString('fullResetPasskeysCounter', numPasskeys),
this.getFormattedSiteDetails(passwordSites),
this.getFormattedSiteDetails(passkeySites),
]);
this.passwordsCount_ = passwordCountString;
this.passkeysCount_ = passkeysCountString;
this.passwordsCountDetails_ = passwordDetails;
this.passkeysCountDetails_ = passkeysDetails;
}
private async getFormattedCountString(key: string, count: number):
Promise<string> {
return PluralStringProxyImpl.getInstance().getPluralString(key, count);
}
private async getFormattedSiteDetails(sites: Set<string>): Promise<string> {
const sitesArray = [...sites];
switch (sites.size) {
case 0:
return '';
case 1:
return this.i18n('fullResetDomainsDisplayOne', sitesArray[0]);
case 2:
return this.i18n(
'fullResetDomainsDisplayTwo', sitesArray[0], sitesArray[1]);
default:
const moreCount = sites.size - 2;
const container = await this.getFormattedCountString(
'fullResetDomainsDisplayTwoAndXMore', moreCount);
return container.replace('$1', sitesArray[0])
.replace('$2', sitesArray[1]);
}
}
private onDeleteAllClick_(): void {
PasswordManagerImpl.getInstance().getSavedPasswordList().then(
credentials => this.updateCounters_(credentials));
this.$.dialog.showModal();
}
private onCancel_(): void {
this.$.dialog.close();
}
private async onConfirm_() {
this.$.dialog.close();
const success =
await PasswordManagerImpl.getInstance().deleteAllPasswordManagerData();
this.showToastWithResult_(success);
}
private showToastWithResult_(success: boolean) {
if (success) {
this.$.successToast.show();
} else {
// TODO(crbug.com/342366264): Show error toast.
}
}
private getConfirmationDialogTitle_(): string {
if (this.isSyncingPasswords || this.isAccountStoreUser) {
return this.i18n('fullResetConfirmationTitle');
}
return this.i18n('fullResetConfirmationTitleLocal');
}
private getAriaLabel_(): string {
return [
this.i18n('fullResetTitle'),
this.i18n('fullResetRowDescription'),
].join('. ');
}
}
declare global {
interface HTMLElementTagNameMap {
'full-data-reset': FullDataResetElement;
}
}
customElements.define(FullDataResetElement.is, FullDataResetElement);
|