mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
dont attempt certain bg tasks when locked state
This commit is contained in:
@@ -4,10 +4,9 @@ import MainBackground from './main.background';
|
|||||||
|
|
||||||
import { Analytics } from 'jslib/misc';
|
import { Analytics } from 'jslib/misc';
|
||||||
|
|
||||||
import {
|
import { LockService } from 'jslib/abstractions/lock.service';
|
||||||
PasswordGenerationService,
|
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||||
PlatformUtilsService,
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
} from 'jslib/abstractions';
|
|
||||||
|
|
||||||
export default class CommandsBackground {
|
export default class CommandsBackground {
|
||||||
private commands: any;
|
private commands: any;
|
||||||
@@ -16,7 +15,8 @@ export default class CommandsBackground {
|
|||||||
private isVivaldi: boolean;
|
private isVivaldi: boolean;
|
||||||
|
|
||||||
constructor(private main: MainBackground, private passwordGenerationService: PasswordGenerationService,
|
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.isSafari = this.platformUtilsService.isSafari();
|
||||||
this.isEdge = this.platformUtilsService.isEdge();
|
this.isEdge = this.platformUtilsService.isEdge();
|
||||||
this.isVivaldi = this.platformUtilsService.isVivaldi();
|
this.isVivaldi = this.platformUtilsService.isVivaldi();
|
||||||
@@ -63,6 +63,10 @@ export default class CommandsBackground {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const options = await this.passwordGenerationService.getOptions();
|
const options = await this.passwordGenerationService.getOptions();
|
||||||
const password = await this.passwordGenerationService.generatePassword(options);
|
const password = await this.passwordGenerationService.generatePassword(options);
|
||||||
this.platformUtilsService.copyToClipboard(password, { window: window });
|
this.platformUtilsService.copyToClipboard(password, { window: window });
|
||||||
@@ -75,6 +79,10 @@ export default class CommandsBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async autoFillLogin(tab?: any) {
|
private async autoFillLogin(tab?: any) {
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!tab) {
|
if (!tab) {
|
||||||
tab = await BrowserApi.getTabFromCurrentWindowId();
|
tab = await BrowserApi.getTabFromCurrentWindowId();
|
||||||
}
|
}
|
||||||
@@ -83,7 +91,7 @@ export default class CommandsBackground {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.main.collectPageDetailsForContentScript(tab, 'autofill_cmd');
|
await this.main.collectPageDetailsForContentScript(tab, 'autofill_cmd');
|
||||||
|
|
||||||
this.analytics.ga('send', {
|
this.analytics.ga('send', {
|
||||||
hitType: 'event',
|
hitType: 'event',
|
||||||
|
|||||||
@@ -4,18 +4,17 @@ import MainBackground from './main.background';
|
|||||||
|
|
||||||
import { Analytics } from 'jslib/misc';
|
import { Analytics } from 'jslib/misc';
|
||||||
|
|
||||||
import {
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
CipherService,
|
import { LockService } from 'jslib/abstractions/lock.service';
|
||||||
PasswordGenerationService,
|
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||||
PlatformUtilsService,
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
} from 'jslib/abstractions';
|
|
||||||
|
|
||||||
export default class ContextMenusBackground {
|
export default class ContextMenusBackground {
|
||||||
private contextMenus: any;
|
private contextMenus: any;
|
||||||
|
|
||||||
constructor(private main: MainBackground, private cipherService: CipherService,
|
constructor(private main: MainBackground, private cipherService: CipherService,
|
||||||
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics,
|
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics,
|
||||||
private platformUtilsService: PlatformUtilsService) {
|
private platformUtilsService: PlatformUtilsService, private lockService: LockService) {
|
||||||
this.contextMenus = chrome.contextMenus;
|
this.contextMenus = chrome.contextMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +34,10 @@ export default class ContextMenusBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async generatePasswordToClipboard() {
|
private async generatePasswordToClipboard() {
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const options = await this.passwordGenerationService.getOptions();
|
const options = await this.passwordGenerationService.getOptions();
|
||||||
const password = await this.passwordGenerationService.generatePassword(options);
|
const password = await this.passwordGenerationService.generatePassword(options);
|
||||||
this.platformUtilsService.copyToClipboard(password, { window: window });
|
this.platformUtilsService.copyToClipboard(password, { window: window });
|
||||||
@@ -55,34 +58,34 @@ export default class ContextMenusBackground {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const ciphers = await this.cipherService.getAllDecrypted();
|
const ciphers = await this.cipherService.getAllDecrypted();
|
||||||
for (let i = 0; i < ciphers.length; i++) {
|
const cipher = ciphers.find((c) => c.id === id);
|
||||||
const cipher = ciphers[i];
|
if (cipher == null) {
|
||||||
if (cipher.id !== id) {
|
return;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (info.parentMenuItemId === 'autofill') {
|
if (info.parentMenuItemId === 'autofill') {
|
||||||
this.analytics.ga('send', {
|
this.analytics.ga('send', {
|
||||||
hitType: 'event',
|
hitType: 'event',
|
||||||
eventAction: 'Autofilled From Context Menu',
|
eventAction: 'Autofilled From Context Menu',
|
||||||
});
|
});
|
||||||
await this.startAutofillPage(cipher);
|
await this.startAutofillPage(cipher);
|
||||||
} else if (info.parentMenuItemId === 'copy-username') {
|
} else if (info.parentMenuItemId === 'copy-username') {
|
||||||
this.analytics.ga('send', {
|
this.analytics.ga('send', {
|
||||||
hitType: 'event',
|
hitType: 'event',
|
||||||
eventAction: 'Copied Username From Context Menu',
|
eventAction: 'Copied Username From Context Menu',
|
||||||
});
|
});
|
||||||
this.platformUtilsService.copyToClipboard(cipher.login.username, { window: window });
|
this.platformUtilsService.copyToClipboard(cipher.login.username, { window: window });
|
||||||
} else if (info.parentMenuItemId === 'copy-password') {
|
} else if (info.parentMenuItemId === 'copy-password') {
|
||||||
this.analytics.ga('send', {
|
this.analytics.ga('send', {
|
||||||
hitType: 'event',
|
hitType: 'event',
|
||||||
eventAction: 'Copied Password From Context Menu',
|
eventAction: 'Copied Password From Context Menu',
|
||||||
});
|
});
|
||||||
this.platformUtilsService.copyToClipboard(cipher.login.password, { window: window });
|
this.platformUtilsService.copyToClipboard(cipher.login.password, { window: window });
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,16 +191,17 @@ export default class MainBackground {
|
|||||||
// Background
|
// Background
|
||||||
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
|
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
|
||||||
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
|
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.tabsBackground = new TabsBackground(this, this.platformUtilsService);
|
||||||
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
|
||||||
this.platformUtilsService, this.analytics);
|
this.platformUtilsService, this.analytics, this.lockService);
|
||||||
|
|
||||||
if (!this.isSafari) {
|
if (!this.isSafari) {
|
||||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
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.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);
|
this.windowsBackground = new WindowsBackground(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,11 +306,15 @@ export default class MainBackground {
|
|||||||
await this.systemService.clearPendingClipboard();
|
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) {
|
if (tab == null || !tab.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const options: any = {};
|
const options: any = {};
|
||||||
if (frameId != null) {
|
if (frameId != null) {
|
||||||
options.frameId = frameId;
|
options.frameId = frameId;
|
||||||
@@ -463,32 +468,36 @@ export default class MainBackground {
|
|||||||
this.actionSetBadgeBackgroundColor(this.sidebarAction);
|
this.actionSetBadgeBackgroundColor(this.sidebarAction);
|
||||||
|
|
||||||
this.menuOptionsLoaded = [];
|
this.menuOptionsLoaded = [];
|
||||||
try {
|
const locked = await this.lockService.isLocked();
|
||||||
const ciphers = await this.cipherService.getAllDecryptedForUrl(url);
|
if (!locked) {
|
||||||
ciphers.sort((a, b) => this.cipherService.sortCiphersByLastUsedThenName(a, b));
|
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) {
|
if (contextMenuEnabled) {
|
||||||
await this.loadNoLoginsContextMenuOptions(this.i18nService.t('noMatchingLogins'));
|
ciphers.forEach((cipher) => {
|
||||||
|
this.loadLoginContextMenuOptions(cipher);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.browserActionSetBadgeText(theText, tabId);
|
let theText = '';
|
||||||
this.sidebarActionSetBadgeText(theText, tabId);
|
if (ciphers.length > 0 && ciphers.length < 9) {
|
||||||
} catch (e) {
|
theText = ciphers.length.toString();
|
||||||
await this.loadMenuAndUpdateBadgeForLockedState(contextMenuEnabled);
|
} 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) {
|
private async loadMenuAndUpdateBadgeForLockedState(contextMenuEnabled: boolean) {
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ import { I18nService } from 'jslib/abstractions/i18n.service';
|
|||||||
|
|
||||||
import { Analytics } from 'jslib/misc';
|
import { Analytics } from 'jslib/misc';
|
||||||
|
|
||||||
import {
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
CipherService,
|
import { LockService } from 'jslib/abstractions/lock.service';
|
||||||
StorageService,
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||||
} from 'jslib/abstractions';
|
|
||||||
import { SystemService } from 'jslib/abstractions/system.service';
|
import { SystemService } from 'jslib/abstractions/system.service';
|
||||||
|
|
||||||
import { BrowserApi } from '../browser/browserApi';
|
import { BrowserApi } from '../browser/browserApi';
|
||||||
@@ -38,7 +37,7 @@ export default class RuntimeBackground {
|
|||||||
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
|
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
|
||||||
private storageService: StorageService, private i18nService: I18nService,
|
private storageService: StorageService, private i18nService: I18nService,
|
||||||
private analytics: Analytics, private notificationsService: NotificationsService,
|
private analytics: Analytics, private notificationsService: NotificationsService,
|
||||||
private systemService: SystemService) {
|
private systemService: SystemService, private lockService: LockService) {
|
||||||
this.isSafari = this.platformUtilsService.isSafari();
|
this.isSafari = this.platformUtilsService.isSafari();
|
||||||
this.runtime = this.isSafari ? safari.application : chrome.runtime;
|
this.runtime = this.isSafari ? safari.application : chrome.runtime;
|
||||||
|
|
||||||
@@ -115,7 +114,7 @@ export default class RuntimeBackground {
|
|||||||
await BrowserApi.tabSendMessageData(sender.tab, 'adjustNotificationBar', msg.data);
|
await BrowserApi.tabSendMessageData(sender.tab, 'adjustNotificationBar', msg.data);
|
||||||
break;
|
break;
|
||||||
case 'bgCollectPageDetails':
|
case 'bgCollectPageDetails':
|
||||||
this.main.collectPageDetailsForContentScript(sender.tab, msg.sender, sender.frameId);
|
await this.main.collectPageDetailsForContentScript(sender.tab, msg.sender, sender.frameId);
|
||||||
break;
|
break;
|
||||||
case 'bgAddLogin':
|
case 'bgAddLogin':
|
||||||
await this.addLogin(msg.login, sender.tab);
|
await this.addLogin(msg.login, sender.tab);
|
||||||
@@ -146,6 +145,9 @@ export default class RuntimeBackground {
|
|||||||
await this.main.reseedStorage();
|
await this.main.reseedStorage();
|
||||||
break;
|
break;
|
||||||
case 'collectPageDetailsResponse':
|
case 'collectPageDetailsResponse':
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (msg.sender) {
|
switch (msg.sender) {
|
||||||
case 'notificationBar':
|
case 'notificationBar':
|
||||||
const forms = this.autofillService.getFormsWithPasswordFields(msg.details);
|
const forms = this.autofillService.getFormsWithPasswordFields(msg.details);
|
||||||
@@ -199,6 +201,10 @@ export default class RuntimeBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async saveAddLogin(tab: any) {
|
private async saveAddLogin(tab: any) {
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
|
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
|
||||||
const queueMessage = this.main.notificationQueue[i];
|
const queueMessage = this.main.notificationQueue[i];
|
||||||
if (queueMessage.tabId !== tab.id || queueMessage.type !== 'addLogin') {
|
if (queueMessage.tabId !== tab.id || queueMessage.type !== 'addLogin') {
|
||||||
@@ -235,6 +241,10 @@ export default class RuntimeBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async saveChangePassword(tab: any) {
|
private async saveChangePassword(tab: any) {
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
|
for (let i = this.main.notificationQueue.length - 1; i >= 0; i--) {
|
||||||
const queueMessage = this.main.notificationQueue[i];
|
const queueMessage = this.main.notificationQueue[i];
|
||||||
if (queueMessage.tabId !== tab.id || queueMessage.type !== 'changePassword') {
|
if (queueMessage.tabId !== tab.id || queueMessage.type !== 'changePassword') {
|
||||||
@@ -284,6 +294,10 @@ export default class RuntimeBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async addLogin(loginInfo: any, tab: any) {
|
private async addLogin(loginInfo: any, tab: any) {
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const loginDomain = Utils.getDomain(loginInfo.url);
|
const loginDomain = Utils.getDomain(loginInfo.url);
|
||||||
if (loginDomain == null) {
|
if (loginDomain == null) {
|
||||||
return;
|
return;
|
||||||
@@ -320,6 +334,10 @@ export default class RuntimeBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async changedPassword(changeData: any, tab: any) {
|
private async changedPassword(changeData: any, tab: any) {
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const loginDomain = Utils.getDomain(changeData.url);
|
const loginDomain = Utils.getDomain(changeData.url);
|
||||||
if (loginDomain == null) {
|
if (loginDomain == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import {
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
CipherService,
|
import { LockService } from 'jslib/abstractions/lock.service';
|
||||||
PlatformUtilsService,
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
} from 'jslib/abstractions';
|
|
||||||
|
|
||||||
export default class WebRequestBackground {
|
export default class WebRequestBackground {
|
||||||
private pendingAuthRequests: any[] = [];
|
private pendingAuthRequests: any[] = [];
|
||||||
private webRequest: any;
|
private webRequest: any;
|
||||||
private isFirefox: boolean;
|
private isFirefox: boolean;
|
||||||
|
|
||||||
constructor(private platformUtilsService: PlatformUtilsService,
|
constructor(platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
|
||||||
private cipherService: CipherService) {
|
private lockService: LockService) {
|
||||||
this.webRequest = (window as any).chrome.webRequest;
|
this.webRequest = (window as any).chrome.webRequest;
|
||||||
this.isFirefox = platformUtilsService.isFirefox();
|
this.isFirefox = platformUtilsService.isFirefox();
|
||||||
}
|
}
|
||||||
@@ -45,6 +44,11 @@ export default class WebRequestBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async resolveAuthCredentials(domain: string, success: Function, error: Function) {
|
private async resolveAuthCredentials(domain: string, success: Function, error: Function) {
|
||||||
|
if (await this.lockService.isLocked()) {
|
||||||
|
error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ciphers = await this.cipherService.getAllDecryptedForUrl(domain);
|
const ciphers = await this.cipherService.getAllDecryptedForUrl(domain);
|
||||||
if (ciphers == null || ciphers.length !== 1) {
|
if (ciphers == null || ciphers.length !== 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user