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

Commit

Permalink
Updated js/flash.js to use the methods in lib/urlutil.js (which have …
Browse files Browse the repository at this point in the history
…unit tests)

Auditors: @bridiver
  • Loading branch information
bsclifton committed Dec 4, 2016
1 parent c9f8030 commit 90bc8f4
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions js/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const messages = require('./constants/messages')
const siteUtil = require('./state/siteUtil')
const urlParse = require('url').parse
const settings = require('./constants/settings')
const { siteHacks } = require('./data/siteHacks')
const {siteHacks} = require('./data/siteHacks')
const urlutil = require('./lib/urlutil')

let flashInstalled = false
const notificationCallbacks = {}
Expand All @@ -43,16 +44,6 @@ const getPepperFlashPath = () => {
return pluginPath
}

/**
* Checks whether a link is an Flash installer URL.
* @param {string} url
* @return {boolean}
*/
const isFlashInstallUrl = (url) => {
const adobeRegex = new RegExp('//(get\\.adobe\\.com/([a-z_-]+/)*flashplayer|www\\.macromedia\\.com/go/getflash|www\\.adobe\\.com/go/getflash)', 'i')
return adobeRegex.test(url)
}

/**
* Shows a Flash CtP notification if Flash is installed and enabled.
* If not enabled, alert user that Flash is installed.
Expand Down Expand Up @@ -169,12 +160,7 @@ const shouldInterceptFlash = (url, isPrivate) => {
return false
}

const parsed = urlParse(url)
const exemptHostPattern = new RegExp('(\\.adobe\\.com|www\\.google(\\.\\w+){1,2}|^duckduckgo\\.com|^search\\.yahoo\\.com)$')
return parsed.hostname &&
['http:', 'https:'].includes(parsed.protocol) &&
!exemptHostPattern.test(parsed.hostname) &&
!['/search', '/search/'].includes(parsed.pathname)
return urlutil.shouldInterceptFlash(url)
}

function handleFlashCTP (details, isPrivate) {
Expand Down Expand Up @@ -221,7 +207,7 @@ function handleFlashInstallUrl (details, isPrivate) {
}

const origin = siteUtil.getOrigin(mainFrameUrl)
if (origin && isFlashInstallUrl(details.url) &&
if (origin && urlutil.isFlashInstallUrl(details.url) &&
shouldInterceptFlash(mainFrameUrl, isPrivate)) {
result.cancel = true
showFlashNotification(origin, details.tabId, details.url)
Expand Down

0 comments on commit 90bc8f4

Please sign in to comment.