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

Commit

Permalink
Fix persistent permissions
Browse files Browse the repository at this point in the history
Already covered by this test:
```
1) notificationBar permissions can accept permission request
persistently:
     Promise was rejected with the following reason: timeout
```

Fix #10957
  • Loading branch information
bbondy committed Sep 14, 2017
1 parent 95d4b7d commit 71ed681
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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)
}
})
}

Expand Down

0 comments on commit 71ed681

Please sign in to comment.