diff --git a/app/extensions.js b/app/extensions.js index e76cc824d4a..5b5dd8f4fbf 100644 --- a/app/extensions.js +++ b/app/extensions.js @@ -162,6 +162,7 @@ let generateBraveManifest = () => { let generateTorrentManifest = () => { let cspDirectives = { 'default-src': '\'self\'', + 'media-src': '\'self\' http://localhost:*', 'frame-src': 'http://localhost:*', 'form-action': '\'none\'', 'referrer': 'no-referrer', diff --git a/app/filtering.js b/app/filtering.js index a6cddce6e43..3e4ab069738 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -358,6 +358,13 @@ function registerPermissionHandler (session, partition) { return } + // The Torrent Viewer extension is always allowed to show fullscreen media + if (permission === 'fullscreen' && + origin.startsWith('chrome-extension://' + config.torrentExtensionId)) { + cb(true) + return + } + // The Brave extension and PDFJS are always allowed to open files in an external app if (permission === 'openExternal' && ( origin.startsWith('chrome-extension://' + config.PDFJSExtensionId) || diff --git a/js/webtorrent/components/mediaViewer.js b/js/webtorrent/components/mediaViewer.js index e32c2eba47c..c8e4598da8d 100644 --- a/js/webtorrent/components/mediaViewer.js +++ b/js/webtorrent/components/mediaViewer.js @@ -1,15 +1,54 @@ const React = require('react') -class MediaViewer extends React.Component { +const SUPPORTED_VIDEO_EXTENSIONS = [ + 'm4v', + 'mkv', + 'mov', + 'mp4', + 'ogv', + 'webm' +] + +const SUPPORTED_AUDIO_EXTENSIONS = [ + 'aac', + 'mp3', + 'ogg', + 'wav', + 'm4a' +] + +module.exports = class MediaViewer extends React.Component { render () { const torrent = this.props.torrent const ix = this.props.ix + const file = torrent.files[ix] + const fileExt = file && getExtension(file.name) + const isVideo = SUPPORTED_VIDEO_EXTENSIONS.includes(fileExt) + const isAudio = SUPPORTED_AUDIO_EXTENSIONS.includes(fileExt) let content - if (torrent.serverURL != null) { - content =