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

set webrtc handling policy in the browser process #9469

Merged
merged 1 commit into from
Jun 20, 2017
Merged
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
29 changes: 28 additions & 1 deletion app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

'use strict'

const appConfig = require('../../../js/constants/appConfig')
const appConstants = require('../../../js/constants/appConstants')
const tabs = require('../tabs')
const windows = require('../windows')
Expand All @@ -12,6 +13,8 @@ const {BrowserWindow} = require('electron')
const tabState = require('../../common/state/tabState')
const windowState = require('../../common/state/windowState')
const tabActions = require('../../common/actions/tabActions')
const siteSettings = require('../../../js/state/siteSettings')
const siteSettingsState = require('../../common/state/siteSettingsState')
const windowConstants = require('../../../js/constants/windowConstants')
const windowActions = require('../../../js/actions/windowActions')
const {makeImmutable} = require('../../common/state/immutableUtil')
Expand Down Expand Up @@ -75,13 +78,37 @@ const updateActiveTab = (state, closeTabId) => {
}
}

const WEBRTC_DEFAULT = 'default'
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'

const getWebRTCPolicy = (state, tabId) => {
const tabValue = tabState.getByTabId(state, tabId)
if (tabValue == null) {
return WEBRTC_DEFAULT
}
const allSiteSettings = siteSettingsState.getAllSiteSettings(state, tabValue.get('incognito') === true)
const tabSiteSettings =
siteSettings.getSiteSettingsForURL(allSiteSettings, tabValue.get('url'))
const activeSiteSettings = siteSettings.activeSettings(tabSiteSettings, state, appConfig)

if (!activeSiteSettings || activeSiteSettings.fingerprintingProtection !== true) {
return WEBRTC_DEFAULT
} else {
return WEBRTC_DISABLE_NON_PROXY
}
}

const tabsReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
switch (action.get('actionType')) {
case tabActions.didStartNavigation.name:
case tabActions.didFinishNavigation.name:
{
state = tabState.setNavigationState(state, action.get('tabId'), action.get('navigationState'))
const tabId = action.get('tabId')
state = tabState.setNavigationState(state, tabId, action.get('navigationState'))
setImmediate(() => {
tabs.setWebRTCIPHandlingPolicy(tabId, getWebRTCPolicy(state, tabId))
})
break
}
case tabActions.reload.name:
Expand Down
7 changes: 7 additions & 0 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,13 @@ const api = {
}
},

setWebRTCIPHandlingPolicy: (tabId, policy) => {
const tab = getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
tab.setWebRTCIPHandlingPolicy(policy)
}
},

goBack: (tabId) => {
const tab = getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
Expand Down
18 changes: 0 additions & 18 deletions app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ const messages = require('../../../../js/constants/messages')
const config = require('../../../../js/constants/config')

const pdfjsOrigin = `chrome-extension://${config.PDFJSExtensionId}/`
const WEBRTC_DEFAULT = 'default'
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'
// Looks like Brave leaks true public IP from behind system proxy when this option
// is on.
// const WEBRTC_PUBLIC_ONLY = 'default_public_interface_only'

function isTorrentViewerURL (url) {
const isEnabled = getSetting(settings.TORRENT_VIEWER_ENABLED)
Expand Down Expand Up @@ -274,10 +269,6 @@ class Frame extends React.Component {

const cb = (prevProps = {}) => {
this.onPropsChanged(prevProps)
if (this.getWebRTCPolicy(prevProps) !== this.getWebRTCPolicy(this.props)) {
this.webview.setWebRTCIPHandlingPolicy(this.getWebRTCPolicy(this.props))
}

if (this.props.isActive && !prevProps.isActive && !this.props.urlBarFocused) {
this.webview.focus()
}
Expand Down Expand Up @@ -893,15 +884,6 @@ class Frame extends React.Component {
}
}

getWebRTCPolicy (props) {
const braverySettings = this.getFrameBraverySettings(props)
if (!braverySettings || braverySettings.get('fingerprintingProtection') !== true) {
return WEBRTC_DEFAULT
} else {
return WEBRTC_DISABLE_NON_PROXY
}
}

mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()
Expand Down