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

add tor menu items, make tor switch per tab #14467

Merged
merged 4 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: frame.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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not result in a tor tab when there are 0 windows open, which is a common macOS scenario (as judging from the number of issues that were raised when I had a similar bug!).

In order to fix this we simply need to make the openFramesInWindow function inside app/browser/windows.js aware of the tor: property for the createTabRequested options argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch thanks!

})
}
}
}
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
4 changes: 3 additions & 1 deletion app/extensions/brave/locales/en-US/newtab.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ preferencesPage.title=Go to Preferences page
privateTabsMore=More about private tabs
privateTabText1=Whether or not you use Tor, private tabs are not logged in page history or counted in Brave Payments calculations. Private tabs and their cookies always vanish when the browser is closed. If you use private tabs without Tor, the sites you visit will be visible to your ISP or your employer. You won’t be anonymous, and sites will learn your public IP address. With Tor, Brave works hard to ensure that you’re extremely difficult to track online while providing a delightful browsing experience. But if your personal safety depends on remaining anonymous you may wish to use the Tor Browser from https://torproject.org/ instead.
privateTabTitle=This is a Private Tab
privateTabTorTitle=Make private tabs much more private with
privateTabTorTitle=Make this tab much more private with
privateTabTorText1=Tor hides your IP address from the sites you visit, and hides the sites you visit from your ISP or your employer. Tor can slow down browsing. Some sites treat anonymous users differently, or might not work at all. Some sites might even ask you to prove you’re human.
privateTabTorText2=By default, DuckDuckGo is the search engine for Private Tabs with Tor.
searchPreferences=Search Preferences...
privateTabSearchSectionTitle=Private search with
privateTabSearchText1=With private search, Brave will use DuckDuckGo to answer your searches while you are in this private tab. DuckDuckGo is a search engine that does not track your search history, enabling you to search privately.
removeBookmarkButton.title=Remove bookmark
Expand Down
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ showHomeButton=Show home button on URL bar
showLess=Show Less
privateTabsSearchSettingsTitle=Private Tabs
useDuckDuckGoForPrivateSearch=Use DuckDuckGo by default for search in Private Tabs
useDuckDuckGoForPrivateSearchTor=Use DuckDuckGo by default for search in Private Tabs with Tor
showOpenedTabMatches=Show tab matches
showTabPreviews=Show tab previews on hover
showTopsiteSuggestions=Show top site suggestions
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
5 changes: 3 additions & 2 deletions app/renderer/reducers/urlBarReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const windowConstants = require('../../../js/constants/windowConstants')
const appConstants = require('../../../js/constants/appConstants')
const {isURL} = require('../../../js/lib/urlutil')
const {activeFrameStatePath, frameStatePath, getFrameByTabId} = require('../../../js/state/frameStateUtil')
const {activeFrameStatePath, frameStatePath, getFrameByTabId, isTor} = require('../../../js/state/frameStateUtil')
const searchProviders = require('../../../js/data/searchProviders')
const Immutable = require('immutable')
const {navigateSiteClickHandler} = require('../suggestionClickHandlers')
Expand Down Expand Up @@ -42,7 +42,8 @@ const updateSearchEngineInfoFromInput = (state, frameProps) => {
}
if (frameProps.get('isPrivate')) {
// handle private tab search with default search provider
const useAlternateDefaultPrivateSearchProvider = getSetting(settings.USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE)
const useAlternateDefaultPrivateSearchProvider =
getSetting(isTor(frameProps) ? settings.USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE_TOR : settings.USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE)
if (useAlternateDefaultPrivateSearchProvider === true) {
// DuckDuckGo hard-coded as Private Tab default provider
// if asked to use a privacy-centric 'alternative'
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
Loading