-
Notifications
You must be signed in to change notification settings - Fork 1
IPFS Integration #1
base: master
Are you sure you want to change the base?
Changes from 2 commits
a6d660c
3e82c59
08b4f38
4d2b5cc
4ca81cf
e248f2d
faa9afe
3952beb
f2a0df9
ca10910
bc43e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ipfs=Distributed Web |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// const ipc = window.chrome.ipcRenderer | ||
|
||
chrome.protocol.registerStringProtocol('ipfs', handler) | ||
chrome.protocol.registerStringProtocol('dweb', handler) | ||
|
||
function handler (request, callback) { | ||
// test to check if handling the protocol works | ||
callback('hi there!' + test()) // eslint-disable-line | ||
|
||
/* | ||
const node = new Ipfs() | ||
node.on('ready', () => { | ||
callback('hi there!' + test() + Ipfs) // eslint-disable-line | ||
}) | ||
*/ | ||
// test loading Ipfs into the background process scope | ||
// callback('hi there!' + test() + Ipfs.toString()) // eslint-disable-line | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function test () { | ||
return 'yeeah' | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a test to make sure I could in fact run a function from another file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"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/main.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To test with IPFS, add here |
||
], | ||
"persistent": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be no longer necessary as we now capture the |
||
* Determines whether a string is a valid URL. Based on node-urlutil.js. | ||
* @param {string} input | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,8 @@ | |
"watch-all": "npm run watch & npm run watch-test", | ||
"watch-test": "cross-env NODE_ENV=test webpack --watch", | ||
"webpack": "webpack", | ||
"win-renpm": "powershell ./tools/windows/re-npm.ps1" | ||
"win-renpm": "powershell ./tools/windows/re-npm.ps1", | ||
"ipfs": "wget https://unpkg.com/ipfs/dist/index.min.js -O app/extensions/ipfs/js/ipfs.min.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this step to make it simpler to reproduce my local set up. |
||
}, | ||
"repository": "brave/browser-laptop", | ||
"author": { | ||
|
@@ -148,6 +149,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", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is no longer necessary as the preference pane doesn't show this message anymore.