From f7f389b3b1aa8c3522cb00e9533d81259ab344c5 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Mon, 4 Jul 2016 12:48:41 -0400 Subject: [PATCH] Fix flash detection Fix #2384 and Fix #2378 When it was not installed it was infinite looping with no message, when it was installed and not enabled it was infinite looping. Both on myspace.com I shortened the message for Flash because the important part gets cut off on macOS notifications. Auditors: @diracdeltas, @aekeus --- .../brave/locales/en-US/app.properties | 2 +- app/index.js | 13 +---------- js/components/frame.js | 22 +++++++++++++------ js/constants/messages.js | 1 - {app => js}/flash.js | 14 ++++++++++-- 5 files changed, 29 insertions(+), 23 deletions(-) rename {app => js}/flash.js (86%) diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index 24ef5a78013..376cd7695e8 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -113,7 +113,7 @@ findResultMatches[other]={{numberOfMatches}} matches inspectElement=Inspect Element urlCopied=URL copied to clipboard passwordCopied=Password copied to clipboard -flashInstalled=Flash is already installed. You can enable it in Preferences > Security. +flashInstalled=Flash can be enabled in Preferences > Security. error=Error caseSensitivity=Match case diff --git a/app/index.js b/app/index.js index a436890b7fd..1ff7e4539c8 100644 --- a/app/index.js +++ b/app/index.js @@ -43,7 +43,7 @@ const keytar = require('keytar') const settings = require('../js/constants/settings') const siteSettings = require('../js/state/siteSettings') const spellCheck = require('./spellCheck') -const flash = require('./flash') +const flash = require('../js/flash') const contentSettings = require('../js/state/contentSettings') // Used to collect the per window state when shutting down the application @@ -421,17 +421,6 @@ app.on('ready', () => { }) }) - ipcMain.on(messages.SHOW_FLASH_INSTALLED_MESSAGE, (e) => { - flash.checkFlashInstalled((installed) => { - if (installed) { - if (BrowserWindow.getFocusedWindow()) { - BrowserWindow.getFocusedWindow().webContents.send(messages.SHOW_NOTIFICATION, - locale.translation('flashInstalled')) - } - } - }) - }) - ipcMain.on(messages.MOVE_SITE, (e, sourceDetail, destinationDetail, prepend, destinationIsParent) => { appActions.moveSite(Immutable.fromJS(sourceDetail), Immutable.fromJS(destinationDetail), prepend, destinationIsParent) }) diff --git a/js/components/frame.js b/js/components/frame.js index 3bc41dafba5..13a1da58646 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -31,6 +31,7 @@ const { isFrameError } = require('../lib/errorUtil') const locale = require('../l10n') const appConfig = require('../constants/appConfig') const { getSiteSettingsForHostPattern } = require('../state/siteSettings') +const flash = require('../flash') const WEBRTC_DEFAULT = 'default' const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp' @@ -546,8 +547,14 @@ class Frame extends ImmutableComponent { } } } else { - ipc.send(messages.SHOW_FLASH_INSTALLED_MESSAGE) - windowActions.loadUrl(this.props.frame, adobeUrl) + flash.checkFlashInstalled((installed) => { + if (installed) { + remote.getCurrentWindow().webContents.send(messages.SHOW_NOTIFICATION, + locale.translation('flashInstalled')) + } else { + windowActions.loadUrl(this.props.frame, adobeUrl) + } + }) } ipc.once(messages.NOTIFICATION_RESPONSE + nonce, (e, msg, buttonIndex, persist) => { const cb = this.notificationCallbacks[msg] @@ -562,12 +569,13 @@ class Frame extends ImmutableComponent { // Instead of telling person to install Flash, ask them if they want to // run Flash if it's installed. if (e.isMainFrame && !e.isErrorPage && !e.isFrameSrcDoc) { - const currentUrl = urlParse(this.props.frame.get('location')) if ((e.url.includes('//get.adobe.com/flashplayer') || - e.url.includes('//www.adobe.com/go/getflash')) && - ['http:', 'https:'].includes(currentUrl.protocol) && - !currentUrl.hostname.includes('.adobe.com')) { - interceptFlash(e.url) + e.url.includes('//www.adobe.com/go/getflash'))) { + const currentProvisionalUrl = urlParse(this.props.frame.get('provisionalLocation')) + if (['http:', 'https:'].includes(currentProvisionalUrl.protocol) && + !currentProvisionalUrl.hostname.includes('.adobe.com')) { + interceptFlash(e.url) + } } windowActions.onWebviewLoadStart(this.props.frame, e.url) const isSecure = parsedUrl.protocol === 'https:' && !this.allowRunningInsecureContent() diff --git a/js/constants/messages.js b/js/constants/messages.js index 76714051d80..fef8d5efb15 100644 --- a/js/constants/messages.js +++ b/js/constants/messages.js @@ -46,7 +46,6 @@ const messages = { LOGIN_REQUIRED: _, /** @arg {Object} details of the login required request */ LOGIN_RESPONSE: _, NOTIFICATION_RESPONSE: _, /** @arg {string} message, @arg {number} buttonId, @arg {boolean} persist */ - SHOW_FLASH_INSTALLED_MESSAGE: _, // Downloads SHOW_DOWNLOADS_TOOLBAR: _, /** Ensures the downloads toolbar is visible */ HIDE_DOWNLOADS_TOOLBAR: _, /** Hides the downloads toolbar */ diff --git a/app/flash.js b/js/flash.js similarity index 86% rename from app/flash.js rename to js/flash.js index 34f53262bb8..fc98c856932 100644 --- a/app/flash.js +++ b/js/flash.js @@ -3,10 +3,20 @@ * 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/. */ -const electron = require('electron') -const app = electron.app const fs = require('fs') const path = require('path') +let electron +let app +try { + electron = require('electron') +} catch (e) { + electron = global.require('electron') +} +if (process.type === 'browser') { + app = electron.app +} else { + app = electron.remote.app +} module.exports.init = () => { // TODO: This only works if sync currently