diff --git a/src/browser/index.jsx b/src/browser/index.jsx index f98c35bd..35649d23 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -317,6 +317,7 @@ var MattermostView = React.createClass({ var currentURL = url.parse(webview.getURL()); var destURL = url.parse(e.url); if (destURL.protocol !== 'http:' && destURL.protocol !== 'https:') { + ipcRenderer.send('confirm-protocol', destURL.protocol, e.url); return; } if (currentURL.host === destURL.host) { diff --git a/src/main.js b/src/main.js index c0b33f19..26b09c57 100644 --- a/src/main.js +++ b/src/main.js @@ -154,6 +154,48 @@ app.on('login', function(event, webContents, request, authInfo, callback) { mainWindow.webContents.send('login-request', request, authInfo); }); +ipc.on('confirm-protocol', (event, protocol, URL) => { + const allowedProtocolFile = path.resolve(app.getPath('userData'), 'allowedProtocols.json') + fs.readFile(allowedProtocolFile, 'utf-8', (err, data) => { + var allowedProtocols = []; + if (!err) { + allowedProtocols = JSON.parse(data); + } + if (allowedProtocols.indexOf(protocol) !== -1) { + require('shell').openExternal(URL); + } + else { + electron.dialog.showMessageBox(mainWindow, { + title: 'Non http(s) protocol', + message: `${protocol} link requires an external application.`, + detail: `The requested link is ${URL} . Do you want to continue?`, + type: 'warning', + buttons: [ + 'Yes', + `Yes (Save ${protocol} as allowed)`, + 'No' + ], + cancelId: 2, + noLink: true + }, (response) => { + switch (response) { + case 1: + allowedProtocols.push(protocol); + fs.writeFile(allowedProtocolFile, JSON.stringify(allowedProtocols), (err) => { + if (err) console.error(err); + }); + // fallthrough + case 0: + require('shell').openExternal(URL); + break; + default: + break; + } + }); + } + }); +}); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.on('ready', function() {