Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Only run dapp detection if metamask is not installed
Browse files Browse the repository at this point in the history
Fix #11569

Auditors: @aekeus
  • Loading branch information
bbondy committed Oct 16, 2017
1 parent 3d2d42b commit edabfa0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
71 changes: 35 additions & 36 deletions app/extensions/brave/content/scripts/dappListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,44 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const script =
`
function __insertWeb3Installed() {
if (!window.alreadyInserted) {
const meta = document.createElement('meta')
meta.name = 'web3-installed'
document.head.appendChild(meta)
window.alreadyInserted = true
}
}
if (window.web3) {
if (!window.web3.currentProvider || !window.web3.currentProvider.isMetaMask) {
__insertWeb3Installed()
if (chrome.contentSettings.dappDetection == 'allow') {
const script =
`
function __insertWeb3Installed() {
if (!window.alreadyInserted) {
const meta = document.createElement('meta')
meta.name = 'web3-installed'
document.head.appendChild(meta)
window.alreadyInserted = true
}
}
} else {
var oldWeb3 = window.web3
Object.defineProperty(window, 'web3', {
configurable: true,
set: function (val) {
__insertWeb3Installed()
oldWeb3 = val
},
get: function () {
if (window.web3) {
if (!window.web3.currentProvider || !window.web3.currentProvider.isMetaMask) {
__insertWeb3Installed()
return oldWeb3
}
})
}`
} else {
var oldWeb3 = window.web3
Object.defineProperty(window, 'web3', {
configurable: true,
set: function (val) {
__insertWeb3Installed()
oldWeb3 = val
},
get: function () {
__insertWeb3Installed()
return oldWeb3
}
})
}`

if (chrome.contentSettings.dappDetection == 'allow') {
executeScript(script)
setTimeout(function () {
const isDapp = document.querySelector('meta[name="web3-installed"]')
if (isDapp) {
chrome.ipcRenderer.send('dispatch-action', JSON.stringify([{
actionType: 'app-dapp-available',
location: window.location.href
}]))
}
}, 3000)
}

setTimeout(function () {
const isDapp = document.querySelector('meta[name="web3-installed"]')
if (isDapp) {
chrome.ipcRenderer.send('dispatch-action', JSON.stringify([{
actionType: 'app-dapp-available',
location: window.location.href
}]))
}
}, 3000)
2 changes: 1 addition & 1 deletion js/state/contentSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const getDefaultUserPrefContentSettings = (braveryDefaults, appSettings, appConf
primaryPattern: '*'
}],
dappDetection: [{
setting: getSetting(settings.METAMASK_PROMPT_DISMISSED) ? 'block' : 'allow',
setting: getSetting(settings.METAMASK_PROMPT_DISMISSED) || getSetting(settings.METAMASK_ENABLED) ? 'block' : 'allow',
primaryPattern: '*'
}],
popups: [{
Expand Down

0 comments on commit edabfa0

Please sign in to comment.