aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-01-27 12:52:46 +0800
committerkumavis <aaron@kumavis.me>2017-01-27 12:52:46 +0800
commit2113979be7ee257c2650916c2c48f68c6390ef1f (patch)
treed1769a1a479dbd0fd253ee40ad90ae3dd4537ffb /app/scripts/background.js
parentfc3a53ec7b2af538d5e9748173fb11b5a09a4e84 (diff)
downloadtangerine-wallet-browser-2113979be7ee257c2650916c2c48f68c6390ef1f.tar
tangerine-wallet-browser-2113979be7ee257c2650916c2c48f68c6390ef1f.tar.gz
tangerine-wallet-browser-2113979be7ee257c2650916c2c48f68c6390ef1f.tar.bz2
tangerine-wallet-browser-2113979be7ee257c2650916c2c48f68c6390ef1f.tar.lz
tangerine-wallet-browser-2113979be7ee257c2650916c2c48f68c6390ef1f.tar.xz
tangerine-wallet-browser-2113979be7ee257c2650916c2c48f68c6390ef1f.tar.zst
tangerine-wallet-browser-2113979be7ee257c2650916c2c48f68c6390ef1f.zip
metamask controller - adopt setup*Communication from background
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r--app/scripts/background.js52
1 files changed, 10 insertions, 42 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 744a0caee..da9c4f24b 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -1,6 +1,5 @@
const urlUtil = require('url')
-const Dnode = require('dnode')
-const eos = require('end-of-stream')
+const endOfStream = require('end-of-stream')
const asyncQ = require('async-q')
const pipe = require('pump')
const LocalStorageStore = require('obs-store/lib/localStorage')
@@ -10,7 +9,6 @@ const migrations = require('./migrations/')
const PortStream = require('./lib/port-stream.js')
const notification = require('./lib/notifications.js')
const messageManager = require('./lib/message-manager')
-const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const MetamaskController = require('./metamask-controller')
const extension = require('./lib/extension')
const firstTimeState = require('./first-time-state')
@@ -93,51 +91,21 @@ function setupController (initState) {
var portStream = new PortStream(remotePort)
if (isMetaMaskInternalProcess) {
// communication with popup
- popupIsOpen = remotePort.name === 'popup'
- setupTrustedCommunication(portStream, 'MetaMask', remotePort.name)
+ popupIsOpen = popupIsOpen || (remotePort.name === 'popup')
+ controller.setupTrustedCommunication(portStream, 'MetaMask', remotePort.name)
+ // record popup as closed
+ if (remotePort.name === 'popup') {
+ endOfStream(portStream, () => {
+ popupIsOpen = false
+ })
+ }
} else {
// communication with page
var originDomain = urlUtil.parse(remotePort.sender.url).hostname
- setupUntrustedCommunication(portStream, originDomain)
+ controller.setupUntrustedCommunication(portStream, originDomain)
}
}
- function setupUntrustedCommunication (connectionStream, originDomain) {
- // setup multiplexing
- var mx = setupMultiplex(connectionStream)
- // connect features
- controller.setupProviderConnection(mx.createStream('provider'), originDomain)
- controller.setupPublicConfig(mx.createStream('publicConfig'))
- }
-
- function setupTrustedCommunication (connectionStream, originDomain) {
- // setup multiplexing
- var mx = setupMultiplex(connectionStream)
- // connect features
- setupControllerConnection(mx.createStream('controller'))
- controller.setupProviderConnection(mx.createStream('provider'), originDomain)
- }
-
- //
- // remote features
- //
-
- function setupControllerConnection (outStream) {
- var api = controller.getApi()
- var dnode = Dnode(api)
- outStream.pipe(dnode).pipe(outStream)
- dnode.on('remote', (remote) => {
- // push updates to popup
- var sendUpdate = remote.sendUpdate.bind(remote)
- controller.on('update', sendUpdate)
- // teardown on disconnect
- eos(outStream, () => {
- controller.removeListener('update', sendUpdate)
- popupIsOpen = false
- })
- })
- }
-
//
// User Interface setup
//