diff options
author | bitpshr <mail@bitpshr.net> | 2018-10-30 05:28:59 +0800 |
---|---|---|
committer | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-11-06 07:07:09 +0800 |
commit | d7618bd5c6cffe02d8737fe6925a31484a1fc0b0 (patch) | |
tree | cc99f09a1a3b56f59ddb78a079542248293076db /app/scripts/contentscript.js | |
parent | ba40fcbcb43c5adcb3a961afd4050cdb2025b7a6 (diff) | |
download | tangerine-wallet-browser-d7618bd5c6cffe02d8737fe6925a31484a1fc0b0.tar tangerine-wallet-browser-d7618bd5c6cffe02d8737fe6925a31484a1fc0b0.tar.gz tangerine-wallet-browser-d7618bd5c6cffe02d8737fe6925a31484a1fc0b0.tar.bz2 tangerine-wallet-browser-d7618bd5c6cffe02d8737fe6925a31484a1fc0b0.tar.lz tangerine-wallet-browser-d7618bd5c6cffe02d8737fe6925a31484a1fc0b0.tar.xz tangerine-wallet-browser-d7618bd5c6cffe02d8737fe6925a31484a1fc0b0.tar.zst tangerine-wallet-browser-d7618bd5c6cffe02d8737fe6925a31484a1fc0b0.zip |
Code bath
Diffstat (limited to 'app/scripts/contentscript.js')
-rw-r--r-- | app/scripts/contentscript.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 0244f6fa0..0723c03f7 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -12,7 +12,7 @@ const TransformStream = require('stream').Transform const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString() const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n' const inpageBundle = inpageContent + inpageSuffix -let originApproved = false +let isEnabled = false // Eventually this streaming injection could be replaced with: // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction @@ -40,7 +40,7 @@ function injectScript (content) { scriptTag.textContent = content container.insertBefore(scriptTag, container.children[0]) } catch (e) { - console.error('Metamask script injection failed.', e) + console.error('MetaMask script injection failed', e) } } @@ -57,12 +57,11 @@ function setupStreams () { const pluginPort = extension.runtime.connect({ name: 'contentscript' }) const pluginStream = new PortStream(pluginPort) - // Until this origin is approved, cut-off publicConfig stream writes at the content - // script level so malicious sites can't snoop on the currently-selected address + // Filter out selectedAddress until this origin is enabled const approvalTransform = new TransformStream({ objectMode: true, transform: (data, _, done) => { - if (typeof data === 'object' && data.name && data.name === 'publicConfig' && !originApproved) { + if (typeof data === 'object' && data.name && data.name === 'publicConfig' && !isEnabled) { data.data.selectedAddress = undefined } done(null, { ...data }) @@ -117,7 +116,7 @@ function setupStreams () { * Establishes listeners for requests to fully-enable the provider from the dapp context * and for full-provider approvals and rejections from the background script context. Dapps * should not post messages directly and should instead call provider.enable(), which - * handles posting these messages automatically. + * handles posting these messages internally. */ function listenForProviderRequest () { window.addEventListener('message', ({ source, data }) => { @@ -143,11 +142,10 @@ function listenForProviderRequest () { } }) - extension.runtime.onMessage.addListener(({ action, isEnabled, isApproved, isUnlocked }) => { - if (!action) { return } + extension.runtime.onMessage.addListener(({ action = '', isApproved, isUnlocked }) => { switch (action) { case 'approve-provider-request': - originApproved = true + isEnabled = true injectScript(`window.dispatchEvent(new CustomEvent('ethereumprovider', { detail: {}}))`) break case 'reject-provider-request': @@ -160,6 +158,7 @@ function listenForProviderRequest () { injectScript(`window.dispatchEvent(new CustomEvent('metamaskisunlocked', { detail: { isUnlocked: ${isUnlocked}}}))`) break case 'metamask-set-locked': + isEnabled = false injectScript(`window.dispatchEvent(new CustomEvent('metamasksetlocked', { detail: {}}))`) break } |