Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use crashpad on Windows (6-0-x) #18766

Merged
merged 1 commit into from Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 18 additions & 17 deletions BUILD.gn
Expand Up @@ -546,21 +546,13 @@ static_library("electron_lib") {
if (is_mac) {
deps += [
"//components/remote_cocoa/app_shim",
"//third_party/crashpad/crashpad/client",
"//ui/accelerated_widget_mac",
]
sources += [
"atom/browser/ui/views/autofill_popup_view.cc",
"atom/browser/ui/views/autofill_popup_view.h",
]
include_dirs += [
# NOTE(nornagon): other chromium files use the full path to include
# crashpad; this is just here for compatibility between GN and GYP, so that
# the #includes can be agnostic about where crashpad is vendored.
"//third_party/crashpad",
]
if (is_mas_build) {
deps -= [ "//third_party/crashpad/crashpad/client" ]
sources += [ "atom/browser/api/atom_api_app_mas.mm" ]
sources -= [
"atom/browser/auto_updater_mac.mm",
Expand Down Expand Up @@ -590,10 +582,14 @@ static_library("electron_lib") {
"//chrome/browser/ui/libgtkui",
"//dbus",
"//device/bluetooth",
"//third_party/breakpad:client",
"//ui/events/devices/x11",
"//ui/events/platform/x11",
"//ui/views/controls/webview",
"//ui/wm",
]
configs += [ ":gio_unix" ]
include_dirs += [ "//third_party/breakpad" ]
defines += [
# Disable warnings for g_settings_list_schemas.
"GLIB_DISABLE_DEPRECATION_WARNINGS",
Expand All @@ -604,20 +600,23 @@ static_library("electron_lib") {
if (is_win) {
libs += [ "dwmapi.lib" ]
deps += [
"//third_party/breakpad:breakpad_handler",
"//third_party/breakpad:breakpad_sender",
"//ui/native_theme:native_theme_browser",
"//ui/views/controls/webview",
"//ui/wm",
"//ui/wm/public",
]
public_deps += [ "//sandbox/win:sandbox" ]
public_deps += [
"//sandbox/win:sandbox",
"//third_party/crashpad/crashpad/handler",
]
}
if (is_linux || is_win) {
deps += [
"//third_party/breakpad:client",
"//ui/views/controls/webview",
"//ui/wm",

if ((is_mac && !is_mas_build) || is_win) {
sources += [
"atom/common/crash_reporter/crash_reporter_crashpad.cc",
"atom/common/crash_reporter/crash_reporter_crashpad.h",
]
include_dirs += [ "//third_party/breakpad" ]
deps += [ "//third_party/crashpad/crashpad/client" ]
}

if (enable_pdf) {
Expand Down Expand Up @@ -844,6 +843,7 @@ if (is_mac) {
}
defines = [ "HELPER_EXECUTABLE" ]
sources = filenames.app_sources
sources += [ "atom/common/atom_constants.cc" ]
include_dirs = [ "." ]
info_plist = "atom/renderer/resources/mac/Info.plist"
extra_substitutions = [ "ATOM_BUNDLE_ID=$electron_mac_bundle_id.helper" ]
Expand Down Expand Up @@ -951,6 +951,7 @@ if (is_mac) {
mac_app_bundle("electron_app") {
output_name = electron_product_name
sources = filenames.app_sources
sources += [ "atom/common/atom_constants.cc" ]
include_dirs = [ "." ]
deps = [
":electron_app_framework_bundle_data",
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Expand Up @@ -12,7 +12,7 @@ vars = {
'chromium_version':
'76.0.3809.23',
'node_version':
'dee0db9864a001ffc16440f725f4952a1a417069',
'229bd3245b2f54c12ea9ad0abcadbc209f8023dc',
MarshallOfSound marked this conversation as resolved.
Show resolved Hide resolved

'boto_version': 'f7574aa6cc2c819430c1f05e9a1a1a666ef8169b',
'pyyaml_version': '3.12',
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Expand Up @@ -28,7 +28,6 @@ build_cloud: libcc-20
image: libcc-20-vs2017-15.9
environment:
GIT_CACHE_PATH: C:\Users\electron\libcc_cache
DISABLE_CRASH_REPORTER_TESTS: true
ELECTRON_OUT_DIR: Default
ELECTRON_ENABLE_STACK_DUMPING: 1
build_script:
Expand Down
32 changes: 18 additions & 14 deletions atom/app/atom_main.cc
Expand Up @@ -4,6 +4,7 @@

#include "atom/app/atom_main.h"

#include <algorithm>
#include <cstdlib>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -39,6 +40,7 @@

#include "atom/app/node_main.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/atom_constants.h"
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "electron/buildflags/buildflags.h"
Expand All @@ -49,10 +51,6 @@

namespace {

#if BUILDFLAG(ENABLE_RUN_AS_NODE)
const char kRunAsNode[] = "ELECTRON_RUN_AS_NODE";
#endif

ALLOW_UNUSED_TYPE bool IsEnvSet(const char* name) {
#if defined(OS_WIN)
size_t required_size;
Expand Down Expand Up @@ -86,6 +84,11 @@ void FixStdioStreams() {
} // namespace

#if defined(OS_WIN)

namespace crash_reporter {
extern const char kCrashpadProcess[];
}

int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
struct Arguments {
int argc = 0;
Expand Down Expand Up @@ -122,7 +125,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
#endif

#if BUILDFLAG(ENABLE_RUN_AS_NODE)
bool run_as_node = IsEnvSet(kRunAsNode);
bool run_as_node = IsEnvSet(atom::kRunAsNode);
#else
bool run_as_node = false;
#endif
Expand All @@ -148,13 +151,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
atexit([]() { OnThreadExit(nullptr, DLL_THREAD_DETACH, nullptr); });
#endif

std::vector<char*> argv(arguments.argc);
std::transform(arguments.argv, arguments.argv + arguments.argc, argv.begin(),
[](auto& a) { return _strdup(base::WideToUTF8(a).c_str()); });
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (run_as_node) {
std::vector<char*> argv(arguments.argc);
std::transform(
arguments.argv, arguments.argv + arguments.argc, argv.begin(),
[](auto& a) { return _strdup(base::WideToUTF8(a).c_str()); });

base::AtExitManager atexit_manager;
base::i18n::InitializeICU();
auto ret = atom::NodeMain(argv.size(), argv.data());
Expand All @@ -163,8 +164,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
}
#endif

if (IsEnvSet("ELECTRON_INTERNAL_CRASH_SERVICE")) {
return crash_service::Main(cmd);
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);
}

if (!atom::CheckCommandLineArguments(arguments.argc, arguments.argv))
Expand All @@ -187,7 +191,7 @@ int main(int argc, char* argv[]) {
FixStdioStreams();

#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (IsEnvSet(kRunAsNode)) {
if (IsEnvSet(atom::kRunAsNode)) {
base::i18n::InitializeICU();
base::AtExitManager atexit_manager;
return atom::NodeMain(argc, argv);
Expand All @@ -208,7 +212,7 @@ int main(int argc, char* argv[]) {
FixStdioStreams();

#if BUILDFLAG(ENABLE_RUN_AS_NODE)
if (IsEnvSet(kRunAsNode)) {
if (IsEnvSet(atom::kRunAsNode)) {
return AtomInitializeICUandStartNode(argc, argv);
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions atom/app/atom_main_delegate.cc
Expand Up @@ -49,6 +49,9 @@

#if defined(OS_WIN)
#include "base/win/win_util.h"
#if defined(_WIN64)
#include "atom/common/crash_reporter/crash_reporter_win.h"
#endif
#endif

namespace atom {
Expand Down Expand Up @@ -133,6 +136,10 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {

logging::LoggingSettings settings;
#if defined(OS_WIN)
#if defined(_WIN64)
crash_reporter::CrashReporterWin::SetUnhandledExceptionFilter();
#endif

// On Windows the terminal returns immediately, so we add a new line to
// prevent output in the same line as the prompt.
if (IsBrowserProcess(command_line))
Expand Down
7 changes: 7 additions & 0 deletions atom/app/node_main.cc
Expand Up @@ -25,6 +25,10 @@
#include "gin/v8_initializer.h"
#include "native_mate/dictionary.h"

#if defined(_WIN64)
#include "atom/common/crash_reporter/crash_reporter_win.h"
#endif

namespace atom {

int NodeMain(int argc, char* argv[]) {
Expand Down Expand Up @@ -52,6 +56,9 @@ int NodeMain(int argc, char* argv[]) {

// Initialize gin::IsolateHolder.
JavascriptEnvironment gin_env(loop);
#if defined(_WIN64)
crash_reporter::CrashReporterWin::SetUnhandledExceptionFilter();
#endif

// Explicitly register electron's builtin modules.
NodeBindings::RegisterBuiltinModules();
Expand Down
16 changes: 16 additions & 0 deletions atom/browser/atom_browser_client.cc
Expand Up @@ -80,6 +80,10 @@
#include "ui/base/resource/resource_bundle.h"
#include "v8/include/v8.h"

#if defined(OS_WIN)
#include "sandbox/win/src/sandbox_policy.h"
#endif

#if defined(USE_NSS_CERTS)
#include "net/ssl/client_cert_store_nss.h"
#elif defined(OS_WIN)
Expand Down Expand Up @@ -907,6 +911,18 @@ void AtomBrowserClient::SetUserAgent(const std::string& user_agent) {
user_agent_override_ = user_agent;
}

#if defined(OS_WIN)
bool AtomBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy) {
// Allow crashpad to communicate via named pipe.
sandbox::ResultCode result = policy->AddRule(
sandbox::TargetPolicy::SUBSYS_FILES,
sandbox::TargetPolicy::FILES_ALLOW_ANY, L"\\??\\pipe\\crashpad_*");
if (result != sandbox::SBOX_ALL_OK)
return false;
return true;
}
#endif // defined(OS_WIN)

std::string AtomBrowserClient::GetApplicationLocale() {
if (BrowserThread::CurrentlyOn(BrowserThread::IO))
return g_io_thread_application_locale.Get();
Expand Down
3 changes: 3 additions & 0 deletions atom/browser/atom_browser_client.h
Expand Up @@ -162,6 +162,9 @@ class AtomBrowserClient : public content::ContentBrowserClient,
network::mojom::NetworkService* network_service) override;
bool ShouldBypassCORB(int render_process_id) const override;
std::string GetProduct() const override;
#if defined(OS_WIN)
bool PreSpawnRenderer(sandbox::TargetPolicy* policy) override;
#endif

// content::RenderProcessHostObserver:
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/ui/inspectable_web_contents.h
Expand Up @@ -25,6 +25,8 @@ namespace atom {
class InspectableWebContentsDelegate;
class InspectableWebContentsView;

// TODO(zcbenz): Remove this abstract wrapper and rename
// InspectableWebContentsImpl to InspectableWebContents instead.
class InspectableWebContents {
public:
// The returned InspectableWebContents takes ownership of the passed-in
Expand Down
15 changes: 13 additions & 2 deletions atom/browser/ui/inspectable_web_contents_impl.cc
Expand Up @@ -3,11 +3,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.

#include "atom/browser/ui/inspectable_web_contents_impl.h"

#include <memory>
#include <utility>

#include "atom/browser/ui/inspectable_web_contents_impl.h"

#include "atom/browser/ui/inspectable_web_contents_delegate.h"
#include "atom/browser/ui/inspectable_web_contents_view.h"
#include "atom/browser/ui/inspectable_web_contents_view_delegate.h"
Expand Down Expand Up @@ -75,6 +75,9 @@ const char kTitleFormat[] = "Developer Tools - %s";

const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;

// Stores all instances of InspectableWebContentsImpl.
InspectableWebContentsImpl::List g_web_contents_instances_;

base::Value RectToDictionary(const gfx::Rect& bounds) {
base::Value dict(base::Value::Type::DICTIONARY);
dict.SetKey("x", base::Value(bounds.x()));
Expand Down Expand Up @@ -227,6 +230,12 @@ class InspectableWebContentsImpl::NetworkResourceLoader
InspectableWebContentsView* CreateInspectableContentsView(
InspectableWebContentsImpl* inspectable_web_contents_impl);

// static
const InspectableWebContentsImpl::List& InspectableWebContentsImpl::GetAll() {
return g_web_contents_instances_;
}

// static
void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(kDevToolsBoundsPref,
RectToDictionary(gfx::Rect(0, 0, 800, 600)));
Expand Down Expand Up @@ -270,9 +279,11 @@ InspectableWebContentsImpl::InspectableWebContentsImpl(
display.y() + (display.height() - devtools_bounds_.height()) / 2);
}
}
g_web_contents_instances_.push_back(this);
}

InspectableWebContentsImpl::~InspectableWebContentsImpl() {
g_web_contents_instances_.remove(this);
// Unsubscribe from devtools and Clean up resources.
if (GetDevToolsWebContents()) {
if (managed_devtools_web_contents_)
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/ui/inspectable_web_contents_impl.h
Expand Up @@ -6,6 +6,7 @@
#ifndef ATOM_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_IMPL_H_
#define ATOM_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_IMPL_H_

#include <list>
#include <map>
#include <memory>
#include <set>
Expand Down Expand Up @@ -38,6 +39,9 @@ class InspectableWebContentsImpl
public content::WebContentsDelegate,
public DevToolsEmbedderMessageDispatcher::Delegate {
public:
using List = std::list<InspectableWebContentsImpl*>;

static const List& GetAll();
static void RegisterPrefs(PrefRegistrySimple* pref_registry);

InspectableWebContentsImpl(content::WebContents* web_contents,
Expand Down
2 changes: 2 additions & 0 deletions atom/common/api/api.mojom
Expand Up @@ -10,6 +10,8 @@ interface ElectronRenderer {
mojo_base.mojom.ListValue arguments,
int32 sender_id);

UpdateCrashpadPipeName(string pipe_name);

TakeHeapSnapshot(handle file) => (bool success);
};

Expand Down
8 changes: 8 additions & 0 deletions atom/common/atom_constants.cc
Expand Up @@ -27,6 +27,14 @@ const char kSecureProtocolDescription[] =
"The connection to this site is using a strong protocol version "
"and cipher suite.";

#if defined(OS_WIN)
const char kCrashpadPipeName[] = "ELECTRON_CRASHPAD_PIPE_NAME";
#endif

#if BUILDFLAG(ENABLE_RUN_AS_NODE)
const char kRunAsNode[] = "ELECTRON_RUN_AS_NODE";
#endif

#if BUILDFLAG(ENABLE_PDF_VIEWER)
const char kPdfPluginMimeType[] = "application/x-google-chrome-pdf";
const char kPdfPluginPath[] = "chrome://pdf-viewer/";
Expand Down