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

Commit

Permalink
Block tab.loadURL in tor tabs until tor is initialized
Browse files Browse the repository at this point in the history
Fix #14680

Test Plan:
1. open brave, turn on showing bookmarks toolbar and showing home button
   in about:preferences. bookmark some sites.
2. open tor tab and try to click on bookmarks before tor finishes
   loading. also try clicking on the home button and clicking the
   History > Home menu item.
3. these loads should be blocked until tor finishes initializing
  • Loading branch information
diracdeltas committed Jul 10, 2018
1 parent a742002 commit bef471d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ const getPartitionNumber = (partition) => {
return Number(partition.split('persist:partition-')[1] || 0)
}

const shouldWaitForTorLoad = (webContents, appState) => {
if (webContents &&
webContents.session &&
webContents.session.partition === appConfig.tor.partition) {
appState = appState || appStore.getState()
if (appState.getIn(['tor', 'online']) !== true) {
console.log('Blocking page load until Tor tab is initialized')
return true
}
}
}

/**
* Obtains the current partition.
* Warning: This function has global side effects in that it increments the
Expand Down Expand Up @@ -905,6 +917,9 @@ const api = {
action = makeImmutable(action)
const tabId = action.get('tabId')
const tab = webContentsCache.getWebContents(tabId)
if (shouldWaitForTorLoad(tab)) {
return
}
if (tab && !tab.isDestroyed()) {
const url = normalizeUrl(action.get('url'))
const currentUrl = tab.getURL()
Expand Down Expand Up @@ -944,6 +959,9 @@ const api = {

loadURLInTab: (state, tabId, url) => {
const tab = webContentsCache.getWebContents(tabId)
if (shouldWaitForTorLoad(tab)) {
return
}
if (tab && !tab.isDestroyed()) {
url = normalizeUrl(url)
tab.loadURL(url)
Expand Down

0 comments on commit bef471d

Please sign in to comment.