Skip to content
This repository was archived by the owner on Jun 16, 2020. It is now read-only.

Commit 98fc299

Browse files
committed
feat: add IPFS (first round, pre convo with brave team)
1 parent a93609f commit 98fc299

47 files changed

Lines changed: 323 additions & 8 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Brave.tar.bz2
5353

5454
app/extensions/brave/gen
5555
app/extensions/torrent/gen
56+
app/extensions/ipfs/gen
57+
5658
*.pfx
5759
buildConfig.js
5860

app/browser/ipfs.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* IPFS node in electron's main process */
2+
3+
// TODO(diasdavid) - review electron's main process support https://github.com/ipfs/js-ipfs/issues/843
4+
5+
// const electron = require('electron')
6+
// const ipc = electron.ipcMain
7+
// const messages = require('../../js/constants/messages')
8+
// const IPFS = require('ipfs')
9+
// const os = require('os')
10+
// const path = require('path')
11+
12+
module.exports = {init}
13+
14+
// Set to see communication between WebTorrent and torrent viewer tabs
15+
const DEBUG_IPC = false
16+
if (DEBUG_IPC) {
17+
console.log('IPFS IPC debugging enabled')
18+
}
19+
20+
// IPFS node
21+
// let node = null
22+
// let channels = {}
23+
24+
// Receive messages via the window process, ultimately from the UI in a <webview> process
25+
function init (state, action) {
26+
if (DEBUG_IPC) {
27+
console.log('IPFS IPC init')
28+
}
29+
30+
return state
31+
32+
/*
33+
node = new IPFS({
34+
repo: path.join(os.homedir(), '/.brave-jsipfs')
35+
})
36+
37+
node.on('ready', () => {
38+
if (DEBUG_IPC) {
39+
console.log('IPFS node is ready')
40+
}
41+
})
42+
43+
node.on('error', (err) => console.log('IPFS: ', err))
44+
45+
// access on the browser with remote.getGlobal('ipfs')
46+
global.ipfs = node
47+
*/
48+
49+
/* TODO(diasdavid) consider enabling the browser tab to start and stop the node
50+
ipc.on(messages.IPFS_MESSAGE, function (event, msg) {
51+
if (DEBUG_IPC) {
52+
console.log('IPFS: Received IPC: ' + JSON.stringify(msg))
53+
}
54+
55+
channels[msg.clientKey] = e.sender
56+
server.receive(msg)
57+
})
58+
*/
59+
}
60+
61+
// Send messages from the browser process (here), thru the window process, to the <webview>
62+
/*
63+
function send (msg) {
64+
if (DEBUG_IPC) console.log('Sending IPC: ' + JSON.stringify(msg))
65+
const channel = channels[msg.clientKey]
66+
if (!channel) {
67+
if (DEBUG_IPC) console.error('Ignoring unrecognized clientKey ' + msg.clientKey)
68+
return
69+
}
70+
if (channel.isDestroyed()) {
71+
if (DEBUG_IPC) console.log('Removing destroyed channel, clientKey ' + msg.clientKey)
72+
delete channels[msg.clientKey]
73+
return
74+
}
75+
channel.send(messages.IPFS_MESSAGE, msg)
76+
}
77+
*/

app/extensions.js

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,53 @@ let generateTorrentManifest = () => {
222222
}
223223
}
224224

225+
// Returns the Chromium extension manifest for the ipfsExtension
226+
// The ipfsExtension handles ipfs:// and dweb:
227+
// Analagous to the PDFJS extension, it shows a special UI for that type of resource
228+
let generateIPFSManifest = () => {
229+
let cspDirectives = {
230+
'default-src': '\'self\'',
231+
// TODO(bridiver) - remove example.com when webtorrent no longer requires it
232+
// (i.e. once Brave uses webpack v2)
233+
'connect-src': '\'self\' https://example.com',
234+
'media-src': '\'self\' http://localhost:*',
235+
'form-action': '\'none\'',
236+
'style-src': '\'self\' \'unsafe-inline\'',
237+
'frame-src': '\'self\' http://localhost:*'
238+
}
239+
240+
if (process.env.NODE_ENV === 'development') {
241+
// allow access to webpack dev server resources
242+
let devServer = 'localhost:' + process.env.npm_package_config_port
243+
cspDirectives['default-src'] += ' http://' + devServer
244+
cspDirectives['connect-src'] += ' http://' + devServer + ' ws://' + devServer
245+
cspDirectives['media-src'] += ' http://' + devServer
246+
cspDirectives['frame-src'] += ' http://' + devServer
247+
cspDirectives['style-src'] += ' http://' + devServer
248+
}
249+
250+
return {
251+
name: 'IPFS Viewer',
252+
description: l10n.translation('ipfsDesc'),
253+
manifest_version: 2,
254+
version: '1.0',
255+
content_security_policy: concatCSP(cspDirectives),
256+
content_scripts: [],
257+
permissions: ['externally_connectable.all_urls', 'tabs', '<all_urls>'],
258+
externally_connectable: {
259+
matches: ['<all_urls>']
260+
},
261+
icons: {
262+
128: 'img/ipfs-128.png',
263+
48: 'img/ipfs-48.png',
264+
16: 'img/ipfs-16.png'
265+
},
266+
incognito: 'split',
267+
// TODO(diasdavid) How to get this key??
268+
key: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyWl+wMvL0wZX3JUs7GeZAvxMP+LWEh2bwMV1HyuBra/lGZIq3Fmh0+AFnvFPXz1NpQkbLS3QWyqhdIn/lepGwuc2ma0glPzzmieqwctUurMGSGManApGO1MkcbSPhb+R1mx8tMam5+wbme4WoW37PI3oATgOs2NvHYuP60qol3U7b/zB3IWuqtwtqKe2Q1xY17btvPuz148ygWWIHneedt0jwfr6Zp+CSLARB9Heq/jqGXV4dPSVZ5ebBHLQ452iZkHxS6fm4Z+IxjKdYs3HNj/s8xbfEZ2ydnArGdJ0lpSK9jkDGYyUBugq5Qp3FH6zV89WqBvoV1dqUmL9gxbHsQIDAQAB'
269+
}
270+
}
271+
225272
let generateSyncManifest = () => {
226273
let cspDirectives = {
227274
'default-src': '\'self\'',
@@ -419,7 +466,10 @@ module.exports.init = () => {
419466
}
420467
if (!extensionInfo.isLoaded(extensionId) && !extensionInfo.isLoading(extensionId)) {
421468
extensionInfo.setState(extensionId, extensionStates.LOADING)
422-
if (extensionId === config.braveExtensionId || extensionId === config.torrentExtensionId || extensionId === config.syncExtensionId) {
469+
if (extensionId === config.braveExtensionId ||
470+
extensionId === config.torrentExtensionId ||
471+
extensionId === config.syncExtensionId ||
472+
extensionId === config.ipfsExtensionId) {
423473
session.defaultSession.extensions.load(extensionPath, manifest, manifestLocation)
424474
return
425475
}
@@ -458,11 +508,13 @@ module.exports.init = () => {
458508
}
459509
}
460510

461-
// Manually install the braveExtension and torrentExtension
511+
// Manually install the braveExtension, torrentExtension and ipfsExtension
462512
extensionInfo.setState(config.braveExtensionId, extensionStates.REGISTERED)
463513
loadExtension(config.braveExtensionId, getExtensionsPath('brave'), generateBraveManifest(), 'component')
464514
extensionInfo.setState(config.syncExtensionId, extensionStates.REGISTERED)
465515
loadExtension(config.syncExtensionId, getExtensionsPath('brave'), generateSyncManifest(), 'unpacked')
516+
517+
// torrentExtension
466518
if (getSetting(settings.TORRENT_VIEWER_ENABLED)) {
467519
extensionInfo.setState(config.torrentExtensionId, extensionStates.REGISTERED)
468520
loadExtension(config.torrentExtensionId, getExtensionsPath('torrent'), generateTorrentManifest(), 'component')
@@ -471,6 +523,16 @@ module.exports.init = () => {
471523
extensionActions.extensionDisabled(config.torrentExtensionId)
472524
}
473525

526+
// ipfsExtension
527+
console.log('IPFS: is extension enabled', getSetting(settings.IPFS_ENABLED))
528+
if (getSetting(settings.IPFS_ENABLED)) {
529+
extensionInfo.setState(config.ipfsExtensionId, extensionStates.REGISTERED)
530+
loadExtension(config.ipfsExtensionId, getExtensionsPath('ipfs'), generateIPFSManifest(), 'component')
531+
} else {
532+
extensionInfo.setState(config.ipfsExtensionId, extensionStates.DISABLED)
533+
extensionActions.extensionDisabled(config.ipfsExtensionId)
534+
}
535+
474536
let registerComponents = (diff) => {
475537
if (getSetting(settings.PDFJS_ENABLED)) {
476538
registerComponent(config.PDFJSExtensionId, config.PDFJSExtensionPublicKey)

app/extensions/brave/locales/bn-BD/preferences.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,4 @@ urlBarOptions=URL Bar Options
376376
disableTitleMode=সর্বদা URL বার দেখান
377377
wideURLbar=Use wide URL bar
378378
autoplay=Autoplay Media
379+
useIPFS=Enable IPFS (requires browser restart)

app/extensions/brave/locales/bn-IN/preferences.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,4 @@ urlBarOptions=URL Bar Options
376376
disableTitleMode=Always show the URL bar
377377
wideURLbar=Use wide URL bar
378378
autoplay=Autoplay Media
379+
useIPFS=Enable IPFS (requires browser restart)

app/extensions/brave/locales/cs/preferences.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,4 @@ urlBarOptions=Volby pro adresní řádek
376376
disableTitleMode=Vždy ukázat adresní řádek
377377
wideURLbar=Použít široký adresní řádek
378378
autoplay=Automatické přehrávání
379+
useIPFS=Enable IPFS (requires browser restart)

app/extensions/brave/locales/de-DE/preferences.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,4 @@ urlBarOptions=Einstellungen der URL-Zeile
376376
disableTitleMode=URL Zeile immer anzeigen
377377
wideURLbar=Lange URL-Zeile verwenden
378378
autoplay=Automatisch Medien abspielen
379+
useIPFS=Enable IPFS (requires browser restart)

app/extensions/brave/locales/en-US/preferences.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,4 @@ urlBarOptions=URL Bar Options
377377
disableTitleMode=Always show the URL bar
378378
wideURLbar=Use wide URL bar
379379
autoplay=Autoplay Media
380+
useIPFS=Enable IPFS (requires browser restart)

app/extensions/brave/locales/es/preferences.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,4 @@ urlBarOptions=URL Bar Options
376376
disableTitleMode=Mostrar siempre la barra de URL
377377
wideURLbar=Use wide URL bar
378378
autoplay=Autoplay Media
379+
useIPFS=Enable IPFS (requires browser restart)

app/extensions/brave/locales/fr-FR/preferences.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,4 @@ urlBarOptions=URL Bar Options
376376
disableTitleMode=Toujours afficher la barre d'adresse
377377
wideURLbar=Use wide URL bar
378378
autoplay=Autoplay Media
379+
useIPFS=Enable IPFS (requires browser restart)

0 commit comments

Comments
 (0)