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

Commit

Permalink
feat: mix in IPFS
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Aug 22, 2017
1 parent eced5c4 commit 6ea5fdf
Show file tree
Hide file tree
Showing 45 changed files with 409 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Brave.tar.bz2
app/extensions/gen
app/extensions/brave/gen
app/extensions/torrent/gen
app/extensions/ipfs/gen

*.pfx
buildConfig.js

Expand Down
24 changes: 18 additions & 6 deletions app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,17 @@ module.exports.init = () => {
return object
}

let loadExtension = (extensionId, extensionPath, manifest = {}, manifestLocation = 'unpacked') => {
if (extensionId === config.PDFJSExtensionId) {
const loadExtension = (extensionId, extensionPath, manifest = {}, manifestLocation = 'unpacked') => {
if (extensionId === config.PDFJSExtensionId ||
extensionId === config.ipfsExtensionId) {
manifestLocation = 'component'
}
if (!extensionInfo.isLoaded(extensionId) && !extensionInfo.isLoading(extensionId)) {
if (!extensionInfo.isLoaded(extensionId) &&
!extensionInfo.isLoading(extensionId)) {
extensionInfo.setState(extensionId, extensionStates.LOADING)
if (extensionId === config.braveExtensionId || extensionId === config.torrentExtensionId || extensionId === config.syncExtensionId) {
if (extensionId === config.braveExtensionId ||
extensionId === config.torrentExtensionId ||
extensionId === config.syncExtensionId) {
session.defaultSession.extensions.load(extensionPath, manifest, manifestLocation)
return
}
Expand All @@ -430,6 +434,7 @@ module.exports.init = () => {
// just a safety net.
fs.exists(path.join(extensionPath, 'manifest.json'), (exists) => {
if (exists) {
console.log('Loading:', extensionId, manifestLocation)
session.defaultSession.extensions.load(extensionPath, manifest, manifestLocation)
} else {
// This is an error condition, but we can recover.
Expand All @@ -454,18 +459,21 @@ module.exports.init = () => {
const extensions = extensionState.getExtensions(appStore.getState())
const extensionPath = extensions.getIn([extensionId, 'filePath'])
if (extensionPath) {
// Otheriwse just install it
// Otherwise just install it
loadExtension(extensionId, extensionPath)
}
}
}

// Manually install the braveExtension and torrentExtension
// Manually install the braveExtension, torrentExtension and ipfsExtension

// braveExtension
extensionInfo.setState(config.braveExtensionId, extensionStates.REGISTERED)
loadExtension(config.braveExtensionId, getExtensionsPath('brave'), generateBraveManifest(), 'component')
extensionInfo.setState(config.syncExtensionId, extensionStates.REGISTERED)
loadExtension(config.syncExtensionId, getExtensionsPath('brave'), generateSyncManifest(), 'unpacked')

// torrentExtension
if (getSetting(settings.TORRENT_VIEWER_ENABLED)) {
extensionInfo.setState(config.torrentExtensionId, extensionStates.REGISTERED)
loadExtension(config.torrentExtensionId, getExtensionsPath('torrent'), generateTorrentManifest(), 'component')
Expand All @@ -474,6 +482,10 @@ module.exports.init = () => {
extensionActions.extensionDisabled(config.torrentExtensionId)
}

// ipfsExtension
extensionInfo.setState(config.ipfsExtensionId, extensionStates.REGISTERED)
loadExtension(config.ipfsExtensionId, getExtensionsPath('ipfs'))

let registerComponents = (diff) => {
if (getSetting(settings.PDFJS_ENABLED)) {
registerComponent(config.PDFJSExtensionId, config.PDFJSExtensionPublicKey)
Expand Down
1 change: 1 addition & 0 deletions app/extensions/brave/locales/bn-BD/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/bn-IN/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/cs/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Dlouhý
normal=Normal
short=Krátký
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/de-DE/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/es/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/eu/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/fr-FR/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/hi-IN/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/id-ID/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Waktunya menunggu sebelum meninjau tab baru
long=Panjang
normal=Normal
short=Pendek
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/it-IT/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/ja-JP/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=長い
normal=Normal
short=短い
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/ko-KR/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/ms-MY/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Tempoh menunggu sebelum previu tab
long=Panjang
normal=Normal
short=Pendek
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/nl-NL/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Lang
normal=Normal
short=Kort
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/pl-PL/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/pt-BR/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/ru/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Время ожидания перед просмотром в
long=Длинное
normal=Normal
short=Короткое
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/sl/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Dolga
normal=Normal
short=Kratka
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/ta/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/te/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ urlBarOptions=URL Bar Options
disableTitleMode=Always show the URL bar
wideURLbar=Use wide URL bar
autoplay=Autoplay Media
<<<<<<< HEAD
tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/tr-TR/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/uk/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
1 change: 1 addition & 0 deletions app/extensions/brave/locales/zh-CN/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab
long=Long
normal=Normal
short=Short
useIPFS=Enable IPFS (requires browser restart)
23 changes: 23 additions & 0 deletions app/extensions/ipfs/_locales/en/app.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
startPrompt=Start Downloading "{{name}}"?
startPromptUntitled=Start Downloading?
startDownload=Start Download
saveTorrentFile=Save Torrent File...
legalNotice=When you start a torrent, its data will be made available to others by means of upload. You are responsible for abiding by your local laws.
missingFilesList=Click "Start Download" to load the torrent file list.
loadingFilesList=Loading the torrent file list...
name=Name
size=Size
poweredByWebTorrent=Powered By WebTorrent.
seeding=Seeding
seedingTorrent=Seeding Torrent
downloading=Downloading
downloadingTorrent=Downloading Torrent
files=Files
num=#
downloadFile=Save File
torrentStatus=Torrent Status
torrentLoadingInfo=Loading torrent info...
torrentLoadingMedia=Loading...
copyMagnetLink=Copy Magnet Link
webtorrentPage=WebTorrent
stopDownload=Stop Download
1 change: 1 addition & 0 deletions app/extensions/ipfs/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions app/extensions/ipfs/ext/l20n.min.js

Large diffs are not rendered by default.

Binary file added app/extensions/ipfs/img/favicon.ico
Binary file not shown.
Binary file added app/extensions/ipfs/img/ipfs-128.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/ipfs/img/ipfs-16.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/ipfs/img/ipfs-48.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/ipfs/img/ipfs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
240 changes: 240 additions & 0 deletions app/extensions/ipfs/js/ipfs.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions app/extensions/ipfs/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// const ipc = window.chrome.ipcRenderer

chrome.protocol.registerStringProtocol('ipfs', (request, callback) => {
/*
const node = new IPFS()
node.on('ready', () => {
callback('hi there!' + test() + IPFS) // eslint-disable-line
})
*/
callback('hi there!' + test() + IPFS) // eslint-disable-line
})
1 change: 1 addition & 0 deletions app/extensions/ipfs/js/some-other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function test () { return 'yeeah' }
21 changes: 21 additions & 0 deletions app/extensions/ipfs/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"manifest_version": 2,
"name": "IPFS",
"version": "0.1.0",
"default_locale": "en",
"description": "InterPlanetary FileSystem",
"icons": {
"128": "img/ipfs-128.png",
"48": "img/ipfs-48.png",
"16": "img/ipfs-16.png"
},
"offline_enabled": true,
"background": {
"scripts": [
"js/some-other.js",
"js/ipfs.min.js",
"js/main.js"
],
"persistent": true
}
}
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ AppStore
'advanced.send-usage-statistics': boolean, // true or undefined if usage reports should be sent
'advanced.smooth-scroll-enabled': boolean, // false if smooth scrolling should be explicitly disabled
'advanced.torrent-viewer-enabled': boolean, // whether to render magnet links in the browser
'advanced.ipfs-enabled': boolean, // whether to use IPFS to render ipfs:// or dweb: links in the browser
'bookmarks.toolbar.show': boolean, // true if the bookmakrs toolbar should be shown
'bookmarks.toolbar.showFavicon': boolean, // true if bookmark favicons should be shown on the bookmarks toolbar
'bookmarks.toolbar.showOnlyFavicon': boolean, // true if only favicons should be shown on the bookmarks toolbar
Expand Down
1 change: 1 addition & 0 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ class AboutPreferences extends React.Component {
settings.LANGUAGE,
settings.PDFJS_ENABLED,
settings.TORRENT_VIEWER_ENABLED,
settings.IPFS_ENABLED,
settings.SMOOTH_SCROLL_ENABLED,
settings.SEND_CRASH_REPORTS,
settings.UPDATE_TO_PREVIEW_RELEASES
Expand Down
7 changes: 6 additions & 1 deletion js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module.exports = {
COOKIEBLOCK: 'cookieblock', // block 3p cookies and referer
COOKIEBLOCK_ALL: 'cookieblockAll', // block all cookies and referer
SITEHACK: 'siteHacks',
WEBTORRENT: 'webtorrent'
WEBTORRENT: 'webtorrent',
IPFS: 'ipfs'
// ... other optional resource files are identified by uuid such as for regional adblock
},
cookieblock: {
Expand Down Expand Up @@ -95,6 +96,9 @@ module.exports = {
webtorrent: {
enabled: true
},
ipfs: {
enabled: true
},
adInsertion: {
enabled: false,
url: adHost
Expand Down Expand Up @@ -207,6 +211,7 @@ module.exports = {
'advanced.default-zoom-level': null,
'advanced.pdfjs-enabled': true,
'advanced.torrent-viewer-enabled': true,
'advanced.ipfs-enabled': true,
'advanced.smooth-scroll-enabled': false,
'advanced.send-crash-reports': true,
'advanced.send-usage-statistics': false,
Expand Down
1 change: 1 addition & 0 deletions js/constants/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = {
widevineComponentPublicKey: 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmhe+02cLPPAViaevk/fzODKUnb/ysaAeD8lpE9pwirV6GYOm+naTo7xPOCh8ujcR6Ryi1nPTq2GTG0CyqdDyOsZ1aRLuMZ5QqX3dJ9jXklS0LqGfosoIpGexfwggbiLvQOo9Q+IWTrAO620KAzYU0U6MV272TJLSmZPUEFY6IGQIDAQAB',
braveExtensionId: 'mnojpmjdmbbfmejpflffifhffcmidifd',
torrentExtensionId: 'fmdpfempfmekjkcfdehndghogpnpjeno',
ipfsExtensionId: 'interplanetaryfilesystemuniverse',
syncExtensionId: 'cjnmeadmgmiihncdidmfiabhenbggfjm',
// PDFJS
// Parent repo: https://github.com/diracdeltas/pdf.js
Expand Down
1 change: 1 addition & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const settings = {
HARDWARE_ACCELERATION_ENABLED: 'advanced.hardware-acceleration-enabled',
PDFJS_ENABLED: 'advanced.pdfjs-enabled',
TORRENT_VIEWER_ENABLED: 'advanced.torrent-viewer-enabled',
IPFS_ENABLED: 'advanced.ipfs-enabled',
DEFAULT_ZOOM_LEVEL: 'advanced.default-zoom-level',
SMOOTH_SCROLL_ENABLED: 'advanced.smooth-scroll-enabled',
SEND_CRASH_REPORTS: 'advanced.send-crash-reports',
Expand Down
53 changes: 53 additions & 0 deletions js/lib/appUrlUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ module.exports.getTorrentExtUrl = function (relativeUrl) {
return 'chrome-extension://' + config.torrentExtensionId + '/' + relativeUrl
}

/**
* Gets the URL of a page hosted by the ipfsExtension
* Returns 'chrome-extension://<...>'
*/
module.exports.getIpfsExtUrl = function (relativeUrl) {
if (relativeUrl === undefined) {
relativeUrl = ''
}

return 'chrome-extension://' + config.ipfsExtensionId + '/' + relativeUrl
}

module.exports.getExtensionsPath = function (extensionDir) {
return (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test')
// the path is different for release builds because extensions are not in the asar file
Expand Down Expand Up @@ -210,6 +222,47 @@ module.exports.isTargetMagnetUrl = function (input) {
return !!module.exports.getSourceMagnetUrl(input)
}

/**
* Obtains the target URL associated with a IPFS path
* Returns null if the input is not a IPFS path
* Example: getTargetIpfsPath('ipfs:/...') -> 'chrome-extension://<...>.html#/ipfs/...'
*/
module.exports.getTargetIpfsPath = function (input) {
if (!input.startsWith('ipfs://') &&
!input.startsWith('dweb:')) {
return null
}
const url = module.exports.getIpfsExtUrl('ipfs.html')
return [url, input].join('#')
}

/**
* Obtains the source IPFS Path associated with a target URL
* Returns null if the input is not the local URL for a IPFS Path
* Example: getSourceIPFSPath('chrome-extension://<...>.html#/ipfs/...') -> 'ipfs:/:...'
*/
module.exports.getSourceIPFSPath = function (input) {
if (getBaseUrl(input) !== module.exports.getIpfsExtUrl('ipfs.html')) return null
const url = decodeURIComponent(getHash(input))
return url
}

/**
* Checks if the input looks like a magnet: URL
* Example: isSourceIpfsPath('ipfs:/..') -> true
*/
module.exports.isSourceIpfsPath = function (input) {
return !!module.exports.getTargetIpfsPath(input)
}

/*
* Checks if the input looks like the local URL for a IPFS Path
* Example: isSourceIpfsPath('chrome-extension://<...>.html#/ipfs/') -> true
*/
module.exports.isTargetIPFSPath = function (input) {
return !!module.exports.getSourceIPFSPath(input)
}

/**
* Determines whether a string is a valid URL. Based on node-urlutil.js.
* @param {string} input
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"electron-chromedriver": "^1.7.1",
"electron-packager": "brave/electron-packager",
"electron-prebuilt": "brave/electron-prebuilt",
"electron-rebuild": "^1.5.11",
"empty-port": "0.0.2",
"enzyme": "^2.9.1",
"flow-bin": "^0.22.1",
Expand Down

0 comments on commit 6ea5fdf

Please sign in to comment.