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

Commit

Permalink
Merge pull request #9469 from brave/webrt-browser
Browse files Browse the repository at this point in the history
set webrtc handling policy in the browser process
  • Loading branch information
bsclifton authored Jun 20, 2017
2 parents 9254bed + 4c826f6 commit 22d2451
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
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 @@ -74,13 +77,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 @@ -770,6 +770,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 @@ -57,11 +57,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 @@ -275,10 +270,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

0 comments on commit 22d2451

Please sign in to comment.