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

changes for https://github.com/brave/muon/pull/317 #11099

Merged
merged 2 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {getFlashResourceId} = require('../../../js/flash')
const {l10nErrorText} = require('../../common/lib/httpUtil')
const Immutable = require('immutable')
const dragTypes = require('../../../js/constants/dragTypes')
const flash = require('../../../js/flash')
const {frameOptsFromFrame} = require('../../../js/state/frameStateUtil')
const {isSourceAboutUrl, isTargetAboutUrl, isNavigatableAboutPage} = require('../../../js/lib/appUrlUtil')

Expand Down Expand Up @@ -341,6 +342,10 @@ const tabsReducer = (state, action, immutableAction) => {
}
break
}
case appConstants.APP_ENABLE_PEPPER_MENU: {
flash.onFlashContextMenu(state, action.get('tabId'))
break
}
case appConstants.APP_DRAG_ENDED: {
const dragData = state.get('dragData')
if (dragData && dragData.get('type') === dragTypes.TAB) {
Expand Down
4 changes: 4 additions & 0 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ const api = {
}
})

tab.on('enable-pepper-menu', (e, params) => {
appActions.enablePepperMenu(params, tabId)
})

tab.on('close', () => {
tab.forceClose()
})
Expand Down
4 changes: 4 additions & 0 deletions app/common/state/tabState.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ const tabState = {
return tabState.getTabPropertyByTabId(state, tabId, 'windowId', windowState.WINDOW_ID_NONE)
},

isIncognito: (state, tabId) => {
return tabState.getTabPropertyByTabId(state, tabId, 'incognito', false)
},

canGoForward: (state, tabId) => {
try {
return tabState.getTabPropertyByTabId(state, tabId, 'canGoForward', false)
Expand Down
8 changes: 0 additions & 8 deletions app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,14 @@ const appActions = {
})
},

enablePepperMenu: function (params, tabId) {
dispatch({
actionType: appConstants.APP_ENABLE_PEPPER_MENU,
params,
tabId
})
},

onPinnedTabReorder: function (siteKey, destinationKey, prepend) {
dispatch({
actionType: appConstants.APP_ON_PINNED_TAB_REORDER,
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const appConstants = {
APP_REMOVE_BOOKMARK: _,
APP_MOVE_BOOKMARK_FOLDER: _,
APP_MOVE_BOOKMARK: _,
APP_ENABLE_PEPPER_MENU: _,
APP_INSPECT_ELEMENT: _
}

Expand Down
39 changes: 0 additions & 39 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -1405,7 +1367,6 @@ function onReloadContextMenu () {

module.exports = {
onHamburgerMenu,
onFlashContextMenu,
onMainContextMenu,
onTabContextMenu,
onNewTabContextMenu,
Expand Down
51 changes: 50 additions & 1 deletion js/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,6 +121,53 @@ module.exports.checkFlashInstalled = (cb) => {
}
}

const flashMenuTemplateInit = (state, tabId) => {
const windowId = tabState.getWindowId(state, tabId)
const location = tabState.getLocation(state, tabId)
const isPrivate = tabState.isIncognito(state, tabId)

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 = (state, tabId) => {
const tab = webContents.fromTabID(tabId)
if (!tab) {
return
}

const flashMenu = Menu.buildFromTemplate(flashMenuTemplateInit(state, tabId))
flashMenu.popup(tab)
}

module.exports.init = () => {
setImmediate(module.exports.checkFlashInstalled)
}
Expand Down