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

Commit

Permalink
Undefined properties and nested folders handling
Browse files Browse the repository at this point in the history
fix #5291
fix #5293

requires brave/muon#85

Auditors: @bridiver, @bbondy

Test Plan:
1. Go to about:preferences#security
2. Select Lastpass as password manager
3. Login to Lastpass
4. Right click to show context menu
5. Nested menu of Lastpass should show
  • Loading branch information
darkdh committed Oct 31, 2016
1 parent d299153 commit 64d594e
Showing 1 changed file with 66 additions and 39 deletions.
105 changes: 66 additions & 39 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,8 @@ function mainTemplateInit (nodeProps, frame) {
})

const passwordManager = getActivePasswordManager()
if (passwordManager.get('extensionId')) {
if (passwordManager.get('extensionId') &&
passwordManager.get('displayName') === 'Dashlane') {
template.push(
CommonMenu.separatorMenuItem,
{
Expand All @@ -1108,58 +1109,84 @@ function mainTemplateInit (nodeProps, frame) {

const extensionContextMenus =
extensionState.getContextMenusProperties(appStore.state)
if (extensionContextMenus.length) {
if (extensionContextMenus !== undefined &&
extensionContextMenus.length) {
template.push(CommonMenu.separatorMenuItem)
let templateMap = {}
extensionContextMenus.forEach((extensionContextMenu) => {
let info = {}
let contextsPassed = false
extensionContextMenu.properties.contexts.forEach((context) => {
if (isTextSelected && (context === 'selection' || context === 'all')) {
info['selectionText'] = nodeProps.selectionText
contextsPassed = true
} else if (isLink && (context === 'link' || context === 'all')) {
info['linkUrl'] = nodeProps.linkURL
contextsPassed = true
} else if (isImage && (context === 'image' || context === 'all')) {
info['mediaType'] = 'image'
contextsPassed = true
} else if (isInputField && (context === 'editable' || context === 'all')) {
info['editable'] = true
contextsPassed = true
} else if (nodeProps.pageURL && (context === 'page' || context === 'all')) {
info['pageUrl'] = nodeProps.pageURL
contextsPassed = true
} else if (isVideo && (context === 'video' || context === 'all')) {
info['mediaType'] = 'video'
contextsPassed = true
} else if (isAudio && (context === 'audio' || context === 'all')) {
info['mediaType'] = 'audio'
contextsPassed = true
} else if (nodeProps.frameURL && (context === 'frame' || context === 'all')) {
info['frameURL'] = nodeProps.frameURL
contextsPassed = true
}
})
if (extensionContextMenu.properties.contexts !== undefined &&
extensionContextMenu.properties.contexts.length) {
extensionContextMenu.properties.contexts.forEach((context) => {
if (isTextSelected && (context === 'selection' || context === 'all')) {
info['selectionText'] = nodeProps.selectionText
contextsPassed = true
} else if (isLink && (context === 'link' || context === 'all')) {
info['linkUrl'] = nodeProps.linkURL
contextsPassed = true
} else if (isImage && (context === 'image' || context === 'all')) {
info['mediaType'] = 'image'
contextsPassed = true
} else if (isInputField && (context === 'editable' || context === 'all')) {
info['editable'] = true
contextsPassed = true
} else if (nodeProps.pageURL && (context === 'page' || context === 'all')) {
info['pageUrl'] = nodeProps.pageURL
contextsPassed = true
} else if (isVideo && (context === 'video' || context === 'all')) {
info['mediaType'] = 'video'
contextsPassed = true
} else if (isAudio && (context === 'audio' || context === 'all')) {
info['mediaType'] = 'audio'
contextsPassed = true
} else if (nodeProps.frameURL && (context === 'frame' || context === 'all')) {
info['frameURL'] = nodeProps.frameURL
contextsPassed = true
}
})
}
if (nodeProps.srcURL) {
info['srcURL'] = nodeProps.srcURL
}
// TODO (Anthony): Browser Action context menu
if (extensionContextMenu.properties.contexts.length === 1 &&
if (extensionContextMenu.properties.contexts !== undefined &&
extensionContextMenu.properties.contexts.length === 1 &&
extensionContextMenu.properties.contexts[0] === 'browser_action') {
contextsPassed = false
}
if (contextsPassed) {
info['menuItemId'] = extensionContextMenu.menuItemId
template.push(
{
label: extensionContextMenu.properties.title,
click: (item, focusedWindow) => {
if (focusedWindow) {
extensionActions.contextMenuClicked(
extensionContextMenu.extensionId, frame.get('tabId'), info)
if (extensionContextMenu.properties.parentId) {
if (templateMap[extensionContextMenu.properties.parentId].submenu === undefined) {
templateMap[extensionContextMenu.properties.parentId].submenu = []
}
templateMap[extensionContextMenu.properties.parentId].submenu.push(
{
label: extensionContextMenu.properties.title,
click: (item, focusedWindow) => {
if (focusedWindow) {
extensionActions.contextMenuClicked(
extensionContextMenu.extensionId, frame.get('tabId'), info)
}
}
}
})
})
const submenuLength = templateMap[extensionContextMenu.properties.parentId].submenu.length
templateMap[extensionContextMenu.menuItemId] =
templateMap[extensionContextMenu.properties.parentId].submenu[submenuLength - 1]
} else {
template.push(
{
label: extensionContextMenu.properties.title,
click: (item, focusedWindow) => {
if (focusedWindow) {
extensionActions.contextMenuClicked(
extensionContextMenu.extensionId, frame.get('tabId'), info)
}
}
})
templateMap[extensionContextMenu.menuItemId] = template[template.length - 1]
}
}
})
}
Expand Down

0 comments on commit 64d594e

Please sign in to comment.