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

Block tab.loadURL in tor tabs until tor is initialized #14709

Merged
merged 1 commit into from
Jul 11, 2018
Merged
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
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