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

Add Firefox and Brave support for Trezor #5797

Merged
merged 42 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
aaed44f
trezor v5 working on firefox
brunobar79 Aug 5, 2018
0ebdd73
clean up
brunobar79 Aug 5, 2018
286bde6
fix merge conflicts
brunobar79 Aug 8, 2018
de058c1
update package-lock.json
brunobar79 Aug 8, 2018
3528298
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
brunobar79 Aug 9, 2018
c8d75f3
use new connect.js file
brunobar79 Aug 10, 2018
728aeb9
add app/vendor dir to eslintignore
brunobar79 Aug 10, 2018
814c642
fixes
brunobar79 Aug 10, 2018
e905c9f
hide export private key for trezor accounts
brunobar79 Aug 10, 2018
eb2f491
add error messages
brunobar79 Aug 10, 2018
6f2c480
undo permission change
brunobar79 Aug 10, 2018
42834fe
fix e2e tests
brunobar79 Aug 10, 2018
6e813db
update package-lock
brunobar79 Aug 20, 2018
ab7eb73
fix merge conflicts
brunobar79 Aug 21, 2018
0e1605b
fix comment
brunobar79 Aug 21, 2018
90886c5
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
brunobar79 Aug 21, 2018
1286dda
update package-lock
brunobar79 Aug 21, 2018
055e0f8
fix merge conflicts
brunobar79 Aug 22, 2018
fdff768
handle onDisconnect
brunobar79 Aug 22, 2018
b208ce7
add port names blacklist
brunobar79 Aug 22, 2018
8ee01f4
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
brunobar79 Sep 5, 2018
a299641
update package-lock.json
brunobar79 Sep 10, 2018
26333ee
fix merge conflicts
brunobar79 Sep 10, 2018
eeecee0
update package-lock.json
brunobar79 Sep 10, 2018
13820b6
fix conflicts
brunobar79 Oct 16, 2018
9c1b210
fix merge conflicts
brunobar79 Oct 21, 2018
c651212
fix merge conflicts
brunobar79 Nov 7, 2018
484aa68
Merge branch 'develop' into trezor-v5
brunobar79 Nov 13, 2018
18f39ef
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
brunobar79 Nov 14, 2018
b636d72
package-lock.json
brunobar79 Nov 14, 2018
b54ed05
try with custom box
brunobar79 Nov 14, 2018
59b089b
test
brunobar79 Nov 14, 2018
517f6e6
test
brunobar79 Nov 14, 2018
4dbc092
test
brunobar79 Nov 14, 2018
e44b750
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
brunobar79 Nov 15, 2018
ca758f0
update package-lock.json
brunobar79 Nov 15, 2018
3219e94
Merge branch 'trezor-v5' of github.com:MetaMask/metamask-extension in…
brunobar79 Nov 15, 2018
c0557b4
clean up
brunobar79 Nov 15, 2018
9b1df38
fix merge conflicts
brunobar79 Nov 20, 2018
7fb9f91
trezor v6
brunobar79 Nov 21, 2018
7a26b70
update package-lock
brunobar79 Nov 21, 2018
b4d48ea
bump eth-trezor-keyring
brunobar79 Nov 21, 2018
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ development/states.js

app/scripts/lib/extension-instance.js
app/scripts/chromereload.js
app/vendor/**

ui/lib/blockies.js

Expand Down
10 changes: 9 additions & 1 deletion app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
],
"run_at": "document_start",
"all_frames": true
},
{
"matches": [
"*://connect.trezor.io/*/popup.html"
],
"js": [
"vendor/trezor/content-script.js"
]
}
],
"permissions": [
Expand All @@ -77,4 +85,4 @@
"*"
]
}
}
}
8 changes: 8 additions & 0 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions app/trezor-usb-permissions.html
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions app/vendor/trezor/content-script.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
50 changes: 50 additions & 0 deletions app/vendor/trezor/usb-permissions.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 4 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ createCopyTasks('fonts', {
source: './app/fonts/',
destinations: commonPlatforms.map(platform => `./dist/${platform}/fonts`),
})
createCopyTasks('vendor', {
source: './app/vendor/',
destinations: commonPlatforms.map(platform => `./dist/${platform}/vendor`),
})
createCopyTasks('reload', {
devOnly: true,
source: './app/scripts/',
Expand Down
Loading