fix: crashReporter incompatible with sandbox on Linux (#23265)

This commit is contained in:
Jeremy Apthorp 2020-05-07 13:31:26 -07:00 committed by GitHub
parent fc434f136b
commit 06bf0d08dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 2235 additions and 2404 deletions

View file

@ -1,12 +0,0 @@
'use strict';
const CrashReporter = require('@electron/internal/common/crash-reporter');
const { crashReporterInit } = require('@electron/internal/browser/crash-reporter-init');
class CrashReporterMain extends CrashReporter {
init (options) {
return crashReporterInit(options);
}
}
module.exports = new CrashReporterMain();

View file

@ -1,47 +1,35 @@
'use strict';
import { app } from 'electron';
const binding = process.electronBinding('crash_reporter');
class CrashReporter {
constructor () {
this.productName = null;
this.crashesDirectory = null;
}
init (options) {
throw new Error('Not implemented');
}
start (options) {
if (options == null) options = {};
start (options: Electron.CrashReporterStartOptions) {
const {
productName,
productName = app.name,
companyName,
extra = {},
globalExtra = {},
ignoreSystemCrashHandler = false,
submitURL,
uploadToServer = true,
rateLimit = false,
compress = false
} = options;
} = options || {};
if (companyName == null) throw new Error('companyName is a required option to crashReporter.start');
if (submitURL == null) throw new Error('submitURL is a required option to crashReporter.start');
const ret = this.init({
submitURL,
productName
});
const appVersion = app.getVersion();
this.productName = ret.productName;
this.crashesDirectory = ret.crashesDirectory;
if (companyName && globalExtra._companyName == null) globalExtra._companyName = companyName;
if (extra._productName == null) extra._productName = ret.productName;
if (extra._companyName == null) extra._companyName = companyName;
if (extra._version == null) extra._version = ret.appVersion;
const globalExtraAmended = {
_productName: productName,
_version: appVersion,
...globalExtra
};
binding.start(submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, rateLimit, compress, extra);
binding.start(submitURL, uploadToServer,
ignoreSystemCrashHandler, rateLimit, compress, globalExtraAmended, extra, false);
}
getLastCrashReport () {
@ -55,17 +43,12 @@ class CrashReporter {
return (reports.length > 0) ? reports[0] : null;
}
getUploadedReports () {
const crashDir = this.getCrashesDirectory();
if (!crashDir) {
throw new Error('crashReporter has not been started');
}
return binding.getUploadedReports(crashDir);
getUploadedReports (): Electron.CrashReport[] {
return binding.getUploadedReports();
}
getCrashesDirectory () {
return this.crashesDirectory;
return app.getPath('crashDumps');
}
getUploadToServer () {
@ -76,7 +59,7 @@ class CrashReporter {
}
}
setUploadToServer (uploadToServer) {
setUploadToServer (uploadToServer: boolean) {
if (process.type === 'browser') {
return binding.setUploadToServer(uploadToServer);
} else {
@ -84,11 +67,11 @@ class CrashReporter {
}
}
addExtraParameter (key, value) {
addExtraParameter (key: string, value: string) {
binding.addExtraParameter(key, value);
}
removeExtraParameter (key) {
removeExtraParameter (key: string) {
binding.removeExtraParameter(key);
}
@ -97,4 +80,4 @@ class CrashReporter {
}
}
module.exports = CrashReporter;
export default new CrashReporter();

View file

@ -1,25 +0,0 @@
'use strict';
const { app } = require('electron');
const path = require('path');
const getTempDirectory = function () {
try {
return app.getPath('temp');
} catch {
// Delibrately laze-load the os module, this file is on the hot
// path when booting Electron and os takes between 5 - 8ms to load and we do not need it yet
return require('os').tmpdir();
}
};
exports.crashReporterInit = function (options) {
const productName = options.productName || app.name;
const crashesDirectory = path.join(getTempDirectory(), `${productName} Crashes`);
return {
productName,
crashesDirectory,
appVersion: app.getVersion()
};
};

View file

@ -7,7 +7,6 @@ const eventBinding = process.electronBinding('event');
const clipboard = process.electronBinding('clipboard');
const features = process.electronBinding('features');
const { crashReporterInit } = require('@electron/internal/browser/crash-reporter-init');
const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-internal');
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils');
const guestViewManager = require('@electron/internal/browser/guest-view-manager');
@ -37,10 +36,6 @@ ipcMainInternal.on('ELECTRON_BROWSER_WINDOW_CLOSE', function (event) {
event.returnValue = null;
});
ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_INIT', function (event, options) {
return crashReporterInit(options);
});
ipcMainInternal.handle('ELECTRON_BROWSER_GET_LAST_WEB_PREFERENCES', function (event) {
return event.sender.getLastWebPreferences();
});
@ -120,3 +115,23 @@ ipcMainUtils.handleSync('ELECTRON_BROWSER_SANDBOX_LOAD', async function (event)
ipcMainInternal.on('ELECTRON_BROWSER_PRELOAD_ERROR', function (event, preloadPath, error) {
event.sender.emit('preload-error', event, preloadPath, error);
});
ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_GET_LAST_CRASH_REPORT', () => {
return electron.crashReporter.getLastCrashReport();
});
ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_GET_UPLOADED_REPORTS', () => {
return electron.crashReporter.getUploadedReports();
});
ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_GET_UPLOAD_TO_SERVER', () => {
return electron.crashReporter.getUploadToServer();
});
ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_SET_UPLOAD_TO_SERVER', (event, uploadToServer) => {
return electron.crashReporter.setUploadToServer(uploadToServer);
});
ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_GET_CRASHES_DIRECTORY', () => {
return electron.crashReporter.getCrashesDirectory();
});

View file

@ -1,12 +0,0 @@
'use strict';
const CrashReporter = require('@electron/internal/common/crash-reporter');
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils');
class CrashReporterRenderer extends CrashReporter {
init (options) {
return ipcRendererUtils.invokeSync('ELECTRON_CRASH_REPORTER_INIT', options);
}
}
module.exports = new CrashReporterRenderer();

View file

@ -0,0 +1,50 @@
import { invokeSync } from '../ipc-renderer-internal-utils';
import { deprecate } from 'electron';
const binding = process.electronBinding('crash_reporter');
export default {
start (options: Electron.CrashReporterStartOptions) {
deprecate.log('crashReporter.start is deprecated in the renderer process. Call it from the main process instead.');
for (const [k, v] of Object.entries(options.extra || {})) {
binding.addExtraParameter(k, String(v));
}
},
getLastCrashReport (): Electron.CrashReport | null {
deprecate.log('crashReporter.getLastCrashReport is deprecated in the renderer process. Call it from the main process instead.');
return invokeSync('ELECTRON_CRASH_REPORTER_GET_LAST_CRASH_REPORT');
},
getUploadedReports () {
deprecate.log('crashReporter.getUploadedReports is deprecated in the renderer process. Call it from the main process instead.');
return invokeSync('ELECTRON_CRASH_REPORTER_GET_UPLOADED_REPORTS');
},
getUploadToServer () {
deprecate.log('crashReporter.getUploadToServer is deprecated in the renderer process. Call it from the main process instead.');
return invokeSync('ELECTRON_CRASH_REPORTER_GET_UPLOAD_TO_SERVER');
},
setUploadToServer (uploadToServer: boolean) {
deprecate.log('crashReporter.setUploadToServer is deprecated in the renderer process. Call it from the main process instead.');
return invokeSync('ELECTRON_CRASH_REPORTER_SET_UPLOAD_TO_SERVER', uploadToServer);
},
getCrashesDirectory () {
deprecate.log('crashReporter.getCrashesDirectory is deprecated in the renderer process. Call it from the main process instead.');
return invokeSync('ELECTRON_CRASH_REPORTER_GET_CRASHES_DIRECTORY');
},
addExtraParameter (key: string, value: string) {
binding.addExtraParameter(key, value);
},
removeExtraParameter (key: string) {
binding.removeExtraParameter(key);
},
getParameters () {
return binding.getParameters();
}
};