diff options
author | Bruno Barbieri <bruno.barbieri@consensys.net> | 2018-11-22 03:45:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-22 03:45:55 +0800 |
commit | ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c (patch) | |
tree | 082e495f1b6e303ca5fca54e9a186ca9ef6292ca /app | |
parent | 7229f0f9fcd6c2579c3c5a5146a3b144929b6d2e (diff) | |
parent | b4d48ea3fc15541c674868a1249f4526cb4ae53c (diff) | |
download | tangerine-wallet-browser-ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c.tar tangerine-wallet-browser-ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c.tar.gz tangerine-wallet-browser-ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c.tar.bz2 tangerine-wallet-browser-ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c.tar.lz tangerine-wallet-browser-ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c.tar.xz tangerine-wallet-browser-ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c.tar.zst tangerine-wallet-browser-ae8626eceb255618d5cdeb5aba7ce2dd377d2c0c.zip |
Merge pull request #5797 from MetaMask/trezor-v6
Add Firefox and Brave support for Trezor
Diffstat (limited to 'app')
-rw-r--r-- | app/manifest.json | 10 | ||||
-rw-r--r-- | app/scripts/background.js | 8 | ||||
-rw-r--r-- | app/trezor-usb-permissions.html | 33 | ||||
-rw-r--r-- | app/vendor/trezor/content-script.js | 21 | ||||
-rw-r--r-- | app/vendor/trezor/usb-permissions.js | 50 |
5 files changed, 121 insertions, 1 deletions
diff --git a/app/manifest.json b/app/manifest.json index 8bf51cfd7..c74d88448 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -52,6 +52,14 @@ ], "run_at": "document_start", "all_frames": true + }, + { + "matches": [ + "*://connect.trezor.io/*/popup.html" + ], + "js": [ + "vendor/trezor/content-script.js" + ] } ], "permissions": [ @@ -77,4 +85,4 @@ "*" ] } -}
\ No newline at end of file +} diff --git a/app/scripts/background.js b/app/scripts/background.js index a6fc5ed78..d577ead41 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -332,6 +332,10 @@ function setupController (initState, initLangCode) { [ENVIRONMENT_TYPE_FULLSCREEN]: true, } + const metamaskBlacklistedPorts = [ + 'trezor-connect', + ] + const isClientOpenStatus = () => { return popupIsOpen || Boolean(Object.keys(openMetamaskTabsIDs).length) || notificationIsOpen } @@ -352,6 +356,10 @@ function setupController (initState, initLangCode) { const processName = remotePort.name const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName] + if (metamaskBlacklistedPorts.includes(remotePort.name)) { + return false + } + if (isMetaMaskInternalProcess) { const portStream = new PortStream(remotePort) // communication with popup diff --git a/app/trezor-usb-permissions.html b/app/trezor-usb-permissions.html new file mode 100644 index 000000000..16f28e5e1 --- /dev/null +++ b/app/trezor-usb-permissions.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8" /> + <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> + <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" /> + <title>TrezorConnect | Trezor</title> + <meta name="description" content="" /> + <meta name="keywords" content="" /> + <meta name="author" content="Trezor info@trezor.io" /> + <meta name="robots" content="noindex, nofollow" /> + <meta name="title" content="Trezor Connect" /> + <meta name="theme-color" content="#ffffff" /> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <style> + * { + margin: 0; + padding: 0; + } + html, body { + position: relative; + width: 100%; + height: 100%; + min-height: 500px; + min-width: 328px; + } + </style> +</head> +<body> + <iframe id="trezor-usb-permissions" src="https://connect.trezor.io/5/extension-permissions.html" allow="usb" frameborder="0" width="100%" height="100%"></iframe> + <script type="text/javascript" src="./vendor/trezor/usb-permissions.js"></script> +</body>
\ No newline at end of file diff --git a/app/vendor/trezor/content-script.js b/app/vendor/trezor/content-script.js new file mode 100644 index 000000000..a21332f46 --- /dev/null +++ b/app/vendor/trezor/content-script.js @@ -0,0 +1,21 @@ +/* +Passing messages from background script to popup +*/ + +let port = chrome.runtime.connect({ name: 'trezor-connect' }); +port.onMessage.addListener(message => { + window.postMessage(message, window.location.origin); +}); +port.onDisconnect.addListener(d => { + port = null; +}); + +/* +Passing messages from popup to background script +*/ + +window.addEventListener('message', event => { + if (port && event.source === window && event.data) { + port.postMessage(event.data); + } +}); diff --git a/app/vendor/trezor/usb-permissions.js b/app/vendor/trezor/usb-permissions.js new file mode 100644 index 000000000..9de47e0a1 --- /dev/null +++ b/app/vendor/trezor/usb-permissions.js @@ -0,0 +1,50 @@ +/* +Handling messages from usb permissions iframe +*/ + +const switchToPopupTab = (event) => { + + window.removeEventListener('beforeunload', switchToPopupTab); + + if (!event) { + // triggered from 'usb-permissions-close' message + // switch tab to previous index and close current + chrome.tabs.query({ + currentWindow: true, + active: true, + }, (current) => { + if (current.length < 0) return; + chrome.tabs.query({ + index: current[0].index - 1 + }, popup => { + if (popup.length < 0) return; + chrome.tabs.update(popup[0].id, { active: true }); + }) + chrome.tabs.remove(current[0].id); + }); + return; + } + + // triggered from 'beforeunload' event + // find tab by popup pattern and switch to it + chrome.tabs.query({ + url: "*://connect.trezor.io/*/popup.html" + }, (tabs) => { + if (tabs.length < 0) return; + chrome.tabs.update(tabs[0].id, { active: true }); + }); +} + +window.addEventListener('message', event => { + if (event.data === 'usb-permissions-init') { + const iframe = document.getElementById('trezor-usb-permissions'); + iframe.contentWindow.postMessage({ + type: 'usb-permissions-init', + extension: chrome.runtime.id, + }, '*'); + } else if (event.data === 'usb-permissions-close') { + switchToPopupTab(); + } +}); + +window.addEventListener('beforeunload', switchToPopupTab);
\ No newline at end of file |