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

Commit

Permalink
Merge pull request #14143 from brave/tor/0.23.x
Browse files Browse the repository at this point in the history
tor frontend changes for 0.23.x
  • Loading branch information
bsclifton authored Jun 28, 2018
2 parents 78b8e96 + 2dbd90b commit 78b6a53
Show file tree
Hide file tree
Showing 81 changed files with 7,273 additions and 4,031 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ app/extensions/brave/content/scripts/sync.js

# script used for signing for widevine
signature_generator.py

# binaries
app/extensions/bin
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
runtime = electron
target_arch = x64
brave_electron_version = 7.0.6
brave_electron_version = 7.1.3
chromedriver_version = 2.37
target = v7.0.6
target = v7.1.3
disturl=https://brave-laptop-binaries.s3.amazonaws.com/atom-shell/dist/
build_from_source = true
6 changes: 5 additions & 1 deletion app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const format = require('date-fns/format')
const Immutable = require('immutable')
const electron = require('electron')
const ipc = electron.ipcMain
const session = electron.session
const path = require('path')
const os = require('os')
const qr = require('qr-image')
Expand All @@ -32,6 +33,7 @@ const updateState = require('../../common/state/updateState')
// Constants
const settings = require('../../../js/constants/settings')
const messages = require('../../../js/constants/messages')
const appConfig = require('../../../js/constants/appConfig')
const ledgerStatuses = require('../../common/constants/ledgerStatuses')

// Utils
Expand Down Expand Up @@ -863,7 +865,9 @@ const shouldTrackTab = (state, tabId) => {
if (tabFromState == null) {
tabFromState = pageDataState.getLastClosedTab(state, tabId)
}
const isPrivate = !tabFromState.get('partition', '').startsWith('persist:') || tabFromState.get('incognito')
const partition = tabFromState.get('partition', '')
const ses = session.fromPartition(partition)
const isPrivate = (ses && ses.isOffTheRecord()) || tabFromState.get('incognito') || partition === appConfig.tor.partition
return !isPrivate && !tabFromState.isEmpty() && ledgerUtil.shouldTrackView(tabFromState)
}

Expand Down
10 changes: 9 additions & 1 deletion app/browser/contentSettings/hostContentSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const { makeImmutable } = require('../../common/state/immutableUtil')
const appConfig = require('../../../js/constants/appConfig')

let registeredCallbacks = []
let registeredSessions = {}
let registeredPrivateSessions = {}
const blockContentSetting = { setting: 'block', primaryPattern: '*' }

module.exports.setContentSettings = (contentSettings, incognito) => {
contentSettings = makeImmutable(contentSettings)

const partitions = incognito ? registeredPrivateSessions : registeredSessions
for (let partition in partitions) {
let newContentSettings = contentSettings
if (partition === appConfig.tor.partition) {
// Do not allow plugins to be enabled in Tor contexts
newContentSettings = contentSettings.set('plugins', makeImmutable([blockContentSetting]))
}

const ses = partitions[partition]

contentSettings.forEach((settings, contentType) => {
newContentSettings.forEach((settings, contentType) => {
ses.contentSettings.clearForOneType(contentType)
settings.forEach((setting) => {
module.exports.setContentSetting(ses, setting.get('primaryPattern'), setting.get('secondaryPattern'),
Expand Down
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
21 changes: 20 additions & 1 deletion app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const tabState = require('../../common/state/tabState')
const windowState = require('../../common/state/windowState')
const siteSettings = require('../../../js/state/siteSettings')
const siteSettingsState = require('../../common/state/siteSettingsState')
const {frameOptsFromFrame} = require('../../../js/state/frameStateUtil')
const {frameOptsFromFrame, isTor} = require('../../../js/state/frameStateUtil')
const updateState = require('../../common/state/updateState')

// Constants
Expand Down Expand Up @@ -51,6 +51,10 @@ const getWebRTCPolicy = (state, tabId) => {
return webrtcConstants.default
}

if (isTor(tabValue)) {
return webrtcConstants.disableNonProxiedUdp
}

const allSiteSettings = siteSettingsState.getAllSiteSettings(state, tabValue.get('incognito') === true)
const tabSiteSettings =
siteSettings.getSiteSettingsForURL(allSiteSettings, tabValue.get('url'))
Expand Down Expand Up @@ -254,6 +258,21 @@ const tabsReducer = (state, action, immutableAction) => {
}
})
break
case appConstants.APP_RECREATE_TOR_TAB:
{
const tabId = action.get('tabId')
tabs.create({
url: 'about:newtab',
isPrivate: true,
windowId: tabState.getWindowId(state, tabId),
index: action.get('index'),
active: true,
isTor: action.get('torEnabled')
}, (tab) => {
appActions.tabCloseRequested(tabId)
})
break
}
case appConstants.APP_TAB_UPDATED:
state = tabState.maybeCreateTab(state, action)
// tabs.debugTabs(state)
Expand Down
31 changes: 31 additions & 0 deletions app/browser/reducers/torReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict'

const filtering = require('../../filtering')
const appConstants = require('../../../js/constants/appConstants')

const torReducer = (state, action) => {
switch (action.actionType) {
case appConstants.APP_RESTART_TOR:
filtering.relaunchTor()
break
case appConstants.APP_SET_TOR_NEW_IDENTITY:
filtering.setTorNewIdentity(action.url, action.tabId)
break
case appConstants.APP_ON_TOR_INIT_ERROR:
state = state.setIn(['tor', 'initializationError'], action.message)
break
case appConstants.APP_ON_TOR_INIT_SUCCESS:
state = state.setIn(['tor', 'initializationError'], false).setIn(['tor', 'percentInitialized'], null)
break
case appConstants.APP_ON_TOR_INIT_PERCENTAGE:
state = state.setIn(['tor', 'percentInitialized'], action.percentage)
break
}
return state
}

module.exports = torReducer
38 changes: 36 additions & 2 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ const { shouldDebugTabEvents } = require('../cmdLine')
const tabState = require('../common/state/tabState')
const {app, extensions, session, ipcMain} = require('electron')
const {makeImmutable, makeJS} = require('../common/state/immutableUtil')
const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl, isIntermediateAboutPage, isTargetMagnetUrl, getSourceMagnetUrl} = require('../../js/lib/appUrlUtil')
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')
const {getBaseUrl} = require('../../js/lib/appUrlUtil')
const siteSettings = require('../../js/state/siteSettings')
const messages = require('../../js/constants/messages')
const webrtcConstants = require('../../js/constants/webrtcConstants')
const debounce = require('../../js/lib/debounce')
const aboutHistoryState = require('../common/state/aboutHistoryState')
const aboutNewTabState = require('../common/state/aboutNewTabState')
Expand All @@ -38,6 +39,8 @@ const bookmarkOrderCache = require('../common/cache/bookmarkOrderCache')
const ledgerState = require('../common/state/ledgerState')
const {getWindow, notifyWindowWebContentsAdded} = require('./windows')
const activeTabHistory = require('./activeTabHistory')
const path = require('path')
const {getTorSocksProxy} = require('../channel')

let adBlockRegions
let currentPartitionNumber = 0
Expand Down Expand Up @@ -101,6 +104,8 @@ const getPartition = (createProperties) => {
let partition = session.defaultSession.partition
if (createProperties.partition) {
partition = createProperties.partition
} else if (createProperties.isTor) {
partition = appConfig.tor.partition
} else if (createProperties.isPrivate) {
partition = 'default'
} else if (createProperties.isPartitioned) {
Expand All @@ -114,6 +119,7 @@ const getPartition = (createProperties) => {

const needsPartitionAssigned = (createProperties) => {
return !createProperties.openerTabId ||
createProperties.isTor ||
createProperties.isPrivate ||
createProperties.isPartitioned ||
createProperties.partitionNumber ||
Expand Down Expand Up @@ -340,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 @@ -511,6 +519,13 @@ const api = {
index = newTabValue.get('index')
}

const ses = session.fromPartition(newTab.session.partition)
let isPrivate
if (ses) {
isPrivate = ses.isOffTheRecord()
}
const isTor = newTab.session.partition === appConfig.tor.partition

const frameOpts = {
location,
displayURL,
Expand All @@ -519,6 +534,8 @@ const api = {
active: !!newTabValue.get('active'),
guestInstanceId: newTab.guestInstanceId,
isPinned: !!newTabValue.get('pinned'),
isPrivate,
isTor,
openerTabId,
disposition,
index,
Expand Down Expand Up @@ -1048,6 +1065,17 @@ const api = {
if (isSessionPartition(createProperties.partition)) {
createProperties.parent_partition = ''
}
if (createProperties.isTor) {
// TODO(riastradh): Duplicate logic in app/filtering.js.
createProperties.isolated_storage = true
createProperties.parent_partition = ''
createProperties.tor_proxy = getTorSocksProxy()
if (process.platform === 'win32') {
createProperties.tor_path = path.join(getExtensionsPath('bin'), 'tor.exe')
} else {
createProperties.tor_path = path.join(getExtensionsPath('bin'), 'tor')
}
}
}

// Tabs are allowed to be initially discarded (unloaded) if they are regular tabs
Expand All @@ -1068,6 +1096,12 @@ const api = {
console.log('Creating tab with properties: ', createProperties)
}
extensions.createTab(createProperties, (tab) => {
if (tab) {
// Initialize WebRTC IP handling to the safest default. This will
// be set based on shield settings in reducers/tabReducer.js once
// navigation starts.
tab.setWebRTCIPHandlingPolicy(webrtcConstants.disableNonProxiedUdp)
}
cb && cb(tab)
})
}
Expand Down
2 changes: 2 additions & 0 deletions app/browser/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,7 @@ function getHeader (headers, headerName) {

module.exports = {
init,
isTorrentFile,
isMagnetURL,
resourceName: 'webtorrent'
}
3 changes: 2 additions & 1 deletion 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,6 +226,7 @@ function openFramesInWindow (win, frames, activeFrameKey) {
url: frame.location || frame.src || frame.provisionalLocation || frame.url,
partitionNumber: frame.partitionNumber,
isPrivate: frame.isPrivate,
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: 31 additions & 0 deletions app/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,34 @@ exports.getLinuxDesktopName = () => {
}
return desktopName
}

// getTorSocksProxy()
//
// Return the socks5:// `URL' for the Tor socks proxy we will
// configure the tor daemon to listen on and muon to connect to,
// depending on which channel we're using. This is provisional
// until we let the OS choose the port number as in
// <https://github.com/brave/browser-laptop/issues/12936>, or
// until we add support for local sockets for SOCKS proxies as in
// <https://github.com/brave/muon/issues/469>.
//
exports.getTorSocksProxy = () => {
let portno
switch (channel) {
case 'dev':
case '':
default:
portno = 9250
break
case 'beta':
portno = 9260
break
case 'nightly':
portno = 9270
break
case 'developer':
portno = 9280
break
}
return `socks5://127.0.0.1:${portno}`
}
15 changes: 14 additions & 1 deletion app/common/commonMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const messages = require('../../js/constants/messages')
const locale = require('../../js/l10n')
const settings = require('../../js/constants/settings')
const {tabs} = require('../../js/constants/config')
const getSetting = require('../../js/settings').getSetting
const {getSetting} = require('../../js/settings')
const communityURL = 'https://community.brave.com/'
const isDarwin = process.platform === 'darwin'
const electron = require('electron')
Expand Down Expand Up @@ -85,6 +85,19 @@ module.exports.newPrivateTabMenuItem = () => {
}
}

module.exports.newTorTabMenuItem = () => {
return {
label: locale.translation('newTorTab'),
click: function (item, focusedWindow) {
ensureAtLeastOneWindow({
url: 'about:newtab',
isPrivate: true,
isTor: true
})
}
}
}

module.exports.newPartitionedTabMenuItem = () => {
const newPartitionedMenuItem = (partitionNumber) => ({
label: `${locale.translation('newSessionTab')} ${partitionNumber}`,
Expand Down
12 changes: 10 additions & 2 deletions app/common/lib/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const sigmoid = (t) => {

const ONE_DAY = 1000 * 60 * 60 * 24

const searchSuggestionsEnabled = (state, tabId) => {
const frame = getFrameByTabId(state, tabId)
if (!frame || frame.get('isPrivate')) {
return false
}
return getSetting(settings.OFFER_SEARCH_SUGGESTIONS)
}

/*
* Calculate the sorting priority for a history item based on number of
* accesses and time since last access
Expand Down Expand Up @@ -564,7 +572,7 @@ const getSearchSuggestions = (state, tabId, urlLocationLower) => {
return new Promise((resolve, reject) => {
const mapListToElements = getMapListToElements(urlLocationLower)
let suggestionsList = Immutable.List()
if (getSetting(settings.OFFER_SEARCH_SUGGESTIONS)) {
if (searchSuggestionsEnabled(state, tabId)) {
const searchResults = state.get('searchResults')
const sortHandler = getSortForSearchSuggestions(urlLocationLower)
if (searchResults) {
Expand Down Expand Up @@ -630,7 +638,7 @@ const generateNewSearchXHRResults = debounce((state, windowId, tabId, input) =>
? frameSearchDetail.get('autocomplete')
: searchDetail.get('autocompleteURL')

const shouldDoSearchSuggestions = getSetting(settings.OFFER_SEARCH_SUGGESTIONS) &&
const shouldDoSearchSuggestions = searchSuggestionsEnabled(state, tabId) &&
autocompleteURL &&
!isUrl(input) &&
input.length !== 0
Expand Down
Loading

0 comments on commit 78b6a53

Please sign in to comment.