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 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
|
// 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.
/**
* @fileoverview PasswordManagerProxy is an abstraction over
* chrome.passwordsPrivate which facilitates testing.
*/
export type BlockedSite = chrome.passwordsPrivate.ExceptionEntry;
export type AccountStorageEnabledStateChangedListener =
(enabledState: boolean) => void;
export type CredentialsChangedListener =
(credentials: chrome.passwordsPrivate.PasswordUiEntry[]) => void;
export type PasswordCheckStatusChangedListener =
(status: chrome.passwordsPrivate.PasswordCheckStatus) => void;
export type BlockedSitesListChangedListener = (entries: BlockedSite[]) => void;
export type PasswordsFileExportProgressListener =
(progress: chrome.passwordsPrivate.PasswordExportProgress) => void;
export type PasswordManagerAuthTimeoutListener = () => void;
/**
* Represents different interactions the user can perform on the Password Check
* page.
*
* These values are persisted to logs. Entries should not be renumbered and
* numeric values should never be reused.
*
* Needs to stay in sync with PasswordCheckInteraction in enums.xml.
*/
export enum PasswordCheckInteraction {
START_CHECK_AUTOMATICALLY = 0,
START_CHECK_MANUALLY = 1,
STOP_CHECK = 2,
CHANGE_PASSWORD = 3,
EDIT_PASSWORD = 4,
REMOVE_PASSWORD = 5,
SHOW_PASSWORD = 6,
MUTE_PASSWORD = 7,
UNMUTE_PASSWORD = 8,
CHANGE_PASSWORD_AUTOMATICALLY = 9,
// Must be last.
COUNT = 10,
}
/**
* Should be kept in sync with PasswordViewPageInteractions in enums.xml.
* These values are persisted to logs. Entries should not be renumbered and
* numeric values should never be reused.
*/
export enum PasswordViewPageInteractions {
CREDENTIAL_ROW_CLICKED = 0,
CREDENTIAL_FOUND = 1,
CREDENTIAL_NOT_FOUND = 2,
USERNAME_COPY_BUTTON_CLICKED = 3,
PASSWORD_COPY_BUTTON_CLICKED = 4,
PASSWORD_SHOW_BUTTON_CLICKED = 5,
PASSWORD_EDIT_BUTTON_CLICKED = 6,
PASSWORD_DELETE_BUTTON_CLICKED = 7,
CREDENTIAL_EDITED = 8,
TIMED_OUT_IN_EDIT_DIALOG = 9,
TIMED_OUT_IN_VIEW_PAGE = 10,
CREDENTIAL_REQUESTED_BY_URL = 11,
PASSKEY_DISPLAY_NAME_COPY_BUTTON_CLICKED = 12,
PASSKEY_DELETE_BUTTON_CLICKED = 13,
PASSKEY_EDIT_BUTTON_CLICKED = 14,
// Must be last.
COUNT = 15,
}
/**
* Interface for all callbacks to the password API.
*/
export interface PasswordManagerProxy {
/**
* Add an observer to the list of saved passwords.
*/
addSavedPasswordListChangedListener(listener: CredentialsChangedListener):
void;
/**
* Remove an observer from the list of saved passwords.
*/
removeSavedPasswordListChangedListener(listener: CredentialsChangedListener):
void;
/**
* Add an observer to the list of blocked sites.
*/
addBlockedSitesListChangedListener(listener: BlockedSitesListChangedListener):
void;
/**
* Remove an observer from the list of blocked sites.
*/
removeBlockedSitesListChangedListener(
listener: BlockedSitesListChangedListener): void;
/**
* Add an observer to the passwords check status change.
*/
addPasswordCheckStatusListener(listener: PasswordCheckStatusChangedListener):
void;
/**
* Remove an observer to the passwords check status change.
*/
removePasswordCheckStatusListener(
listener: PasswordCheckStatusChangedListener): void;
/**
* Add an observer to the insecure passwords change.
*/
addInsecureCredentialsListener(listener: CredentialsChangedListener): void;
/**
* Remove an observer to the insecure passwords change.
*/
removeInsecureCredentialsListener(listener: CredentialsChangedListener): void;
/**
* Request the list of saved passwords.
*/
getSavedPasswordList(): Promise<chrome.passwordsPrivate.PasswordUiEntry[]>;
/**
* Request grouped credentials.
*/
getCredentialGroups(): Promise<chrome.passwordsPrivate.CredentialGroup[]>;
/**
* Request the list of blocked sites.
*/
getBlockedSitesList(): Promise<BlockedSite[]>;
/**
* Requests the current status of the check.
*/
getPasswordCheckStatus():
Promise<chrome.passwordsPrivate.PasswordCheckStatus>;
/**
* Requests the latest information about insecure credentials.
*/
getInsecureCredentials(): Promise<chrome.passwordsPrivate.PasswordUiEntry[]>;
/**
* Requests the latest information about insecure credentials.
*/
getCredentialsWithReusedPassword():
Promise<chrome.passwordsPrivate.PasswordUiEntryList[]>;
/**
* Requests the start of the bulk password check.
*/
startBulkPasswordCheck(): Promise<void>;
/**
* Records a given interaction on the Password Check page.
*/
recordPasswordCheckInteraction(interaction: PasswordCheckInteraction): void;
/**
* Records a given interaction on the Password details page.
*/
recordPasswordViewInteraction(interaction: PasswordViewPageInteractions):
void;
/**
* Triggers the shortcut creation dialog.
*/
showAddShortcutDialog(): void;
/**
* Gets the list of full (with note and password) credentials for given ids.
* @param ids The id for the password entries being retrieved.
* @return A promise that resolves to |PasswordUiEntry[]|.
*/
requestCredentialsDetails(ids: number[]):
Promise<chrome.passwordsPrivate.PasswordUiEntry[]>;
/**
* Gets the saved password for a given id and reason.
* @param id The id for the password entry being being retrieved.
* @param reason The reason why the plaintext password is requested.
* @return A promise that resolves to the plaintext password.
*/
requestPlaintextPassword(
id: number,
reason: chrome.passwordsPrivate.PlaintextReason): Promise<string>;
/**
* Saves a new password entry described by the given |options|.
* @param options Details about a new password and storage to be used.
* @return A promise that resolves when the new entry is added.
*/
addPassword(options: chrome.passwordsPrivate.AddPasswordOptions):
Promise<void>;
/**
* Fetches family members (password share recipients).
* @return A promise that resolves the FamilyFetchResults.
*/
fetchFamilyMembers(): Promise<chrome.passwordsPrivate.FamilyFetchResults>;
/**
* Sends sharing invitations to the recipients.
* @param id The id of the password entry to be shared.
* @param recipients The list of selected recipients.
*/
sharePassword(
id: number, recipients: chrome.passwordsPrivate.RecipientInfo[]): void;
/**
* Updates the given credential. Not all parameters can be updated.
* @param credential the credential to update.
* @return A promise that resolves if the credential was found and updated,
* rejects otherwise.
*/
changeCredential(credential: chrome.passwordsPrivate.PasswordUiEntry):
Promise<void>;
/**
* Should remove the credential and notify that the list has changed.
* @param id The id for the credential being removed. No-op if |id| is not in
* the list.
* @param fromStores The store from which credential should be removed.
*/
removeCredential(
id: number, fromStores: chrome.passwordsPrivate.PasswordStoreSet): void;
/**
* Should remove the blocked site and notify that the list has changed.
* @param id The id for the blocked url entry being removed. No-op if |id|
* is not in the list.
*/
removeBlockedSite(id: number): void;
/**
* Dismisses / mutes the |insecureCredential| in the passwords store.
*/
muteInsecureCredential(insecureCredential:
chrome.passwordsPrivate.PasswordUiEntry): void;
/**
* Restores / unmutes the |insecureCredential| in the passwords store.
*/
unmuteInsecureCredential(insecureCredential:
chrome.passwordsPrivate.PasswordUiEntry): void;
/**
* Should undo the last saved password or exception removal and notify that
* the list has changed.
*/
undoRemoveSavedPasswordOrException(): void;
/**
* Triggers the dialog for importing passwords.
* @return A promise that resolves to the import results.
*/
importPasswords(toStore: chrome.passwordsPrivate.PasswordStoreSet):
Promise<chrome.passwordsPrivate.ImportResults>;
/**
* Resumes the password import process when user has selected which passwords
* to replace.
* @return A promise that resolves to the |ImportResults|.
*/
continueImport(selectedIds: number[]):
Promise<chrome.passwordsPrivate.ImportResults>;
/**
* Resets the PasswordImporter if it is in the CONFLICTS/FINISHED state and
* the user closes the dialog. Only when the PasswordImporter is in FINISHED
* state, |deleteFile| option is taken into account.
* @param deleteFile Whether to trigger deletion of the last imported file.
*/
resetImporter(deleteFile: boolean): Promise<void>;
/**
* Queries the status of any ongoing export.
*/
requestExportProgressStatus():
Promise<chrome.passwordsPrivate.ExportProgressStatus>;
/**
* Triggers the dialog for exporting passwords.
*/
exportPasswords(): Promise<void>;
/**
* Add an observer to the export progress.
*/
addPasswordsFileExportProgressListener(
listener: PasswordsFileExportProgressListener): void;
/**
* Remove an observer from the export progress.
*/
removePasswordsFileExportProgressListener(
listener: PasswordsFileExportProgressListener): void;
/**
* Switches Biometric authentication before filling state after
* successful authentication.
* @return A promise that resolves with authentication result.
*/
switchBiometricAuthBeforeFillingState(): Promise<boolean>;
/**
* Shows the file with the exported passwords in the OS shell.
*/
showExportedFileInShell(filePath: string): void;
/**
* Requests whether the given |url| meets the requirements to save a password
* for it (e.g. valid, has proper scheme etc.).
* @return A promise that resolves to the corresponding URLCollection on
* success and to null otherwise.
*/
getUrlCollection(url: string):
Promise<chrome.passwordsPrivate.UrlCollection|null>;
/**
* Add an observer for authentication timeout.
*/
addPasswordManagerAuthTimeoutListener(
listener: PasswordManagerAuthTimeoutListener): void;
/**
* Remove the specified observer for authentication timeout.
*/
removePasswordManagerAuthTimeoutListener(
listener: PasswordManagerAuthTimeoutListener): void;
/**
* Requests extension of authentication validity.
*/
extendAuthValidity(): void;
/**
* Add an observer to the account storage enabled state.
*/
addAccountStorageEnabledStateListener(
listener: AccountStorageEnabledStateChangedListener): void;
/**
* Remove an observer to the account storage enabled state.
*/
removeAccountStorageEnabledStateListener(
listener: AccountStorageEnabledStateChangedListener): void;
/**
* Requests the account-storage enabled state of the current user.
* @return A promise that resolves to the enabled state.
*/
isAccountStorageEnabled(): Promise<boolean>;
/**
* Triggers the enabling/disabling flow for the account storage.
* @param enabled Whether the user wants to enable or disable.
*/
setAccountStorageEnabled(enabled: boolean): void;
/**
* Moves a list of passwords from the device to the account
* @param ids The ids for the password entries being moved.
*/
movePasswordsToAccount(ids: number[]): void;
/** Dismiss the menu notifications for the Safety Hub password module. */
dismissSafetyHubPasswordMenuNotification(): void;
/** Starts the flow for changing Password Manager PIN. */
changePasswordManagerPin(): Promise<boolean>;
/** Checks whether changing the Password Manager PIN is possible. */
isPasswordManagerPinAvailable(): Promise<boolean>;
/**
* Starts the flow for disconnecting the Cloud Authenticator
* (Passkeys Enclave).
*/
disconnectCloudAuthenticator(): Promise<boolean>;
/**
* Checks whether the Chrome client is connected to the Cloud Authenticator
* (Passkeys Enclave).
*/
isConnectedToCloudAuthenticator(): Promise<boolean>;
/**
* Deletes all password manager data (passwords, passkeys, etc.)
*/
deleteAllPasswordManagerData(): Promise<boolean>;
}
/**
* Implementation that accesses the private API.
*/
export class PasswordManagerImpl implements PasswordManagerProxy {
addSavedPasswordListChangedListener(listener: CredentialsChangedListener) {
chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(listener);
}
removeSavedPasswordListChangedListener(listener: CredentialsChangedListener) {
chrome.passwordsPrivate.onSavedPasswordsListChanged.removeListener(
listener);
}
addBlockedSitesListChangedListener(listener:
BlockedSitesListChangedListener) {
chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener(
listener);
}
removeBlockedSitesListChangedListener(listener:
BlockedSitesListChangedListener) {
chrome.passwordsPrivate.onPasswordExceptionsListChanged.removeListener(
listener);
}
addPasswordCheckStatusListener(listener: PasswordCheckStatusChangedListener) {
chrome.passwordsPrivate.onPasswordCheckStatusChanged.addListener(listener);
}
removePasswordCheckStatusListener(listener:
PasswordCheckStatusChangedListener) {
chrome.passwordsPrivate.onPasswordCheckStatusChanged.removeListener(
listener);
}
addInsecureCredentialsListener(listener: CredentialsChangedListener) {
chrome.passwordsPrivate.onInsecureCredentialsChanged.addListener(listener);
}
removeInsecureCredentialsListener(listener: CredentialsChangedListener) {
chrome.passwordsPrivate.onInsecureCredentialsChanged.removeListener(
listener);
}
getSavedPasswordList() {
return chrome.passwordsPrivate.getSavedPasswordList().catch(() => []);
}
getCredentialGroups() {
return chrome.passwordsPrivate.getCredentialGroups();
}
getBlockedSitesList() {
return chrome.passwordsPrivate.getPasswordExceptionList().catch(() => []);
}
getPasswordCheckStatus() {
return chrome.passwordsPrivate.getPasswordCheckStatus();
}
getInsecureCredentials() {
return chrome.passwordsPrivate.getInsecureCredentials();
}
getCredentialsWithReusedPassword() {
return chrome.passwordsPrivate.getCredentialsWithReusedPassword();
}
startBulkPasswordCheck() {
return chrome.passwordsPrivate.startPasswordCheck();
}
recordPasswordCheckInteraction(interaction: PasswordCheckInteraction) {
chrome.metricsPrivate.recordEnumerationValue(
'PasswordManager.BulkCheck.UserAction', interaction,
PasswordCheckInteraction.COUNT);
}
recordPasswordViewInteraction(interaction: PasswordViewPageInteractions) {
chrome.metricsPrivate.recordEnumerationValue(
'PasswordManager.PasswordViewPage.UserActions', interaction,
PasswordViewPageInteractions.COUNT);
}
showAddShortcutDialog() {
chrome.passwordsPrivate.showAddShortcutDialog();
}
requestCredentialsDetails(ids: number[]) {
return chrome.passwordsPrivate.requestCredentialsDetails(ids);
}
requestPlaintextPassword(
id: number, reason: chrome.passwordsPrivate.PlaintextReason) {
return chrome.passwordsPrivate.requestPlaintextPassword(id, reason);
}
addPassword(options: chrome.passwordsPrivate.AddPasswordOptions) {
return chrome.passwordsPrivate.addPassword(options);
}
changeCredential(credential: chrome.passwordsPrivate.PasswordUiEntry) {
return chrome.passwordsPrivate.changeCredential(credential);
}
removeCredential(
id: number, fromStores: chrome.passwordsPrivate.PasswordStoreSet) {
chrome.passwordsPrivate.removeCredential(id, fromStores);
}
removeBlockedSite(id: number) {
chrome.passwordsPrivate.removePasswordException(id);
}
muteInsecureCredential(insecureCredential:
chrome.passwordsPrivate.PasswordUiEntry) {
chrome.passwordsPrivate.muteInsecureCredential(insecureCredential);
}
unmuteInsecureCredential(insecureCredential:
chrome.passwordsPrivate.PasswordUiEntry) {
chrome.passwordsPrivate.unmuteInsecureCredential(insecureCredential);
}
undoRemoveSavedPasswordOrException() {
chrome.passwordsPrivate.undoRemoveSavedPasswordOrException();
}
fetchFamilyMembers() {
return chrome.passwordsPrivate.fetchFamilyMembers();
}
sharePassword(
id: number, recipients: chrome.passwordsPrivate.RecipientInfo[]) {
chrome.passwordsPrivate.sharePassword(id, recipients);
}
importPasswords(toStore: chrome.passwordsPrivate.PasswordStoreSet) {
return chrome.passwordsPrivate.importPasswords(toStore);
}
continueImport(selectedIds: number[]) {
return chrome.passwordsPrivate.continueImport(selectedIds);
}
resetImporter(deleteFile: boolean) {
return chrome.passwordsPrivate.resetImporter(deleteFile);
}
requestExportProgressStatus() {
return chrome.passwordsPrivate.requestExportProgressStatus();
}
exportPasswords() {
return chrome.passwordsPrivate.exportPasswords();
}
addPasswordsFileExportProgressListener(
listener: PasswordsFileExportProgressListener) {
chrome.passwordsPrivate.onPasswordsFileExportProgress.addListener(listener);
}
removePasswordsFileExportProgressListener(
listener: PasswordsFileExportProgressListener) {
chrome.passwordsPrivate.onPasswordsFileExportProgress.removeListener(
listener);
}
switchBiometricAuthBeforeFillingState() {
return chrome.passwordsPrivate.switchBiometricAuthBeforeFillingState();
}
showExportedFileInShell(filePath: string) {
chrome.passwordsPrivate.showExportedFileInShell(filePath);
}
getUrlCollection(url: string) {
return chrome.passwordsPrivate.getUrlCollection(url);
}
addPasswordManagerAuthTimeoutListener(
listener: PasswordManagerAuthTimeoutListener) {
chrome.passwordsPrivate.onPasswordManagerAuthTimeout.addListener(listener);
}
removePasswordManagerAuthTimeoutListener(
listener: PasswordManagerAuthTimeoutListener) {
chrome.passwordsPrivate.onPasswordManagerAuthTimeout.removeListener(
listener);
}
extendAuthValidity() {
chrome.passwordsPrivate.extendAuthValidity();
}
addAccountStorageEnabledStateListener(
listener: AccountStorageEnabledStateChangedListener) {
chrome.passwordsPrivate.onAccountStorageEnabledStateChanged.addListener(
listener);
}
removeAccountStorageEnabledStateListener(
listener: AccountStorageEnabledStateChangedListener) {
chrome.passwordsPrivate.onAccountStorageEnabledStateChanged.removeListener(
listener);
}
isAccountStorageEnabled() {
return chrome.passwordsPrivate.isAccountStorageEnabled();
}
setAccountStorageEnabled(enabled: boolean) {
chrome.passwordsPrivate.setAccountStorageEnabled(enabled);
}
movePasswordsToAccount(ids: number[]) {
chrome.passwordsPrivate.movePasswordsToAccount(ids);
}
dismissSafetyHubPasswordMenuNotification() {
chrome.send('dismissSafetyHubPasswordMenuNotification');
}
changePasswordManagerPin() {
return chrome.passwordsPrivate.changePasswordManagerPin();
}
isPasswordManagerPinAvailable() {
return chrome.passwordsPrivate.isPasswordManagerPinAvailable();
}
disconnectCloudAuthenticator() {
return chrome.passwordsPrivate.disconnectCloudAuthenticator();
}
isConnectedToCloudAuthenticator() {
return chrome.passwordsPrivate.isConnectedToCloudAuthenticator();
}
deleteAllPasswordManagerData() {
return chrome.passwordsPrivate.deleteAllPasswordManagerData();
}
static getInstance(): PasswordManagerProxy {
return instance || (instance = new PasswordManagerImpl());
}
static setInstance(obj: PasswordManagerProxy) {
instance = obj;
}
}
let instance: PasswordManagerProxy|null = null;
|