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

Commit

Permalink
Show Flash notification bar if page loads small/hidden Flash elements
Browse files Browse the repository at this point in the history
Fix #7523

Test Plan:
1. automated flash tests should pass
  • Loading branch information
diracdeltas committed Mar 8, 2017
1 parent 83c55eb commit f1236fb
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ let generateBraveManifest = () => {
js: [
'content/scripts/adInsertion.js',
'content/scripts/passwordManager.js',
'content/scripts/pageInformation.js'
'content/scripts/pageInformation.js',
'content/scripts/flashListener.js'
]
},
{
Expand Down
82 changes: 82 additions & 0 deletions app/extensions/brave/content/scripts/flashListener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
* Whether a src is a .swf file.
* If so, returns the origin of the file. Otherwise returns false.
* @param {string} src
* @return {boolean|string}
*/
function isSWF (src) {
if (!src) {
return false
}
let a = document.createElement('a')
a.href = src
if (a.pathname && a.pathname.toLowerCase().endsWith('.swf')) {
return a.origin
} else {
return false
}
}

/**
* Whether an element is invisible or very small.
* @param {Element} elem
* @return {boolean}
*/
function isHiddenElement (el) {
if (!el) {
return false
}
const minSize = 20
if (el.offsetWidth < minSize || el.offsetHeight < minSize) {
return true
}
if (!el.getClientRects().length) {
return true
}
return false
}

/**
* Whether there is a small/hidden flash object on the page
* Reference:
* https://helpx.adobe.com/flash/kb/flash-object-embed-tag-attributes.html
* @param {Element} elem - HTML element to search
* @return {Array.<string>}
*/
function hasHiddenFlashElement (elem) {
let foundElement = Array.from(elem.getElementsByTagName('embed')).some((el) => {
return isSWF(el.getAttribute('src')) && isHiddenElement(el)
})

if (foundElement) {
return true
}

return Array.from(elem.getElementsByTagName('object')).some((el) => {
if (!isHiddenElement(el)) {
return false
}
let origin = isSWF(el.getAttribute('data'))
return origin
? true
: Array.from(el.getElementsByTagName('param')).some((param) => {
let name = param.getAttribute('name')
let origin = isSWF(param.getAttribute('value'))
return name && ['movie', 'src'].includes(name.toLowerCase()) && origin
})
})
}


// If Flash is enabled but not runnable, show a permission notification for small
// Flash elements
if (chrome.contentSettings.flashEnabled == 'allow' && chrome.contentSettings.plugins != 'allow' && hasHiddenFlashElement(document.documentElement)) {
chrome.ipcRenderer.send('dispatch-action', JSON.stringify([{
actionType: 'app-flash-permission-requested',
location: window.location.href
}]))
}
22 changes: 22 additions & 0 deletions test/components/flashTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,26 @@ describe('flash install interception', function () {
return this.getText(notificationBar).then((val) => val.includes('run Flash Player'))
})
})
it('shows flash notification bar when small element is loaded', function * () {
const flashUrl = Brave.server.url('flash_small.html')
yield this.app.client
.tabByIndex(0)
.loadUrl(flashUrl)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitUntil(function () {
return this.getText(notificationBar).then((val) => val.includes('run Flash Player'))
})
})
it('shows flash notification bar when invisible element is loaded', function * () {
const flashUrl = Brave.server.url('flash_invisible.html')
yield this.app.client
.tabByIndex(0)
.loadUrl(flashUrl)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitUntil(function () {
return this.getText(notificationBar).then((val) => val.includes('run Flash Player'))
})
})
})
5 changes: 5 additions & 0 deletions test/fixtures/flash_invisible.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<body>
<div align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="550" height="200">
<object data="nonexistent.swf" width="100" height="100" style="display:none;"></object>
</object></div>
</body>
3 changes: 3 additions & 0 deletions test/fixtures/flash_small.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<body>
<embed src="https://example.com/nonexistent.swf" width="10" height="10"></embed>
</body>

0 comments on commit f1236fb

Please sign in to comment.