diff --git a/app/browser/webtorrent.js b/app/browser/webtorrent.js index b2e0ce3ad57..4ed3f4cb4a5 100644 --- a/app/browser/webtorrent.js +++ b/app/browser/webtorrent.js @@ -145,5 +145,7 @@ function getHeader (headers, headerName) { module.exports = { init, + isTorrentFile, + isMagnetURL, resourceName: 'webtorrent' } diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index ef89a4df0b6..e0266b502d5 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -237,6 +237,8 @@ streetAddress=Street Address submit=Submit tabsSuggestionTitle=Tabs topSiteSuggestionTitle=Top Site +torrentBlockedInTor=For your privacy, torrents are blocked in private tabs when Tor is enabled. +torrentWarningOk=Ok turnOffNotifications=Turn off notifications unknownError=Oops, something went wrong. unmuteTab=Unmute tab diff --git a/app/filtering.js b/app/filtering.js index 6f89022292e..96bcfa058f1 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -28,6 +28,7 @@ const ipcMain = electron.ipcMain const app = electron.app const path = require('path') const getOrigin = require('../js/lib/urlutil').getOrigin +const {isTorrentFile, isMagnetURL} = require('./browser/webtorrent') const {adBlockResourceName} = require('./adBlock') const {updateElectronDownloadItem} = require('./browser/electronDownloadItem') const {fullscreenOption} = require('./common/constants/settingsEnums') @@ -42,6 +43,7 @@ const tor = require('./tor') let appStore = null +const tabMessageBox = require('./browser/tabMessageBox') const beforeSendHeadersFilteringFns = [] const beforeRequestFilteringFns = [] const beforeRedirectFilteringFns = [] @@ -119,6 +121,11 @@ function registerForBeforeRequest (session, partition) { return } + if ((isMagnetURL(details)) && partition === appConfig.tor.partition) { + showTorrentBlockedInTorWarning(details) + return + } + const firstPartyUrl = module.exports.getMainFrameUrl(details) const url = details.url // this can happen if the tab is closed and the webContents is no longer available @@ -350,6 +357,16 @@ function registerForBeforeSendHeaders (session, partition) { }) } +function showTorrentBlockedInTorWarning (details) { + if (details.tabId) { + tabMessageBox.show(details.tabId, { + message: `${locale.translation('torrentBlockedInTor')}`, + title: 'Brave', + buttons: [locale.translation('torrentWarningOk')] + }) + } +} + /** * Register for notifications for webRequest.onHeadersReceived for a particular * session. @@ -363,6 +380,10 @@ function registerForHeadersReceived (session, partition) { muonCb({}) return } + if ((isTorrentFile(details)) && partition === appConfig.tor.partition) { + showTorrentBlockedInTorWarning(details) + return + } const firstPartyUrl = module.exports.getMainFrameUrl(details) // this can happen if the tab is closed and the webContents is no longer available if (!firstPartyUrl) { diff --git a/app/locale.js b/app/locale.js index a11933d42ca..c9e5abed254 100644 --- a/app/locale.js +++ b/app/locale.js @@ -257,6 +257,8 @@ var rendererIdentifiers = function () { 'downloadPaused', 'noDownloads', 'torrentDesc', + 'torrentBlockedInTor', + 'torrentWarningOk', 'multiSelectionBookmarks', // Caption buttons in titlebar (min/max/close - Windows only) 'windowCaptionButtonMinimize',