Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow other extensions to connect #3997

Merged
merged 1 commit into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"externally_connectable": {
"matches": [
"https://metamask.io/*"
]
],
"ids": ["*"]
}
}
14 changes: 10 additions & 4 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function setupController (initState, initLangCode) {
// connect to other contexts
//
extension.runtime.onConnect.addListener(connectRemote)
extension.runtime.onConnectExternal.addListener(connectExternal)

const metamaskInternalProcessHash = {
[ENVIRONMENT_TYPE_POPUP]: true,
Expand All @@ -211,9 +212,9 @@ function setupController (initState, initLangCode) {
function connectRemote (remotePort) {
const processName = remotePort.name
const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName]
const portStream = new PortStream(remotePort)

if (isMetaMaskInternalProcess) {
const portStream = new PortStream(remotePort)
// communication with popup
controller.isClientOpen = true
controller.setupTrustedCommunication(portStream, 'MetaMask')
Expand Down Expand Up @@ -246,12 +247,17 @@ function setupController (initState, initLangCode) {
})
}
} else {
// communication with page
const originDomain = urlUtil.parse(remotePort.sender.url).hostname
controller.setupUntrustedCommunication(portStream, originDomain)
connectExternal(remotePort)
}
}

// communication with page or other extension
function connectExternal(remotePort) {
const originDomain = urlUtil.parse(remotePort.sender.url).hostname
const portStream = new PortStream(remotePort)
controller.setupUntrustedCommunication(portStream, originDomain)
}

//
// User Interface setup
//
Expand Down