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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
// Copyright 2022 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_action_menu/cr_action_menu.js';
import 'chrome://resources/cr_elements/cr_collapse/cr_collapse.js';
import 'chrome://resources/cr_elements/cr_expand_button/cr_expand_button.js';
import 'chrome://resources/cr_elements/cr_icon/cr_icon.js';
import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.js';
import 'chrome://resources/cr_elements/icons.html.js';
import './shared_style.css.js';
import './checkup_list_item.js';
import {PrefsMixin} from '/shared/settings/prefs/prefs_mixin.js';
import type {CrActionMenuElement} from 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.js';
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
import {assert} from 'chrome://resources/js/assert.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 './checkup_details_section.html.js';
import type {CheckupListItemElement} from './checkup_list_item.js';
import type {CredentialsChangedListener} from './password_manager_proxy.js';
import {PasswordCheckInteraction, PasswordManagerImpl} from './password_manager_proxy.js';
import type {Route} from './router.js';
import {CheckupSubpage, Page, RouteObserverMixin, Router} from './router.js';
export class ReusedPasswordInfo {
constructor(credentials: chrome.passwordsPrivate.PasswordUiEntry[]) {
this.credentials = credentials;
}
async init() {
this.title = await PluralStringProxyImpl.getInstance().getPluralString(
'numberOfPasswordReuse', this.credentials.length);
}
credentials: chrome.passwordsPrivate.PasswordUiEntry[];
title: string;
}
export interface CheckupDetailsSectionElement {
$: {
backButton: HTMLElement,
description: HTMLElement,
moreActionsMenu: CrActionMenuElement,
menuShowPassword: HTMLButtonElement,
menuEditPassword: HTMLButtonElement,
menuDeletePassword: HTMLButtonElement,
subtitle: HTMLElement,
};
}
const CheckupDetailsSectionElementBase =
PrefsMixin(I18nMixin(RouteObserverMixin(PolymerElement)));
export class CheckupDetailsSectionElement extends
CheckupDetailsSectionElementBase {
static get is() {
return 'checkup-details-section';
}
static get template() {
return getTemplate();
}
static get properties() {
return {
pageTitle_: String,
pageSubtitle_: String,
insecurityType_: {
type: String,
observer: 'updateShownCredentials_',
},
groups_: {
type: Array,
},
allInsecureCredentials_: {
type: Array,
observer: 'updateShownCredentials_',
},
shownInsecureCredentials_: {
type: Array,
observer: 'onCredentialsChanged_',
},
credentialsWithReusedPassword_: {
type: Array,
},
mutedCompromisedCredentials_: {
type: Array,
},
activeListItem_: {
type: Object,
value: null,
},
/**
* The ids of insecure credentials for which user clicked "Change
* Password" button
*/
clickedChangePasswordIds_: {
type: Object,
value: () => new Set(),
},
isMutingDisabled_: {
type: Boolean,
computed: 'computeIsMutingDisabled_(' +
'prefs.profile.password_dismiss_compromised_alert.value)',
},
};
}
declare private pageTitle_: string;
declare private pageSubtitle_: string;
declare private insecurityType_: CheckupSubpage|undefined;
declare private groups_: chrome.passwordsPrivate.CredentialGroup[];
declare private allInsecureCredentials_:
chrome.passwordsPrivate.PasswordUiEntry[];
declare private shownInsecureCredentials_:
chrome.passwordsPrivate.PasswordUiEntry[];
declare private credentialsWithReusedPassword_: ReusedPasswordInfo[];
declare private mutedCompromisedCredentials_:
chrome.passwordsPrivate.PasswordUiEntry[];
declare private activeListItem_: CheckupListItemElement|null;
declare private clickedChangePasswordIds_: Set<number>;
declare private isMutingDisabled_: boolean;
private insecureCredentialsChangedListener_: CredentialsChangedListener|null =
null;
override connectedCallback() {
super.connectedCallback();
const updateGroups = () => {
PasswordManagerImpl.getInstance().getCredentialGroups().then(
groups => this.groups_ = groups);
};
this.insecureCredentialsChangedListener_ = insecureCredentials => {
this.allInsecureCredentials_ = insecureCredentials;
updateGroups();
};
updateGroups();
PasswordManagerImpl.getInstance().getInsecureCredentials().then(
this.insecureCredentialsChangedListener_);
PasswordManagerImpl.getInstance().addInsecureCredentialsListener(
this.insecureCredentialsChangedListener_);
}
override currentRouteChanged(route: Route, oldRoute: Route): void {
if (route.page !== Page.CHECKUP_DETAILS) {
return;
}
this.insecurityType_ = route.details as unknown as CheckupSubpage;
// Focus back button when it's not direct navigation.
if (oldRoute !== undefined) {
setTimeout(() => { // Async to allow page to load.
this.$.backButton.focus();
});
}
}
private navigateBack_() {
Router.getInstance().navigateTo(Page.CHECKUP);
}
private async updateShownCredentials_() {
if (!this.insecurityType_ || !this.allInsecureCredentials_) {
return;
}
const insecureCredentialsForThisType = this.allInsecureCredentials_.filter(
cred => cred.compromisedInfo!.compromiseTypes.some(type => {
return this.getInsecurityType_().includes(type);
}));
const insuecureCredentialsSorter =
(lhs: chrome.passwordsPrivate.PasswordUiEntry,
rhs: chrome.passwordsPrivate.PasswordUiEntry) => {
if ((this.getCurrentGroup_(lhs.id)?.name || '') >
(this.getCurrentGroup_(rhs.id)?.name || '')) {
return 1;
}
return -1;
};
if (this.isCompromisedType()) {
// Compromised credentials can be muted. Show muted credentials
// separately.
this.mutedCompromisedCredentials_ = insecureCredentialsForThisType.filter(
cred => cred.compromisedInfo!.isMuted);
this.shownInsecureCredentials_ = insecureCredentialsForThisType.filter(
cred => !cred.compromisedInfo!.isMuted);
} else {
insecureCredentialsForThisType.sort(insuecureCredentialsSorter);
this.shownInsecureCredentials_ = insecureCredentialsForThisType;
}
if (this.isReusedType()) {
const allReusedCredentials = await PasswordManagerImpl.getInstance()
.getCredentialsWithReusedPassword();
this.credentialsWithReusedPassword_ =
await Promise.all(allReusedCredentials.map(
async(credentials): Promise<ReusedPasswordInfo> => {
const reuseInfo = new ReusedPasswordInfo(
credentials.entries.sort(insuecureCredentialsSorter));
await reuseInfo.init();
return reuseInfo;
}));
this.credentialsWithReusedPassword_.sort(
(lhs, rhs) =>
(lhs.credentials.length > rhs.credentials.length ? -1 : 1));
}
}
private async onCredentialsChanged_() {
assert(this.insecurityType_);
this.pageTitle_ = await PluralStringProxyImpl.getInstance().getPluralString(
this.insecurityType_.concat('Passwords'),
this.shownInsecureCredentials_.length);
if (this.insecurityType_ === CheckupSubpage.COMPROMISED) {
this.pageSubtitle_ =
await PluralStringProxyImpl.getInstance().getPluralString(
`${this.insecurityType_}PasswordsTitle`,
this.shownInsecureCredentials_.length);
} else {
this.pageSubtitle_ = this.i18n(`${this.insecurityType_}PasswordsTitle`);
}
}
private getInsecurityType_(): chrome.passwordsPrivate.CompromiseType[] {
assert(this.insecurityType_);
switch (this.insecurityType_) {
case CheckupSubpage.COMPROMISED:
return [
chrome.passwordsPrivate.CompromiseType.LEAKED,
chrome.passwordsPrivate.CompromiseType.PHISHED,
];
case CheckupSubpage.REUSED:
return [chrome.passwordsPrivate.CompromiseType.REUSED];
case CheckupSubpage.WEAK:
return [chrome.passwordsPrivate.CompromiseType.WEAK];
}
}
private getDescription_() {
assert(this.insecurityType_);
return this.i18n(`${this.insecurityType_}PasswordsDescription`);
}
private isCompromisedType(): boolean {
return this.insecurityType_ === CheckupSubpage.COMPROMISED;
}
private isReusedType(): boolean {
return this.insecurityType_ === CheckupSubpage.REUSED;
}
private onMoreActionsClick_(event: CustomEvent) {
const target = event.detail.target;
this.$.moreActionsMenu.showAt(target);
this.activeListItem_ =
event.detail.listItem as unknown as CheckupListItemElement;
}
private onMenuShowPasswordClick_() {
this.activeListItem_?.showHidePassword();
this.$.moreActionsMenu.close();
this.activeListItem_ = null;
PasswordManagerImpl.getInstance().recordPasswordCheckInteraction(
PasswordCheckInteraction.SHOW_PASSWORD);
}
private onMenuEditPasswordClick_() {
this.activeListItem_?.showEditDialog();
this.$.moreActionsMenu.close();
this.activeListItem_ = null;
PasswordManagerImpl.getInstance().recordPasswordCheckInteraction(
PasswordCheckInteraction.EDIT_PASSWORD);
}
private onMenuDeletePasswordClick_() {
this.activeListItem_?.showDeleteDialog();
this.$.moreActionsMenu.close();
this.activeListItem_ = null;
}
private getShowHideTitle_(): string {
return this.activeListItem_?.getShowHideButtonLabel() || '';
}
private computeIsMutingDisabled_(): boolean {
return !this.getPref('profile.password_dismiss_compromised_alert').value;
}
private getMuteUnmuteLabel_(): string {
return this.activeListItem_?.item.compromisedInfo?.isMuted === true ?
this.i18n('unmuteCompromisedPassword') :
this.i18n('muteCompromisedPassword');
}
private onMenuMuteUnmuteClick_() {
assert(this.activeListItem_);
if (this.activeListItem_.item.compromisedInfo?.isMuted === true) {
PasswordManagerImpl.getInstance().recordPasswordCheckInteraction(
PasswordCheckInteraction.UNMUTE_PASSWORD);
PasswordManagerImpl.getInstance().unmuteInsecureCredential(
this.activeListItem_.item);
} else {
PasswordManagerImpl.getInstance().recordPasswordCheckInteraction(
PasswordCheckInteraction.MUTE_PASSWORD);
PasswordManagerImpl.getInstance().muteInsecureCredential(
this.activeListItem_.item);
}
this.$.moreActionsMenu.close();
}
private getCurrentGroup_(id: number): chrome.passwordsPrivate.CredentialGroup
|undefined {
return this.groups_.find(
group => group.entries.some(entry => entry.id === id));
}
private onChangePasswordClick_(event: CustomEvent<number>) {
this.clickedChangePasswordIds_.add(event.detail);
this.notifyPath('clickedChangePasswordIds_.size');
PasswordManagerImpl.getInstance().recordPasswordCheckInteraction(
PasswordCheckInteraction.CHANGE_PASSWORD);
}
private clickedChangePassword_(item: chrome.passwordsPrivate.PasswordUiEntry):
boolean {
return this.clickedChangePasswordIds_.has(item.id);
}
}
declare global {
interface HTMLElementTagNameMap {
'checkup-details-section': CheckupDetailsSectionElement;
}
}
customElements.define(
CheckupDetailsSectionElement.is, CheckupDetailsSectionElement);
|