get data for tab

This commit is contained in:
Kyle Spearrin 2018-01-13 10:13:31 -05:00
parent 0229ef328a
commit ce4e8a9fae
3 changed files with 19 additions and 6 deletions

View File

@ -84,9 +84,8 @@ export default class RuntimeBackground {
setTimeout(async () => await this.main.refreshBadgeAndMenu(), 2000);
}
break;
case 'bgGetAutofillOnPageLoadEnabled':
await this.sendStorageValueToTab(ConstantsService.enableAutoFillOnPageLoadKey, sender.tab,
msg.responseCommand);
case 'bgGetDataForTab':
await this.getDataForTab(sender.tab, msg.responseCommand);
break;
case 'bgOpenNotificationBar':
await BrowserApi.tabSendMessageData(sender.tab, 'openNotificationBar', msg.data);
@ -265,4 +264,18 @@ export default class RuntimeBackground {
const val = await this.storageService.get<any>(storageKey);
await BrowserApi.tabSendMessageData(tab, responseCommand, val);
}
private async getDataForTab(tab: any, responseCommand: string) {
const responseVal: any = {};
if (responseCommand === 'notificationBarDataResponse') {
responseVal.neverDomains = await this.storageService.get<string[]>(ConstantsService.neverDomainsKey);
responseVal.disableAddLoginNotification = await this.storageService.get<boolean>(
ConstantsService.disableAddLoginNotificationKey);
} else if (responseCommand === 'autofillerAutofillOnPageLoadEnabledResponse') {
responseVal.enableAutoFillOnPageLoadKey = await this.storageService.get<boolean>(
ConstantsService.enableAutoFillOnPageLoadKey);
}
await BrowserApi.tabSendMessageData(tab, responseCommand, responseVal);
}
}

View File

@ -5,12 +5,12 @@ document.addEventListener('DOMContentLoaded', (event) => {
if ((typeof safari !== 'undefined')) {
const responseCommand = 'autofillerAutofillOnPageLoadEnabledResponse';
safari.self.tab.dispatchMessage('bitwarden', {
command: 'bgGetAutofillOnPageLoadEnabled',
command: 'bgGetDataForTab',
responseCommand: responseCommand
});
safari.self.addEventListener('message', function (msgEvent) {
const msg = msgEvent.message;
if (msg.command === responseCommand && msg.data === true) {
if (msg.command === responseCommand && msg.data[enabledKey] === true) {
setInterval(doFillIfNeeded, 500);
}
}, false);

View File

@ -19,7 +19,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
if (isSafariApi) {
const responseCommand = 'notificationBarDataResponse';
safari.self.tab.dispatchMessage('bitwarden', {
command: 'bgGetNotificationBarData',
command: 'bgGetDataForTab',
responseCommand: responseCommand
});
safari.self.addEventListener('message', function (msgEvent) {