From 71ed6819a8893b1658af4f25da165b8154bdbe01 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Thu, 14 Sep 2017 16:30:00 -0400 Subject: [PATCH] Fix persistent permissions Already covered by this test: ``` 1) notificationBar permissions can accept permission request persistently: Promise was rejected with the following reason: timeout ``` Fix #10957 --- app/filtering.js | 65 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/app/filtering.js b/app/filtering.js index 83608e677f7..76220afbacf 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -449,6 +449,7 @@ function registerPermissionHandler (session, partition) { let response = [] for (let i = 0; i < permissionTypes.length; i++) { + const responseSizeThisIteration = response.length const permission = permissionTypes[i] const alwaysAllowFullscreen = module.exports.alwaysAllowFullscreen() === fullscreenOption.ALWAYS_ALLOW if (!permissions[permission]) { @@ -490,38 +491,44 @@ function registerPermissionHandler (session, partition) { permissionCallbacks[message](0, false) } - appActions.showNotification({ - buttons: [ - {text: locale.translation('deny')}, - {text: locale.translation('allow')} - ], - frameOrigin: getOrigin(mainFrameUrl), - options: { - persist: !!origin, - index: i - }, - message - }) - - // Use a closure here for the index instead of passing an index to the - // function because ipcMain.on(messages.NOTIFICATION_RESPONSE above - // calls into the callback without knowing an index. - const index = i - permissionCallbacks[message] = (buttonIndex, persist) => { - // hide the notification if this was triggered automatically - appActions.hideNotification(message) - const result = !!(buttonIndex) - response[index] = result - if (persist) { - // remember site setting for this host - appActions.changeSiteSetting(origin, permission + 'Permission', result, isPrivate) - } - if (response.length === permissionTypes.length) { - permissionCallbacks[message] = null - cb(response) + const responseAutoAdded = responseSizeThisIteration !== response.length + if (!responseAutoAdded) { + appActions.showNotification({ + buttons: [ + {text: locale.translation('deny')}, + {text: locale.translation('allow')} + ], + frameOrigin: getOrigin(mainFrameUrl), + options: { + persist: !!origin, + index: i + }, + message + }) + + // Use a closure here for the index instead of passing an index to the + // function because ipcMain.on(messages.NOTIFICATION_RESPONSE above + // calls into the callback without knowing an index. + const index = i + permissionCallbacks[message] = (buttonIndex, persist) => { + // hide the notification if this was triggered automatically + appActions.hideNotification(message) + const result = !!(buttonIndex) + response[index] = result + if (persist) { + // remember site setting for this host + appActions.changeSiteSetting(origin, permission + 'Permission', result, isPrivate) + } + if (response.length === permissionTypes.length) { + permissionCallbacks[message] = null + cb(response) + } } } } + if (response.length === permissionTypes.length) { + cb(response) + } }) }