1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

"Auto-fill on page load" options (#199)

* add autofill on page load props to models and view

For new per-login autofill on page load settings

* filter and cache ciphers per autofill setting

Used by the new autofill on page load feature to identify
matching ciphers and filter according to their autofill setting

* fix null check on array

* fix linting and style errors

* change cacheKey to avoid collision with real url

* Fix linting, set default value for aopl-options

* Fix linting

* update UI

* Remove autofillOnPageLoad from export

* Change enum to boolean

* Add storage key for autofillOnPageLoad default

* fix style
This commit is contained in:
Thomas Rittson
2021-05-18 10:08:28 +10:00
committed by GitHub
parent 7b3f9f12a4
commit 3d4ecaeb6a
9 changed files with 45 additions and 14 deletions

View File

@@ -454,16 +454,16 @@ export class CipherService implements CipherServiceAbstraction {
}
}
async getLastUsedForUrl(url: string): Promise<CipherView> {
return this.getCipherForUrl(url, true, false);
async getLastUsedForUrl(url: string, autofillOnPageLoad: boolean = false): Promise<CipherView> {
return this.getCipherForUrl(url, true, false, autofillOnPageLoad);
}
async getLastLaunchedForUrl(url: string): Promise<CipherView> {
return this.getCipherForUrl(url, false, true);
async getLastLaunchedForUrl(url: string, autofillOnPageLoad: boolean = false): Promise<CipherView> {
return this.getCipherForUrl(url, false, true, autofillOnPageLoad);
}
async getNextCipherForUrl(url: string): Promise<CipherView> {
return this.getCipherForUrl(url, false, false);
return this.getCipherForUrl(url, false, false, false);
}
updateLastUsedIndexForUrl(url: string) {
@@ -1032,6 +1032,7 @@ export class CipherService implements CipherServiceAbstraction {
case CipherType.Login:
cipher.login = new Login();
cipher.login.passwordRevisionDate = model.login.passwordRevisionDate;
cipher.login.autofillOnPageLoad = model.login.autofillOnPageLoad;
await this.encryptObjProperty(model.login, cipher.login, {
username: null,
password: null,
@@ -1093,21 +1094,33 @@ export class CipherService implements CipherServiceAbstraction {
}
}
private async getCipherForUrl(url: string, lastUsed: boolean, lastLaunched: boolean): Promise<CipherView> {
if (!this.sortedCiphersCache.isCached(url)) {
const ciphers = await this.getAllDecryptedForUrl(url);
private async getCipherForUrl(url: string, lastUsed: boolean, lastLaunched: boolean, autofillOnPageLoad: boolean): Promise<CipherView> {
const cacheKey = autofillOnPageLoad ? 'autofillOnPageLoad-' + url : url;
if (!this.sortedCiphersCache.isCached(cacheKey)) {
let ciphers = await this.getAllDecryptedForUrl(url);
if (!ciphers) {
return null;
}
this.sortedCiphersCache.addCiphers(url, ciphers);
if (autofillOnPageLoad) {
const autofillOnPageLoadDefault = await this.storageService.get(ConstantsService.autoFillOnPageLoadDefaultKey);
ciphers = ciphers.filter(cipher => cipher.login.autofillOnPageLoad ||
(cipher.login.autofillOnPageLoad === null && autofillOnPageLoadDefault));
if (ciphers.length === 0) {
return null;
}
}
this.sortedCiphersCache.addCiphers(cacheKey, ciphers);
}
if (lastLaunched) {
return this.sortedCiphersCache.getLastLaunched(url);
return this.sortedCiphersCache.getLastLaunched(cacheKey);
} else if (lastUsed) {
return this.sortedCiphersCache.getLastUsed(url);
return this.sortedCiphersCache.getLastUsed(cacheKey);
} else {
return this.sortedCiphersCache.getNext(url);
return this.sortedCiphersCache.getNext(cacheKey);
}
}
}