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

Commit 64bdfd5

Browse files
diracdeltasbsclifton
authored andcommitted
add tor menu items, make tor switch per tab
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
1 parent 559c51d commit 64bdfd5

File tree

17 files changed

+67
-80
lines changed

17 files changed

+67
-80
lines changed

app/browser/menu.js

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const createFileSubmenu = () => {
5252
const submenu = [
5353
CommonMenu.newTabMenuItem(),
5454
CommonMenu.newPrivateTabMenuItem(),
55+
CommonMenu.newTorTabMenuItem(),
5556
CommonMenu.newPartitionedTabMenuItem(),
5657
CommonMenu.newWindowMenuItem(),
5758
CommonMenu.separatorMenuItem,

app/browser/reducers/aboutNewTabReducer.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ const aboutNewTabReducer = (state, action) => {
1414
switch (action.actionType) {
1515
case appConstants.APP_SET_STATE:
1616
const useAlternativePrivateSearchEngine = getSetting(settings.USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE, state.get('settings'))
17-
const torEnabled = getSetting(settings.USE_TOR_PRIVATE_TABS)
1817
state = aboutNewTabState.mergeDetails(state, {
1918
newTabPageDetail: {
20-
useAlternativePrivateSearchEngine,
21-
torEnabled
19+
useAlternativePrivateSearchEngine
2220
}
2321
})
2422
break
@@ -38,12 +36,6 @@ const aboutNewTabReducer = (state, action) => {
3836
useAlternativePrivateSearchEngine: action.value
3937
}
4038
})
41-
} else if (action.key === settings.USE_TOR_PRIVATE_TABS) {
42-
state = aboutNewTabState.mergeDetails(state, {
43-
newTabPageDetail: {
44-
torEnabled: action.value
45-
}
46-
})
4739
}
4840
}
4941
return state

app/browser/tabs.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {app, extensions, session, ipcMain} = require('electron')
1111
const {makeImmutable, makeJS} = require('../common/state/immutableUtil')
1212
const {getExtensionsPath, getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl, isIntermediateAboutPage, isTargetMagnetUrl, getSourceMagnetUrl} = require('../../js/lib/appUrlUtil')
1313
const {isURL, getUrlFromInput, toPDFJSLocation, getDefaultFaviconUrl, isHttpOrHttps, getLocationIfPDF} = require('../../js/lib/urlutil')
14-
const {isSessionPartition} = require('../../js/state/frameStateUtil')
14+
const {isSessionPartition, isTor} = require('../../js/state/frameStateUtil')
1515
const {getOrigin} = require('../../js/lib/urlutil')
1616
const settingsStore = require('../../js/settings')
1717
const settings = require('../../js/constants/settings')
@@ -346,12 +346,14 @@ const updateAboutDetails = (tabId) => {
346346
const trackedBlockersCount = appState.getIn(['trackingProtection', 'count'], 0)
347347
const httpsUpgradedCount = appState.getIn(['httpsEverywhere', 'count'], 0)
348348
const adblockCount = appState.getIn(['adblock', 'count'], 0)
349+
const torEnabled = isTor(getTabValue(tabId))
349350
sendAboutDetails(tabId, messages.NEWTAB_DATA_UPDATED, {
350351
showEmptyPage,
351352
showImages,
352353
trackedBlockersCount,
353354
adblockCount,
354355
httpsUpgradedCount,
356+
torEnabled,
355357
newTabDetail: newTabDetail.toJS()
356358
})
357359
} else if (location === 'about:autofill') {
@@ -522,7 +524,7 @@ const api = {
522524
if (ses) {
523525
isPrivate = ses.isOffTheRecord()
524526
}
525-
const isTor = isPrivate && settingsStore.getSetting(settings.USE_TOR_PRIVATE_TABS)
527+
const isTor = newTab.session.partition === appConfig.tor.partition
526528

527529
const frameOpts = {
528530
location,

app/browser/windows.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ function openFramesInWindow (win, frames, activeFrameKey) {
211211
let frameIndex = -1
212212
for (const frame of frames) {
213213
frameIndex++
214+
const tab = webContentsCache.getWebContents(frame.tabId)
214215
if (frame.tabId != null && frame.guestInstanceId != null) {
215216
if (shouldDebugTabEvents) {
216217
console.log('notifyWindowWebContentsAdded: on window create with existing tab', win.id)
217218
}
218219
api.notifyWindowWebContentsAdded(win.id, frame)
219-
const tab = webContentsCache.getWebContents(frame.tabId)
220220
if (tab && !tab.isDestroyed()) {
221221
tab.moveTo(frameIndex, win.id)
222222
}
@@ -226,7 +226,7 @@ function openFramesInWindow (win, frames, activeFrameKey) {
226226
url: frame.location || frame.src || frame.provisionalLocation || frame.url,
227227
partitionNumber: frame.partitionNumber,
228228
isPrivate: frame.isPrivate,
229-
isTor: frame.isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS),
229+
isTor: tab && tab.session && tab.session.partition === appConfig.tor.partition,
230230
active: activeFrameKey ? frame.key === activeFrameKey : true,
231231
discarded: frame.unloaded,
232232
title: frame.title,

app/common/commonMenu.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,23 @@ module.exports.newPrivateTabMenuItem = () => {
7777
label: locale.translation('newPrivateTab'),
7878
accelerator: 'Shift+CmdOrCtrl+P',
7979
click: function (item, focusedWindow) {
80-
// Check if Tor is available
81-
const useTor = getSetting(settings.USE_TOR_PRIVATE_TABS)
82-
if (useTor) {
83-
ensureAtLeastOneWindow({
84-
url: 'about:newtab',
85-
isPrivate: true,
86-
isTor: true
87-
})
88-
} else {
89-
ensureAtLeastOneWindow({
90-
url: 'about:newtab',
91-
isPrivate: true
92-
})
93-
}
80+
ensureAtLeastOneWindow({
81+
url: 'about:newtab',
82+
isPrivate: true
83+
})
84+
}
85+
}
86+
}
87+
88+
module.exports.newTorTabMenuItem = () => {
89+
return {
90+
label: locale.translation('newTorTab'),
91+
click: function (item, focusedWindow) {
92+
ensureAtLeastOneWindow({
93+
url: 'about:newtab',
94+
isPrivate: true,
95+
isTor: true
96+
})
9497
}
9598
}
9699
}

app/extensions/brave/locales/en-US/menu.properties

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ muteTab=Mute Tab
9999
muteTabs=Mute Tabs
100100
new=New
101101
newPrivateTab=New Private Tab
102+
newTorTab=New Private Tab with Tor
102103
newSessionTab=New Session Tab
103104
newTab=New Tab
104105
newWindow=New Window
@@ -108,6 +109,8 @@ openFlashPreferences=Enable Flash in Preferences…
108109
openImageInNewTab=Open Image in New Tab
109110
openInNewPrivateTab=Open Link in New Private Tab
110111
openInNewPrivateTabs=Open Links in New Private Tabs
112+
openInNewTorTab=Open Link in New Private Tab with Tor
113+
openInNewTorTabs=Open Links in New Private Tabs with Tor
111114
openInNewSessionTab=Open Link in New Session Tab
112115
openInNewSessionTabs=Open Links in New Session Tabs
113116
openInNewTab=Open Link in New Tab

app/locale.js

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ var rendererIdentifiers = function () {
4646
'openInNewSessionTabs',
4747
'openInNewPrivateTab',
4848
'openInNewPrivateTabs',
49+
'openInNewTorTab',
50+
'openInNewTorTabs',
4951
'openInNewTab',
5052
'openInNewTabs',
5153
'openAllInTabs',
@@ -153,6 +155,7 @@ var rendererIdentifiers = function () {
153155
'hideOthers',
154156
'showAll',
155157
'newPrivateTab',
158+
'newTorTab',
156159
'newSessionTab',
157160
'newWindow',
158161
'reopenLastClosedTab',

app/renderer/components/main/siteInfo.js

-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ const urlUtil = require('../../../../js/lib/urlutil')
3030
const globalStyles = require('../styles/global')
3131
const commonStyles = require('../styles/commonStyles')
3232

33-
// Constants
34-
const settings = require('../../../../js/constants/settings')
35-
3633
class SiteInfo extends React.Component {
3734
constructor (props) {
3835
super(props)
@@ -66,7 +63,6 @@ class SiteInfo extends React.Component {
6663
}
6764

6865
onDisableTor () {
69-
appActions.changeSetting(settings.USE_TOR_PRIVATE_TABS, false)
7066
appActions.recreateTorTab(false, this.props.activeTabId,
7167
this.props.activeTabIndex)
7268
}

app/renderer/reducers/contextMenuReducer.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,15 @@ const onTabPageMenu = function (state, action) {
109109
tabPageMenu.popup(getCurrentWindow())
110110
}
111111

112-
const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => {
112+
const openInNewTabMenuItem = (url, partitionNumber, openerTabId) => {
113113
const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true
114-
const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS)
115114
if (Array.isArray(url) && Array.isArray(partitionNumber)) {
116115
return {
117116
label: locale.translation('openInNewTabs'),
118117
click: () => {
119118
for (let i = 0; i < url.length; ++i) {
120119
appActions.createTabRequested({
121120
url: url[i],
122-
isPrivate,
123-
isTor,
124121
partitionNumber: partitionNumber[i],
125122
openerTabId,
126123
active
@@ -134,8 +131,6 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => {
134131
click: () => {
135132
appActions.createTabRequested({
136133
url,
137-
isPrivate,
138-
isTor,
139134
partitionNumber,
140135
openerTabId,
141136
active
@@ -145,12 +140,11 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => {
145140
}
146141
}
147142

148-
const openInNewPrivateTabMenuItem = (url, openerTabId) => {
143+
const openInNewPrivateTabMenuItem = (url, openerTabId, isTor) => {
149144
const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true
150-
const isTor = getSetting(settings.USE_TOR_PRIVATE_TABS)
151145
if (Array.isArray(url)) {
152146
return {
153-
label: locale.translation('openInNewPrivateTabs'),
147+
label: locale.translation(isTor ? 'openInNewTorTabs' : 'openInNewPrivateTabs'),
154148
click: () => {
155149
for (let i = 0; i < url.length; ++i) {
156150
appActions.createTabRequested({
@@ -165,7 +159,7 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => {
165159
}
166160
} else {
167161
return {
168-
label: locale.translation('openInNewPrivateTab'),
162+
label: locale.translation(isTor ? 'openInNewTorTab' : 'openInNewPrivateTab'),
169163
click: () => {
170164
appActions.createTabRequested({
171165
url,
@@ -210,12 +204,11 @@ const openInNewSessionTabMenuItem = (url, openerTabId) => {
210204
}
211205
}
212206

213-
const openInNewWindowMenuItem = (location, isPrivate, partitionNumber) => {
214-
const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS)
207+
const openInNewWindowMenuItem = (location, partitionNumber) => {
215208
return {
216209
label: locale.translation('openInNewWindow'),
217210
click: () => {
218-
appActions.newWindow({ location, isPrivate, isTor, partitionNumber })
211+
appActions.newWindow({ location, partitionNumber })
219212
}
220213
}
221214
}
@@ -321,9 +314,10 @@ const siteDetailTemplateInit = (state, siteKey, type) => {
321314
const location = siteDetail.get('location')
322315

323316
template.push(
324-
openInNewTabMenuItem(location, undefined, siteDetail.get('partitionNumber')),
317+
openInNewTabMenuItem(location, siteDetail.get('partitionNumber')),
325318
openInNewPrivateTabMenuItem(location),
326-
openInNewWindowMenuItem(location, undefined, siteDetail.get('partitionNumber')),
319+
openInNewPrivateTabMenuItem(location, undefined, true),
320+
openInNewWindowMenuItem(location, siteDetail.get('partitionNumber')),
327321
openInNewSessionTabMenuItem(location),
328322
copyAddressMenuItem('copyLinkAddress', location),
329323
CommonMenu.separatorMenuItem

app/renderer/rendererShortcutHandler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function handleShortcut (frameKey, shortcut, e, args) {
120120
appActions.createTabRequested({
121121
url: sourceLocation,
122122
isPrivate,
123-
isTor: isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS),
123+
isTor: frameStateUtil.isTor(frame),
124124
partitionNumber: frame.get('partitionNumber'),
125125
openerTabId: tabId,
126126
active: true

docs/state.md

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ AppStore
3434
pinnedTopSites: [string], // list of pinned sites to be used on gridLayout. Defaults to 1 Brave-related site; see data/newTabData.js => pinnedTopSites
3535
sites: [string], // list of sites to be used on gridLayout. Defaults to 6 Brave-related sites; see data/newTabData.js => topSites
3636
updatedStamp: number, // timestamp for when the data was last updated
37-
torEnabled: boolean, // whether Tor private tabs is enabled
3837
},
3938
preferences: {
4039
backupNotifyCount: number, // number of times user has been reminded to backup wallet

js/about/newprivatetab.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ const aboutActions = require('./aboutActions')
1919
require('../../less/about/newtab.less')
2020

2121
const useAlternativePrivateSearchEngineDataKeys = ['newTabDetail', 'useAlternativePrivateSearchEngine']
22-
const torEnabled = ['newTabDetail', 'torEnabled']
2322
const torFAQ = 'https://github.com/brave/browser-laptop/wiki/Using-Tor-in-Brave#faq'
2423

2524
const onChangeTor = (value) => {
26-
aboutActions.changeSetting(settings.USE_TOR_PRIVATE_TABS, value)
27-
if (value === true) {
28-
// Also change DDG to enabled since Google is unusable with Tor.
29-
aboutActions.changeSetting(settings.USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE, value)
30-
}
3125
aboutActions.recreateTorTab(value)
3226
}
3327

@@ -46,15 +40,15 @@ class NewPrivateTab extends React.Component {
4640
}
4741

4842
onClickTorTitle () {
49-
const newSettingValue = !this.props.newTabData.getIn(torEnabled)
43+
const newSettingValue = !this.props.torEnabled
5044
onChangeTor(newSettingValue)
5145
}
5246

5347
render () {
5448
if (!this.props.newTabData) {
5549
return null
5650
}
57-
const isTor = Boolean(this.props.newTabData.getIn(torEnabled))
51+
const isTor = Boolean(this.props.torEnabled)
5852
return <div data-test-id='privateTabContent' className={css(styles.newPrivateTab, styles.newPrivateTabVars)}>
5953
<div className='statsBar'>
6054
<Stats newTabData={this.props.newTabData} />

js/about/newtab.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class NewTabPage extends React.Component {
4848
updatedStamp: undefined,
4949
showEmptyPage: true,
5050
showImages: false,
51+
torEnabled: false,
5152
backgroundImage: undefined
5253
}
5354

@@ -68,6 +69,7 @@ class NewTabPage extends React.Component {
6869
newTabData: data,
6970
updatedStamp,
7071
showEmptyPage,
72+
torEnabled: data.get('torEnabled'),
7173
showImages: !!data.get('showImages') && !showEmptyPage,
7274
backgroundImage: showImages
7375
? this.state.backgroundImage || this.randomBackgroundImage
@@ -263,7 +265,7 @@ class NewTabPage extends React.Component {
263265

264266
// TODO: use this.props.isIncognito when muon supports it for tor tabs
265267
if (this.props.isIncognito) {
266-
return <NewPrivateTab newTabData={this.state.newTabData} />
268+
return <NewPrivateTab newTabData={this.state.newTabData} torEnabled={this.state.torEnabled} />
267269
}
268270

269271
// don't render until object is found

js/constants/appConfig.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module.exports = {
151151
'general.spellcheck-languages': Immutable.fromJS(['en-US']),
152152
'search.default-search-engine': 'Google',
153153
'search.offer-search-suggestions': false, // false by default for privacy reasons
154-
'search.use-alternate-private-search-engine': false,
154+
'search.use-alternate-private-search-engine': true,
155155
'tabs.switch-to-new-tabs': false,
156156
'tabs.paint-tabs': true,
157157
'tabs.tabs-per-page': 20,
@@ -174,7 +174,6 @@ module.exports = {
174174
'security.autoplay.media': autoplayOption.ALWAYS_ALLOW,
175175
'security.flash.installed': false,
176176
'security.site-isolation-enabled': false,
177-
'tor.private-tabs.enabled': false,
178177
'shields.blocked-count-badge': true,
179178
'shields.compact-bravery-panel': false,
180179
// sync

js/constants/settings.js

-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ const settings = {
102102
// Debug settings
103103
DEBUG_ALLOW_MANUAL_TAB_DISCARD: 'debug.manual-tab-discard.enabled',
104104
DEBUG_VERBOSE_TAB_INFO: 'debug.verbose-tab-info.enabled',
105-
// Tor settings
106-
USE_TOR_PRIVATE_TABS: 'tor.private-tabs.enabled',
107105

108106
// DEPRECATED settings
109107
// DO NOT REMOVE OR CHANGE THESE VALUES

0 commit comments

Comments
 (0)