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

Ledger beta integration #3195

Merged
merged 16 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let generateBraveManifest = () => {
match_about_blank: true,
js: [
'content/scripts/util.js',
'js/actions/extensionActions.js',
'content/scripts/navigator.js',
'content/scripts/blockFlash.js',
'content/scripts/blockCanvasFingerprinting.js',
Expand All @@ -49,10 +48,10 @@ let generateBraveManifest = () => {
getIndexHTML()
],
js: [
'js/actions/extensionActions.js',
'content/scripts/passwordManager.js',
'content/scripts/flashListener.js',
'content/scripts/themeColor.js'
'content/scripts/themeColor.js',
'content/scripts/pageInformation.js'
]
},
{
Expand Down Expand Up @@ -110,7 +109,8 @@ let generateBraveManifest = () => {
'form-action': '\'none\'',
'referrer': 'no-referrer',
'style-src': '\'self\' \'unsafe-inline\'',
'img-src': '* data:'
'img-src': '* data:',
'frame-src': '\'self\' https://buy.coinbase.com'
}

if (process.env.NODE_ENV === 'development') {
Expand Down
181 changes: 181 additions & 0 deletions app/extensions/brave/content/scripts/pageInformation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */

/* jshint asi: true */
/* jshint esversion: 6 */

(function () { try {
var resolve = (tree, context) => {
var node = tree.body ? tree.body[0] : tree

var traverse = (expr, computed) => {
var args, op1, op2, value

switch (expr.type) {
case 'ExpressionStatement':
return traverse(expr.expression)

case 'ArrayExpression':
value = []
expr.elements.forEach((element) => { value.push(traverse(element)) })
return value

case 'BinaryExpression':
op1 = traverse(expr.left)
op2 = traverse(expr.right)
switch (expr.operator) {
case '==': return (op1 === op2)
case '===': return (op1 === op2)
case '!=': return (op1 !== op2)
case '!==': return (op1 !== op2)
case '<': return (op1 < op2)
case '<=': return (op1 <= op2)
case '>': return (op1 > op2)
case '>=': return (op1 >= op2)
case '<<': return (op1 << op2)
case '>>': return (op1 >> op2)
case '>>>': return (op1 >>> op2)
case '+': return (op1 + op2)
case '-': return (op1 - op2)
case '*': return (op1 * op2)
case '/': return (op1 < op2)
case '%': return (op1 % op2)
case '|': return (op1 | op2)
case '^': return (op1 ^ op2)
case '&': return (op1 & op2)
case 'in': return (op1 in op2)

default:
throw new Error('unsupported binary operator: ' + expr.operator)
}
break

case 'CallExpression':
op1 = expr.callee
if (op1.type !== 'MemberExpression') throw new Error('unexpected callee: ' + op1.type)
value = traverse(op1.object, op1.computed)
args = []
expr['arguments'].forEach((argument) => { args.push(traverse(argument)) })
return value[traverse(op1.property, true)].apply(value, args)

case 'ConditionalExpression':
return (traverse(expr.test) ? traverse(expr.consequent) : traverse(expr.alternate))

case 'LogicalExpression':
op1 = traverse(expr.left)
op2 = traverse(expr.right)
switch (expr.operator) {
case '&&': return (op1 && op2)
case '||': return (op1 || op2)

default:
throw new Error('unsupported logical operator: ' + expr.operator)
}
break

case 'MemberExpression':
value = traverse(expr.object, expr.computed)
return value[traverse(expr.property)]

case 'UnaryExpression':
if (!expr.prefix) throw new Error('unsupported unary operator suffix: ' + expr.operator)

op1 = traverse(expr.argument)
switch (expr.operator) {
case '-': return (-op1)
case '+': return (+op1)
case '!': return (!op1)
case '~': return (~op1)
case 'typeof': return (typeof op1)

default:
throw new Error('unsupported unary operator: ' + expr.operator)
}
break

case 'Identifier':
value = computed ? expr.name : context[expr.name]
if (value !== 'eval') return value
throw new Error('eval not allowed in expression')

case 'Literal':
return (expr.regex ? new RegExp(expr.regex.pattern) : expr.value)

default:
throw new Error('unsupported evaluation type: ' + expr.type)
}
}

if ((!node) || (node.type !== 'ExpressionStatement')) throw new Error('invalid expression')

return traverse(node.expression)
}

if ((typeof module !== 'undefined') && (typeof exports !== 'undefined')) {
module.exports = { resolve: resolve }

return
}

if (window.top !== window.self) return

var results = { timestamp: new Date().getTime(), protocol: document.location.protocol }

var node = document.head.querySelector("link[rel='icon']")
if (!node) node = document.head.querySelector("link[rel='shortcut icon']")
if (node) results.faviconURL = node.getAttribute('href')

var pubinfo = chrome.ipc.sendSync('ledger-publisher', document.location.href)
if ((!pubinfo) || (!pubinfo.context) || (!pubinfo.rules)) return console.log('no pubinfo avaialble')

var context = pubinfo.context
var rules = pubinfo.rules

var i, publisher, rule
for (i = 0; i < rules.length; i++) {
rule = rules[i]

try {
if (!resolve(rule.condition, context)) continue
} catch (ex) {
console.log('error resolving rule at position #' + i + '\n' + ex.stack)
continue
}

if (rule.publisher) {
context.node = document.body.querySelector(rule.publisher.selector)
publisher = resolve(rule.publisher.consequent, context)
} else {
delete context.node
publisher = rule.consequent ? resolve(rule.consequent, context) : rule.consequent
}
if (publisher === '') continue

if (typeof publisher !== 'string') return console.log('NOT a string')

publisher.replace(new RegExp('^./+|./+$', 'g'), '')

results.publisher = publisher
if (rule.faviconURL) {
context.node = document.body.querySelector(rule.faviconURL.selector)
results.faviconURL = resolve(rule.faviconURL.consequent, context)
}
break
}

if (results.faviconURL) {
var prefix = (results.faviconURL.indexOf('//') === 0) ? document.location.protocol
: (results.faviconURL.indexOf('/') === 0) ? document.location.protocol + '//' + document.location.host
: (results.faviconURL.indexOf(':') === -1) ? document.location.protocol + '//' + document.location.host + '/'
: null
if (prefix) results.faviconURL = prefix + results.faviconURL
}

results.url = window.location.href
chrome.ipc.send('dispatch-action', JSON.stringify({
location: window.location.href,
actionType: 'event-set-page-info',
pageInfo: results
}))
} catch (ex) { console.log(ex.toString() + '\n' + ex.stack) } })()
Binary file added app/extensions/brave/img/bitgo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/extensions/brave/img/coinbase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 0 additions & 27 deletions app/extensions/brave/js/actions/extensionActions.js

This file was deleted.

28 changes: 22 additions & 6 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,46 @@ sync=Sync
privacy=Privacy
shields=Shields
security=Security
publisher=Publisher
visits=Visits
publisher=Site
publishers=Publishers
publisherEmptyText=Publisher settings coming soon.
publisherPaymentsTitle=Publishers
payments=Payments
paymentsWelcomeTitle=Welcome to Brave Payments!
paymentsWelcomeText1=Brave has created a simple way to make automated contributions to the publisher sites you use most. Your funds are transferred to the site owner through an anonymous ledger system that makes it impossible for you to ever be identified based on the sites you visit and contribute to. This allows publishers to stay in business even though you may have blocked their advertisements with Brave - while keeping your data private.
paymentsWelcomeText2=Brave Payments is currently in Beta. With your help, we can fine tune the system over the next several weeks before it rolls out to our release channel.
paymentsWelcomeText3=To begin using Brave Payments, simply flick the switch at the top of this window. The rest is easy.
paymentsWelcomeText4=Learn more...
publisherPaymentsTitle=Brave Payments Beta
paymentsFooterText=Transaction IP addresses anonymized using
accountBalance=account balance
monthlyBudget=monthly budget
status=status
createWallet=create wallet
createWalletStatus=Click the Create Wallet button to get started.
creatingWallet=creating...
creatingWalletStatus=Creating wallet...
createdWalletStatus=Your wallet is ready! New funds may take 30+ minutes to appear.
tableEmptyText=No table data.
notificationEmptyText=Top publisher visits
syncEmptyText=Sync settings coming soon.
bitcoin=Bitcoin
bitcoinAdd=Use your Bitcoin wallet
bitcoinBuy=Buy Bitcoin
bitcoinCopyAddress=Copy Bitcoin address
bitcoinCopyAddress=Copy Bitcoin address to clipboard
bitcoinVisitAccount=Add Bitcoin
bitcoinBalance=Please transfer:&nbsp;
usd=&#36;
done=Done
moneyAdd=Use your debit card
enable=Enable
moneyAdd=Use your debit or credit card
add=Buy with Coinbase
addFundsTitle=Add Funds
addFunds=Add funds to your Brave Payments Account
advanced=Advanced
rank=Rank
views=Views
timeSpent=Time Spent
adjustment=Adjustment
include=Include
bravery=Bravery
hintsTitle=Helpful hints
hint0=The Bravery panel allows you turn HTTPS Everywhere on or off. HTTPS Everywhere automatically rewrites your HTTP traffic to HTTPS for supported sites to keep you more secure.
Expand Down
14 changes: 14 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const keytar = require('keytar')
const settings = require('../js/constants/settings')
const siteSettings = require('../js/state/siteSettings')
const spellCheck = require('./spellCheck')
const ledger = require('./ledger')
const flash = require('../js/flash')
const contentSettings = require('../js/state/contentSettings')
const FrameStateUtil = require('../js/state/frameStateUtil')
Expand Down Expand Up @@ -275,6 +276,10 @@ app.on('ready', () => {
return
}

// When the browser is closing we need to send a signal
// to record the currently active location in the ledger
ledger.quit()

e.preventDefault()

clearTimeout(initiateSessionStateSave)
Expand Down Expand Up @@ -544,6 +549,15 @@ app.on('ready', () => {
}
})

ledger.init()

ipcMain.on(messages.LEDGER_CREATE_WALLET, () => {
ledger.boot()
})
ipcMain.on(messages.LEDGER_ENABLE, (e, enabled) => {
ledger.enable(enabled)
})

let masterKey
ipcMain.on(messages.DELETE_PASSWORD, (e, password) => {
appActions.deletePassword(password)
Expand Down
Loading