2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2018-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-05-24 19:13:16 +00:00
|
|
|
// The list of permissions is here:
|
|
|
|
// https://electronjs.org/docs/api/session#sessetpermissionrequesthandlerhandler
|
|
|
|
|
|
|
|
const PERMISSIONS = {
|
|
|
|
// Allowed
|
|
|
|
fullscreen: true, // required to show videos in full-screen
|
|
|
|
notifications: true, // required to show OS notifications for new messages
|
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
// Off by default, can be enabled by user
|
2020-06-04 18:16:19 +00:00
|
|
|
media: false, // required for access to microphone and camera, used for voice notes and calling
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2018-05-24 19:13:16 +00:00
|
|
|
// Not allowed
|
|
|
|
geolocation: false,
|
|
|
|
midiSysex: false,
|
|
|
|
openExternal: false, // we don't need this; we open links via 'will-navigate' event
|
|
|
|
pointerLock: false,
|
|
|
|
};
|
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
function _createPermissionHandler(userConfig) {
|
2020-06-04 18:16:19 +00:00
|
|
|
return (webContents, permission, callback, details) => {
|
|
|
|
// We default 'media' permission to false, but the user can override that for
|
|
|
|
// the microphone and camera.
|
|
|
|
if (
|
|
|
|
permission === 'media' &&
|
|
|
|
details.mediaTypes.includes('audio') &&
|
|
|
|
userConfig.get('mediaPermissions')
|
|
|
|
) {
|
|
|
|
return callback(true);
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
permission === 'media' &&
|
|
|
|
details.mediaTypes.includes('video') &&
|
|
|
|
userConfig.get('mediaCameraPermissions')
|
|
|
|
) {
|
2018-07-12 21:52:34 +00:00
|
|
|
return callback(true);
|
2018-07-03 22:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PERMISSIONS[permission]) {
|
|
|
|
console.log(`Approving request for permission '${permission}'`);
|
|
|
|
return callback(true);
|
|
|
|
}
|
2018-05-24 19:13:16 +00:00
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
console.log(`Denying request for permission '${permission}'`);
|
|
|
|
return callback(false);
|
|
|
|
};
|
2018-05-24 19:13:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
function installPermissionsHandler({ session, userConfig }) {
|
|
|
|
// Setting the permission request handler to null first forces any permissions to be
|
|
|
|
// requested again. Without this, revoked permissions might still be available if
|
|
|
|
// they've already been used successfully.
|
|
|
|
session.defaultSession.setPermissionRequestHandler(null);
|
|
|
|
|
|
|
|
session.defaultSession.setPermissionRequestHandler(
|
|
|
|
_createPermissionHandler(userConfig)
|
|
|
|
);
|
2018-05-24 19:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
installPermissionsHandler,
|
|
|
|
};
|