From ce4e8a9faee3b32169baa5af26e7f1c25e6be9d4 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 13 Jan 2018 10:13:31 -0500 Subject: [PATCH] get data for tab --- src/background/runtime.background.ts | 19 ++++++++++++++++--- src/content/autofiller.js | 4 ++-- src/content/notificationBar.js | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index d4eeb8e8b4..df703b7af2 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -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(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(ConstantsService.neverDomainsKey); + responseVal.disableAddLoginNotification = await this.storageService.get( + ConstantsService.disableAddLoginNotificationKey); + } else if (responseCommand === 'autofillerAutofillOnPageLoadEnabledResponse') { + responseVal.enableAutoFillOnPageLoadKey = await this.storageService.get( + ConstantsService.enableAutoFillOnPageLoadKey); + } + + await BrowserApi.tabSendMessageData(tab, responseCommand, responseVal); + } } diff --git a/src/content/autofiller.js b/src/content/autofiller.js index c666563043..3f5f97e07b 100644 --- a/src/content/autofiller.js +++ b/src/content/autofiller.js @@ -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); diff --git a/src/content/notificationBar.js b/src/content/notificationBar.js index e58577c8c4..d0e353fe7e 100644 --- a/src/content/notificationBar.js +++ b/src/content/notificationBar.js @@ -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) {