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

WIP show UI indicator on Tor tabs #14206

Closed
wants to merge 19 commits into from
Closed
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
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 = 6.0.11
brave_electron_version = 6.1.5
chromedriver_version = 2.36
target = v6.0.11
target = v6.1.5
disturl=https://brave-laptop-binaries.s3.amazonaws.com/atom-shell/dist/
build_from_source = true
5 changes: 4 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 Down Expand Up @@ -845,7 +846,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')
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
18 changes: 17 additions & 1 deletion app/browser/reducers/aboutNewTabReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ 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
useAlternativePrivateSearchEngine,
torEnabled
}
})
break
Expand All @@ -36,6 +38,20 @@ const aboutNewTabReducer = (state, action) => {
useAlternativePrivateSearchEngine: action.value
}
})
} else if (action.key === settings.USE_TOR_PRIVATE_TABS) {
state = aboutNewTabState.mergeDetails(state, {
newTabPageDetail: {
torEnabled: action.value
}
})
if (action.value === true) {
// Also enable DDG
state = aboutNewTabState.mergeDetails(state, {
newTabPageDetail: {
useAlternativePrivateSearchEngine: action.value
}
})
}
}
}
return state
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 @@ -248,6 +252,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
27 changes: 26 additions & 1 deletion app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 {getOrigin} = require('../../js/lib/urlutil')
Expand Down Expand Up @@ -38,6 +38,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 +103,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 +118,7 @@ const getPartition = (createProperties) => {

const needsPartitionAssigned = (createProperties) => {
return !createProperties.openerTabId ||
createProperties.isTor ||
createProperties.isPrivate ||
createProperties.isPartitioned ||
createProperties.partitionNumber ||
Expand Down Expand Up @@ -508,6 +513,13 @@ const api = {
index = newTabValue.get('index')
}

const ses = session.fromPartition(newTab.session.partition)
let isPrivate
if (ses) {
isPrivate = ses.isOffTheRecord()
}
const isTor = isPrivate && settingsStore.getSetting(settings.USE_TOR_PRIVATE_TABS)

const frameOpts = {
location,
displayURL,
Expand All @@ -516,6 +528,8 @@ const api = {
active: !!newTabValue.get('active'),
guestInstanceId: newTab.guestInstanceId,
isPinned: !!newTabValue.get('pinned'),
isPrivate,
isTor,
openerTabId,
disposition,
index,
Expand Down Expand Up @@ -1030,6 +1044,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 Down
1 change: 1 addition & 0 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS),
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}`
}
20 changes: 15 additions & 5 deletions 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 @@ -77,10 +77,20 @@ module.exports.newPrivateTabMenuItem = () => {
label: locale.translation('newPrivateTab'),
accelerator: 'Shift+CmdOrCtrl+P',
click: function (item, focusedWindow) {
ensureAtLeastOneWindow({
url: 'about:newtab',
isPrivate: true
})
// 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
})
}
}
}
}
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
18 changes: 17 additions & 1 deletion app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ let generateBraveManifest = () => {
'content/scripts/themeColor.js'
]
},
{
run_at: 'document_end',
all_frames: false,
matches: ['<all_urls>'],
include_globs: [
'http://*/*', 'https://*/*'
],
exclude_globs: [
indexHTML,
getBraveExtUrl('about-*.html'),
getBraveExtUrl('about-*.html') + '#*'
],
js: [
'content/scripts/favicon.js'
]
},
{
run_at: 'document_start',
js: [
Expand Down Expand Up @@ -273,7 +289,7 @@ let generateTorrentManifest = () => {
48: 'img/webtorrent-48.png',
16: 'img/webtorrent-16.png'
},
incognito: 'split',
incognito: 'not_allowed',
key: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyWl+wMvL0wZX3JUs7GeZAvxMP+LWEh2bwMV1HyuBra/lGZIq3Fmh0+AFnvFPXz1NpQkbLS3QWyqhdIn/lepGwuc2ma0glPzzmieqwctUurMGSGManApGO1MkcbSPhb+R1mx8tMam5+wbme4WoW37PI3oATgOs2NvHYuP60qol3U7b/zB3IWuqtwtqKe2Q1xY17btvPuz148ygWWIHneedt0jwfr6Zp+CSLARB9Heq/jqGXV4dPSVZ5ebBHLQ452iZkHxS6fm4Z+IxjKdYs3HNj/s8xbfEZ2ydnArGdJ0lpSK9jkDGYyUBugq5Qp3FH6zV89WqBvoV1dqUmL9gxbHsQIDAQAB'
}
}
Expand Down
1 change: 1 addition & 0 deletions app/extensions/brave/about-newtab.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="ext/l20n.min.js"></script>
<script src="gen/aboutPages.entry.js" async></script>
<link rel="localization" href="locales/{locale}/newtab.properties">
<link rel="localization" href="locales/{locale}/preferences.properties">
</head>
<body>
<div id="appContainer"/>
Expand Down
27 changes: 27 additions & 0 deletions app/extensions/brave/content/scripts/favicon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const getBase64FromImageUrl = (url) => {
return new Promise((resolve, reject) => {
const img = new window.Image()
img.onerror = function () {
reject(new Error('unable to load image'))
}
img.onload = function () {
const canvas = document.createElement('canvas')
canvas.width = this.naturalWidth
canvas.height = this.naturalHeight
canvas.getContext('2d')
.drawImage(this, 0, 0)
resolve(canvas.toDataURL('image/png'))
}
img.src = url
})
}

let faviconUrl = window.location.origin + '/favicon.ico'
const faviconNode = document.head.querySelector("link[rel='icon']") || document.head.querySelector("link[rel='shortcut icon']")
if (faviconNode) {
faviconUrl = faviconNode.getAttribute('href') || faviconUrl
}

getBase64FromImageUrl(faviconUrl).then((data) => {
chrome.ipcRenderer.sendToHost('got-page-favicon', data)
})
Loading