From c79e31ba416f34dad97ac8797fc8b8d767f7cfa3 Mon Sep 17 00:00:00 2001 From: bridiver Date: Fri, 22 Sep 2017 13:40:24 -0700 Subject: [PATCH] changes for https://github.com/brave/muon/pull/317 --- app/browser/tabs.js | 6 ++++ app/renderer/components/frame/frame.js | 8 ----- js/contextMenus.js | 39 --------------------- js/flash.js | 47 +++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 441ad89f701..80dab9e6309 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -34,6 +34,7 @@ const bookmarkFoldersState = require('../common/state/bookmarkFoldersState') const historyState = require('../common/state/historyState') const bookmarkOrderCache = require('../common/cache/bookmarkOrderCache') const {getWindow} = require('./windows') +const flash = require('../../js/flash') let currentPartitionNumber = 0 const incrementPartitionNumber = () => ++currentPartitionNumber @@ -460,6 +461,11 @@ const api = { } }) + tab.on('enable-pepper-menu', (e) => { + // TODO(bridiver) - this should be called from an action so we don't have to pass the state + flash.onFlashContextMenu(tab, appStore.getState(), tabId) + }) + tab.on('close', () => { tab.forceClose() }) diff --git a/app/renderer/components/frame/frame.js b/app/renderer/components/frame/frame.js index 56abee13e78..8cc118b4ba7 100644 --- a/app/renderer/components/frame/frame.js +++ b/app/renderer/components/frame/frame.js @@ -459,14 +459,6 @@ class Frame extends React.Component { } windowActions.setBlockedRunInsecureContent(this.frame, e.details[0]) }, { passive: true }) - this.webview.addEventListener('enable-pepper-menu', (e) => { - if (this.frame.isEmpty()) { - return - } - contextMenus.onFlashContextMenu(e.params, this.frame) - e.preventDefault() - e.stopPropagation() - }) this.webview.addEventListener('context-menu', (e) => { if (this.frame.isEmpty()) { return diff --git a/js/contextMenus.js b/js/contextMenus.js index 273bbf9da33..cf63d87e1fa 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -425,39 +425,6 @@ function autofillTemplateInit (suggestions, frame) { return menuUtil.sanitizeTemplateItems(template) } -function flashTemplateInit (frameProps) { - const canRunFlash = appStoreRenderer.state.getIn(['flash', 'enabled']) && getSetting(settings.FLASH_INSTALLED) - const template = [] - if (!canRunFlash) { - template.push({ - label: locale.translation('openFlashPreferences'), - click: () => { - appActions.createTabRequested({ - url: 'about:preferences#plugins', - windowId: frameProps.get('windowId'), - active: true - }) - } - }) - } else { - template.push({ - label: locale.translation('allowFlashOnce'), - click: () => { - appActions.allowFlashOnce(frameProps.get('tabId'), frameProps.get('location'), frameProps.get('isPrivate')) - } - }) - if (!frameProps.get('isPrivate')) { - template.push({ - label: locale.translation('allowFlashAlways'), - click: () => { - appActions.allowFlashAlways(frameProps.get('tabId'), frameProps.get('location')) - } - }) - } - } - return template -} - function tabTemplateInit (frameProps) { const frameKey = frameProps.get('key') const tabId = frameProps.get('tabId') @@ -1305,11 +1272,6 @@ function onMainContextMenu (nodeProps, frame, tab, contextMenuType) { } } -function onFlashContextMenu (nodeProps, frameProps) { - const flashMenu = Menu.buildFromTemplate(flashTemplateInit(frameProps)) - flashMenu.popup(getCurrentWindow()) -} - function onTabContextMenu (frameProps, e) { e.stopPropagation() const tabMenu = Menu.buildFromTemplate(tabTemplateInit(frameProps)) @@ -1405,7 +1367,6 @@ function onReloadContextMenu () { module.exports = { onHamburgerMenu, - onFlashContextMenu, onMainContextMenu, onTabContextMenu, onNewTabContextMenu, diff --git a/js/flash.js b/js/flash.js index 068923fc4a1..64adedcb606 100644 --- a/js/flash.js +++ b/js/flash.js @@ -5,13 +5,15 @@ const fs = require('fs') const path = require('path') -const {app, ipcMain, webContents} = require('electron') +const {app, ipcMain, webContents, Menu} = require('electron') const appActions = require('./actions/appActions') const {getOrigin} = require('./lib/urlutil') const locale = require('../app/locale') const messages = require('./constants/messages') const settings = require('./constants/settings') +const {getSetting} = require('./settings') const {memoize} = require('underscore') +const tabState = require('../app/common/state/tabState') // set to true if the flash install check has succeeded let flashInstalled = false @@ -119,6 +121,49 @@ module.exports.checkFlashInstalled = (cb) => { } } +const flashMenuTemplateInit = (state, tabId) => { + const tab = tabState.getByTabId(state, tabId) + const windowId = tabState.getWindowId(state, tabId) + const location = tabState.getLocation(state, tabId) + const isPrivate = tab.get('incognito') + + const canRunFlash = state.getIn(['flash', 'enabled']) && getSetting(settings.FLASH_INSTALLED) + const template = [] + if (!canRunFlash) { + template.push({ + label: locale.translation('openFlashPreferences'), + click: () => { + appActions.createTabRequested({ + url: 'about:preferences#plugins', + windowId: windowId, + active: true + }) + } + }) + } else { + template.push({ + label: locale.translation('allowFlashOnce'), + click: () => { + appActions.allowFlashOnce(tabId, location, isPrivate) + } + }) + if (!isPrivate) { + template.push({ + label: locale.translation('allowFlashAlways'), + click: () => { + appActions.allowFlashAlways(tabId, location) + } + }) + } + } + return template +} + +module.exports.onFlashContextMenu = (tab, state, tabId) => { + const flashMenu = Menu.buildFromTemplate(flashMenuTemplateInit(state, tabId)) + flashMenu.popup(tab) +} + module.exports.init = () => { setImmediate(module.exports.checkFlashInstalled) }