diff options
Begin implementing live-updating blacklist, not working yet
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r-- | app/scripts/background.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index e8987394f..c9505b237 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -90,6 +90,10 @@ function setupController (initState) { extension.runtime.onConnect.addListener(connectRemote) function connectRemote (remotePort) { + if (remotePort.name === 'blacklister') { + return setupBlacklist(connectRemote) + } + var isMetaMaskInternalProcess = remotePort.name === 'popup' || remotePort.name === 'notification' var portStream = new PortStream(remotePort) if (isMetaMaskInternalProcess) { @@ -135,6 +139,29 @@ function setupController (initState) { return Promise.resolve() } +// Listen for new pages and return if blacklisted: +function setupBlacklist (port) { + console.log('Blacklist connection established') + const handler = handleNewPageLoad.bind(port) + port.onMessage.addListener(handler) + setTimeout(() => { + port.onMessage.removeListener(handler) + }, 30000) +} + +function handleNewPageLoad (message) { + const { pageLoaded } = message + console.log('blaclist message received', message.pageLoaded) + if (!pageLoaded || !global.metamaskController) return + + const state = global.metamaskController.getState() + const { blacklist } = state.metamask + + if (blacklist && blacklist.includes(pageLoaded)) { + this.postMessage({ 'blacklist': pageLoaded }) + } +} + // // Etc... // |