From 30501d3329d1fe7e161aac1a5845e77987bbe994 Mon Sep 17 00:00:00 2001 From: yan Date: Wed, 16 May 2018 20:19:17 -0700 Subject: [PATCH] Open link in new private tab should use tor if enabled fix https://github.com/brave/browser-laptop/issues/14103 Test Plan: 1. make sure tor tabs is enabled 2. go to a link and right-click 'open in new private tab' 3. in the new private tab, go to check.torproject.org to make sure Tor is enabled 4. right click on the onion image, select 'open image in new tab' 5. in the new tab, go to check.torproect.org to make sure Tor is enabled auditors: @darkdh --- app/browser/tabs.js | 2 ++ app/browser/windows.js | 1 + app/renderer/reducers/contextMenuReducer.js | 9 ++++++++- app/renderer/rendererShortcutHandler.js | 4 +++- js/contextMenus.js | 20 +++++++++++++++++--- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/browser/tabs.js b/app/browser/tabs.js index b11a0dd7ffb..b7cd1ece9e3 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -521,6 +521,7 @@ const api = { if (ses) { isPrivate = ses.isOffTheRecord() } + const isTor = isPrivate && settingsStore.getSetting(settings.USE_TOR_PRIVATE_TABS) const frameOpts = { location, @@ -531,6 +532,7 @@ const api = { guestInstanceId: newTab.guestInstanceId, isPinned: !!newTabValue.get('pinned'), isPrivate, + isTor, openerTabId, disposition, index, diff --git a/app/browser/windows.js b/app/browser/windows.js index 6009dbd4604..3e09f9b68fc 100644 --- a/app/browser/windows.js +++ b/app/browser/windows.js @@ -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, diff --git a/app/renderer/reducers/contextMenuReducer.js b/app/renderer/reducers/contextMenuReducer.js index de189624937..72ecbedad33 100644 --- a/app/renderer/reducers/contextMenuReducer.js +++ b/app/renderer/reducers/contextMenuReducer.js @@ -111,6 +111,7 @@ const onTabPageMenu = function (state, action) { const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true + const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) if (Array.isArray(url) && Array.isArray(partitionNumber)) { return { label: locale.translation('openInNewTabs'), @@ -119,6 +120,7 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { appActions.createTabRequested({ url: url[i], isPrivate, + isTor, partitionNumber: partitionNumber[i], openerTabId, active @@ -133,6 +135,7 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { appActions.createTabRequested({ url, isPrivate, + isTor, partitionNumber, openerTabId, active @@ -144,6 +147,7 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { const openInNewPrivateTabMenuItem = (url, openerTabId) => { const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true + const isTor = getSetting(settings.USE_TOR_PRIVATE_TABS) if (Array.isArray(url)) { return { label: locale.translation('openInNewPrivateTabs'), @@ -152,6 +156,7 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => { appActions.createTabRequested({ url: url[i], isPrivate: true, + isTor, openerTabId, active }) @@ -165,6 +170,7 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => { appActions.createTabRequested({ url, isPrivate: true, + isTor, openerTabId, active }) @@ -205,10 +211,11 @@ const openInNewSessionTabMenuItem = (url, openerTabId) => { } const openInNewWindowMenuItem = (location, isPrivate, partitionNumber) => { + const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) return { label: locale.translation('openInNewWindow'), click: () => { - appActions.newWindow({ location, isPrivate, partitionNumber }) + appActions.newWindow({ location, isPrivate, isTor, partitionNumber }) } } } diff --git a/app/renderer/rendererShortcutHandler.js b/app/renderer/rendererShortcutHandler.js index b35fa34e477..280c5904657 100644 --- a/app/renderer/rendererShortcutHandler.js +++ b/app/renderer/rendererShortcutHandler.js @@ -116,9 +116,11 @@ function handleShortcut (frameKey, shortcut, e, args) { if (sourceLocation !== null) { const frame = frameStateUtil.getFrameByKey(windowStore.state, frameKey) + const isPrivate = frame.get('isPrivate', false) appActions.createTabRequested({ url: sourceLocation, - isPrivate: frame.get('isPrivate', false), + isPrivate, + isTor: isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS), partitionNumber: frame.get('partitionNumber'), openerTabId: tabId, active: true diff --git a/js/contextMenus.js b/js/contextMenus.js index 659af1cad90..751048fb83f 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -735,6 +735,7 @@ function hamburgerTemplateInit (location, e) { } const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { + const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true if (Array.isArray(url) && Array.isArray(partitionNumber)) { return { @@ -744,6 +745,7 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { appActions.createTabRequested({ url: url[i], isPrivate, + isTor, partitionNumber: partitionNumber[i], openerTabId, active @@ -758,6 +760,7 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => { appActions.createTabRequested({ url, isPrivate, + isTor, partitionNumber, openerTabId, active @@ -778,6 +781,7 @@ const openAllInNewTabsMenuItem = (folderDetail) => { const openInNewPrivateTabMenuItem = (url, openerTabId) => { const active = getSetting(settings.SWITCH_TO_NEW_TABS) === true + const isTor = getSetting(settings.USE_TOR_PRIVATE_TABS) if (Array.isArray(url)) { return { label: locale.translation('openInNewPrivateTabs'), @@ -786,6 +790,7 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => { appActions.createTabRequested({ url: url[i], isPrivate: true, + isTor, openerTabId, active }) @@ -799,6 +804,7 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => { appActions.createTabRequested({ url, isPrivate: true, + isTor, openerTabId, active }) @@ -808,10 +814,11 @@ const openInNewPrivateTabMenuItem = (url, openerTabId) => { } const openInNewWindowMenuItem = (location, isPrivate, partitionNumber) => { + const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) return { label: locale.translation('openInNewWindow'), click: () => { - appActions.newWindow({ location, isPrivate, partitionNumber }) + appActions.newWindow({ location, isPrivate, isTor, partitionNumber }) } } } @@ -887,9 +894,12 @@ const searchSelectionMenuItem = (location) => { let activeFrame = windowStore.getState().get('activeFrameKey') let frame = windowStore.getFrame(activeFrame) let searchUrl = appStoreRenderer.state.getIn(['searchDetail', 'searchURL']).replace('{searchTerms}', encodeURIComponent(location)) + const isPrivate = frame.get('isPrivate') + const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) appActions.createTabRequested({ url: searchUrl, - isPrivate: frame.get('isPrivate'), + isPrivate, + isTor, partitionNumber: frame.get('partitionNumber'), windowId: frame.get('windowId') }) @@ -955,6 +965,7 @@ function mainTemplateInit (nodeProps, frame, tab) { const isTextSelected = nodeProps.selectionText && nodeProps.selectionText.length > 0 const isAboutPage = aboutUrls.has(frame.get('location')) const isPrivate = frame.get('isPrivate') + const isTor = isPrivate && getSetting(settings.USE_TOR_PRIVATE_TABS) if (isLink) { template = addLinkMenu(nodeProps.linkURL, frame) @@ -972,7 +983,9 @@ function mainTemplateInit (nodeProps, frame, tab) { appActions.createTabRequested({ url: nodeProps.srcURL, openerTabId: frame.get('tabId'), - partition: frameStateUtil.getPartitionFromNumber(frame.get('partitionNumber'), isPrivate), + isPrivate, + isTor, + partitionNumber: frame.get('partitionNumber'), active: active }) } @@ -1001,6 +1014,7 @@ function mainTemplateInit (nodeProps, frame, tab) { appActions.createTabRequested({ url: searchUrl, isPrivate, + isTor, partitionNumber: frame.get('partitionNumber') }) }