aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/contentscript.js
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-04-19 05:02:08 +0800
committerbitpshr <mail@bitpshr.net>2018-04-19 05:02:08 +0800
commitc9f83fe8bc60a87876242a2dfb5350fceafffca1 (patch)
tree2def53846824b39fde470931cf36ee67a8e4a03b /app/scripts/contentscript.js
parent7e21fc2aa780ccb4ffb2f642156385db22c47a52 (diff)
downloadtangerine-wallet-browser-c9f83fe8bc60a87876242a2dfb5350fceafffca1.tar
tangerine-wallet-browser-c9f83fe8bc60a87876242a2dfb5350fceafffca1.tar.gz
tangerine-wallet-browser-c9f83fe8bc60a87876242a2dfb5350fceafffca1.tar.bz2
tangerine-wallet-browser-c9f83fe8bc60a87876242a2dfb5350fceafffca1.tar.lz
tangerine-wallet-browser-c9f83fe8bc60a87876242a2dfb5350fceafffca1.tar.xz
tangerine-wallet-browser-c9f83fe8bc60a87876242a2dfb5350fceafffca1.tar.zst
tangerine-wallet-browser-c9f83fe8bc60a87876242a2dfb5350fceafffca1.zip
Add JSDoc to various background scripts
Diffstat (limited to 'app/scripts/contentscript.js')
-rw-r--r--app/scripts/contentscript.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index fe1766273..728aab8cb 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -23,6 +23,9 @@ if (shouldInjectWeb3()) {
setupStreams()
}
+/**
+ * Creates a script tag that injects inpage.js
+ */
function setupInjection () {
try {
// inject in-page script
@@ -37,6 +40,10 @@ function setupInjection () {
}
}
+/**
+ * Sets up two-way communication streams between the
+ * browser extension and local per-page browser context
+ */
function setupStreams () {
// setup communication to page and plugin
const pageStream = new LocalMessageDuplexStream({
@@ -89,17 +96,34 @@ function setupStreams () {
mux.ignoreStream('publicConfig')
}
+
+/**
+ * Error handler for page to plugin stream disconnections
+ *
+ * @param {string} remoteLabel Remote stream name
+ * @param {Error} err Stream connection error
+ */
function logStreamDisconnectWarning (remoteLabel, err) {
let warningMsg = `MetamaskContentscript - lost connection to ${remoteLabel}`
if (err) warningMsg += '\n' + err.stack
console.warn(warningMsg)
}
+/**
+ * Determines if Web3 should be injected
+ *
+ * @returns {boolean} True of Web3 should be injected
+ */
function shouldInjectWeb3 () {
return doctypeCheck() && suffixCheck()
&& documentElementCheck() && !blacklistedDomainCheck()
}
+/**
+ * Checks the doctype of the current document if it exists
+ *
+ * @returns {boolean} True if the doctype is html or if none exists
+ */
function doctypeCheck () {
const doctype = window.document.doctype
if (doctype) {
@@ -109,6 +133,11 @@ function doctypeCheck () {
}
}
+/**
+ * Checks the current document extension
+ *
+ * @returns {boolean} True if the current extension is not prohibited
+ */
function suffixCheck () {
var prohibitedTypes = ['xml', 'pdf']
var currentUrl = window.location.href
@@ -122,6 +151,11 @@ function suffixCheck () {
return true
}
+/**
+ * Checks the documentElement of the current document
+ *
+ * @returns {boolean} True if the documentElement is an html node or if none exists
+ */
function documentElementCheck () {
var documentElement = document.documentElement.nodeName
if (documentElement) {
@@ -130,6 +164,11 @@ function documentElementCheck () {
return true
}
+/**
+ * Checks if the current domain is blacklisted
+ *
+ * @returns {boolean} True if the current domain is blacklisted
+ */
function blacklistedDomainCheck () {
var blacklistedDomains = [
'uscourts.gov',
@@ -148,6 +187,9 @@ function blacklistedDomainCheck () {
return false
}
+/**
+ * Redirects the current page to a phishing information page
+ */
function redirectToPhishingWarning () {
console.log('MetaMask - redirecting to phishing warning')
window.location.href = 'https://metamask.io/phishing.html'