Skip to content

Commit

Permalink
Add 1102 support for other extensions
Browse files Browse the repository at this point in the history
Fixes #5950 when combined with an update to
`metamask-extension-provider`.
  • Loading branch information
danfinlay committed Jan 3, 2019
1 parent da7208c commit 66eb966
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
58 changes: 42 additions & 16 deletions app/scripts/controllers/provider-approval.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,49 @@ class ProviderApprovalController {
providerRequests: [],
})

const internalListener = ({ action = '', force, origin, siteTitle, siteImage, target, name }) => {
switch (action) {
case 'init-provider-request':
this._handleProviderRequest(origin, siteTitle, siteImage, force)
break
case 'init-is-approved':
this._handleIsApproved(origin)
break
case 'init-is-unlocked':
this._handleIsUnlocked()
break
case 'init-privacy-request':
this._handlePrivacyRequest()
break
}
}

const externalListener = (opts, sender) => {
const { action, force, origin, siteTitle, siteImage, target, name } = opts
const title = origin || siteTitle || 'Extension'
switch (action) {
case 'init-provider-request':
this._handleProviderRequest(sender.id, title, siteImage, force)
break
case 'init-is-approved':
this._handleIsApproved(origin)
break
case 'init-is-unlocked':
this._handleIsUnlocked()
break
case 'init-privacy-request':
this._handlePrivacyRequest()
break
}
}

if (platform && platform.addMessageListener) {
platform.addMessageListener(({ action = '', force, origin, siteTitle, siteImage }) => {
switch (action) {
case 'init-provider-request':
this._handleProviderRequest(origin, siteTitle, siteImage, force)
break
case 'init-is-approved':
this._handleIsApproved(origin)
break
case 'init-is-unlocked':
this._handleIsUnlocked()
break
case 'init-privacy-request':
this._handlePrivacyRequest()
break
}
})
platform.addMessageListener(internalListener)
}

// Allow cross-extension provider requests:
if (platform && platform.addExternalMessageListener) {
platform.addExternalMessageListener(externalListener)
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/scripts/platforms/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class ExtensionPlatform {
extension.runtime.onMessage.addListener(cb)
}

addExternalMessageListener (cb) {
extension.runtime.onMessageExternal.addListener(cb)
}

sendMessage (message, query = {}) {
extension.tabs.query(query, tabs => {
tabs.forEach(tab => {
Expand Down

0 comments on commit 66eb966

Please sign in to comment.