This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show Flash notification bar if page loads small/hidden Flash elements
Fix #7523 Test Plan: 1. automated flash tests should pass
- Loading branch information
1 parent
83c55eb
commit f1236fb
Showing
5 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |