diff --git a/atom/common/api/atom_api_crash_reporter.cc b/atom/common/api/atom_api_crash_reporter.cc index 5dff9e667fe6..aaaf200b32f3 100644 --- a/atom/common/api/atom_api_crash_reporter.cc +++ b/atom/common/api/atom_api_crash_reporter.cc @@ -40,6 +40,10 @@ void Initialize(v8::Local exports, v8::Local unused, base::Bind(&CrashReporter::Start, report)); dict.SetMethod("_getUploadedReports", base::Bind(&CrashReporter::GetUploadedReports, report)); + dict.SetMethod("_setUploadToServer", + base::Bind(&CrashReporter::SetUploadToServer, report)); + dict.SetMethod("_getUploadToServer", + base::Bind(&CrashReporter::GetUploadToServer, report)); } } // namespace diff --git a/atom/common/crash_reporter/crash_reporter.cc b/atom/common/crash_reporter/crash_reporter.cc index 1254f3fde6cf..5e13bd6fe5b0 100644 --- a/atom/common/crash_reporter/crash_reporter.cc +++ b/atom/common/crash_reporter/crash_reporter.cc @@ -26,13 +26,13 @@ void CrashReporter::Start(const std::string& product_name, const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler, const StringMap& extra_parameters) { SetUploadParameters(extra_parameters); InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url, - crashes_dir, auto_submit, skip_system_crash_handler); + crashes_dir, upload_to_server, skip_system_crash_handler); } void CrashReporter::SetUploadParameters(const StringMap& parameters) { @@ -43,6 +43,13 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) { SetUploadParameters(); } +void CrashReporter::SetUploadToServer(const bool upload_to_server) { +} + +bool CrashReporter::GetUploadToServer() { + return true; +} + std::vector CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) { std::string file_content; diff --git a/atom/common/crash_reporter/crash_reporter.h b/atom/common/crash_reporter/crash_reporter.h index ef153523acfd..6eb43d0a2dfe 100644 --- a/atom/common/crash_reporter/crash_reporter.h +++ b/atom/common/crash_reporter/crash_reporter.h @@ -26,13 +26,16 @@ class CrashReporter { const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler, const StringMap& extra_parameters); virtual std::vector GetUploadedReports( const base::FilePath& crashes_dir); + virtual void SetUploadToServer(bool upload_to_server); + virtual bool GetUploadToServer(); + protected: CrashReporter(); virtual ~CrashReporter(); @@ -42,7 +45,7 @@ class CrashReporter { const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler); virtual void SetUploadParameters(); diff --git a/atom/common/crash_reporter/crash_reporter_linux.cc b/atom/common/crash_reporter/crash_reporter_linux.cc index 2442d7e168e3..50e1c5ec862c 100644 --- a/atom/common/crash_reporter/crash_reporter_linux.cc +++ b/atom/common/crash_reporter/crash_reporter_linux.cc @@ -60,7 +60,7 @@ void CrashReporterLinux::InitBreakpad(const std::string& product_name, const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler) { EnableCrashDumping(crashes_dir); diff --git a/atom/common/crash_reporter/crash_reporter_linux.h b/atom/common/crash_reporter/crash_reporter_linux.h index 36a369973211..846e1f1b0a91 100644 --- a/atom/common/crash_reporter/crash_reporter_linux.h +++ b/atom/common/crash_reporter/crash_reporter_linux.h @@ -32,7 +32,7 @@ class CrashReporterLinux : public CrashReporter { const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler) override; void SetUploadParameters() override; diff --git a/atom/common/crash_reporter/crash_reporter_mac.h b/atom/common/crash_reporter/crash_reporter_mac.h index ed4888bbaf1b..9066f2017bb2 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.h +++ b/atom/common/crash_reporter/crash_reporter_mac.h @@ -11,6 +11,7 @@ #include "atom/common/crash_reporter/crash_reporter.h" #include "base/compiler_specific.h" #include "base/strings/string_piece.h" +#include "vendor/crashpad/client/crash_report_database.h" #include "vendor/crashpad/client/simple_string_dictionary.h" namespace base { @@ -28,9 +29,11 @@ class CrashReporterMac : public CrashReporter { const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler) override; void SetUploadParameters() override; + void SetUploadToServer(bool upload_to_server) override; + bool GetUploadToServer() override; private: friend struct base::DefaultSingletonTraits; @@ -46,6 +49,7 @@ class CrashReporterMac : public CrashReporter { const base::FilePath& crashes_dir) override; std::unique_ptr simple_string_dictionary_; + std::unique_ptr database_; DISALLOW_COPY_AND_ASSIGN(CrashReporterMac); }; diff --git a/atom/common/crash_reporter/crash_reporter_mac.mm b/atom/common/crash_reporter/crash_reporter_mac.mm index 82e3ea140c73..d5107b5edb99 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.mm +++ b/atom/common/crash_reporter/crash_reporter_mac.mm @@ -13,7 +13,6 @@ #include "base/strings/string_piece.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" -#include "vendor/crashpad/client/crash_report_database.h" #include "vendor/crashpad/client/crashpad_client.h" #include "vendor/crashpad/client/crashpad_info.h" #include "vendor/crashpad/client/settings.h" @@ -31,7 +30,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler) { // check whether crashpad has been initialized. // Only need to initialize once. @@ -73,11 +72,23 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, SetCrashKeyValue(upload_parameter.first, upload_parameter.second); } if (is_browser_) { - std::unique_ptr database = + database_ = crashpad::CrashReportDatabase::Initialize(crashes_dir); - if (database) { - database->GetSettings()->SetUploadsEnabled(auto_submit); - } + SetUploadToServer(upload_to_server); + } +} + +bool CrashReporterMac::GetUploadToServer() { + bool enabled = true; + if (database_) { + database_->GetSettings()->GetUploadsEnabled(&enabled); + } + return enabled; +} + +void CrashReporterMac::SetUploadToServer(const bool upload_to_server) { + if (database_) { + database_->GetSettings()->SetUploadsEnabled(upload_to_server); } } diff --git a/atom/common/crash_reporter/crash_reporter_win.cc b/atom/common/crash_reporter/crash_reporter_win.cc index a465edcb45ea..25969dc32eb3 100644 --- a/atom/common/crash_reporter/crash_reporter_win.cc +++ b/atom/common/crash_reporter/crash_reporter_win.cc @@ -150,7 +150,7 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name, const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler) { skip_system_crash_handler_ = skip_system_crash_handler; diff --git a/atom/common/crash_reporter/crash_reporter_win.h b/atom/common/crash_reporter/crash_reporter_win.h index 20a537d89224..3fc139aca190 100644 --- a/atom/common/crash_reporter/crash_reporter_win.h +++ b/atom/common/crash_reporter/crash_reporter_win.h @@ -28,7 +28,7 @@ class CrashReporterWin : public CrashReporter { const std::string& company_name, const std::string& submit_url, const base::FilePath& crashes_dir, - bool auto_submit, + bool upload_to_server, bool skip_system_crash_handler) override; void SetUploadParameters() override; diff --git a/docs/api/crash-reporter.md b/docs/api/crash-reporter.md index cec860ad61f5..a8a61025a525 100644 --- a/docs/api/crash-reporter.md +++ b/docs/api/crash-reporter.md @@ -40,7 +40,7 @@ The `crashReporter` module has the following methods: * `companyName` String (optional) * `submitURL` String - URL that crash reports will be sent to as POST. * `productName` String (optional) - Defaults to `app.getName()`. - * `autoSubmit` Boolean (optional) - Send the crash report without user interaction. + * `uploadToServer` Boolean (optional) _macOS_ - Whether crash reports should be sent to the server Default is `true`. * `ignoreSystemCrashHandler` Boolean (optional) - Default is `false`. * `extra` Object (optional) - An object you can define that will be sent along with the @@ -70,6 +70,22 @@ Returns [`CrashReport[]`](structures/crash-report.md): Returns all uploaded crash reports. Each report contains the date and uploaded ID. +### `crashReporter.getUploadToServer()` _macOS_ + +Returns `Boolean` - Whether reports should be submitted to the server. Set through +the `start` method or `setUploadToServer`. + +**Note:** This API can only be called from the main process. + +### `crashReporter.setUploadToServer(uploadToServer)` _macOS_ + +* `uploadToServer` Boolean _macOS_ - Whether reports should be submitted to the server + +This would normally be controlled by user preferences. This has no effect if +called before `start` is called. + +**Note:** This API can only be called from the main process. + ## Crash Report Payload The crash reporter will send the following data to the `submitURL` as diff --git a/docs/tutorial/planned-breaking-changes.md b/docs/tutorial/planned-breaking-changes.md index ed3606f123c2..4e604945ef4d 100644 --- a/docs/tutorial/planned-breaking-changes.md +++ b/docs/tutorial/planned-breaking-changes.md @@ -40,6 +40,23 @@ clipboard.writeHtml() clipboard.writeHTML() ``` +## `crashReporter` + +```js +// Deprecated +crashReporter.start({ + companyName: 'Crashly', + submitURL: 'https://crash.server.com', + autoSubmit: true +}) +// Replace with +crashReporter.start({ + companyName: 'Crashly', + submitURL: 'https://crash.server.com', + uploadToServer: true +}) +``` + ## `nativeImage` ```js diff --git a/lib/common/api/crash-reporter.js b/lib/common/api/crash-reporter.js index 7749583f79cf..c5a462cf5110 100644 --- a/lib/common/api/crash-reporter.js +++ b/lib/common/api/crash-reporter.js @@ -13,11 +13,17 @@ class CrashReporter { options = {} } this.productName = options.productName != null ? options.productName : app.getName() - let {autoSubmit, companyName, extra, ignoreSystemCrashHandler, submitURL} = options + let {companyName, extra, ignoreSystemCrashHandler, submitURL, uploadToServer} = options - if (autoSubmit == null) { - autoSubmit = true + if (uploadToServer == null) { + // TODO: Remove deprecated autoSubmit property in 2.0 + uploadToServer = options.autoSubmit } + + if (uploadToServer == null) { + uploadToServer = true + } + if (ignoreSystemCrashHandler == null) { ignoreSystemCrashHandler = false } @@ -56,7 +62,7 @@ class CrashReporter { }) } - binding.start(this.getProductName(), companyName, submitURL, this.getCrashesDirectory(), autoSubmit, ignoreSystemCrashHandler, extra) + binding.start(this.getProductName(), companyName, submitURL, this.getCrashesDirectory(), uploadToServer, ignoreSystemCrashHandler, extra) } getLastCrashReport () { @@ -95,6 +101,22 @@ class CrashReporter { } return this.tempDirectory } + + getUploadToServer () { + if (process.type === 'browser') { + return binding._getUploadToServer() + } else { + throw new Error('getUploadToServer can only be called from the main process') + } + } + + setUploadToServer (uploadToServer) { + if (process.type === 'browser') { + return binding._setUploadToServer(uploadToServer) + } else { + throw new Error('setUploadToServer can only be called from the main process') + } + } } module.exports = new CrashReporter() diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index fe8c3f6c62d9..df4bbfa8ba29 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -117,6 +117,27 @@ describe('crashReporter module', function () { }) }) }) + + describe('.get/setUploadToServer', function () { + it('throws an error when called from the renderer process', function () { + assert.throws(() => require('electron').crashReporter.getUploadToServer()) + }) + + it('can be read/set from the main process', function () { + if (process.platform === 'darwin') { + crashReporter.start({ + companyName: 'Umbrella Corporation', + submitURL: 'http://127.0.0.1/crashes', + autoSubmit: true + }) + assert.equal(crashReporter.getUploadToServer(), true) + crashReporter.setUploadToServer(false) + assert.equal(crashReporter.getUploadToServer(), false) + } else { + assert.equal(crashReporter.getUploadToServer(), true) + } + }) + }) }) const waitForCrashReport = () => {