2016-12-12 11:05:29 +01:00
|
|
|
// Copyright 2016 The Chromium Embedded Framework Authors. Portions copyright
|
|
|
|
// 2016 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.
|
2013-11-21 23:43:36 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/crash_reporter_client.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
|
2024-04-23 22:06:00 +02:00
|
|
|
#include <string_view>
|
2016-06-21 00:59:23 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2013-11-21 23:43:36 +01:00
|
|
|
|
2018-03-28 23:15:05 +02:00
|
|
|
#include "base/environment.h"
|
2013-11-21 23:43:36 +01:00
|
|
|
#include "base/logging.h"
|
2019-02-01 17:42:40 +01:00
|
|
|
#include "base/stl_util.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2013-11-21 23:43:36 +01:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2018-02-15 01:12:09 +01:00
|
|
|
#include "components/crash/core/common/crash_key.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2018-02-15 01:12:09 +01:00
|
|
|
#include "third_party/crashpad/crashpad/client/annotation.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/util_mac.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_POSIX)
|
2016-12-12 11:05:29 +01:00
|
|
|
// Don't use CommandLine, FilePath or PathService on Windows. FilePath has
|
|
|
|
// dependencies outside of kernel32, which is disallowed by chrome_elf.
|
|
|
|
// CommandLine and PathService depend on global state that will not be
|
|
|
|
// initialized at the time the CefCrashReporterClient object is created.
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/environment.h"
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/path_service.h"
|
|
|
|
#include "chrome/common/chrome_paths.h"
|
|
|
|
#endif
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/cef_crash_report_utils.h"
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
#include "base/debug/leak_annotations.h"
|
|
|
|
#include "chrome/install_static/install_util.h"
|
2020-04-14 21:31:00 +02:00
|
|
|
#include "components/crash/core/app/crashpad.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-12-06 21:40:25 +01:00
|
|
|
using PathString = std::wstring;
|
2016-12-12 11:05:29 +01:00
|
|
|
const char kPathSep = '\\';
|
|
|
|
#else
|
2021-12-06 21:40:25 +01:00
|
|
|
using PathString = std::string;
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
PathString GetCrashConfigPath() {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
// Start with the path to the running executable.
|
|
|
|
wchar_t module_path[MAX_PATH];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (GetModuleFileName(nullptr, module_path, MAX_PATH) == 0) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return PathString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
PathString config_path = module_path;
|
|
|
|
|
|
|
|
// Remove the executable file name.
|
|
|
|
PathString::size_type last_backslash =
|
|
|
|
config_path.rfind(kPathSep, config_path.size());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (last_backslash != PathString::npos) {
|
2016-12-12 11:05:29 +01:00
|
|
|
config_path.erase(last_backslash + 1);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
config_path += L"crash_reporter.cfg";
|
|
|
|
return config_path;
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_POSIX)
|
2016-12-12 11:05:29 +01:00
|
|
|
base::FilePath config_path;
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2017-01-27 01:14:56 +01:00
|
|
|
// Start with the path to the main app Resources directory. May be empty if
|
|
|
|
// not running in an app bundle.
|
|
|
|
config_path = util_mac::GetMainResourcesDirectory();
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
|
2017-01-27 01:14:56 +01:00
|
|
|
if (config_path.empty()) {
|
|
|
|
// Start with the path to the running executable.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!base::PathService::Get(base::DIR_EXE, &config_path)) {
|
2017-01-27 01:14:56 +01:00
|
|
|
return PathString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
return config_path.Append(FILE_PATH_LITERAL("crash_reporter.cfg")).value();
|
2022-01-24 18:58:02 +01:00
|
|
|
#endif // BUILDFLAG(IS_POSIX)
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-01-23 18:36:54 +01:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// On Windows, FAT32 and NTFS both limit filenames to a maximum of 255
|
|
|
|
// characters. On POSIX systems, the typical filename length limit is 255
|
|
|
|
// character units. HFS+'s limit is actually 255 Unicode characters using
|
|
|
|
// Apple's modification of Normalization Form D, but the differences aren't
|
|
|
|
// really worth dealing with here.
|
|
|
|
const unsigned maxFilenameLength = 255;
|
|
|
|
|
|
|
|
const char kInvalidFileChars[] = "<>:\"/\\|?*";
|
|
|
|
|
|
|
|
bool isInvalidFileCharacter(unsigned char c) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (c < ' ' || c == 0x7F) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2024-01-20 23:48:57 +01:00
|
|
|
for (char kInvalidFileChar : kInvalidFileChars) {
|
|
|
|
if (c == kInvalidFileChar) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAbsolutePath(const std::string& s) {
|
|
|
|
// Check for local paths (beginning with "c:\") and network paths
|
|
|
|
// (beginning with "\\").
|
|
|
|
return s.length() > 2 &&
|
|
|
|
((isalpha(s[0]) && s[1] == ':' && s[2] == kPathSep) ||
|
|
|
|
(s[0] == kPathSep && s[1] == kPathSep));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string extractAbsolutePathStart(std::string& s) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!isAbsolutePath(s)) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return std::string();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
std::string start;
|
|
|
|
if (s[0] == kPathSep) {
|
|
|
|
// Network path.
|
|
|
|
start = s.substr(0, 2);
|
|
|
|
s = s.substr(2);
|
|
|
|
} else {
|
|
|
|
// Local path.
|
|
|
|
start = s.substr(0, 3);
|
|
|
|
s = s.substr(3);
|
|
|
|
}
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string sanitizePathComponentPart(const std::string& s) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (s.empty()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return std::string();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
std::string result;
|
|
|
|
result.reserve(s.length());
|
2017-01-13 21:23:19 +01:00
|
|
|
for (size_t i = 0; i < s.length(); ++i) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!isInvalidFileCharacter(s[i])) {
|
2017-01-13 21:23:19 +01:00
|
|
|
result.push_back(s[i]);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-13 21:23:19 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string sanitizePathComponent(const std::string& s) {
|
|
|
|
std::string name, ext;
|
|
|
|
|
|
|
|
// Separate name and extension, if any.
|
|
|
|
std::string::size_type pos = s.rfind('.');
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
name = s.substr(0, pos);
|
|
|
|
ext = s.substr(pos + 1);
|
|
|
|
} else {
|
|
|
|
name = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove invalid characters.
|
|
|
|
name = sanitizePathComponentPart(name);
|
|
|
|
ext = sanitizePathComponentPart(ext);
|
|
|
|
|
|
|
|
// Remove a ridiculously-long extension.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (ext.length() >= maxFilenameLength) {
|
2016-12-12 11:05:29 +01:00
|
|
|
ext = std::string();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
// Truncate an overly-long filename, reserving one character for a dot.
|
|
|
|
std::string::size_type max_name_len = maxFilenameLength - ext.length() - 1;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (name.length() > max_name_len) {
|
2016-12-12 11:05:29 +01:00
|
|
|
name = name.substr(0, max_name_len);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
return ext.empty() ? name : name + "." + ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string sanitizePath(const std::string& s) {
|
|
|
|
std::string path = s;
|
|
|
|
|
|
|
|
// Extract the absolute path start component, if any (e.g. "c:\" on Windows).
|
|
|
|
std::string result = extractAbsolutePathStart(path);
|
|
|
|
result.reserve(s.length());
|
|
|
|
|
|
|
|
std::vector<std::string> parts =
|
|
|
|
base::SplitString(path, std::string() + kPathSep, base::KEEP_WHITESPACE,
|
|
|
|
base::SPLIT_WANT_NONEMPTY);
|
2024-01-20 23:48:57 +01:00
|
|
|
for (auto part : parts) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (part != "." && part != "..") {
|
2016-12-12 11:05:29 +01:00
|
|
|
part = sanitizePathComponent(part);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!result.empty() && result[result.length() - 1] != kPathSep) {
|
2016-12-12 11:05:29 +01:00
|
|
|
result += kPathSep;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
result += part;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string joinPath(const std::string& s1, const std::string& s2) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (s1.empty() && s2.empty()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return std::string();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (s1.empty()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return s2;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (s2.empty()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return s1;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
// Don't try to join absolute paths on Windows.
|
|
|
|
// Skip this check on POSIX where it's more difficult to differentiate.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (isAbsolutePath(s2)) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return s2;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
std::string result = s1;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (result[result.size() - 1] != kPathSep) {
|
2016-12-12 11:05:29 +01:00
|
|
|
result += kPathSep;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (s2[0] == kPathSep) {
|
2016-12-12 11:05:29 +01:00
|
|
|
result += s2.substr(1);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2016-12-12 11:05:29 +01:00
|
|
|
result += s2;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will only be non-nullptr in the chrome_elf address space.
|
|
|
|
CefCrashReporterClient* g_crash_reporter_client = nullptr;
|
2017-01-23 18:36:54 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
const char kKeyMapDelim = ',';
|
|
|
|
|
2024-04-23 22:06:00 +02:00
|
|
|
std::string NormalizeCrashKey(const std::string_view& key) {
|
2021-06-04 03:34:56 +02:00
|
|
|
std::string str(key);
|
2018-02-15 01:12:09 +01:00
|
|
|
std::replace(str.begin(), str.end(), kKeyMapDelim, '-');
|
|
|
|
if (str.length() > crashpad::Annotation::kNameMaxLength) {
|
|
|
|
return str.substr(0, crashpad::Annotation::kNameMaxLength);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:15:05 +02:00
|
|
|
void ParseURL(const std::string& value, std::string* url) {
|
|
|
|
if (value.find("http://") == 0 || value.find("https://") == 0) {
|
|
|
|
*url = value;
|
|
|
|
if (url->rfind('/') <= 8) {
|
|
|
|
// Make sure the URL includes a path component. Otherwise, crash
|
|
|
|
// upload will fail on older Windows versions due to
|
|
|
|
// https://crbug.com/826564.
|
|
|
|
*url += "/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParseBool(const std::string& value) {
|
|
|
|
return base::EqualsCaseInsensitiveASCII(value, "true") || value == "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
int ParseZeroBasedInt(const std::string& value) {
|
|
|
|
int int_val;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (base::StringToInt(value, &int_val) && int_val > 0) {
|
2018-03-28 23:15:05 +02:00
|
|
|
return int_val;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-03-28 23:15:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
} // namespace
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
// Export functions from chrome_elf that are required by crash_reporting.cc
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
int __declspec(dllexport) __cdecl SetCrashKeyValueImpl(const char* key,
|
|
|
|
size_t key_size,
|
|
|
|
const char* value,
|
|
|
|
size_t value_size) {
|
|
|
|
if (g_crash_reporter_client) {
|
|
|
|
return g_crash_reporter_client->SetCrashKeyValue(
|
2024-04-23 22:06:00 +02:00
|
|
|
std::string_view(key, key_size), std::string_view(value, value_size));
|
2018-02-15 01:12:09 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
int __declspec(dllexport) __cdecl IsCrashReportingEnabledImpl() {
|
|
|
|
return g_crash_reporter_client &&
|
|
|
|
g_crash_reporter_client->HasCrashConfigFile();
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
// The below functions were deleted from chrome/install_static/install_util.cc
|
|
|
|
// in https://crbug.com/565446#c17.
|
|
|
|
|
|
|
|
constexpr wchar_t kUserDataDirname[] = L"User Data";
|
|
|
|
|
|
|
|
// Populates |result| with the default User Data directory for the current
|
|
|
|
// user.This may be overidden by a command line option. Returns false if all
|
|
|
|
// attempts at locating a User Data directory fail.
|
2017-05-17 11:29:28 +02:00
|
|
|
bool GetDefaultUserDataDirectory(std::wstring* result,
|
|
|
|
const std::wstring& install_sub_directory) {
|
2017-01-23 18:36:54 +01:00
|
|
|
// This environment variable should be set on Windows Vista and later
|
|
|
|
// (https://msdn.microsoft.com/library/windows/desktop/dd378457.aspx).
|
|
|
|
std::wstring user_data_dir =
|
2021-03-04 23:36:57 +01:00
|
|
|
install_static::GetEnvironmentString(L"LOCALAPPDATA");
|
2017-01-23 18:36:54 +01:00
|
|
|
|
|
|
|
if (user_data_dir.empty()) {
|
|
|
|
// LOCALAPPDATA was not set; fallback to the temporary files path.
|
|
|
|
DWORD size = ::GetTempPath(0, nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!size) {
|
2017-01-23 18:36:54 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
user_data_dir.resize(size + 1);
|
|
|
|
size = ::GetTempPath(size + 1, &user_data_dir[0]);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!size || size >= user_data_dir.size()) {
|
2017-01-23 18:36:54 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
user_data_dir.resize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
result->swap(user_data_dir);
|
2023-01-02 23:59:03 +01:00
|
|
|
if ((*result)[result->length() - 1] != L'\\') {
|
2017-01-23 18:36:54 +01:00
|
|
|
result->push_back(L'\\');
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
result->append(install_sub_directory);
|
|
|
|
result->push_back(L'\\');
|
|
|
|
result->append(kUserDataDirname);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populates |crash_dir| with the default crash dump location regardless of
|
|
|
|
// whether DIR_USER_DATA or DIR_CRASH_DUMPS has been overridden.
|
2017-05-17 11:29:28 +02:00
|
|
|
bool GetDefaultCrashDumpLocation(std::wstring* crash_dir,
|
|
|
|
const std::wstring& install_sub_directory) {
|
2017-01-23 18:36:54 +01:00
|
|
|
// In order to be able to start crash handling very early, we do not rely on
|
|
|
|
// chrome's PathService entries (for DIR_CRASH_DUMPS) being available on
|
|
|
|
// Windows. See https://crbug.com/564398.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!GetDefaultUserDataDirectory(crash_dir, install_sub_directory)) {
|
2017-01-23 18:36:54 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
|
|
|
|
// We have to make sure the user data dir exists on first run. See
|
|
|
|
// http://crbug.com/591504.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!install_static::RecursiveDirectoryCreate(*crash_dir)) {
|
2017-01-23 18:36:54 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
crash_dir->append(L"\\Crashpad");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif // OS_WIN
|
2013-11-21 23:43:36 +01:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefCrashReporterClient::CefCrashReporterClient() = default;
|
|
|
|
CefCrashReporterClient::~CefCrashReporterClient() = default;
|
2013-11-21 23:43:36 +01:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// Be aware that logging is not initialized at the time this method is called.
|
|
|
|
bool CefCrashReporterClient::ReadCrashConfigFile() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (has_crash_config_file_) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
PathString config_path = GetCrashConfigPath();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (config_path.empty()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
FILE* fp = _wfopen(config_path.c_str(), L"r");
|
|
|
|
#else
|
|
|
|
FILE* fp = fopen(config_path.c_str(), "r");
|
|
|
|
#endif
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!fp) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
char line[1000];
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
size_t small_index = 0;
|
|
|
|
size_t medium_index = 0;
|
|
|
|
size_t large_index = 0;
|
|
|
|
std::string map_keys;
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
enum section {
|
|
|
|
kNoSection,
|
|
|
|
kConfigSection,
|
|
|
|
kCrashKeysSection,
|
|
|
|
} current_section = kNoSection;
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
while (fgets(line, sizeof(line) - 1, fp) != nullptr) {
|
2016-12-12 11:05:29 +01:00
|
|
|
std::string str = line;
|
|
|
|
base::TrimString(str, base::kWhitespaceASCII, &str);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (str.empty() || str[0] == '#') {
|
2016-12-12 11:05:29 +01:00
|
|
|
continue;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
if (str == "[Config]") {
|
|
|
|
current_section = kConfigSection;
|
|
|
|
continue;
|
|
|
|
} else if (str == "[CrashKeys]") {
|
|
|
|
current_section = kCrashKeysSection;
|
|
|
|
continue;
|
|
|
|
} else if (str[0] == '[') {
|
|
|
|
current_section = kNoSection;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (current_section == kNoSection) {
|
2016-12-12 11:05:29 +01:00
|
|
|
continue;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
size_t div = str.find('=');
|
2023-01-02 23:59:03 +01:00
|
|
|
if (div == std::string::npos) {
|
2016-12-12 11:05:29 +01:00
|
|
|
continue;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
std::string name_str = str.substr(0, div);
|
|
|
|
base::TrimString(name_str, base::kWhitespaceASCII, &name_str);
|
|
|
|
std::string val_str = str.substr(div + 1);
|
|
|
|
base::TrimString(val_str, base::kWhitespaceASCII, &val_str);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (name_str.empty()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
continue;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
if (current_section == kConfigSection) {
|
|
|
|
if (name_str == "ServerURL") {
|
2018-03-28 23:15:05 +02:00
|
|
|
ParseURL(val_str, &server_url_);
|
2017-01-12 17:44:35 +01:00
|
|
|
} else if (name_str == "ProductName") {
|
|
|
|
product_name_ = val_str;
|
|
|
|
} else if (name_str == "ProductVersion") {
|
|
|
|
product_version_ = val_str;
|
2016-12-12 11:05:29 +01:00
|
|
|
} else if (name_str == "RateLimitEnabled") {
|
2018-03-28 23:15:05 +02:00
|
|
|
rate_limit_ = ParseBool(val_str);
|
2016-12-12 11:05:29 +01:00
|
|
|
} else if (name_str == "MaxUploadsPerDay") {
|
2018-03-28 23:15:05 +02:00
|
|
|
max_uploads_ = ParseZeroBasedInt(val_str);
|
2016-12-12 11:05:29 +01:00
|
|
|
} else if (name_str == "MaxDatabaseSizeInMb") {
|
2018-03-28 23:15:05 +02:00
|
|
|
max_db_size_ = ParseZeroBasedInt(val_str);
|
2016-12-12 11:05:29 +01:00
|
|
|
} else if (name_str == "MaxDatabaseAgeInDays") {
|
2018-03-28 23:15:05 +02:00
|
|
|
max_db_age_ = ParseZeroBasedInt(val_str);
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
else if (name_str == "ExternalHandler") {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!val_str.empty()) {
|
2017-01-12 17:44:35 +01:00
|
|
|
external_handler_ = sanitizePath(val_str);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
} else if (name_str == "AppName") {
|
2017-01-23 18:36:54 +01:00
|
|
|
if (!val_str.empty()) {
|
|
|
|
val_str = sanitizePathComponent(val_str);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!val_str.empty()) {
|
2017-01-23 18:36:54 +01:00
|
|
|
app_name_ = val_str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2017-02-06 20:23:59 +01:00
|
|
|
else if (name_str == "BrowserCrashForwardingEnabled") {
|
2018-03-28 23:15:05 +02:00
|
|
|
enable_browser_crash_forwarding_ = ParseBool(val_str);
|
2017-02-06 20:23:59 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
#endif
|
|
|
|
} else if (current_section == kCrashKeysSection) {
|
2018-02-15 01:12:09 +01:00
|
|
|
// Skip duplicate definitions.
|
|
|
|
if (!crash_keys_.empty() &&
|
|
|
|
crash_keys_.find(name_str) != crash_keys_.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeySize size;
|
|
|
|
size_t index;
|
|
|
|
char group;
|
|
|
|
if (val_str == "small") {
|
|
|
|
size = SMALL_SIZE;
|
|
|
|
index = small_index++;
|
|
|
|
group = 'S';
|
|
|
|
} else if (val_str == "medium") {
|
|
|
|
size = MEDIUM_SIZE;
|
|
|
|
index = medium_index++;
|
|
|
|
group = 'M';
|
|
|
|
} else if (val_str == "large") {
|
|
|
|
size = LARGE_SIZE;
|
|
|
|
index = large_index++;
|
|
|
|
group = 'L';
|
|
|
|
} else {
|
2016-12-12 11:05:29 +01:00
|
|
|
continue;
|
2018-02-15 01:12:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
name_str = NormalizeCrashKey(name_str);
|
|
|
|
crash_keys_.insert(std::make_pair(name_str, std::make_pair(size, index)));
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
const std::string& key =
|
|
|
|
std::string(1, group) + "-" + std::string(1, 'A' + index);
|
|
|
|
if (!map_keys.empty()) {
|
|
|
|
map_keys.append(std::string(1, kKeyMapDelim));
|
|
|
|
}
|
|
|
|
map_keys.append(key + "=" + name_str);
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
if (!map_keys.empty()) {
|
|
|
|
// Split |map_keys| across multiple Annotations if necessary.
|
|
|
|
// Must match the logic in crash_report_utils::FilterParameters.
|
|
|
|
using IDKey =
|
|
|
|
crash_reporter::CrashKeyString<crashpad::Annotation::kValueMaxSize>;
|
|
|
|
static IDKey ids[] = {
|
|
|
|
{"K-A", IDKey::Tag::kArray},
|
|
|
|
{"K-B", IDKey::Tag::kArray},
|
|
|
|
{"K-C", IDKey::Tag::kArray},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure we can fit all possible name/value pairs.
|
2022-03-26 02:12:30 +01:00
|
|
|
static_assert(std::size(ids) * crashpad::Annotation::kValueMaxSize >=
|
2018-02-15 01:12:09 +01:00
|
|
|
3 * 26 /* sizes (small, medium, large) * slots (A to Z) */
|
|
|
|
* (3 + 2 /* key size ("S-A") + delim size ("=,") */
|
|
|
|
+ crashpad::Annotation::kNameMaxLength),
|
|
|
|
"Not enough storage for key map");
|
|
|
|
|
|
|
|
size_t offset = 0;
|
2024-01-20 23:48:57 +01:00
|
|
|
for (auto& id : ids) {
|
2018-02-15 01:12:09 +01:00
|
|
|
size_t length = std::min(map_keys.size() - offset,
|
|
|
|
crashpad::Annotation::kValueMaxSize);
|
2024-04-23 22:06:00 +02:00
|
|
|
id.Set(std::string_view(map_keys.data() + offset, length));
|
2018-02-15 01:12:09 +01:00
|
|
|
offset += length;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (offset >= map_keys.size()) {
|
2018-02-15 01:12:09 +01:00
|
|
|
break;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:15:05 +02:00
|
|
|
// Allow override of some values via environment variables.
|
|
|
|
{
|
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
std::string val_str;
|
|
|
|
|
|
|
|
if (env->GetVar("CEF_CRASH_REPORTER_SERVER_URL", &val_str)) {
|
|
|
|
ParseURL(val_str, &server_url_);
|
|
|
|
}
|
|
|
|
if (env->GetVar("CEF_CRASH_REPORTER_RATE_LIMIT_ENABLED", &val_str)) {
|
|
|
|
rate_limit_ = ParseBool(val_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
has_crash_config_file_ = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::HasCrashConfigFile() const {
|
|
|
|
return has_crash_config_file_;
|
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
void CefCrashReporterClient::InitializeCrashReportingForProcess() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (g_crash_reporter_client) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
g_crash_reporter_client = new CefCrashReporterClient();
|
|
|
|
ANNOTATE_LEAKING_OBJECT_PTR(g_crash_reporter_client);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!g_crash_reporter_client->ReadCrashConfigFile()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
std::wstring process_type = install_static::GetSwitchValueFromCommandLine(
|
|
|
|
::GetCommandLineW(), install_static::kProcessType);
|
2016-12-12 11:05:29 +01:00
|
|
|
if (process_type != install_static::kCrashpadHandler) {
|
|
|
|
crash_reporter::SetCrashReporterClient(g_crash_reporter_client);
|
|
|
|
|
|
|
|
// If |embedded_handler| is true then we launch another instance of the main
|
|
|
|
// executable as the crashpad-handler process.
|
|
|
|
const bool embedded_handler =
|
|
|
|
!g_crash_reporter_client->HasCrashExternalHandler();
|
|
|
|
if (embedded_handler) {
|
|
|
|
crash_reporter::InitializeCrashpadWithEmbeddedHandler(
|
2021-03-04 23:36:57 +01:00
|
|
|
process_type.empty(), install_static::WideToUTF8(process_type),
|
2018-04-19 17:44:42 +02:00
|
|
|
std::string(), base::FilePath());
|
2016-12-12 11:05:29 +01:00
|
|
|
} else {
|
2017-01-23 18:36:54 +01:00
|
|
|
crash_reporter::InitializeCrashpad(
|
2021-03-04 23:36:57 +01:00
|
|
|
process_type.empty(), install_static::WideToUTF8(process_type));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetAlternativeCrashDumpLocation(
|
2021-04-21 00:52:34 +02:00
|
|
|
std::wstring* crash_dir) {
|
2016-12-12 11:05:29 +01:00
|
|
|
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
|
|
|
|
// location to write breakpad crash dumps can be set.
|
2021-03-04 23:36:57 +01:00
|
|
|
*crash_dir = install_static::GetEnvironmentString(L"BREAKPAD_DUMP_LOCATION");
|
2016-12-12 11:05:29 +01:00
|
|
|
return !crash_dir->empty();
|
|
|
|
}
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
void CefCrashReporterClient::GetProductNameAndVersion(
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::wstring& exe_path,
|
|
|
|
std::wstring* product_name,
|
|
|
|
std::wstring* version,
|
|
|
|
std::wstring* special_build,
|
|
|
|
std::wstring* channel_name) {
|
|
|
|
*product_name = base::ASCIIToWide(product_name_);
|
|
|
|
*version = base::ASCIIToWide(product_version_);
|
|
|
|
*special_build = std::wstring();
|
|
|
|
*channel_name = std::wstring();
|
2013-11-21 23:43:36 +01:00
|
|
|
}
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
bool CefCrashReporterClient::GetCrashDumpLocation(std::wstring* crash_dir) {
|
2016-12-12 11:05:29 +01:00
|
|
|
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
|
|
|
|
// location to write breakpad crash dumps can be set.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (GetAlternativeCrashDumpLocation(crash_dir)) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
return GetDefaultCrashDumpLocation(crash_dir, base::UTF8ToWide(app_name_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetCrashMetricsLocation(
|
2021-04-21 00:52:34 +02:00
|
|
|
std::wstring* metrics_dir) {
|
|
|
|
return GetDefaultUserDataDirectory(metrics_dir, base::UTF8ToWide(app_name_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#elif BUILDFLAG(IS_POSIX)
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefCrashReporterClient::GetProductNameAndVersion(const char** product_name,
|
|
|
|
const char** version) {
|
2017-01-12 17:44:35 +01:00
|
|
|
*product_name = product_name_.c_str();
|
|
|
|
*version = product_version_.c_str();
|
2013-11-21 23:43:36 +01:00
|
|
|
}
|
|
|
|
|
2018-05-21 14:54:08 +02:00
|
|
|
void CefCrashReporterClient::GetProductNameAndVersion(std::string* product_name,
|
|
|
|
std::string* version,
|
|
|
|
std::string* channel) {
|
|
|
|
*product_name = product_name_;
|
|
|
|
*version = product_version_;
|
|
|
|
}
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
bool CefCrashReporterClient::GetCrashDumpLocation(base::FilePath* crash_dir) {
|
2016-12-12 11:05:29 +01:00
|
|
|
// By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
|
|
|
|
// location to write breakpad crash dumps can be set.
|
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
std::string alternate_crash_dump_location;
|
|
|
|
if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) {
|
|
|
|
base::FilePath crash_dumps_dir_path =
|
|
|
|
base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
|
2018-05-14 13:24:05 +02:00
|
|
|
base::PathService::Override(chrome::DIR_CRASH_DUMPS, crash_dumps_dir_path);
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
2018-05-14 13:24:05 +02:00
|
|
|
return base::PathService::Get(chrome::DIR_CRASH_DUMPS, crash_dir);
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#endif // !BUILDFLAG(IS_POSIX)
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetCollectStatsConsent() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::GetCollectStatsInSample() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::ReportingIsEnforcedByPolicy(
|
|
|
|
bool* crashpad_enabled) {
|
|
|
|
*crashpad_enabled = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-09 19:48:00 +02:00
|
|
|
std::string CefCrashReporterClient::GetUploadUrl() {
|
2016-12-12 11:05:29 +01:00
|
|
|
return server_url_;
|
2016-04-27 22:38:52 +02:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
// See HandlerMain() in third_party/crashpad/crashpad/handler/handler_main.cc
|
|
|
|
// for supported arguments.
|
|
|
|
void CefCrashReporterClient::GetCrashOptionalArguments(
|
|
|
|
std::vector<std::string>* arguments) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!rate_limit_) {
|
2024-01-20 23:48:57 +01:00
|
|
|
arguments->emplace_back("--no-rate-limit");
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
|
|
|
|
if (max_uploads_ > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
arguments->push_back(std::string("--max-uploads=") +
|
2019-06-05 16:15:45 +02:00
|
|
|
base::NumberToString(max_uploads_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max_db_size_ > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
arguments->push_back(std::string("--max-db-size=") +
|
2019-06-05 16:15:45 +02:00
|
|
|
base::NumberToString(max_db_size_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max_db_age_ > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
arguments->push_back(std::string("--max-db-age=") +
|
2019-06-05 16:15:45 +02:00
|
|
|
base::NumberToString(max_db_age_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2021-03-04 23:36:57 +01:00
|
|
|
std::wstring CefCrashReporterClient::GetCrashExternalHandler(
|
|
|
|
const std::wstring& exe_dir) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (external_handler_.empty()) {
|
2016-12-12 11:05:29 +01:00
|
|
|
return CrashReporterClient::GetCrashExternalHandler(exe_dir);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (isAbsolutePath(external_handler_)) {
|
2021-03-04 23:36:57 +01:00
|
|
|
return base::UTF8ToWide(external_handler_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-12-12 11:05:29 +01:00
|
|
|
return base::UTF8ToWide(
|
2021-03-04 23:36:57 +01:00
|
|
|
joinPath(base::WideToUTF8(exe_dir), external_handler_));
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefCrashReporterClient::HasCrashExternalHandler() const {
|
|
|
|
return !external_handler_.empty();
|
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2017-02-06 20:23:59 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2017-02-06 20:23:59 +01:00
|
|
|
bool CefCrashReporterClient::EnableBrowserCrashForwarding() {
|
|
|
|
return enable_browser_crash_forwarding_;
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-15 01:12:09 +01:00
|
|
|
|
|
|
|
// The new Crashpad Annotation API requires that annotations be declared using
|
|
|
|
// static storage. We work around this limitation by defining a fixed amount of
|
|
|
|
// storage for each key size and later substituting the actual key name during
|
|
|
|
// crash dump processing.
|
|
|
|
|
|
|
|
#define IDKEY(name) \
|
|
|
|
{ name, IDKey::Tag::kArray }
|
|
|
|
|
|
|
|
#define IDKEY_ENTRIES(n) \
|
|
|
|
IDKEY(n "-A"), IDKEY(n "-B"), IDKEY(n "-C"), IDKEY(n "-D"), IDKEY(n "-E"), \
|
|
|
|
IDKEY(n "-F"), IDKEY(n "-G"), IDKEY(n "-H"), IDKEY(n "-I"), \
|
|
|
|
IDKEY(n "-J"), IDKEY(n "-K"), IDKEY(n "-L"), IDKEY(n "-M"), \
|
|
|
|
IDKEY(n "-N"), IDKEY(n "-O"), IDKEY(n "-P"), IDKEY(n "-Q"), \
|
|
|
|
IDKEY(n "-R"), IDKEY(n "-S"), IDKEY(n "-T"), IDKEY(n "-U"), \
|
|
|
|
IDKEY(n "-V"), IDKEY(n "-W"), IDKEY(n "-X"), IDKEY(n "-Y"), \
|
|
|
|
IDKEY(n "-Z")
|
|
|
|
|
2024-04-23 22:06:00 +02:00
|
|
|
#define IDKEY_FUNCTION(name, size_) \
|
|
|
|
static_assert(size_ <= crashpad::Annotation::kValueMaxSize, \
|
|
|
|
"Annotation size is too large."); \
|
|
|
|
bool Set##name##Annotation(size_t index, const std::string_view& value) { \
|
|
|
|
using IDKey = crash_reporter::CrashKeyString<size_>; \
|
|
|
|
static IDKey ids[] = {IDKEY_ENTRIES(#name)}; \
|
|
|
|
if (index < std::size(ids)) { \
|
|
|
|
if (value.empty()) { \
|
|
|
|
ids[index].Clear(); \
|
|
|
|
} else { \
|
|
|
|
ids[index].Set(value); \
|
|
|
|
} \
|
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
return false; \
|
2018-02-15 01:12:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The first argument must be kept synchronized with the logic in
|
|
|
|
// CefCrashReporterClient::ReadCrashConfigFile and
|
|
|
|
// crash_report_utils::FilterParameters.
|
|
|
|
IDKEY_FUNCTION(S, 64)
|
|
|
|
IDKEY_FUNCTION(M, 256)
|
|
|
|
IDKEY_FUNCTION(L, 1024)
|
|
|
|
|
2024-04-23 22:06:00 +02:00
|
|
|
bool CefCrashReporterClient::SetCrashKeyValue(const std::string_view& key,
|
|
|
|
const std::string_view& value) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (key.empty() || crash_keys_.empty()) {
|
2018-02-15 01:12:09 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-02-15 01:12:09 +01:00
|
|
|
|
|
|
|
KeyMap::const_iterator it = crash_keys_.find(NormalizeCrashKey(key));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it == crash_keys_.end()) {
|
2018-02-15 01:12:09 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-02-15 01:12:09 +01:00
|
|
|
|
|
|
|
const KeySize size = it->second.first;
|
|
|
|
const size_t index = it->second.second;
|
|
|
|
|
|
|
|
base::AutoLock lock_scope(crash_key_lock_);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case SMALL_SIZE:
|
|
|
|
return SetSAnnotation(index, value);
|
|
|
|
case MEDIUM_SIZE:
|
|
|
|
return SetMAnnotation(index, value);
|
|
|
|
case LARGE_SIZE:
|
|
|
|
return SetLAnnotation(index, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|