From 8970035e5feab94b80d10f3447840af38e0c18ff Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 31 Oct 2016 18:16:57 -0400 Subject: [PATCH] Undefined properties and nested folders handling fix #5291 fix #5293 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 --- js/contextMenus.js | 105 ++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/js/contextMenus.js b/js/contextMenus.js index aba135e2872..4d5ecb68ac5 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -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, { @@ -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] + } } }) }