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

Commit

Permalink
UI and misc front-end changes for tor
Browse files Browse the repository at this point in the history
Disable search suggestions in private mode for Tor
Fix #13064

set ddg as default search engine in tor private tabs
fix #13212

Disable webtorrent in tor private mode
fix #13063

load favicons in Tor tabs as data: URLs
fix #13065

Omit unlocked icon for HTTP onion sites
Fix #12990
also fix unittests
Test Plan:
1. go to http://3expgpdnrrzezf7r.onion/ in a private tab
2. no icon should be in the urlbar
3. go to https://3g2upl4pq6kufc4m.onion/
4. you should see a lock icon
  • Loading branch information
diracdeltas committed Mar 27, 2018
1 parent 19af8f3 commit 7ddf69e
Show file tree
Hide file tree
Showing 19 changed files with 2,529 additions and 196 deletions.
2 changes: 1 addition & 1 deletion app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const getPartition = (createProperties) => {
if (createProperties.partition) {
partition = createProperties.partition
} else if (createProperties.isTor) {
partition = 'persist:tor'
partition = appConfig.tor.partition
} else if (createProperties.isPrivate) {
partition = 'default'
} else if (createProperties.isPartitioned) {
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 @@ -120,6 +120,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 @@ -265,7 +281,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
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)
})
2 changes: 0 additions & 2 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ submit=Submit
tabsSuggestionTitle=Tabs
topSiteSuggestionTitle=Top Site
turnOffNotifications=Turn off notifications
torCheckFailure=Could not find Tor on your computer. To use Brave with Tor, make sure Tor is installed and running as a SOCKS5 proxy on port 9050.
torCheckError=Could not connect to check.torproject.org. Please try again later.
unknownError=Oops, something went wrong.
unmuteTab=Unmute tab
unselectAll=Unselect all
Expand Down
4 changes: 2 additions & 2 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ function registerForMagnetHandler (session) {
}

module.exports.setTorNewIdentity = (url, tabId) => {
const ses = session.fromPartition('persist:tor')
const ses = session.fromPartition(appConfig.tor.partition)
if (!ses || !url) {
return
}
Expand All @@ -661,7 +661,7 @@ function initSession (ses, partition) {
}

const initPartition = (partition) => {
const isTorPartition = partition === 'persist:tor'
const isTorPartition = partition === appConfig.tor.partition
// Partitions can only be initialized once the app is ready
if (!app.isReady()) {
partitionsToInitialize.push(partition)
Expand Down
5 changes: 3 additions & 2 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ var rendererIdentifiers = function () {
'showAll',
'newPrivateTab',
'newSessionTab',
'newTorIdentity',
'newWindow',
'reopenLastClosedTab',
'print',
Expand Down Expand Up @@ -287,8 +286,10 @@ var rendererIdentifiers = function () {
'corruptedOverlayMessage',
'corruptedOverlayText',
// Tor
'newTorIdentity',
'torCheckError',
'torCheckFailure'
'torCheckFailure',
'promotionClaimedErrorTitle'
].concat(countryCodes).concat(availableLanguages)
}

Expand Down
11 changes: 11 additions & 0 deletions app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ class Frame extends React.Component {
if (this.frame.isEmpty()) {
return
}
if (frameStateUtil.isTor(this.frame)) {
// This will be set as a data: URL by the page content script
return
}
if (e.favicons &&
e.favicons.length > 0 &&
// Favicon changes lead to recalculation of top site data so only fire
Expand Down Expand Up @@ -583,6 +587,13 @@ class Frame extends React.Component {
case messages.HIDE_CONTEXT_MENU:
method = () => windowActions.setContextMenuDetail()
break
case messages.GOT_PAGE_FAVICON:
method = (dataUrl) => {
if (frameStateUtil.isTor(this.frame)) {
windowActions.setFavicon(this.frame, dataUrl)
}
}
break
}
method.apply(this, e.args)
}, { passive: true })
Expand Down
5 changes: 4 additions & 1 deletion app/renderer/components/navigation/urlBarIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const dndData = require('../../../../js/dndData')
const UrlUtil = require('../../../../js/lib/urlutil')
const frameStateUtil = require('../../../../js/state/frameStateUtil')
const {isSourceAboutUrl} = require('../../../../js/lib/appUrlUtil')
const {isPotentialPhishingUrl} = require('../../../../js/lib/urlutil')
const {isPotentialPhishingUrl, isOnionUrl} = require('../../../../js/lib/urlutil')

const searchIconSize = 16

Expand All @@ -44,6 +44,8 @@ class UrlBarIcon extends React.Component {
} else if (this.props.isHTTPPage && !this.props.active) {
if (this.props.isSecure === true) {
return ['fa-lock']
} else if (this.props.isOnionUrl) {
return []
} else if (this.props.isSecure === false || this.props.isSecure === 2) {
return ['fa-unlock', 'insecure-color']
} else if (this.props.isSecure === 1) {
Expand Down Expand Up @@ -158,6 +160,7 @@ class UrlBarIcon extends React.Component {
props.activeTabShowingMessageBox = tabState.isShowingMessageBox(state, activeTabId)
props.isAboutPage = isSourceAboutUrl(props.location) && props.location !== 'about:newtab'
props.isPotentialPhishingUrl = isPotentialPhishingUrl(props.location)
props.isOnionUrl = isOnionUrl(props.location)

// used in other functions
props.title = activeFrame.get('title', '')
Expand Down
20 changes: 19 additions & 1 deletion app/renderer/components/tabs/content/favIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ const {spinKeyframes, opacityIncreaseElementKeyframes} = require('../../styles/a

const defaultIconSvg = require('../../../../extensions/brave/img/tabs/default.svg')
const loadingIconSvg = require('../../../../extensions/brave/img/tabs/loading.svg')
const settings = require('../../../../../js/constants/settings')
const {getSetting} = require('../../../../../js/settings')
const appConfig = require('../../../../../js/constants/appConfig')
const domUtil = require('../../../lib/domUtil')

const isLocalFavicon = (favicon) => {
if (!favicon) {
return true
}
favicon = favicon.toLowerCase()
return favicon.startsWith('data:') ||
favicon.startsWith('chrome:') ||
favicon.startsWith('chrome-extension://') ||
favicon.startsWith('file://')
}

class Favicon extends React.Component {
constructor (props) {
Expand All @@ -34,9 +49,11 @@ class Favicon extends React.Component {
const currentWindow = state.get('currentWindow')
const tabId = ownProps.tabId
const frameKey = frameStateUtil.getFrameKeyByTabId(currentWindow, tabId)
const frame = frameStateUtil.getFrameByKey(currentWindow, frameKey)

const props = {}
props.isPinned = tabState.isTabPinned(state, tabId)
props.isTor = frameStateUtil.isTor(frame)
props.favicon = faviconState.getFavicon(currentWindow, frameKey)
props.showIcon = faviconState.showFavicon(currentWindow, frameKey)
props.tabLoading = faviconState.showLoadingIcon(currentWindow, frameKey)
Expand Down Expand Up @@ -91,7 +108,8 @@ class Favicon extends React.Component {

const themeLight = this.props.tabIconColor === 'white'
const instanceStyles = { }
if (this.props.favicon) {
if (this.props.favicon && (!this.props.isTor || isLocalFavicon(this.props.favicon))) {
// Ensure that remote favicons do not load in Tor mode
instanceStyles['--faviconsrc'] = `url(${this.props.favicon})`
}

Expand Down
5 changes: 4 additions & 1 deletion js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ module.exports = {
delayNotificationTryPayments: 1000 * 60 * 60 * 24 * 10, // 10 days (from firstRunTimestamp)
defaultContributionAmount: 7.5
},
tor: {
partition: 'persist:tor'
},
updates: {
// Check for front end updates every hour
appUpdateCheckFrequency: 1000 * 60 * 60,
Expand Down Expand Up @@ -147,7 +150,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, // use true for DDG search in Private Tab
'search.use-alternate-private-search-engine': true, // true for DDG search in Private Tab since Tor is enabled
'tabs.switch-to-new-tabs': false,
'tabs.paint-tabs': true,
'tabs.tabs-per-page': 20,
Expand Down
1 change: 1 addition & 0 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const messages = {
PASSWORD_DETAILS_UPDATED: _, /** @arg {Object} passwords app state */
PASSWORD_SITE_DETAILS_UPDATED: _, /** @arg {Object} passwords app state */
RECREATE_TOR_TAB: _, /** @arg {boolean} torEnabled */
GOT_PAGE_FAVICON: _, /** @arg {string} dataUrl */
// Init
INITIALIZE_WINDOW: _,
// Session restore
Expand Down
14 changes: 14 additions & 0 deletions js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,20 @@ const UrlUtil = {
return url
.replace(/((#?\/?)|(\/#?))$/, '') // remove trailing # and /
.trim() // remove whitespaces
},

/**
* Whether a site is a Tor Hidden Service .onion URL
* @param {string} url
* @return {boolean}
*/
isOnionUrl: (url) => {
if (typeof url !== 'string') { return false }
const hostname = urlParse(url).hostname
if (!hostname) {
return false
}
return hostname.endsWith('.onion')
}
}

Expand Down
8 changes: 8 additions & 0 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@ const isFirstFrameKeyInTabPage = (state, frameKey) => {
return firstFrame && firstFrame.get('key') === frameKey
}

/**
* Check if frame is tor private tab
*/
function isTor (frame) {
return !!(frame && frame.get('isPrivate') && getSetting(settings.USE_TOR_PRIVATE_TABS))
}

const getTabPageIndex = (state) => {
const tabPageIndex = state.getIn(['ui', 'tabs', 'tabPageIndex'], 0)
const previewTabPageIndex = state.getIn(['ui', 'tabs', 'previewTabPageIndex'])
Expand Down Expand Up @@ -798,6 +805,7 @@ module.exports = {
onFindBarHide,
getTotalBlocks,
isPinned,
isTor,
isFirstFrameKeyInTabPage,
getTabPageIndex,
updateTabPageIndex,
Expand Down
Loading

0 comments on commit 7ddf69e

Please sign in to comment.