diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/manifest.json | 10 | ||||
-rw-r--r-- | app/scripts/contentscript.js | 33 | ||||
-rw-r--r-- | app/scripts/lib/extension-instance.js | 25 | ||||
-rw-r--r-- | app/scripts/lib/remote-store.js | 2 |
4 files changed, 50 insertions, 20 deletions
diff --git a/app/manifest.json b/app/manifest.json index 88b097f5d..95aee245c 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -8,6 +8,11 @@ "16": "images/icon-16.png", "128": "images/icon-128.png" }, + "applications": { + "gecko": { + "id": "webextension@metamask.io" + } + }, "default_locale": "en", "background": { "scripts": [ @@ -37,11 +42,6 @@ "all_frames": false } ], - "applications": { - "gecko": { - "id": "MOZILLA_EXTENSION_ID" - } - }, "permissions": [ "notifications", "storage", diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 0ffe93e3c..1eb04059d 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -3,19 +3,37 @@ const PortStream = require('./lib/port-stream.js') const ObjectMultiplex = require('./lib/obj-multiplex') const extension = require('./lib/extension') +const fs = require('fs') +const path = require('path') +const inpageText = fs.readFileSync(path.join(__dirname + '/inpage.js')).toString() + +// Eventually this streaming injection could be replaced with: +// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction +// +// But for now that is only Firefox +// If we create a FireFox-only code path using that API, +// MetaMask will be much faster loading and performant on Firefox. + if (shouldInjectWeb3()) { setupInjection() setupStreams() } function setupInjection(){ - // inject in-page script - var scriptTag = document.createElement('script') - scriptTag.src = extension.extension.getURL('scripts/inpage.js') - scriptTag.onload = function () { this.parentNode.removeChild(this) } - var container = document.head || document.documentElement - // append as first child - container.insertBefore(scriptTag, container.children[0]) + try { + + // inject in-page script + var scriptTag = document.createElement('script') + scriptTag.src = extension.extension.getURL('scripts/inpage.js') + scriptTag.textContent = inpageText + scriptTag.onload = function () { this.parentNode.removeChild(this) } + var container = document.head || document.documentElement + // append as first child + container.insertBefore(scriptTag, container.children[0]) + + } catch (e) { + console.error('Metamask injection failed.', e) + } } function setupStreams(){ @@ -44,7 +62,6 @@ function setupStreams(){ pluginStream.on('close', function () { reloadStream.write({ method: 'reset' }) }) - } function shouldInjectWeb3(){ diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js index eeab6c6d0..eb3b8a1e9 100644 --- a/app/scripts/lib/extension-instance.js +++ b/app/scripts/lib/extension-instance.js @@ -24,14 +24,27 @@ const apis = [ function Extension () { const _this = this - let global = window - - if (window.chrome) { - global = window.chrome - } apis.forEach(function (api) { - _this[api] = global[api] + + _this[api] = null + + try { + if (chrome[api]) { + _this[api] = chrome[api] + } + } catch (e) {} + + try { + if (window[api]) { + _this[api] = window[api] + } + } catch (e) {} + + try { + _this.api = browser.extension[api] + } catch (e) {} + }) } diff --git a/app/scripts/lib/remote-store.js b/app/scripts/lib/remote-store.js index fbfab7bad..c81d5151c 100644 --- a/app/scripts/lib/remote-store.js +++ b/app/scripts/lib/remote-store.js @@ -52,7 +52,7 @@ HostStore.prototype.set = function (key, value) { HostStore.prototype.createStream = function () { var dnode = Dnode({ - // update: this._didUpdate.bind(this), + update: this._didUpdate.bind(this), }) dnode.on('remote', this._didConnect.bind(this)) return dnode |