aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-01-28 06:17:12 +0800
committerFrankie <frankie.diamond@gmail.com>2017-01-28 06:17:12 +0800
commita8ed780d9b3659474c59c7856ab2ee1430c17b42 (patch)
treecff1a4b3b8f6d12836667d1fcab31e7e9319d60e /app/scripts/background.js
parent451845142ed40d1e10bd993cedca1b28e59baba1 (diff)
parent61528bdf088e304150698d95218806d7b4faa56e (diff)
downloadtangerine-wallet-browser-a8ed780d9b3659474c59c7856ab2ee1430c17b42.tar
tangerine-wallet-browser-a8ed780d9b3659474c59c7856ab2ee1430c17b42.tar.gz
tangerine-wallet-browser-a8ed780d9b3659474c59c7856ab2ee1430c17b42.tar.bz2
tangerine-wallet-browser-a8ed780d9b3659474c59c7856ab2ee1430c17b42.tar.lz
tangerine-wallet-browser-a8ed780d9b3659474c59c7856ab2ee1430c17b42.tar.xz
tangerine-wallet-browser-a8ed780d9b3659474c59c7856ab2ee1430c17b42.tar.zst
tangerine-wallet-browser-a8ed780d9b3659474c59c7856ab2ee1430c17b42.zip
Merge branch 'dev' into messageManagerCleanUp
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r--app/scripts/background.js53
1 files changed, 10 insertions, 43 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 18882e5d5..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,52 +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 (stream) {
- controller.stream = stream
- var api = controller.getApi()
- var dnode = Dnode(api)
- stream.pipe(dnode).pipe(stream)
- dnode.on('remote', (remote) => {
- // push updates to popup
- var sendUpdate = remote.sendUpdate.bind(remote)
- controller.on('update', sendUpdate)
- // teardown on disconnect
- eos(stream, () => {
- controller.removeListener('update', sendUpdate)
- popupIsOpen = false
- })
- })
- }
-
//
// User Interface setup
//