Merge pull request #900 from mattermost/verious-fixes

MM-13145 Some improvments to navigation and messaging.
This commit is contained in:
Yuya Ochiai
2019-01-08 00:05:59 +09:00
committed by GitHub

View File

@@ -6,6 +6,8 @@
import os from 'os'; import os from 'os';
import path from 'path'; import path from 'path';
import {URL} from 'url';
import electron from 'electron'; import electron from 'electron';
const { const {
app, app,
@@ -308,22 +310,34 @@ app.on('certificate-error', (event, webContents, url, error, certificate, callba
if (certificateStore.isExisting(url)) { if (certificateStore.isExisting(url)) {
detail = 'Certificate is different from previous one.\n\n' + detail; detail = 'Certificate is different from previous one.\n\n' + detail;
} }
dialog.showMessageBox(mainWindow, { dialog.showMessageBox(mainWindow, {
title: 'Certificate error', title: 'Certificate Error',
message: `Do you trust certificate from "${certificate.issuerName}"?`, message: 'There is a configuration issue with this Mattermost server, or someone is trying to intercept your connection. You also may need to sign into the Wi-Fi you are connected to using your web browser.',
detail, type: 'error',
type: 'warning',
buttons: [ buttons: [
'Yes', 'More Details',
'No', 'Cancel Connection',
], ],
cancelId: 1, cancelId: 1,
}, (response) => { }, (response) => {
if (response === 0) { if (response === 0) {
certificateStore.add(url, certificate); dialog.showMessageBox(mainWindow, {
certificateStore.save(); title: 'Certificate Error',
webContents.loadURL(url); message: `Certificate from "${certificate.issuerName}" is not trusted.`,
detail,
type: 'error',
buttons: [
'Trust Insecure Certificate',
'Cancel Connection',
],
cancelId: 1,
}, (responseTwo) => { //eslint-disable-line max-nested-callbacks
if (responseTwo === 0) {
certificateStore.add(url, certificate);
certificateStore.save();
webContents.loadURL(url);
}
});
} }
}); });
callback(false); callback(false);
@@ -351,8 +365,8 @@ app.on('login', (event, webContents, request, authInfo, callback) => {
allowProtocolDialog.init(mainWindow); allowProtocolDialog.init(mainWindow);
ipcMain.on('download-url', (event, URL) => { ipcMain.on('download-url', (event, url) => {
downloadURL(mainWindow, URL, (err) => { downloadURL(mainWindow, url, (err) => {
if (err) { if (err) {
dialog.showMessageBox(mainWindow, { dialog.showMessageBox(mainWindow, {
type: 'error', type: 'error',
@@ -673,3 +687,28 @@ app.on('ready', () => {
// Open the DevTools. // Open the DevTools.
// mainWindow.openDevTools(); // mainWindow.openDevTools();
}); });
app.on('web-contents-created', (dc, contents) => {
contents.on('will-attach-webview', (event, webPreferences) => {
webPreferences.nodeIntegration = false;
});
contents.on('will-navigate', (event, navigationUrl) => {
const parsedUrl = new URL(navigationUrl);
const trustedURLs = settings.mergeDefaultTeams(config.teams).map((team) => new URL(team.url)); //eslint-disable-line max-nested-callbacks
let trusted = false;
for (const url of trustedURLs) {
if (parsedUrl.origin === url.origin) {
trusted = true;
break;
}
}
if (!trusted) {
event.preventDefault();
}
});
contents.on('new-window', (event) => {
event.preventDefault();
});
});