-
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 3 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 |
---|---|---|
|
@@ -384,3 +384,4 @@ tabPreviewTiming=Time to wait before previewing a tab | |
long=Long | ||
normal=Normal | ||
short=Short | ||
useIPFS=Enable IPFS (requires browser restart) | ||
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 believe this is no longer necessary as the preference pane doesn't show this message anymore. |
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,32 @@ | ||
/* global Ipfs */ | ||
|
||
// 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', () => { | ||
node.files.cat('QmSmuETUoXzh4Qo5upHxJWZJK8AEpXXZdTqs34ttE3qMYn', (err, stream) => { | ||
if (err) { | ||
return callback('failed to get the hash') | ||
} | ||
let buf = '' | ||
stream.on('data', (data) => { | ||
buf += data.toString() | ||
}) | ||
stream.on('end', () => { | ||
callback(buf) | ||
}) | ||
}) | ||
// callback('I am online!') // 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,22 @@ | ||
{ | ||
"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" | ||
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 | ||
}, | ||
"content_security_policy": "script-src 'self' 'unsafe-eval'" | ||
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 believe the csp you have defined in the page above can be defined here instead 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. if the CSP is just for the IPFS extension, it should be defined here instead of in index-dev.html. i would still encourage refactoring such that unsafe-eval isn't needed. 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. @bridiver @diracdeltas agreed that we should not have the need for unsafe-eval. We are working on it :) 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. @diasdavid I think the latest version of js-ipfs-api is ready to be tested without evals :) 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. 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. that is definitely still a protobuf thing 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. looks like we missed two modules
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. 💡 So it is evident. Nice, I was worried that it was npm false deduping. Thanks for catching that! 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. 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. 🎉 🎉 🎉 |
||
} |
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 | ||
|
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.
added the
'unsafe-eval'
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.
why is that needed? I think @diracdeltas will likely have an issue with it
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.
Unfortunately
unsafe-eval
removes most of the purpose of having a CSP - please avoid it by refactoring all inline script code into external files.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.
Removed it from here. It was not necessary