mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: crashReporter incompatible with sandbox on Linux (#23265)
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "ppapi/buildflags/buildflags.h"
|
||||
#include "shell/browser/electron_paths.h"
|
||||
#include "shell/common/electron_paths.h"
|
||||
#include "shell/common/options_switches.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
209
shell/app/electron_crash_reporter_client.cc
Normal file
209
shell/app/electron_crash_reporter_client.cc
Normal file
@@ -0,0 +1,209 @@
|
||||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "shell/app/electron_crash_reporter_client.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "components/crash/core/common/crash_keys.h"
|
||||
#include "components/upload_list/crash_upload_list.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/electron_version.h"
|
||||
#include "services/service_manager/embedder/switches.h"
|
||||
#include "shell/common/electron_paths.h"
|
||||
|
||||
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
||||
#include "components/version_info/version_info_values.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_POSIX)
|
||||
#include "base/debug/dump_without_crashing.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
ElectronCrashReporterClient* Instance() {
|
||||
static base::NoDestructor<ElectronCrashReporterClient> crash_client;
|
||||
return crash_client.get();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
void ElectronCrashReporterClient::Create() {
|
||||
crash_reporter::SetCrashReporterClient(Instance());
|
||||
|
||||
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
|
||||
// location to write crash dumps can be set.
|
||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||
std::string alternate_crash_dump_location;
|
||||
base::FilePath crash_dumps_dir_path;
|
||||
if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) {
|
||||
crash_dumps_dir_path =
|
||||
base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
|
||||
}
|
||||
if (!crash_dumps_dir_path.empty()) {
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
base::PathService::Override(electron::DIR_CRASH_DUMPS,
|
||||
crash_dumps_dir_path);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
ElectronCrashReporterClient* ElectronCrashReporterClient::Get() {
|
||||
return Instance();
|
||||
}
|
||||
|
||||
void ElectronCrashReporterClient::SetCollectStatsConsent(bool upload_allowed) {
|
||||
collect_stats_consent_ = upload_allowed;
|
||||
}
|
||||
|
||||
void ElectronCrashReporterClient::SetUploadUrl(const std::string& url) {
|
||||
upload_url_ = url;
|
||||
}
|
||||
|
||||
void ElectronCrashReporterClient::SetShouldRateLimit(bool rate_limit) {
|
||||
rate_limit_ = rate_limit;
|
||||
}
|
||||
|
||||
void ElectronCrashReporterClient::SetShouldCompressUploads(bool compress) {
|
||||
compress_uploads_ = compress;
|
||||
}
|
||||
|
||||
void ElectronCrashReporterClient::SetGlobalAnnotations(
|
||||
const std::map<std::string, std::string>& annotations) {
|
||||
global_annotations_ = annotations;
|
||||
}
|
||||
|
||||
ElectronCrashReporterClient::ElectronCrashReporterClient() {}
|
||||
|
||||
ElectronCrashReporterClient::~ElectronCrashReporterClient() {}
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
void ElectronCrashReporterClient::SetCrashReporterClientIdFromGUID(
|
||||
const std::string& client_guid) {
|
||||
crash_keys::SetMetricsClientIdFromGUID(client_guid);
|
||||
}
|
||||
void ElectronCrashReporterClient::GetProductNameAndVersion(
|
||||
const char** product_name,
|
||||
const char** version) {
|
||||
DCHECK(product_name);
|
||||
DCHECK(version);
|
||||
*product_name = ELECTRON_PRODUCT_NAME;
|
||||
*version = ELECTRON_VERSION_STRING;
|
||||
}
|
||||
|
||||
void ElectronCrashReporterClient::GetProductNameAndVersion(
|
||||
std::string* product_name,
|
||||
std::string* version,
|
||||
std::string* channel) {
|
||||
const char* c_product_name;
|
||||
const char* c_version;
|
||||
GetProductNameAndVersion(&c_product_name, &c_version);
|
||||
*product_name = c_product_name;
|
||||
*version = c_version;
|
||||
*channel = "";
|
||||
}
|
||||
|
||||
base::FilePath ElectronCrashReporterClient::GetReporterLogFilename() {
|
||||
return base::FilePath(CrashUploadList::kReporterLogFilename);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void ElectronCrashReporterClient::GetProductNameAndVersion(
|
||||
const base::string16& exe_path,
|
||||
base::string16* product_name,
|
||||
base::string16* version,
|
||||
base::string16* special_build,
|
||||
base::string16* channel_name) {
|
||||
*product_name = base::UTF8ToUTF16(ELECTRON_PRODUCT_NAME);
|
||||
*version = base::UTF8ToUTF16(ELECTRON_VERSION_STRING);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
bool ElectronCrashReporterClient::GetCrashDumpLocation(
|
||||
base::string16* crash_dir_str) {
|
||||
base::FilePath crash_dir;
|
||||
if (!base::PathService::Get(electron::DIR_CRASH_DUMPS, &crash_dir))
|
||||
return false;
|
||||
*crash_dir_str = crash_dir.value();
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool ElectronCrashReporterClient::GetCrashDumpLocation(
|
||||
base::FilePath* crash_dir) {
|
||||
return base::PathService::Get(electron::DIR_CRASH_DUMPS, crash_dir);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
||||
bool ElectronCrashReporterClient::GetCrashMetricsLocation(
|
||||
base::FilePath* metrics_dir) {
|
||||
return base::PathService::Get(electron::DIR_USER_DATA, metrics_dir);
|
||||
}
|
||||
#endif // OS_MACOSX || OS_LINUX
|
||||
|
||||
bool ElectronCrashReporterClient::IsRunningUnattended() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ElectronCrashReporterClient::GetCollectStatsConsent() {
|
||||
return collect_stats_consent_;
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool ElectronCrashReporterClient::ReportingIsEnforcedByPolicy(
|
||||
bool* breakpad_enabled) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ElectronCrashReporterClient::GetShouldRateLimit() {
|
||||
return rate_limit_;
|
||||
}
|
||||
|
||||
bool ElectronCrashReporterClient::GetShouldCompressUploads() {
|
||||
return compress_uploads_;
|
||||
}
|
||||
|
||||
void ElectronCrashReporterClient::GetProcessSimpleAnnotations(
|
||||
std::map<std::string, std::string>* annotations) {
|
||||
*annotations = global_annotations_;
|
||||
(*annotations)["prod"] = ELECTRON_PRODUCT_NAME;
|
||||
(*annotations)["ver"] = ELECTRON_VERSION_STRING;
|
||||
}
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_MACOSX)
|
||||
bool ElectronCrashReporterClient::ShouldMonitorCrashHandlerExpensively() {
|
||||
return false;
|
||||
}
|
||||
#endif // OS_LINUX
|
||||
|
||||
bool ElectronCrashReporterClient::GetUploadUrl(std::string* url) {
|
||||
*url = upload_url_;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ElectronCrashReporterClient::EnableBreakpadForProcess(
|
||||
const std::string& process_type) {
|
||||
return process_type == switches::kRendererProcess ||
|
||||
process_type == switches::kPpapiPluginProcess ||
|
||||
process_type == service_manager::switches::kZygoteProcess ||
|
||||
process_type == switches::kGpuProcess ||
|
||||
process_type == switches::kUtilityProcess || process_type == "node";
|
||||
}
|
||||
96
shell/app/electron_crash_reporter_client.h
Normal file
96
shell/app/electron_crash_reporter_client.h
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_APP_ELECTRON_CRASH_REPORTER_CLIENT_H_
|
||||
#define SHELL_APP_ELECTRON_CRASH_REPORTER_CLIENT_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "build/build_config.h"
|
||||
#include "components/crash/core/app/crash_reporter_client.h"
|
||||
|
||||
class ElectronCrashReporterClient : public crash_reporter::CrashReporterClient {
|
||||
public:
|
||||
static void Create();
|
||||
|
||||
static ElectronCrashReporterClient* Get();
|
||||
void SetCollectStatsConsent(bool upload_allowed);
|
||||
void SetUploadUrl(const std::string& url);
|
||||
void SetShouldRateLimit(bool rate_limit);
|
||||
void SetShouldCompressUploads(bool compress_uploads);
|
||||
void SetGlobalAnnotations(
|
||||
const std::map<std::string, std::string>& annotations);
|
||||
|
||||
// crash_reporter::CrashReporterClient implementation.
|
||||
#if defined(OS_LINUX)
|
||||
void SetCrashReporterClientIdFromGUID(
|
||||
const std::string& client_guid) override;
|
||||
void GetProductNameAndVersion(const char** product_name,
|
||||
const char** version) override;
|
||||
void GetProductNameAndVersion(std::string* product_name,
|
||||
std::string* version,
|
||||
std::string* channel) override;
|
||||
base::FilePath GetReporterLogFilename() override;
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void GetProductNameAndVersion(const base::string16& exe_path,
|
||||
base::string16* product_name,
|
||||
base::string16* version,
|
||||
base::string16* special_build,
|
||||
base::string16* channel_name) override;
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
bool GetCrashDumpLocation(base::string16* crash_dir) override;
|
||||
#else
|
||||
bool GetCrashDumpLocation(base::FilePath* crash_dir) override;
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
||||
bool GetCrashMetricsLocation(base::FilePath* metrics_dir) override;
|
||||
#endif
|
||||
|
||||
bool IsRunningUnattended() override;
|
||||
|
||||
bool GetCollectStatsConsent() override;
|
||||
|
||||
bool GetShouldRateLimit() override;
|
||||
bool GetShouldCompressUploads() override;
|
||||
|
||||
void GetProcessSimpleAnnotations(
|
||||
std::map<std::string, std::string>* annotations) override;
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled) override;
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
||||
bool ShouldMonitorCrashHandlerExpensively() override;
|
||||
#endif
|
||||
|
||||
bool EnableBreakpadForProcess(const std::string& process_type) override;
|
||||
|
||||
bool GetUploadUrl(std::string* url) override;
|
||||
|
||||
private:
|
||||
friend class base::NoDestructor<ElectronCrashReporterClient>;
|
||||
|
||||
std::string upload_url_;
|
||||
bool collect_stats_consent_;
|
||||
bool rate_limit_ = false;
|
||||
bool compress_uploads_ = false;
|
||||
std::map<std::string, std::string> global_annotations_;
|
||||
|
||||
ElectronCrashReporterClient();
|
||||
~ElectronCrashReporterClient() override;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ElectronCrashReporterClient);
|
||||
};
|
||||
|
||||
#endif // SHELL_APP_ELECTRON_CRASH_REPORTER_CLIENT_H_
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#if defined(OS_WIN)
|
||||
@@ -21,11 +23,15 @@
|
||||
#include "base/process/launch.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/win/windows_version.h"
|
||||
#include "components/browser_watcher/exit_code_watcher_win.h"
|
||||
#include "components/crash/core/app/crash_switches.h"
|
||||
#include "components/crash/core/app/run_as_crashpad_handler_win.h"
|
||||
#include "content/public/app/sandbox_helper_win.h"
|
||||
#include "sandbox/win/src/sandbox_types.h"
|
||||
#include "shell/app/command_line_args.h"
|
||||
#include "shell/app/electron_main_delegate.h"
|
||||
#include "shell/common/crash_reporter/win/crash_service_main.h"
|
||||
#include "third_party/crashpad/crashpad/util/win/initial_client_data.h"
|
||||
|
||||
#elif defined(OS_LINUX) // defined(OS_WIN)
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
@@ -51,6 +57,13 @@
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Redefined here so we don't have to introduce a dependency on //content
|
||||
// from //electron:electron_app
|
||||
const char kUserDataDir[] = "user-data-dir";
|
||||
const char kProcessType[] = "type";
|
||||
#endif
|
||||
|
||||
ALLOW_UNUSED_TYPE bool IsEnvSet(const char* name) {
|
||||
#if defined(OS_WIN)
|
||||
size_t required_size;
|
||||
@@ -138,10 +151,49 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||
#endif
|
||||
|
||||
base::CommandLine::Init(argv.size(), argv.data());
|
||||
const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
|
||||
if (cmd_line.GetSwitchValueASCII("type") ==
|
||||
crash_reporter::kCrashpadProcess) {
|
||||
return crash_service::Main(&argv);
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
|
||||
const std::string process_type =
|
||||
command_line->GetSwitchValueASCII(kProcessType);
|
||||
|
||||
if (process_type == crash_reporter::switches::kCrashpadHandler) {
|
||||
// Check if we should monitor the exit code of this process
|
||||
std::unique_ptr<browser_watcher::ExitCodeWatcher> exit_code_watcher;
|
||||
|
||||
// Retrieve the client process from the command line
|
||||
crashpad::InitialClientData initial_client_data;
|
||||
if (initial_client_data.InitializeFromString(
|
||||
command_line->GetSwitchValueASCII("initial-client-data"))) {
|
||||
// Setup exit code watcher to monitor the parent process
|
||||
HANDLE duplicate_handle = INVALID_HANDLE_VALUE;
|
||||
if (DuplicateHandle(
|
||||
::GetCurrentProcess(), initial_client_data.client_process(),
|
||||
::GetCurrentProcess(), &duplicate_handle,
|
||||
PROCESS_QUERY_INFORMATION, FALSE, DUPLICATE_SAME_ACCESS)) {
|
||||
base::Process parent_process(duplicate_handle);
|
||||
exit_code_watcher =
|
||||
std::make_unique<browser_watcher::ExitCodeWatcher>();
|
||||
if (exit_code_watcher->Initialize(std::move(parent_process))) {
|
||||
exit_code_watcher->StartWatching();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The handler process must always be passed the user data dir on the
|
||||
// command line.
|
||||
DCHECK(command_line->HasSwitch(kUserDataDir));
|
||||
|
||||
base::FilePath user_data_dir =
|
||||
command_line->GetSwitchValuePath(kUserDataDir);
|
||||
int crashpad_status = crash_reporter::RunAsCrashpadHandler(
|
||||
*command_line, user_data_dir, kProcessType, kUserDataDir);
|
||||
if (crashpad_status != 0 && exit_code_watcher) {
|
||||
// Crashpad failed to initialize, explicitly stop the exit code watcher
|
||||
// so the crashpad-handler process can exit with an error
|
||||
exit_code_watcher->StopWatching();
|
||||
}
|
||||
return crashpad_status;
|
||||
}
|
||||
|
||||
if (!electron::CheckCommandLineArguments(arguments.argc, arguments.argv))
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/debug/stack_trace.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "components/content_settings/core/common/content_settings_pattern.h"
|
||||
#include "components/crash/core/app/crashpad.h"
|
||||
#include "components/crash/core/common/crash_key.h"
|
||||
#include "components/crash/core/common/crash_keys.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "extensions/common/constants.h"
|
||||
@@ -28,10 +33,14 @@
|
||||
#include "services/service_manager/sandbox/switches.h"
|
||||
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
|
||||
#include "shell/app/electron_content_client.h"
|
||||
#include "shell/app/electron_crash_reporter_client.h"
|
||||
#include "shell/browser/api/electron_api_crash_reporter.h"
|
||||
#include "shell/browser/electron_browser_client.h"
|
||||
#include "shell/browser/electron_gpu_client.h"
|
||||
#include "shell/browser/feature_list.h"
|
||||
#include "shell/browser/relauncher.h"
|
||||
#include "shell/common/crash_keys.h"
|
||||
#include "shell/common/electron_paths.h"
|
||||
#include "shell/common/options_switches.h"
|
||||
#include "shell/renderer/electron_renderer_client.h"
|
||||
#include "shell/renderer/electron_sandboxed_renderer_client.h"
|
||||
@@ -46,9 +55,13 @@
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "base/win/win_util.h"
|
||||
#if defined(_WIN64)
|
||||
#include "shell/common/crash_reporter/crash_reporter_win.h"
|
||||
#include "chrome/child/v8_crashpad_support_win.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
#include "components/crash/core/app/breakpad_linux.h"
|
||||
#include "v8/include/v8-wasm-trap-handler-posix.h"
|
||||
#include "v8/include/v8.h"
|
||||
#endif
|
||||
|
||||
namespace electron {
|
||||
@@ -71,7 +84,7 @@ bool IsSandboxEnabled(base::CommandLine* command_line) {
|
||||
// and resources loaded.
|
||||
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
|
||||
return
|
||||
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
||||
#if defined(OS_LINUX)
|
||||
// The zygote process opens the resources for the renderers.
|
||||
process_type == service_manager::switches::kZygoteProcess ||
|
||||
#endif
|
||||
@@ -98,6 +111,41 @@ void InvalidParameterHandler(const wchar_t*,
|
||||
|
||||
} // namespace
|
||||
|
||||
// TODO(nornagon): move path provider overriding to its own file in
|
||||
// shell/common
|
||||
namespace electron {
|
||||
|
||||
bool GetDefaultCrashDumpsPath(base::FilePath* path) {
|
||||
base::FilePath cur;
|
||||
if (!base::PathService::Get(DIR_USER_DATA, &cur))
|
||||
return false;
|
||||
#if defined(OS_MACOSX) || defined(OS_WIN)
|
||||
cur = cur.Append(FILE_PATH_LITERAL("Crashpad"));
|
||||
#else
|
||||
cur = cur.Append(FILE_PATH_LITERAL("Crash Reports"));
|
||||
#endif
|
||||
// TODO(bauerb): http://crbug.com/259796
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
if (!base::PathExists(cur) && !base::CreateDirectory(cur))
|
||||
return false;
|
||||
*path = cur;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ElectronPathProvider(int key, base::FilePath* path) {
|
||||
if (key == DIR_CRASH_DUMPS) {
|
||||
return GetDefaultCrashDumpsPath(path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RegisterPathProvider() {
|
||||
base::PathService::RegisterProvider(ElectronPathProvider, PATH_START,
|
||||
PATH_END);
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
||||
void LoadResourceBundle(const std::string& locale) {
|
||||
const bool initialized = ui::ResourceBundle::HasSharedInstance();
|
||||
if (initialized)
|
||||
@@ -134,9 +182,7 @@ bool ElectronMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
|
||||
logging::LoggingSettings settings;
|
||||
#if defined(OS_WIN)
|
||||
#if defined(_WIN64)
|
||||
crash_reporter::CrashReporterWin::SetUnhandledExceptionFilter();
|
||||
#endif
|
||||
v8_crashpad_support::SetUp();
|
||||
|
||||
// On Windows the terminal returns immediately, so we add a new line to
|
||||
// prevent output in the same line as the prompt.
|
||||
@@ -185,6 +231,8 @@ bool ElectronMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
tracing::TracingSamplerProfiler::CreateOnMainThread();
|
||||
|
||||
chrome::RegisterPathProvider();
|
||||
electron::RegisterPathProvider();
|
||||
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
ContentSettingsPattern::SetNonWildcardDomainNonPortSchemes(
|
||||
kNonWildcardDomainNonPortSchemes, kNonWildcardDomainNonPortSchemesSize);
|
||||
@@ -272,6 +320,10 @@ void ElectronMainDelegate::PreSandboxStartup() {
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
||||
|
||||
#if !defined(MAS_BUILD)
|
||||
crash_reporter::InitializeCrashKeys();
|
||||
#endif
|
||||
|
||||
// Initialize ResourceBundle which handles files loaded from external
|
||||
// sources. The language should have been passed in to us from the
|
||||
// browser process as a command line flag.
|
||||
@@ -280,17 +332,40 @@ void ElectronMainDelegate::PreSandboxStartup() {
|
||||
LoadResourceBundle(locale);
|
||||
}
|
||||
|
||||
// Only append arguments for browser process.
|
||||
if (!IsBrowserProcess(command_line))
|
||||
return;
|
||||
#if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(MAS_BUILD))
|
||||
// In the main process, we wait for JS to call crashReporter.start() before
|
||||
// initializing crashpad. If we're in the renderer, we want to initialize it
|
||||
// immediately at boot.
|
||||
if (!process_type.empty()) {
|
||||
ElectronCrashReporterClient::Create();
|
||||
crash_reporter::InitializeCrashpad(false, process_type);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Allow file:// URIs to read other file:// URIs by default.
|
||||
command_line->AppendSwitch(::switches::kAllowFileAccessFromFiles);
|
||||
#if defined(OS_LINUX)
|
||||
if (process_type != service_manager::switches::kZygoteProcess &&
|
||||
!process_type.empty()) {
|
||||
ElectronCrashReporterClient::Create();
|
||||
breakpad::InitCrashReporter(process_type);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MAS_BUILD)
|
||||
crash_keys::SetCrashKeysFromCommandLine(*command_line);
|
||||
crash_keys::SetPlatformCrashKey();
|
||||
#endif
|
||||
|
||||
if (IsBrowserProcess(command_line)) {
|
||||
// Only append arguments for browser process.
|
||||
|
||||
// Allow file:// URIs to read other file:// URIs by default.
|
||||
command_line->AppendSwitch(::switches::kAllowFileAccessFromFiles);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// Enable AVFoundation.
|
||||
command_line->AppendSwitch("enable-avfoundation");
|
||||
// Enable AVFoundation.
|
||||
command_line->AppendSwitch("enable-avfoundation");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void ElectronMainDelegate::PreCreateMainMessageLoop() {
|
||||
@@ -350,4 +425,20 @@ bool ElectronMainDelegate::ShouldLockSchemeRegistry() {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
void ElectronMainDelegate::ZygoteForked() {
|
||||
// Needs to be called after we have DIR_USER_DATA. BrowserMain sets
|
||||
// this up for the browser process in a different manner.
|
||||
ElectronCrashReporterClient::Create();
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
||||
breakpad::InitCrashReporter(process_type);
|
||||
|
||||
// Reset the command line for the newly spawned process.
|
||||
crash_keys::SetCrashKeysFromCommandLine(*command_line);
|
||||
}
|
||||
#endif // defined(OS_LINUX)
|
||||
|
||||
} // namespace electron
|
||||
|
||||
@@ -41,6 +41,9 @@ class ElectronMainDelegate : public content::ContentMainDelegate {
|
||||
const content::MainFunctionParams& main_function_params) override;
|
||||
bool ShouldCreateFeatureList() override;
|
||||
bool ShouldLockSchemeRegistry() override;
|
||||
#if defined(OS_LINUX)
|
||||
void ZygoteForked() override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
|
||||
@@ -4,33 +4,43 @@
|
||||
|
||||
#include "shell/app/node_main.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/base_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/task/thread_pool/thread_pool_instance.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "components/crash/core/app/crashpad.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/electron_version.h"
|
||||
#include "gin/array_buffer.h"
|
||||
#include "gin/public/isolate_holder.h"
|
||||
#include "gin/v8_initializer.h"
|
||||
#include "shell/app/electron_crash_reporter_client.h"
|
||||
#include "shell/app/uv_task_runner.h"
|
||||
#include "shell/browser/api/electron_api_crash_reporter.h"
|
||||
#include "shell/browser/javascript_environment.h"
|
||||
#include "shell/browser/node_debugger.h"
|
||||
#include "shell/common/api/electron_bindings.h"
|
||||
#include "shell/common/crash_reporter/crash_reporter.h"
|
||||
#include "shell/common/crash_keys.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/node_bindings.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
|
||||
#if defined(_WIN64)
|
||||
#include "shell/common/crash_reporter/crash_reporter_win.h"
|
||||
#if defined(OS_LINUX)
|
||||
#include "components/crash/core/app/breakpad_linux.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "chrome/child/v8_crashpad_support_win.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
@@ -78,19 +88,64 @@ void SetNodeCliFlags() {
|
||||
|
||||
namespace electron {
|
||||
|
||||
#if !defined(OS_LINUX)
|
||||
void AddExtraParameter(const std::string& key, const std::string& value) {
|
||||
crash_reporter::CrashReporter::GetInstance()->AddExtraParameter(key, value);
|
||||
}
|
||||
#if defined(OS_LINUX)
|
||||
void CrashReporterStart(gin_helper::Dictionary options) {
|
||||
std::string submit_url;
|
||||
bool upload_to_server = true;
|
||||
bool ignore_system_crash_handler = false;
|
||||
bool rate_limit = false;
|
||||
bool compress = false;
|
||||
std::map<std::string, std::string> global_extra;
|
||||
std::map<std::string, std::string> extra;
|
||||
options.Get("submitURL", &submit_url);
|
||||
options.Get("uploadToServer", &upload_to_server);
|
||||
options.Get("ignoreSystemCrashHandler", &ignore_system_crash_handler);
|
||||
options.Get("rateLimit", &rate_limit);
|
||||
options.Get("compress", &compress);
|
||||
options.Get("extra", &extra);
|
||||
options.Get("globalExtra", &global_extra);
|
||||
|
||||
void RemoveExtraParameter(const std::string& key) {
|
||||
crash_reporter::CrashReporter::GetInstance()->RemoveExtraParameter(key);
|
||||
std::string product_name;
|
||||
if (options.Get("productName", &product_name))
|
||||
global_extra["_productName"] = product_name;
|
||||
std::string company_name;
|
||||
if (options.Get("companyName", &company_name))
|
||||
global_extra["_companyName"] = company_name;
|
||||
api::crash_reporter::Start(submit_url, upload_to_server,
|
||||
ignore_system_crash_handler, rate_limit, compress,
|
||||
global_extra, extra, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
v8::Local<v8::Value> GetParameters(v8::Isolate* isolate) {
|
||||
std::map<std::string, std::string> keys;
|
||||
#if !defined(MAS_BUILD)
|
||||
electron::crash_keys::GetCrashKeys(&keys);
|
||||
#endif
|
||||
return gin::ConvertToV8(isolate, keys);
|
||||
}
|
||||
|
||||
int NodeMain(int argc, char* argv[]) {
|
||||
base::CommandLine::Init(argc, argv);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
v8_crashpad_support::SetUp();
|
||||
#endif
|
||||
|
||||
#if !defined(MAS_BUILD)
|
||||
ElectronCrashReporterClient::Create();
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(MAS_BUILD))
|
||||
crash_reporter::InitializeCrashpad(false, "node");
|
||||
#endif
|
||||
|
||||
#if !defined(MAS_BUILD)
|
||||
crash_keys::SetCrashKeysFromCommandLine(
|
||||
*base::CommandLine::ForCurrentProcess());
|
||||
crash_keys::SetPlatformCrashKey();
|
||||
#endif
|
||||
|
||||
int exit_code = 1;
|
||||
{
|
||||
// Feed gin::PerIsolateData with a task runner.
|
||||
@@ -104,10 +159,6 @@ int NodeMain(int argc, char* argv[]) {
|
||||
feature_list->InitializeFromCommandLine("", "");
|
||||
base::FeatureList::SetInstance(std::move(feature_list));
|
||||
|
||||
#if defined(_WIN64)
|
||||
crash_reporter::CrashReporterWin::SetUnhandledExceptionFilter();
|
||||
#endif
|
||||
|
||||
// We do not want to double-set the error level and promise rejection
|
||||
// callback.
|
||||
node::g_standalone_mode = false;
|
||||
@@ -159,16 +210,18 @@ int NodeMain(int argc, char* argv[]) {
|
||||
#endif
|
||||
process.SetMethod("crash", &ElectronBindings::Crash);
|
||||
|
||||
// Setup process.crashReporter.start in child node processes
|
||||
// Setup process.crashReporter in child node processes
|
||||
gin_helper::Dictionary reporter = gin::Dictionary::CreateEmpty(isolate);
|
||||
reporter.SetMethod("start",
|
||||
&crash_reporter::CrashReporter::StartInstance);
|
||||
|
||||
#if !defined(OS_LINUX)
|
||||
reporter.SetMethod("addExtraParameter", &AddExtraParameter);
|
||||
reporter.SetMethod("removeExtraParameter", &RemoveExtraParameter);
|
||||
#if defined(OS_LINUX)
|
||||
reporter.SetMethod("start", &CrashReporterStart);
|
||||
#endif
|
||||
|
||||
reporter.SetMethod("getParameters", &GetParameters);
|
||||
reporter.SetMethod("addExtraParameter",
|
||||
&electron::crash_keys::SetCrashKey);
|
||||
reporter.SetMethod("removeExtraParameter",
|
||||
&electron::crash_keys::ClearCrashKey);
|
||||
|
||||
process.Set("crashReporter", reporter);
|
||||
|
||||
gin_helper::Dictionary versions;
|
||||
|
||||
Reference in New Issue
Block a user