dont attempt certain bg tasks when locked state

This commit is contained in:
Kyle Spearrin 2019-03-06 16:50:04 -05:00
parent f4496a6f15
commit 856776a7cf
5 changed files with 118 additions and 76 deletions

View File

@ -4,10 +4,9 @@ import MainBackground from './main.background';
import { Analytics } from 'jslib/misc';
import {
PasswordGenerationService,
PlatformUtilsService,
} from 'jslib/abstractions';
import { LockService } from 'jslib/abstractions/lock.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export default class CommandsBackground {
private commands: any;
@ -16,7 +15,8 @@ export default class CommandsBackground {
private isVivaldi: boolean;
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
private platformUtilsService: PlatformUtilsService, private analytics: Analytics) {
private platformUtilsService: PlatformUtilsService, private analytics: Analytics,
private lockService: LockService) {
this.isSafari = this.platformUtilsService.isSafari();
this.isEdge = this.platformUtilsService.isEdge();
this.isVivaldi = this.platformUtilsService.isVivaldi();
@ -63,6 +63,10 @@ export default class CommandsBackground {
return;
}
if (await this.lockService.isLocked()) {
return;
}
const options = await this.passwordGenerationService.getOptions();
const password = await this.passwordGenerationService.generatePassword(options);
this.platformUtilsService.copyToClipboard(password, { window: window });
@ -75,6 +79,10 @@ export default class CommandsBackground {
}
private async autoFillLogin(tab?: any) {
if (await this.lockService.isLocked()) {
return;
}
if (!tab) {
tab = await BrowserApi.getTabFromCurrentWindowId();
}
@ -83,7 +91,7 @@ export default class CommandsBackground {
return;
}
this.main.collectPageDetailsForContentScript(tab, 'autofill_cmd');
await this.main.collectPageDetailsForContentScript(tab, 'autofill_cmd');
this.analytics.ga('send', {
hitType: 'event',

View File

@ -4,18 +4,17 @@ import MainBackground from './main.background';
import { Analytics } from 'jslib/misc';
import {
CipherService,
PasswordGenerationService,
PlatformUtilsService,
} from 'jslib/abstractions';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { LockService } from 'jslib/abstractions/lock.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export default class ContextMenusBackground {
private contextMenus: any;
constructor(private main: MainBackground, private cipherService: CipherService,
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics,
private platformUtilsService: PlatformUtilsService) {
private platformUtilsService: PlatformUtilsService, private lockService: LockService) {
this.contextMenus = chrome.contextMenus;
}
@ -35,6 +34,10 @@ export default class ContextMenusBackground {
}
private async generatePasswordToClipboard() {
if (await this.lockService.isLocked()) {
return;
}
const options = await this.passwordGenerationService.getOptions();
const password = await this.passwordGenerationService.generatePassword(options);
this.platformUtilsService.copyToClipboard(password, { window: window });
@ -55,34 +58,34 @@ export default class ContextMenusBackground {
return;
}
if (await this.lockService.isLocked()) {
return;
}
const ciphers = await this.cipherService.getAllDecrypted();
for (let i = 0; i < ciphers.length; i++) {
const cipher = ciphers[i];
if (cipher.id !== id) {
continue;
}
const cipher = ciphers.find((c) => c.id === id);
if (cipher == null) {
return;
}
if (info.parentMenuItemId === 'autofill') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Autofilled From Context Menu',
});
await this.startAutofillPage(cipher);
} else if (info.parentMenuItemId === 'copy-username') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Copied Username From Context Menu',
});
this.platformUtilsService.copyToClipboard(cipher.login.username, { window: window });
} else if (info.parentMenuItemId === 'copy-password') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Copied Password From Context Menu',
});
this.platformUtilsService.copyToClipboard(cipher.login.password, { window: window });
}
break;
if (info.parentMenuItemId === 'autofill') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Autofilled From Context Menu',
});
await this.startAutofillPage(cipher);
} else if (info.parentMenuItemId === 'copy-username') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Copied Username From Context Menu',
});
this.platformUtilsService.copyToClipboard(cipher.login.username, { window: window });
} else if (info.parentMenuItemId === 'copy-password') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Copied Password From Context Menu',
});
this.platformUtilsService.copyToClipboard(cipher.login.password, { window: window });
}
}

View File

@ -191,16 +191,17 @@ export default class MainBackground {
// Background
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
this.analytics, this.notificationsService, this.systemService);
this.analytics, this.notificationsService, this.systemService, this.lockService);
this.tabsBackground = new TabsBackground(this, this.platformUtilsService);
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
this.platformUtilsService, this.analytics);
this.platformUtilsService, this.analytics, this.lockService);
if (!this.isSafari) {
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
this.passwordGenerationService, this.analytics, this.platformUtilsService);
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService);
this.idleBackground = new IdleBackground(this.lockService, this.storageService, this.notificationsService);
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService);
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService,
this.lockService);
this.windowsBackground = new WindowsBackground(this);
}
}
@ -305,11 +306,15 @@ export default class MainBackground {
await this.systemService.clearPendingClipboard();
}
collectPageDetailsForContentScript(tab: any, sender: string, frameId: number = null) {
async collectPageDetailsForContentScript(tab: any, sender: string, frameId: number = null) {
if (tab == null || !tab.id) {
return;
}
if (await this.lockService.isLocked()) {
return;
}
const options: any = {};
if (frameId != null) {
options.frameId = frameId;
@ -463,32 +468,36 @@ export default class MainBackground {
this.actionSetBadgeBackgroundColor(this.sidebarAction);
this.menuOptionsLoaded = [];
try {
const ciphers = await this.cipherService.getAllDecryptedForUrl(url);
ciphers.sort((a, b) => this.cipherService.sortCiphersByLastUsedThenName(a, b));
const locked = await this.lockService.isLocked();
if (!locked) {
try {
const ciphers = await this.cipherService.getAllDecryptedForUrl(url);
ciphers.sort((a, b) => this.cipherService.sortCiphersByLastUsedThenName(a, b));
if (contextMenuEnabled) {
ciphers.forEach((cipher) => {
this.loadLoginContextMenuOptions(cipher);
});
}
let theText = '';
if (ciphers.length > 0 && ciphers.length < 9) {
theText = ciphers.length.toString();
} else if (ciphers.length > 0) {
theText = '9+';
} else {
if (contextMenuEnabled) {
await this.loadNoLoginsContextMenuOptions(this.i18nService.t('noMatchingLogins'));
ciphers.forEach((cipher) => {
this.loadLoginContextMenuOptions(cipher);
});
}
}
this.browserActionSetBadgeText(theText, tabId);
this.sidebarActionSetBadgeText(theText, tabId);
} catch (e) {
await this.loadMenuAndUpdateBadgeForLockedState(contextMenuEnabled);
let theText = '';
if (ciphers.length > 0 && ciphers.length < 9) {
theText = ciphers.length.toString();
} else if (ciphers.length > 0) {
theText = '9+';
} else {
if (contextMenuEnabled) {
await this.loadNoLoginsContextMenuOptions(this.i18nService.t('noMatchingLogins'));
}
}
this.browserActionSetBadgeText(theText, tabId);
this.sidebarActionSetBadgeText(theText, tabId);
return;
} catch { }
}
await this.loadMenuAndUpdateBadgeForLockedState(contextMenuEnabled);
}
private async loadMenuAndUpdateBadgeForLockedState(contextMenuEnabled: boolean) {

View File

@ -10,10 +10,9 @@ import { I18nService } from 'jslib/abstractions/i18n.service';
import { Analytics } from 'jslib/misc';
import {
CipherService,
StorageService,
} from 'jslib/abstractions';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { LockService } from 'jslib/abstractions/lock.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { SystemService } from 'jslib/abstractions/system.service';
import { BrowserApi } from '../browser/browserApi';
@ -38,7 +37,7 @@ export default class RuntimeBackground {
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
private storageService: StorageService, private i18nService: I18nService,
private analytics: Analytics, private notificationsService: NotificationsService,
private systemService: SystemService) {
private systemService: SystemService, private lockService: LockService) {
this.isSafari = this.platformUtilsService.isSafari();
this.runtime = this.isSafari ? safari.application : chrome.runtime;
@ -115,7 +114,7 @@ export default class RuntimeBackground {
await BrowserApi.tabSendMessageData(sender.tab, 'adjustNotificationBar', msg.data);
break;
case 'bgCollectPageDetails':
this.main.collectPageDetailsForContentScript(sender.tab, msg.sender, sender.frameId);
await this.main.collectPageDetailsForContentScript(sender.tab, msg.sender, sender.frameId);
break;
case 'bgAddLogin':
await this.addLogin(msg.login, sender.tab);
@ -146,6 +145,9 @@ export default class RuntimeBackground {
await this.main.reseedStorage();
break;
case 'collectPageDetailsResponse':
if (await this.lockService.isLocked()) {
return;
}
switch (msg.sender) {
case 'notificationBar':
const forms = this.autofillService.getFormsWithPasswordFields(msg.details);
@ -199,6 +201,10 @@ export default class RuntimeBackground {
}
private async saveAddLogin(tab: any) {
if (await this.lockService.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') {
@ -235,6 +241,10 @@ export default class RuntimeBackground {
}
private async saveChangePassword(tab: any) {
if (await this.lockService.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') {
@ -284,6 +294,10 @@ export default class RuntimeBackground {
}
private async addLogin(loginInfo: any, tab: any) {
if (await this.lockService.isLocked()) {
return;
}
const loginDomain = Utils.getDomain(loginInfo.url);
if (loginDomain == null) {
return;
@ -320,6 +334,10 @@ export default class RuntimeBackground {
}
private async changedPassword(changeData: any, tab: any) {
if (await this.lockService.isLocked()) {
return;
}
const loginDomain = Utils.getDomain(changeData.url);
if (loginDomain == null) {
return;

View File

@ -1,15 +1,14 @@
import {
CipherService,
PlatformUtilsService,
} from 'jslib/abstractions';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { LockService } from 'jslib/abstractions/lock.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export default class WebRequestBackground {
private pendingAuthRequests: any[] = [];
private webRequest: any;
private isFirefox: boolean;
constructor(private platformUtilsService: PlatformUtilsService,
private cipherService: CipherService) {
constructor(platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
private lockService: LockService) {
this.webRequest = (window as any).chrome.webRequest;
this.isFirefox = platformUtilsService.isFirefox();
}
@ -45,6 +44,11 @@ export default class WebRequestBackground {
}
private async resolveAuthCredentials(domain: string, success: Function, error: Function) {
if (await this.lockService.isLocked()) {
error();
return;
}
try {
const ciphers = await this.cipherService.getAllDecryptedForUrl(domain);
if (ciphers == null || ciphers.length !== 1) {