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

Commit

Permalink
fix flash checks for chromium 54
Browse files Browse the repository at this point in the history
auditors: @bbondy @diractdeltas
  • Loading branch information
bridiver committed Nov 29, 2016
1 parent 9ed262a commit dcfd67d
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 325 deletions.
6 changes: 4 additions & 2 deletions app/browser/basicAuth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {app} = require('electron')
const { app } = require('electron')
const appActions = require('../../js/actions/appActions')
const basicAuthState = require('../common/state/basicAuthState')
const { makeImmutable } = require('../common/state/immutableUtil')
Expand All @@ -11,7 +11,7 @@ const cleanupAuthCallback = (tabId) => {
}

const basicAuth = {
init: () => {
init: (state, action) => {
app.on('login', (e, webContents, request, authInfo, cb) => {
e.preventDefault()
let tabId = webContents.getId()
Expand All @@ -29,6 +29,8 @@ const basicAuth = {
})
})
})

return state
},

setLoginResponseDetail: (state, action) => {
Expand Down
47 changes: 38 additions & 9 deletions app/browser/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const electron = require('electron')
const ipc = electron.ipcMain
const messages = require('../../js/constants/messages')
const WebTorrentRemoteServer = require('webtorrent-remote/server')

module.exports = {init}
const Filtering = require('../filtering')
const { getTargetMagnetUrl } = require('../../js/lib/appUrlUtil')

// Set to see communication between WebTorrent and torrent viewer tabs
const DEBUG_IPC = false
Expand All @@ -14,15 +14,39 @@ if (DEBUG_IPC) console.log('WebTorrent IPC debugging enabled')
let server = null
let channels = {}

function handleMangetUrl (details, isPrivate) {
const result = {
resourceName: module.exports.resourceName,
redirectURL: null,
cancel: false
}

if (details.resourceType !== 'mainFrame') {
return result
}

const magnetUrl = getTargetMagnetUrl(details.url)
if (magnetUrl) {
result.redirectUrl = magnetUrl
}

return result
}

// Receive messages via the window process, ultimately from the UI in a <webview> process
function init () {
if (DEBUG_IPC) console.log('WebTorrent IPC init')
server = new WebTorrentRemoteServer(send, {trace: DEBUG_IPC})
ipc.on(messages.TORRENT_MESSAGE, function (e, msg) {
if (DEBUG_IPC) console.log('Received IPC: ' + JSON.stringify(msg))
channels[msg.clientKey] = e.sender
server.receive(msg)
function init (state, action) {
setImmediate(() => {
if (DEBUG_IPC) console.log('WebTorrent IPC init')
server = new WebTorrentRemoteServer(send, {trace: DEBUG_IPC})
ipc.on(messages.TORRENT_MESSAGE, function (e, msg) {
if (DEBUG_IPC) console.log('Received IPC: ' + JSON.stringify(msg))
channels[msg.clientKey] = e.sender
server.receive(msg)
})

Filtering.registerBeforeRequestFilteringCB(handleMangetUrl)
})
return state
}

// Send messages from the browser process (here), thru the window process, to the <webview>
Expand All @@ -40,3 +64,8 @@ function send (msg) {
}
channel.send(messages.TORRENT_MESSAGE, msg)
}

module.exports = {
init,
resourceName: 'webtorrent'
}
1 change: 0 additions & 1 deletion app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const api = {
cleanupWindow(windowId)
})
win.webContents.on('new-window', (e, url, frameName, disposition, options = {}) => {
console.log(options)
let userGesture = options.userGesture
if (userGesture === false) {
e.preventDefault()
Expand Down
24 changes: 0 additions & 24 deletions app/extensions/brave/content/scripts/flashListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ function isAdobeLink (href) {
return adobeRegex.test(href)
}

function showFlashNotification (origin, e) {
chrome.ipcRenderer.sendToHost('show-flash-notification', origin)
e.preventDefault()
e.stopPropagation()
}

/**
* Whether a src is a .swf file.
* If so, returns the origin of the file. Otherwise returns false.
Expand Down Expand Up @@ -137,24 +131,6 @@ function insertFlashPlaceholders (elem = document.documentElement) {
if (chrome.contentSettings.flashActive != 'allow' ||
chrome.contentSettings.flashEnabled != 'allow') {
// Open flash links in the same tab so we can intercept them correctly
(function () {
function replaceAdobeLinks () {
Array.from(document.querySelectorAll('a')).forEach((elem) => {
const href = elem.getAttribute('href')
if (isAdobeLink(href)) {
elem.onclick = showFlashNotification.bind(null, window.location.origin)
}
})
}
replaceAdobeLinks()
let interval = setInterval(replaceAdobeLinks, 3000)
document.addEventListener('visibilitychange', () => {
clearInterval(interval)
if (document.visibilityState !== 'hidden') {
interval = setInterval(replaceAdobeLinks, 3000)
}
})
})()
insertFlashPlaceholders()
let interval = setInterval(insertFlashPlaceholders, 3000)
document.addEventListener('visibilitychange', () => {
Expand Down
111 changes: 65 additions & 46 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const electron = require('electron')
const session = electron.session
const BrowserWindow = electron.BrowserWindow
const webContents = electron.webContents
const appStore = require('../js/stores/appStore')
const appActions = require('../js/actions/appActions')
const appConfig = require('../js/constants/appConfig')
const downloadStates = require('../js/constants/downloadStates')
Expand All @@ -33,6 +32,8 @@ const path = require('path')
const getOrigin = require('../js/state/siteUtil').getOrigin
const {adBlockResourceName} = require('./adBlock')

let appStore = null

const beforeSendHeadersFilteringFns = []
const beforeRequestFilteringFns = []
const beforeRedirectFilteringFns = []
Expand Down Expand Up @@ -563,54 +564,76 @@ function shouldIgnoreUrl (url) {
return true
}

module.exports.init = () => {
['default'].forEach((partition) => {
initForPartition(partition)
})
ipcMain.on(messages.INITIALIZE_PARTITION, (e, partition) => {
if (initializedPartitions[partition]) {
module.exports.init = (state, action, store) => {
appStore = store

setImmediate(() => {
['default'].forEach((partition) => {
initForPartition(partition)
})
ipcMain.on(messages.INITIALIZE_PARTITION, (e, partition) => {
if (initializedPartitions[partition]) {
e.returnValue = true
return e.returnValue
}
initForPartition(partition)
e.returnValue = true
return e.returnValue
}
initForPartition(partition)
e.returnValue = true
return e.returnValue
})
ipcMain.on(messages.DOWNLOAD_ACTION, (e, downloadId, action) => {
const item = downloadMap[downloadId]
switch (action) {
case downloadActions.CANCEL:
updateDownloadState(downloadId, item, downloadStates.CANCELLED)
if (item) {
item.cancel()
}
break
case downloadActions.PAUSE:
if (item) {
item.pause()
}
updateDownloadState(downloadId, item, downloadStates.PAUSED)
break
case downloadActions.RESUME:
if (item) {
item.resume()
}
updateDownloadState(downloadId, item, downloadStates.IN_PROGRESS)
break
}
})
ipcMain.on(messages.NOTIFICATION_RESPONSE, (e, message, buttonIndex, persist) => {
if (permissionCallbacks[message]) {
permissionCallbacks[message](buttonIndex, persist)
}
})
ipcMain.on(messages.DOWNLOAD_ACTION, (e, downloadId, action) => {
const item = downloadMap[downloadId]
switch (action) {
case downloadActions.CANCEL:
updateDownloadState(downloadId, item, downloadStates.CANCELLED)
if (item) {
item.cancel()
}
break
case downloadActions.PAUSE:
if (item) {
item.pause()
}
updateDownloadState(downloadId, item, downloadStates.PAUSED)
break
case downloadActions.RESUME:
if (item) {
item.resume()
}
updateDownloadState(downloadId, item, downloadStates.IN_PROGRESS)
break
}
})
ipcMain.on(messages.NOTIFICATION_RESPONSE, (e, message, buttonIndex, persist) => {
if (permissionCallbacks[message]) {
permissionCallbacks[message](buttonIndex, persist)
}
})
})

return state
}

module.exports.getSiteSettings = (url, isPrivate) => {
const appState = appStore.getState()
let settings = appState.get('siteSettings')
if (isPrivate) {
settings = settings.mergeDeep(appState.get('temporarySiteSettings'))
}
return siteSettings.getSiteSettingsForURL(settings, url)
}

module.exports.isResourceEnabled = (resourceName, url, isPrivate) => {
if (resourceName === 'siteHacks') {
return true
}

// TODO(bridiver) - need to clean up the rest of this so web can
// remove this because it duplicates checks made in siteSettings
// and not all resources are controlled by shields up/down
if (resourceName === 'flash' || resourceName === 'webtorrent') {
return true
}

const appState = appStore.getState()
const settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), url)
const tempSettings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), url)
Expand Down Expand Up @@ -694,13 +717,9 @@ module.exports.getMainFrameUrl = (details) => {
if (details.resourceType === 'mainFrame') {
return details.url
}
const tabId = details.tabId
const wc = webContents.getAllWebContents()
if (wc && tabId) {
const content = wc.find((item) => item.getId() === tabId)
if (content) {
return content.getURL()
}
const tab = webContents.fromTabID(details.tabId)
if (tab) {
return tab.getURL()
}
return null
}
21 changes: 0 additions & 21 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const AppStore = require('../js/stores/appStore')
const PackageLoader = require('./package-loader')
const Autofill = require('./autofill')
const Extensions = require('./extensions')
const Filtering = require('./filtering')
const TrackingProtection = require('./trackingProtection')
const AdBlock = require('./adBlock')
const AdInsertion = require('./browser/ads/adInsertion')
Expand All @@ -73,12 +72,10 @@ const siteSettings = require('../js/state/siteSettings')
const spellCheck = require('./spellCheck')
const locale = require('./locale')
const ledger = require('./ledger')
const flash = require('../js/flash')
const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')
const async = require('async')
const settings = require('../js/constants/settings')
const webtorrent = require('./browser/webtorrent')

// temporary fix for #4517, #4518 and #4472
app.commandLine.appendSwitch('enable-use-zoom-for-dsf', 'false')
Expand Down Expand Up @@ -240,8 +237,6 @@ const initiateSessionStateSave = (beforeQuit) => {

let loadAppStatePromise = SessionStore.loadAppState()

let flashInitialized = false

// Some settings must be set right away on startup, those settings should be handled here.
loadAppStatePromise.then((initialState) => {
const {HARDWARE_ACCELERATION_ENABLED, SMOOTH_SCROLL_ENABLED, SEND_CRASH_REPORTS} = require('../js/constants/settings')
Expand All @@ -257,13 +252,6 @@ loadAppStatePromise.then((initialState) => {
if (initialState.settings[SMOOTH_SCROLL_ENABLED] === false) {
app.commandLine.appendSwitch('disable-smooth-scrolling')
}
if (initialState.flash && initialState.flash.enabled === true) {
if (flash.init()) {
// Flash was initialized successfully
flashInitialized = true
return
}
}
})

const notifyCertError = (webContents, url, error, cert) => {
Expand Down Expand Up @@ -410,7 +398,6 @@ app.on('ready', () => {
// For tests we always want to load default app state
const loadedPerWindowState = initialState.perWindowState
delete initialState.perWindowState
initialState.flashInitialized = flashInitialized
appActions.setState(Immutable.fromJS(initialState))
Menu.init(initialState, null)
return loadedPerWindowState
Expand All @@ -419,14 +406,12 @@ app.on('ready', () => {
privacy.init()
Autofill.init()
Extensions.init()
Filtering.init()
SiteHacks.init()
spellCheck.init()
HttpsEverywhere.init()
TrackingProtection.init()
AdBlock.init()
AdInsertion.init()
webtorrent.init()

if (!loadedPerWindowState || loadedPerWindowState.length === 0) {
if (!CmdLine.newWindowURL()) {
Expand Down Expand Up @@ -498,12 +483,6 @@ app.on('ready', () => {
electron.clipboard.writeText(text)
})

ipcMain.on(messages.CHECK_FLASH_INSTALLED, (e) => {
flash.checkFlashInstalled((installed) => {
e.sender.send(messages.FLASH_UPDATED, installed)
})
})

ipcMain.on(messages.OPEN_DOWNLOAD_PATH, (e, download) => {
downloadActions.openDownloadPath(Immutable.fromJS(download))
})
Expand Down
6 changes: 2 additions & 4 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ class SecurityTab extends ImmutableComponent {

const isLinux = navigator.appVersion.indexOf('Linux') !== -1

const flashInstalled = getSetting(settings.FLASH_INSTALLED, this.props.settings)
return <div>
<div className='sectionTitle' data-l10n-id='privateData' />
<SettingsList dataL10nId='privateDataMessage'>
Expand Down Expand Up @@ -1602,7 +1603,7 @@ class SecurityTab extends ImmutableComponent {
</SettingsList>
<div className='sectionTitle' data-l10n-id='pluginSettings' />
<SettingsList>
<SettingCheckbox checked={this.props.flashInstalled ? this.props.braveryDefaults.get('flash') : false} dataL10nId='enableFlash' onChange={this.onToggleFlash} disabled={!this.props.flashInstalled} />
<SettingCheckbox checked={flashInstalled ? this.props.braveryDefaults.get('flash') : false} dataL10nId='enableFlash' onChange={this.onToggleFlash} disabled={!flashInstalled} />
<span className='subtext'>
<span className='fa fa-info-circle' id='flashInfoIcon' />
{
Expand Down Expand Up @@ -1794,9 +1795,6 @@ class AboutPreferences extends React.Component {
ipc.on(messages.BRAVERY_DEFAULTS_UPDATED, (e, braveryDefaults) => {
this.setState({ braveryDefaults: Immutable.fromJS(braveryDefaults || {}) })
})
ipc.on(messages.FLASH_UPDATED, (e, flashInstalled) => {
this.setState({ flashInstalled })
})
ipc.on(messages.LANGUAGE, (e, {langCode, languageCodes}) => {
this.setState({ languageCodes })
})
Expand Down
Loading

0 comments on commit dcfd67d

Please sign in to comment.