Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
add tor menu items, make tor switch per tab
Browse files Browse the repository at this point in the history
fix #14459

test plan:
1. every menu that says 'open in new private tab' should also have an
   item that says 'open in new tor tab'
2. opening in a new tor tab should show the tor indicator on
3. opening in a new private tab should show the tor indicator off
4. ddg is enabled by default for now but can be turned off
5. cmd+click should open in the same type as the current tab
6. turning the tor switch on/off in a new tab should work
7. in a tor tab, right-click should show 'open in new tor tab' first
  • Loading branch information
diracdeltas authored and bsclifton committed Jun 26, 2018
1 parent e99703c commit 89e6de2
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 80 deletions.
1 change: 1 addition & 0 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const createFileSubmenu = () => {
const submenu = [
CommonMenu.newTabMenuItem(),
CommonMenu.newPrivateTabMenuItem(),
CommonMenu.newTorTabMenuItem(),
CommonMenu.newPartitionedTabMenuItem(),
CommonMenu.newWindowMenuItem(),
CommonMenu.separatorMenuItem,
Expand Down
10 changes: 1 addition & 9 deletions app/browser/reducers/aboutNewTabReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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,
Expand Down
31 changes: 17 additions & 14 deletions app/common/commonMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/extensions/brave/locales/en-US/menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var rendererIdentifiers = function () {
'openInNewSessionTabs',
'openInNewPrivateTab',
'openInNewPrivateTabs',
'openInNewTorTab',
'openInNewTorTabs',
'openInNewTab',
'openInNewTabs',
'openAllInTabs',
Expand Down Expand Up @@ -153,6 +155,7 @@ var rendererIdentifiers = function () {
'hideOthers',
'showAll',
'newPrivateTab',
'newTorTab',
'newSessionTab',
'newWindow',
'reopenLastClosedTab',
Expand Down
4 changes: 0 additions & 4 deletions app/renderer/components/main/siteInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
24 changes: 9 additions & 15 deletions app/renderer/reducers/contextMenuReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,15 @@ 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'),
click: () => {
for (let i = 0; i < url.length; ++i) {
appActions.createTabRequested({
url: url[i],
isPrivate,
isTor,
partitionNumber: partitionNumber[i],
openerTabId,
active
Expand All @@ -134,8 +131,6 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => {
click: () => {
appActions.createTabRequested({
url,
isPrivate,
isTor,
partitionNumber,
openerTabId,
active
Expand All @@ -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({
Expand All @@ -165,7 +159,7 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => {
}
} else {
return {
label: locale.translation('openInNewPrivateTab'),
label: locale.translation(isTor ? 'openInNewTorTab' : 'openInNewPrivateTab'),
click: () => {
appActions.createTabRequested({
url,
Expand Down Expand Up @@ -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 })
}
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/rendererShortcutHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions js/about/newprivatetab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -46,15 +40,15 @@ class NewPrivateTab extends React.Component {
}

onClickTorTitle () {
const newSettingValue = !this.props.newTabData.getIn(torEnabled)
const newSettingValue = !this.props.torEnabled
onChangeTor(newSettingValue)
}

render () {
if (!this.props.newTabData) {
return null
}
const isTor = Boolean(this.props.newTabData.getIn(torEnabled))
const isTor = Boolean(this.props.torEnabled)
return <div data-test-id='privateTabContent' className={css(styles.newPrivateTab, styles.newPrivateTabVars)}>
<div className='statsBar'>
<Stats newTabData={this.props.newTabData} />
Expand Down
4 changes: 3 additions & 1 deletion js/about/newtab.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class NewTabPage extends React.Component {
updatedStamp: undefined,
showEmptyPage: true,
showImages: false,
torEnabled: false,
backgroundImage: undefined
}

Expand All @@ -68,6 +69,7 @@ class NewTabPage extends React.Component {
newTabData: data,
updatedStamp,
showEmptyPage,
torEnabled: data.get('torEnabled'),
showImages: !!data.get('showImages') && !showEmptyPage,
backgroundImage: showImages
? this.state.backgroundImage || this.randomBackgroundImage
Expand Down Expand Up @@ -263,7 +265,7 @@ class NewTabPage extends React.Component {

// TODO: use this.props.isIncognito when muon supports it for tor tabs
if (this.props.isIncognito) {
return <NewPrivateTab newTabData={this.state.newTabData} />
return <NewPrivateTab newTabData={this.state.newTabData} torEnabled={this.state.torEnabled} />
}

// don't render until object is found
Expand Down
3 changes: 1 addition & 2 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = {
'general.spellcheck-languages': Immutable.fromJS(['en-US']),
'search.default-search-engine': 'Google',
'search.offer-search-suggestions': false, // false by default for privacy reasons
'search.use-alternate-private-search-engine': false,
'search.use-alternate-private-search-engine': true,
'tabs.switch-to-new-tabs': false,
'tabs.paint-tabs': true,
'tabs.tabs-per-page': 20,
Expand All @@ -174,7 +174,6 @@ module.exports = {
'security.autoplay.media': autoplayOption.ALWAYS_ALLOW,
'security.flash.installed': false,
'security.site-isolation-enabled': false,
'tor.private-tabs.enabled': false,
'shields.blocked-count-badge': true,
'shields.compact-bravery-panel': false,
// sync
Expand Down
2 changes: 0 additions & 2 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ const settings = {
// Debug settings
DEBUG_ALLOW_MANUAL_TAB_DISCARD: 'debug.manual-tab-discard.enabled',
DEBUG_VERBOSE_TAB_INFO: 'debug.verbose-tab-info.enabled',
// Tor settings
USE_TOR_PRIVATE_TABS: 'tor.private-tabs.enabled',

// DEPRECATED settings
// DO NOT REMOVE OR CHANGE THESE VALUES
Expand Down
Loading

0 comments on commit 89e6de2

Please sign in to comment.