diff --git a/app/browser/menu.js b/app/browser/menu.js index cf456a27e0c..ae26d3ece25 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -52,6 +52,7 @@ const createFileSubmenu = () => { const submenu = [ CommonMenu.newTabMenuItem(), CommonMenu.newPrivateTabMenuItem(), + CommonMenu.newTorTabMenuItem(), CommonMenu.newPartitionedTabMenuItem(), CommonMenu.newWindowMenuItem(), CommonMenu.separatorMenuItem, diff --git a/app/browser/reducers/aboutNewTabReducer.js b/app/browser/reducers/aboutNewTabReducer.js index 3290d04cf32..fa5fa549881 100644 --- a/app/browser/reducers/aboutNewTabReducer.js +++ b/app/browser/reducers/aboutNewTabReducer.js @@ -14,11 +14,9 @@ const aboutNewTabReducer = (state, action) => { switch (action.actionType) { case appConstants.APP_SET_STATE: const useAlternativePrivateSearchEngine = getSetting(settings.USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE, state.get('settings')) - const torEnabled = getSetting(settings.USE_TOR_PRIVATE_TABS) state = aboutNewTabState.mergeDetails(state, { newTabPageDetail: { - useAlternativePrivateSearchEngine, - torEnabled + useAlternativePrivateSearchEngine } }) break @@ -38,12 +36,6 @@ const aboutNewTabReducer = (state, action) => { useAlternativePrivateSearchEngine: action.value } }) - } else if (action.key === settings.USE_TOR_PRIVATE_TABS) { - state = aboutNewTabState.mergeDetails(state, { - newTabPageDetail: { - torEnabled: action.value - } - }) } } return state diff --git a/app/browser/tabs.js b/app/browser/tabs.js index dbc131b693d..4ced028fa5b 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -11,7 +11,7 @@ const {app, extensions, session, ipcMain} = require('electron') const {makeImmutable, makeJS} = require('../common/state/immutableUtil') const {getExtensionsPath, getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl, isIntermediateAboutPage, isTargetMagnetUrl, getSourceMagnetUrl} = require('../../js/lib/appUrlUtil') const {isURL, getUrlFromInput, toPDFJSLocation, getDefaultFaviconUrl, isHttpOrHttps, getLocationIfPDF} = require('../../js/lib/urlutil') -const {isSessionPartition} = require('../../js/state/frameStateUtil') +const {isSessionPartition, isTor} = require('../../js/state/frameStateUtil') const {getOrigin} = require('../../js/lib/urlutil') const settingsStore = require('../../js/settings') const settings = require('../../js/constants/settings') @@ -346,12 +346,14 @@ const updateAboutDetails = (tabId) => { const trackedBlockersCount = appState.getIn(['trackingProtection', 'count'], 0) const httpsUpgradedCount = appState.getIn(['httpsEverywhere', 'count'], 0) const adblockCount = appState.getIn(['adblock', 'count'], 0) + const torEnabled = isTor(getTabValue(tabId)) sendAboutDetails(tabId, messages.NEWTAB_DATA_UPDATED, { showEmptyPage, showImages, trackedBlockersCount, adblockCount, httpsUpgradedCount, + torEnabled, newTabDetail: newTabDetail.toJS() }) } else if (location === 'about:autofill') { @@ -522,7 +524,7 @@ const api = { if (ses) { isPrivate = ses.isOffTheRecord() } - const isTor = isPrivate && settingsStore.getSetting(settings.USE_TOR_PRIVATE_TABS) + const isTor = newTab.session.partition === appConfig.tor.partition const frameOpts = { location, diff --git a/app/browser/windows.js b/app/browser/windows.js index 3e09f9b68fc..8080039a3ee 100644 --- a/app/browser/windows.js +++ b/app/browser/windows.js @@ -211,12 +211,12 @@ function openFramesInWindow (win, frames, activeFrameKey) { let frameIndex = -1 for (const frame of frames) { frameIndex++ + const tab = webContentsCache.getWebContents(frame.tabId) if (frame.tabId != null && frame.guestInstanceId != null) { if (shouldDebugTabEvents) { console.log('notifyWindowWebContentsAdded: on window create with existing tab', win.id) } api.notifyWindowWebContentsAdded(win.id, frame) - const tab = webContentsCache.getWebContents(frame.tabId) if (tab && !tab.isDestroyed()) { tab.moveTo(frameIndex, win.id) } @@ -226,7 +226,7 @@ function openFramesInWindow (win, frames, activeFrameKey) { url: frame.location || frame.src || frame.provisionalLocation || frame.url, partitionNumber: frame.partitionNumber, isPrivate: frame.isPrivate, - isTor: frame.isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS), + isTor: tab && tab.session && tab.session.partition === appConfig.tor.partition, active: activeFrameKey ? frame.key === activeFrameKey : true, discarded: frame.unloaded, title: frame.title, diff --git a/app/common/commonMenu.js b/app/common/commonMenu.js index 5ad784bf957..d7f7a90e570 100644 --- a/app/common/commonMenu.js +++ b/app/common/commonMenu.js @@ -77,20 +77,23 @@ module.exports.newPrivateTabMenuItem = () => { label: locale.translation('newPrivateTab'), accelerator: 'Shift+CmdOrCtrl+P', click: function (item, focusedWindow) { - // Check if Tor is available - const useTor = getSetting(settings.USE_TOR_PRIVATE_TABS) - if (useTor) { - ensureAtLeastOneWindow({ - url: 'about:newtab', - isPrivate: true, - isTor: true - }) - } else { - ensureAtLeastOneWindow({ - url: 'about:newtab', - isPrivate: true - }) - } + ensureAtLeastOneWindow({ + url: 'about:newtab', + isPrivate: true + }) + } + } +} + +module.exports.newTorTabMenuItem = () => { + return { + label: locale.translation('newTorTab'), + click: function (item, focusedWindow) { + ensureAtLeastOneWindow({ + url: 'about:newtab', + isPrivate: true, + isTor: true + }) } } } diff --git a/app/extensions/brave/locales/en-US/menu.properties b/app/extensions/brave/locales/en-US/menu.properties index c8c29775870..d2e3e58a14f 100644 --- a/app/extensions/brave/locales/en-US/menu.properties +++ b/app/extensions/brave/locales/en-US/menu.properties @@ -99,6 +99,7 @@ muteTab=Mute Tab muteTabs=Mute Tabs new=New newPrivateTab=New Private Tab +newTorTab=New Private Tab with Tor newSessionTab=New Session Tab newTab=New Tab newWindow=New Window @@ -108,6 +109,8 @@ openFlashPreferences=Enable Flash in Preferences… openImageInNewTab=Open Image in New Tab openInNewPrivateTab=Open Link in New Private Tab openInNewPrivateTabs=Open Links in New Private Tabs +openInNewTorTab=Open Link in New Private Tab with Tor +openInNewTorTabs=Open Links in New Private Tabs with Tor openInNewSessionTab=Open Link in New Session Tab openInNewSessionTabs=Open Links in New Session Tabs openInNewTab=Open Link in New Tab diff --git a/app/locale.js b/app/locale.js index c97c3991e59..f018e3818e6 100644 --- a/app/locale.js +++ b/app/locale.js @@ -46,6 +46,8 @@ var rendererIdentifiers = function () { 'openInNewSessionTabs', 'openInNewPrivateTab', 'openInNewPrivateTabs', + 'openInNewTorTab', + 'openInNewTorTabs', 'openInNewTab', 'openInNewTabs', 'openAllInTabs', @@ -153,6 +155,7 @@ var rendererIdentifiers = function () { 'hideOthers', 'showAll', 'newPrivateTab', + 'newTorTab', 'newSessionTab', 'newWindow', 'reopenLastClosedTab', diff --git a/app/renderer/components/main/siteInfo.js b/app/renderer/components/main/siteInfo.js index 8fd8264fbf6..68d4643d7cd 100644 --- a/app/renderer/components/main/siteInfo.js +++ b/app/renderer/components/main/siteInfo.js @@ -30,9 +30,6 @@ const urlUtil = require('../../../../js/lib/urlutil') const globalStyles = require('../styles/global') const commonStyles = require('../styles/commonStyles') -// Constants -const settings = require('../../../../js/constants/settings') - class SiteInfo extends React.Component { constructor (props) { super(props) @@ -66,7 +63,6 @@ class SiteInfo extends React.Component { } onDisableTor () { - appActions.changeSetting(settings.USE_TOR_PRIVATE_TABS, false) appActions.recreateTorTab(false, this.props.activeTabId, this.props.activeTabIndex) } diff --git a/app/renderer/reducers/contextMenuReducer.js b/app/renderer/reducers/contextMenuReducer.js index 72ecbedad33..029523a8280 100644 --- a/app/renderer/reducers/contextMenuReducer.js +++ b/app/renderer/reducers/contextMenuReducer.js @@ -109,9 +109,8 @@ const onTabPageMenu = function (state, action) { tabPageMenu.popup(getCurrentWindow()) } -const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { +const openInNewTabMenuItem = (url, partitionNumber, openerTabId) => { const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true - const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) if (Array.isArray(url) && Array.isArray(partitionNumber)) { return { label: locale.translation('openInNewTabs'), @@ -119,8 +118,6 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { for (let i = 0; i < url.length; ++i) { appActions.createTabRequested({ url: url[i], - isPrivate, - isTor, partitionNumber: partitionNumber[i], openerTabId, active @@ -134,8 +131,6 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { click: () => { appActions.createTabRequested({ url, - isPrivate, - isTor, partitionNumber, openerTabId, active @@ -145,12 +140,11 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { } } -const openInNewPrivateTabMenuItem = (url, openerTabId) => { +const openInNewPrivateTabMenuItem = (url, openerTabId, isTor) => { const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true - const isTor = getSetting(settings.USE_TOR_PRIVATE_TABS) if (Array.isArray(url)) { return { - label: locale.translation('openInNewPrivateTabs'), + label: locale.translation(isTor ? 'openInNewTorTabs' : 'openInNewPrivateTabs'), click: () => { for (let i = 0; i < url.length; ++i) { appActions.createTabRequested({ @@ -165,7 +159,7 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => { } } else { return { - label: locale.translation('openInNewPrivateTab'), + label: locale.translation(isTor ? 'openInNewTorTab' : 'openInNewPrivateTab'), click: () => { appActions.createTabRequested({ url, @@ -210,12 +204,11 @@ const openInNewSessionTabMenuItem = (url, openerTabId) => { } } -const openInNewWindowMenuItem = (location, isPrivate, partitionNumber) => { - const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) +const openInNewWindowMenuItem = (location, partitionNumber) => { return { label: locale.translation('openInNewWindow'), click: () => { - appActions.newWindow({ location, isPrivate, isTor, partitionNumber }) + appActions.newWindow({ location, partitionNumber }) } } } @@ -321,9 +314,10 @@ const siteDetailTemplateInit = (state, siteKey, type) => { const location = siteDetail.get('location') template.push( - openInNewTabMenuItem(location, undefined, siteDetail.get('partitionNumber')), + openInNewTabMenuItem(location, siteDetail.get('partitionNumber')), openInNewPrivateTabMenuItem(location), - openInNewWindowMenuItem(location, undefined, siteDetail.get('partitionNumber')), + openInNewPrivateTabMenuItem(location, undefined, true), + openInNewWindowMenuItem(location, siteDetail.get('partitionNumber')), openInNewSessionTabMenuItem(location), copyAddressMenuItem('copyLinkAddress', location), CommonMenu.separatorMenuItem diff --git a/app/renderer/rendererShortcutHandler.js b/app/renderer/rendererShortcutHandler.js index 280c5904657..462d1d99233 100644 --- a/app/renderer/rendererShortcutHandler.js +++ b/app/renderer/rendererShortcutHandler.js @@ -120,7 +120,7 @@ function handleShortcut (frameKey, shortcut, e, args) { appActions.createTabRequested({ url: sourceLocation, isPrivate, - isTor: isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS), + isTor: frameStateUtil.isTor(frame), partitionNumber: frame.get('partitionNumber'), openerTabId: tabId, active: true diff --git a/docs/state.md b/docs/state.md index f5526cbda13..5eef6ab04f0 100644 --- a/docs/state.md +++ b/docs/state.md @@ -34,7 +34,6 @@ AppStore pinnedTopSites: [string], // list of pinned sites to be used on gridLayout. Defaults to 1 Brave-related site; see data/newTabData.js => pinnedTopSites sites: [string], // list of sites to be used on gridLayout. Defaults to 6 Brave-related sites; see data/newTabData.js => topSites updatedStamp: number, // timestamp for when the data was last updated - torEnabled: boolean, // whether Tor private tabs is enabled }, preferences: { backupNotifyCount: number, // number of times user has been reminded to backup wallet diff --git a/js/about/newprivatetab.js b/js/about/newprivatetab.js index a017b6efd85..c979022131d 100644 --- a/js/about/newprivatetab.js +++ b/js/about/newprivatetab.js @@ -19,15 +19,9 @@ const aboutActions = require('./aboutActions') require('../../less/about/newtab.less') const useAlternativePrivateSearchEngineDataKeys = ['newTabDetail', 'useAlternativePrivateSearchEngine'] -const torEnabled = ['newTabDetail', 'torEnabled'] const torFAQ = 'https://github.com/brave/browser-laptop/wiki/Using-Tor-in-Brave#faq' const onChangeTor = (value) => { - aboutActions.changeSetting(settings.USE_TOR_PRIVATE_TABS, value) - if (value === true) { - // Also change DDG to enabled since Google is unusable with Tor. - aboutActions.changeSetting(settings.USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE, value) - } aboutActions.recreateTorTab(value) } @@ -46,7 +40,7 @@ class NewPrivateTab extends React.Component { } onClickTorTitle () { - const newSettingValue = !this.props.newTabData.getIn(torEnabled) + const newSettingValue = !this.props.torEnabled onChangeTor(newSettingValue) } @@ -54,7 +48,7 @@ class NewPrivateTab extends React.Component { if (!this.props.newTabData) { return null } - const isTor = Boolean(this.props.newTabData.getIn(torEnabled)) + const isTor = Boolean(this.props.torEnabled) return