From 6cbd6dfa5e978a048b633effb60de64e51ac14ae Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 16 Mar 2017 19:32:42 +0000 Subject: [PATCH] Improve flash hidden element detection Separates plugin content setting from flashEnabled setting so that shields down allows tiny flash elements to be detected. Also improves hidden element detection for slow/delayed element loads. Fix #4020 Auditors: @srirambv @bbondy Test Plan: 1. go to reverso.net with flash enabled in about:preferences and shields down 2. enter something in the box and click translate 3. you should see a flash notification bar. click 'allow' 4. click on the copy-paste icon in the results box. the page should tell you that the text was copied. --- .../brave/content/scripts/flashListener.js | 23 ++++++++++++++----- js/state/contentSettings.js | 7 +++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/extensions/brave/content/scripts/flashListener.js b/app/extensions/brave/content/scripts/flashListener.js index f0a04100851..b3f74d7f554 100644 --- a/app/extensions/brave/content/scripts/flashListener.js +++ b/app/extensions/brave/content/scripts/flashListener.js @@ -71,12 +71,23 @@ function hasHiddenFlashElement (elem) { }) } - // 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 - }])) +if (chrome.contentSettings.flashEnabled == 'allow' && chrome.contentSettings.flashAllowed != 'allow') { + const maxFlashAttempts = 3 + let flashAttempts = 0 + const intervalId = window.setInterval(() => { + if (flashAttempts >= maxFlashAttempts) { + window.clearInterval(intervalId) + return + } + flashAttempts = flashAttempts + 1 + if (hasHiddenFlashElement(document.documentElement)) { + chrome.ipcRenderer.send('dispatch-action', JSON.stringify([{ + actionType: 'app-flash-permission-requested', + location: window.location.href + }])) + window.clearInterval(intervalId) + } + }, 1000) } diff --git a/js/state/contentSettings.js b/js/state/contentSettings.js index c0e419d4326..604d8f6461c 100644 --- a/js/state/contentSettings.js +++ b/js/state/contentSettings.js @@ -97,10 +97,14 @@ const getDefaultUserPrefContentSettings = (braveryDefaults, appSettings, appConf setting: 'block', primaryPattern: '*' }], - flashEnabled: [{ + flashEnabled: [{ // whether flash is installed and enabled setting: braveryDefaults.get('flash') ? 'allow' : 'block', primaryPattern: '*' }], + flashAllowed: [{ // whether user has expressed intent to run flash + setting: 'block', + primaryPattern: '*' + }], popups: [{ setting: 'block', primaryPattern: '*' @@ -268,6 +272,7 @@ const siteSettingsToContentSettings = (currentSiteSettings, defaultContentSettin } if (typeof siteSetting.get('flash') === 'number' && braveryDefaults.get('flash')) { contentSettings = addContentSettings(contentSettings, 'plugins', primaryPattern, '*', 'allow', getFlashResourceId()) + contentSettings = addContentSettings(contentSettings, 'flashAllowed', primaryPattern, '*', 'allow', getFlashResourceId()) } if (typeof siteSetting.get('widevine') === 'number' && braveryDefaults.get('widevine')) { contentSettings = addContentSettings(contentSettings, 'plugins', primaryPattern, '*', 'allow', appConfig.widevine.resourceId)