@@ -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+
225272let 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 )
0 commit comments