Remove methods that are not used

This commit is contained in:
Robyn MacCallum 2021-12-13 14:41:34 -05:00
parent f7d2e9c6a4
commit edadeb95ea
1 changed files with 2 additions and 222 deletions

View File

@ -201,194 +201,6 @@ export default class RuntimeBackground {
this.pageDetailsToAutoFill = [];
}
private async saveAddLogin(tab: any, folderId: string) {
if (await this.vaultTimeoutService.isLocked()) {
return;
}
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
const queueMessage = this.main.notificationQueue[i];
if (queueMessage.tabId !== tab.id || queueMessage.type !== 'addLogin') {
continue;
}
const tabDomain = Utils.getDomain(tab.url);
if (tabDomain != null && tabDomain !== queueMessage.domain) {
continue;
}
this.main.notificationQueue.splice(i, 1);
BrowserApi.tabSendMessageData(tab, 'closeNotificationBar');
const loginModel = new LoginView();
const loginUri = new LoginUriView();
loginUri.uri = queueMessage.uri;
loginModel.uris = [loginUri];
loginModel.username = queueMessage.username;
loginModel.password = queueMessage.password;
const model = new CipherView();
model.name = Utils.getHostname(queueMessage.uri) || queueMessage.domain;
model.name = model.name.replace(/^www\./, '');
model.type = CipherType.Login;
model.login = loginModel;
if (!Utils.isNullOrWhitespace(folderId)) {
const folders = await this.folderService.getAllDecrypted();
if (folders.some(x => x.id === folderId)) {
model.folderId = folderId;
}
}
const cipher = await this.cipherService.encrypt(model);
await this.cipherService.saveWithServer(cipher);
}
}
private async saveChangePassword(tab: any) {
if (await this.vaultTimeoutService.isLocked()) {
return;
}
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
const queueMessage = this.main.notificationQueue[i];
if (queueMessage.tabId !== tab.id || queueMessage.type !== 'changePassword') {
continue;
}
const tabDomain = Utils.getDomain(tab.url);
if (tabDomain != null && tabDomain !== queueMessage.domain) {
continue;
}
this.main.notificationQueue.splice(i, 1);
BrowserApi.tabSendMessageData(tab, 'closeNotificationBar');
const cipher = await this.cipherService.get(queueMessage.cipherId);
if (cipher != null && cipher.type === CipherType.Login) {
const model = await cipher.decrypt();
model.login.password = queueMessage.newPassword;
const newCipher = await this.cipherService.encrypt(model);
await this.cipherService.saveWithServer(newCipher);
}
}
}
private async saveNever(tab: any) {
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
const queueMessage = this.main.notificationQueue[i];
if (queueMessage.tabId !== tab.id || queueMessage.type !== 'addLogin') {
continue;
}
const tabDomain = Utils.getDomain(tab.url);
if (tabDomain != null && tabDomain !== queueMessage.domain) {
continue;
}
this.main.notificationQueue.splice(i, 1);
BrowserApi.tabSendMessageData(tab, 'closeNotificationBar');
const hostname = Utils.getHostname(tab.url);
await this.cipherService.saveNeverDomain(hostname);
}
}
private async addLogin(loginInfo: any, tab: any) {
if (await this.vaultTimeoutService.isLocked()) {
return;
}
const loginDomain = Utils.getDomain(loginInfo.url);
if (loginDomain == null) {
return;
}
let normalizedUsername = loginInfo.username;
if (normalizedUsername != null) {
normalizedUsername = normalizedUsername.toLowerCase();
}
const ciphers = await this.cipherService.getAllDecryptedForUrl(loginInfo.url);
const usernameMatches = ciphers.filter(c =>
c.login.username != null && c.login.username.toLowerCase() === normalizedUsername);
if (usernameMatches.length === 0) {
const disabledAddLogin = await this.stateService.getDisableAddLoginNotification();
if (disabledAddLogin) {
return;
}
if (!(await this.allowPersonalOwnership())) {
return;
}
// remove any old messages for this tab
this.removeTabFromNotificationQueue(tab);
this.main.notificationQueue.push({
type: 'addLogin',
username: loginInfo.username,
password: loginInfo.password,
domain: loginDomain,
uri: loginInfo.url,
tabId: tab.id,
expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes
});
await this.main.checkNotificationQueue(tab);
} else if (usernameMatches.length === 1 && usernameMatches[0].login.password !== loginInfo.password) {
const disabledChangePassword = await this.stateService.getDisableChangedPasswordNotification();
if (disabledChangePassword) {
return;
}
this.addChangedPasswordToQueue(usernameMatches[0].id, loginDomain, loginInfo.password, tab);
}
}
private async changedPassword(changeData: any, tab: any) {
if (await this.vaultTimeoutService.isLocked()) {
return;
}
const loginDomain = Utils.getDomain(changeData.url);
if (loginDomain == null) {
return;
}
let id: string = null;
const ciphers = await this.cipherService.getAllDecryptedForUrl(changeData.url);
if (changeData.currentPassword != null) {
const passwordMatches = ciphers.filter(c => c.login.password === changeData.currentPassword);
if (passwordMatches.length === 1) {
id = passwordMatches[0].id;
}
} else if (ciphers.length === 1) {
id = ciphers[0].id;
}
if (id != null) {
this.addChangedPasswordToQueue(id, loginDomain, changeData.newPassword, tab);
}
}
private async addChangedPasswordToQueue(cipherId: string, loginDomain: string, newPassword: string, tab: any) {
// remove any old messages for this tab
this.removeTabFromNotificationQueue(tab);
this.main.notificationQueue.push({
type: 'changePassword',
cipherId: cipherId,
newPassword: newPassword,
domain: loginDomain,
tabId: tab.id,
expires: new Date((new Date()).getTime() + 30 * 60000), // 30 minutes
});
await this.main.checkNotificationQueue(tab);
}
private removeTabFromNotificationQueue(tab: any) {
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
if (this.main.notificationQueue[i].tabId === tab.id) {
this.main.notificationQueue.splice(i, 1);
}
}
}
private async checkOnInstalled() {
setTimeout(async () => {
if (this.onInstalledReason != null) {
@ -406,45 +218,13 @@ export default class RuntimeBackground {
// Default timeout option to "on restart".
const currentVaultTimeout = await this.stateService.getVaultTimeout();
if (currentVaultTimeout == null) {
// await this.stateService.setVaultTimeout(-1);
await this.stateService.setVaultTimeout(-1);
}
// Default action to "lock".
const currentVaultTimeoutAction = await this.stateService.getVaultTimeoutAction();
if (currentVaultTimeoutAction == null) {
// await this.stateService.setVaultTimeoutAction('lock');
await this.stateService.setVaultTimeoutAction('lock');
}
}
private async getDataForTab(tab: any, responseCommand: string) {
const responseData: any = {};
if (responseCommand === 'notificationBarDataResponse') {
responseData.neverDomains = await this.stateService.getNeverDomains();
const disableAddLoginFromOptions = await this.stateService.getDisableAddLoginNotification();
responseData.disabledAddLoginNotification = disableAddLoginFromOptions || !(await this.allowPersonalOwnership());
responseData.disabledChangedPasswordNotification = await this.stateService.getDisableChangedPasswordNotification();
} else if (responseCommand === 'autofillerAutofillOnPageLoadEnabledResponse') {
responseData.autofillEnabled = await this.stateService.getEnableAutoFillOnPageLoad();
} else if (responseCommand === 'notificationBarFrameDataResponse') {
responseData.i18n = {
appName: this.i18nService.t('appName'),
close: this.i18nService.t('close'),
yes: this.i18nService.t('yes'),
never: this.i18nService.t('never'),
notificationAddSave: this.i18nService.t('notificationAddSave'),
notificationNeverSave: this.i18nService.t('notificationNeverSave'),
notificationAddDesc: this.i18nService.t('notificationAddDesc'),
notificationChangeSave: this.i18nService.t('notificationChangeSave'),
notificationChangeDesc: this.i18nService.t('notificationChangeDesc'),
};
} else if (responseCommand === 'notificationBarGetFoldersList') {
responseData.folders = await this.folderService.getAllDecrypted();
}
await BrowserApi.tabSendMessageData(tab, responseCommand, responseData);
}
private async allowPersonalOwnership(): Promise<boolean> {
return !await this.policyService.policyAppliesToUser(PolicyType.PersonalOwnership);
}
}