2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 01:46:58 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/app/electron_main_delegate.h"
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2015-10-10 03:39:02 +00:00
|
|
|
#include <iostream>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2016-08-26 22:30:02 +00:00
|
|
|
#include <string>
|
2021-11-24 08:45:59 +00:00
|
|
|
#include <utility>
|
2014-03-16 01:13:06 +00:00
|
|
|
|
2021-06-15 00:32:56 +00:00
|
|
|
#include "base/base_switches.h"
|
2013-04-20 03:19:25 +00:00
|
|
|
#include "base/command_line.h"
|
2022-02-11 01:43:14 +00:00
|
|
|
#include "base/debug/stack_trace.h"
|
2014-10-08 10:27:39 +00:00
|
|
|
#include "base/environment.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "base/files/file_util.h"
|
2013-07-08 03:09:53 +00:00
|
|
|
#include "base/logging.h"
|
2018-10-23 12:16:13 +00:00
|
|
|
#include "base/mac/bundle_locations.h"
|
|
|
|
#include "base/path_service.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "base/strings/string_split.h"
|
2015-11-13 05:05:16 +00:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2021-06-15 00:32:56 +00:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "components/content_settings/core/common/content_settings_pattern.h"
|
2022-10-03 20:21:00 +00:00
|
|
|
#include "content/public/app/initialize_mojo_core.h"
|
2013-04-20 03:19:25 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2018-10-23 12:16:13 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2022-09-15 20:21:16 +00:00
|
|
|
#include "electron/fuses.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "extensions/common/constants.h"
|
2018-07-21 12:30:16 +00:00
|
|
|
#include "ipc/ipc_buildflags.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "sandbox/policy/switches.h"
|
2019-11-22 02:05:41 +00:00
|
|
|
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
|
2021-09-03 21:16:33 +00:00
|
|
|
#include "shell/app/command_line_args.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/app/electron_content_client.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"
|
2021-06-15 00:32:56 +00:00
|
|
|
#include "shell/common/application_info.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "shell/common/electron_paths.h"
|
2021-06-17 21:17:25 +00:00
|
|
|
#include "shell/common/logging.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2021-06-15 00:32:56 +00:00
|
|
|
#include "shell/common/platform_util.h"
|
2022-11-17 19:59:23 +00:00
|
|
|
#include "shell/common/thread_restrictions.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/renderer/electron_renderer_client.h"
|
|
|
|
#include "shell/renderer/electron_sandboxed_renderer_client.h"
|
|
|
|
#include "shell/utility/electron_content_utility_client.h"
|
2022-07-13 21:26:16 +00:00
|
|
|
#include "third_party/abseil-cpp/absl/types/variant.h"
|
2014-07-16 07:05:02 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2018-10-23 12:16:13 +00:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
2013-09-12 07:42:36 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/app/electron_main_delegate_mac.h"
|
2018-10-03 20:49:18 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-05-14 22:42:39 +00:00
|
|
|
#include "base/win/win_util.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "chrome/child/v8_crashpad_support_win.h"
|
2019-06-13 06:42:21 +00:00
|
|
|
#endif
|
2020-05-07 20:31:26 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2021-06-15 00:32:56 +00:00
|
|
|
#include "base/nix/xdg_util.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "v8/include/v8-wasm-trap-handler-posix.h"
|
|
|
|
#include "v8/include/v8.h"
|
2019-05-14 22:42:39 +00:00
|
|
|
#endif
|
|
|
|
|
2022-11-14 20:46:52 +00:00
|
|
|
#if !IS_MAS_BUILD()
|
2021-07-19 17:11:10 +00:00
|
|
|
#include "components/crash/core/app/crash_switches.h" // nogncheck
|
|
|
|
#include "components/crash/core/app/crashpad.h" // nogncheck
|
2020-06-16 21:19:57 +00:00
|
|
|
#include "components/crash/core/common/crash_key.h"
|
|
|
|
#include "components/crash/core/common/crash_keys.h"
|
|
|
|
#include "shell/app/electron_crash_reporter_client.h"
|
|
|
|
#include "shell/browser/api/electron_api_crash_reporter.h"
|
|
|
|
#include "shell/common/crash_keys.h"
|
|
|
|
#endif
|
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2015-10-15 04:44:55 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-07-02 00:51:52 +00:00
|
|
|
const char kRelauncherProcess[] = "relauncher";
|
2016-06-01 09:22:14 +00:00
|
|
|
|
2021-06-17 21:17:25 +00:00
|
|
|
constexpr base::StringPiece kElectronDisableSandbox("ELECTRON_DISABLE_SANDBOX");
|
|
|
|
constexpr base::StringPiece kElectronEnableStackDumping(
|
|
|
|
"ELECTRON_ENABLE_STACK_DUMPING");
|
|
|
|
|
2015-10-15 04:44:55 +00:00
|
|
|
bool IsBrowserProcess(base::CommandLine* cmd) {
|
2016-08-15 10:59:08 +00:00
|
|
|
std::string process_type = cmd->GetSwitchValueASCII(::switches::kProcessType);
|
2015-10-15 04:44:55 +00:00
|
|
|
return process_type.empty();
|
|
|
|
}
|
|
|
|
|
2018-10-23 12:16:13 +00:00
|
|
|
// Returns true if this subprocess type needs the ResourceBundle initialized
|
|
|
|
// and resources loaded.
|
|
|
|
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
|
|
|
|
return
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2018-10-23 12:16:13 +00:00
|
|
|
// The zygote process opens the resources for the renderers.
|
2020-10-16 01:30:41 +00:00
|
|
|
process_type == ::switches::kZygoteProcess ||
|
2018-10-23 12:16:13 +00:00
|
|
|
#endif
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-10-23 12:16:13 +00:00
|
|
|
// Mac needs them too for scrollbar related images and for sandbox
|
|
|
|
// profiles.
|
|
|
|
process_type == ::switches::kGpuProcess ||
|
|
|
|
#endif
|
2021-06-22 03:46:53 +00:00
|
|
|
process_type == ::switches::kPpapiPluginProcess ||
|
2018-10-23 12:16:13 +00:00
|
|
|
process_type == ::switches::kRendererProcess ||
|
|
|
|
process_type == ::switches::kUtilityProcess;
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-04-18 01:55:30 +00:00
|
|
|
void InvalidParameterHandler(const wchar_t*,
|
|
|
|
const wchar_t*,
|
|
|
|
const wchar_t*,
|
|
|
|
unsigned int,
|
|
|
|
uintptr_t) {
|
2016-05-25 04:45:25 +00:00
|
|
|
// noop.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
// TODO(nornagon): move path provider overriding to its own file in
|
|
|
|
// shell/common
|
2021-06-15 00:32:56 +00:00
|
|
|
bool ElectronPathProvider(int key, base::FilePath* result) {
|
|
|
|
bool create_dir = false;
|
2020-05-07 20:31:26 +00:00
|
|
|
base::FilePath cur;
|
2021-06-15 00:32:56 +00:00
|
|
|
switch (key) {
|
|
|
|
case chrome::DIR_USER_DATA:
|
|
|
|
if (!base::PathService::Get(DIR_APP_DATA, &cur))
|
|
|
|
return false;
|
2021-07-14 20:10:37 +00:00
|
|
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe(
|
|
|
|
GetPossiblyOverriddenApplicationName()));
|
2021-06-15 00:32:56 +00:00
|
|
|
create_dir = true;
|
|
|
|
break;
|
|
|
|
case DIR_CRASH_DUMPS:
|
|
|
|
if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur))
|
|
|
|
return false;
|
|
|
|
cur = cur.Append(FILE_PATH_LITERAL("Crashpad"));
|
|
|
|
create_dir = true;
|
|
|
|
break;
|
|
|
|
case chrome::DIR_APP_DICTIONARIES:
|
|
|
|
// TODO(nornagon): can we just default to using Chrome's logic here?
|
2022-05-09 14:26:57 +00:00
|
|
|
if (!base::PathService::Get(DIR_SESSION_DATA, &cur))
|
2021-06-15 00:32:56 +00:00
|
|
|
return false;
|
|
|
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe("Dictionaries"));
|
|
|
|
create_dir = true;
|
|
|
|
break;
|
2022-05-09 14:26:57 +00:00
|
|
|
case DIR_SESSION_DATA:
|
|
|
|
// By default and for backward, equivalent to DIR_USER_DATA.
|
|
|
|
return base::PathService::Get(chrome::DIR_USER_DATA, result);
|
2021-06-15 00:32:56 +00:00
|
|
|
case DIR_USER_CACHE: {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_POSIX)
|
2021-06-15 00:32:56 +00:00
|
|
|
int parent_key = base::DIR_CACHE;
|
2020-05-07 20:31:26 +00:00
|
|
|
#else
|
2021-06-15 00:32:56 +00:00
|
|
|
// On Windows, there's no OS-level centralized location for caches, so
|
|
|
|
// store the cache in the app data directory.
|
2021-11-24 08:45:59 +00:00
|
|
|
int parent_key = base::DIR_ROAMING_APP_DATA;
|
2020-05-07 20:31:26 +00:00
|
|
|
#endif
|
2021-06-15 00:32:56 +00:00
|
|
|
if (!base::PathService::Get(parent_key, &cur))
|
|
|
|
return false;
|
2021-07-14 20:10:37 +00:00
|
|
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe(
|
|
|
|
GetPossiblyOverriddenApplicationName()));
|
2021-06-15 00:32:56 +00:00
|
|
|
create_dir = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2021-06-15 00:32:56 +00:00
|
|
|
case DIR_APP_DATA: {
|
|
|
|
auto env = base::Environment::Create();
|
|
|
|
cur = base::nix::GetXDGDirectory(
|
|
|
|
env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-06-15 00:32:56 +00:00
|
|
|
case DIR_RECENT:
|
|
|
|
if (!platform_util::GetFolderPath(DIR_RECENT, &cur))
|
|
|
|
return false;
|
|
|
|
create_dir = true;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case DIR_APP_LOGS:
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2021-06-15 00:32:56 +00:00
|
|
|
if (!base::PathService::Get(base::DIR_HOME, &cur))
|
|
|
|
return false;
|
|
|
|
cur = cur.Append(FILE_PATH_LITERAL("Library"));
|
|
|
|
cur = cur.Append(FILE_PATH_LITERAL("Logs"));
|
2021-07-14 20:10:37 +00:00
|
|
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe(
|
|
|
|
GetPossiblyOverriddenApplicationName()));
|
2021-06-15 00:32:56 +00:00
|
|
|
#else
|
|
|
|
if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur))
|
|
|
|
return false;
|
|
|
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe("logs"));
|
|
|
|
#endif
|
|
|
|
create_dir = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
// TODO(bauerb): http://crbug.com/259796
|
2022-11-17 19:59:23 +00:00
|
|
|
ScopedAllowBlockingForElectron allow_blocking;
|
2021-06-15 00:32:56 +00:00
|
|
|
if (create_dir && !base::PathExists(cur) && !base::CreateDirectory(cur)) {
|
2020-05-07 20:31:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-06-15 00:32:56 +00:00
|
|
|
|
|
|
|
*result = cur;
|
|
|
|
|
|
|
|
return true;
|
2020-05-07 20:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterPathProvider() {
|
|
|
|
base::PathService::RegisterProvider(ElectronPathProvider, PATH_START,
|
|
|
|
PATH_END);
|
|
|
|
}
|
|
|
|
|
2020-10-28 16:18:47 +00:00
|
|
|
} // namespace
|
2020-05-07 20:31:26 +00:00
|
|
|
|
2020-10-28 16:18:47 +00:00
|
|
|
std::string LoadResourceBundle(const std::string& locale) {
|
2018-10-23 12:16:13 +00:00
|
|
|
const bool initialized = ui::ResourceBundle::HasSharedInstance();
|
2020-10-28 16:18:47 +00:00
|
|
|
DCHECK(!initialized);
|
2018-10-23 12:16:13 +00:00
|
|
|
|
|
|
|
// Load other resource files.
|
|
|
|
base::FilePath pak_dir;
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-10-23 12:16:13 +00:00
|
|
|
pak_dir =
|
|
|
|
base::mac::FrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
|
|
|
#else
|
|
|
|
base::PathService::Get(base::DIR_MODULE, &pak_dir);
|
|
|
|
#endif
|
|
|
|
|
2020-10-28 16:18:47 +00:00
|
|
|
std::string loaded_locale = ui::ResourceBundle::InitSharedInstanceWithLocale(
|
2018-10-23 12:16:13 +00:00
|
|
|
locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
|
|
|
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
|
|
|
bundle.AddDataPackFromPath(pak_dir.Append(FILE_PATH_LITERAL("resources.pak")),
|
2021-08-24 00:52:17 +00:00
|
|
|
ui::kScaleFactorNone);
|
2020-10-28 16:18:47 +00:00
|
|
|
return loaded_locale;
|
2018-10-23 12:16:13 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ElectronMainDelegate::ElectronMainDelegate() = default;
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ElectronMainDelegate::~ElectronMainDelegate() = default;
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
const char* const ElectronMainDelegate::kNonWildcardDomainNonPortSchemes[] = {
|
|
|
|
extensions::kExtensionScheme};
|
|
|
|
const size_t ElectronMainDelegate::kNonWildcardDomainNonPortSchemesSize =
|
2022-03-25 01:39:03 +00:00
|
|
|
std::size(kNonWildcardDomainNonPortSchemes);
|
2020-01-13 22:55:58 +00:00
|
|
|
|
2022-08-17 18:35:53 +00:00
|
|
|
absl::optional<int> ElectronMainDelegate::BasicStartupComplete() {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2015-10-15 04:44:55 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-05-07 20:31:26 +00:00
|
|
|
v8_crashpad_support::SetUp();
|
2019-06-13 06:42:21 +00:00
|
|
|
|
2015-10-10 03:39:02 +00:00
|
|
|
// On Windows the terminal returns immediately, so we add a new line to
|
|
|
|
// prevent output in the same line as the prompt.
|
2015-10-15 04:44:55 +00:00
|
|
|
if (IsBrowserProcess(command_line))
|
|
|
|
std::wcout << std::endl;
|
2022-02-10 02:58:52 +00:00
|
|
|
#endif // !BUILDFLAG(IS_WIN)
|
2015-10-03 07:33:55 +00:00
|
|
|
|
2018-06-18 07:32:55 +00:00
|
|
|
auto env = base::Environment::Create();
|
2013-12-23 14:04:49 +00:00
|
|
|
|
2022-05-17 16:48:40 +00:00
|
|
|
gin_helper::Locker::SetIsBrowserProcess(IsBrowserProcess(command_line));
|
|
|
|
|
2020-10-13 17:25:21 +00:00
|
|
|
// Enable convenient stack printing. This is enabled by default in
|
|
|
|
// non-official builds.
|
2021-06-17 21:17:25 +00:00
|
|
|
if (env->HasVar(kElectronEnableStackDumping))
|
2015-10-20 05:02:48 +00:00
|
|
|
base::debug::EnableInProcessStackDumping();
|
2014-02-19 11:07:52 +00:00
|
|
|
|
2021-06-17 21:17:25 +00:00
|
|
|
if (env->HasVar(kElectronDisableSandbox))
|
2020-07-14 01:13:34 +00:00
|
|
|
command_line->AppendSwitch(sandbox::policy::switches::kNoSandbox);
|
2019-01-29 06:30:17 +00:00
|
|
|
|
2019-11-22 02:05:41 +00:00
|
|
|
tracing_sampler_profiler_ =
|
|
|
|
tracing::TracingSamplerProfiler::CreateOnMainThread();
|
|
|
|
|
2015-11-13 05:05:16 +00:00
|
|
|
chrome::RegisterPathProvider();
|
2020-05-07 20:31:26 +00:00
|
|
|
electron::RegisterPathProvider();
|
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
ContentSettingsPattern::SetNonWildcardDomainNonPortSchemes(
|
|
|
|
kNonWildcardDomainNonPortSchemes, kNonWildcardDomainNonPortSchemesSize);
|
|
|
|
#endif
|
2015-11-13 05:05:16 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-10-23 12:16:13 +00:00
|
|
|
OverrideChildProcessPath();
|
|
|
|
OverrideFrameworkBundlePath();
|
2016-05-18 07:42:26 +00:00
|
|
|
SetUpBundleOverrides();
|
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-05-25 04:45:25 +00:00
|
|
|
// Ignore invalid parameter errors.
|
|
|
|
_set_invalid_parameter_handler(InvalidParameterHandler);
|
2017-02-14 08:23:20 +00:00
|
|
|
// Disable the ActiveVerifier, which is used by Chrome to track possible
|
|
|
|
// bugs, but no use in Electron.
|
|
|
|
base::win::DisableHandleVerifier();
|
2019-05-14 22:42:39 +00:00
|
|
|
|
|
|
|
if (IsBrowserProcess(command_line))
|
|
|
|
base::win::PinUser32();
|
2016-05-25 04:45:25 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2019-07-15 14:38:41 +00:00
|
|
|
// Check for --no-sandbox parameter when running as root.
|
|
|
|
if (getuid() == 0 && IsSandboxEnabled(command_line))
|
|
|
|
LOG(FATAL) << "Running as root without --"
|
2020-07-14 01:13:34 +00:00
|
|
|
<< sandbox::policy::switches::kNoSandbox
|
2019-07-15 14:38:41 +00:00
|
|
|
<< " is not supported. See https://crbug.com/638180.";
|
|
|
|
#endif
|
|
|
|
|
2022-11-14 20:46:52 +00:00
|
|
|
#if IS_MAS_BUILD()
|
2020-02-24 03:08:57 +00:00
|
|
|
// In MAS build we are using --disable-remote-core-animation.
|
|
|
|
//
|
|
|
|
// According to ccameron:
|
|
|
|
// If you're running with --disable-remote-core-animation, you may want to
|
|
|
|
// also run with --disable-gpu-memory-buffer-compositor-resources as well.
|
|
|
|
// That flag makes it so we use regular GL textures instead of IOSurfaces
|
|
|
|
// for compositor resources. IOSurfaces are very heavyweight to
|
|
|
|
// create/destroy, but they can be displayed directly by CoreAnimation (and
|
|
|
|
// --disable-remote-core-animation makes it so we don't use this property,
|
|
|
|
// so they're just heavyweight with no upside).
|
|
|
|
command_line->AppendSwitch(
|
|
|
|
::switches::kDisableGpuMemoryBufferCompositorResources);
|
|
|
|
#endif
|
|
|
|
|
2022-08-17 18:35:53 +00:00
|
|
|
return absl::nullopt;
|
2013-07-08 03:09:53 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 03:19:25 +00:00
|
|
|
void ElectronMainDelegate::PreSandboxStartup() {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2014-01-30 13:06:56 +00:00
|
|
|
|
2018-10-23 12:16:13 +00:00
|
|
|
std::string process_type =
|
|
|
|
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
|
|
|
2021-06-15 00:32:56 +00:00
|
|
|
base::FilePath user_data_dir =
|
|
|
|
command_line->GetSwitchValuePath(::switches::kUserDataDir);
|
|
|
|
if (!user_data_dir.empty()) {
|
|
|
|
base::PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
|
|
|
|
user_data_dir, false, true);
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if !BUILDFLAG(IS_WIN)
|
2021-06-17 21:17:25 +00:00
|
|
|
// For windows we call InitLogging later, after the sandbox is initialized.
|
|
|
|
//
|
|
|
|
// On Linux, we force a "preinit" in the zygote (i.e. never log to a default
|
|
|
|
// log file), because the zygote is booted prior to JS running, so it can't
|
|
|
|
// know the correct user-data directory. (And, further, accessing the
|
|
|
|
// application name on Linux can cause glib calls that end up spawning
|
|
|
|
// threads, which if done before the zygote is booted, causes a CHECK().)
|
|
|
|
logging::InitElectronLogging(*command_line,
|
|
|
|
/* is_preinit = */ process_type.empty() ||
|
|
|
|
process_type == ::switches::kZygoteProcess);
|
|
|
|
#endif
|
|
|
|
|
2022-11-14 20:46:52 +00:00
|
|
|
#if !IS_MAS_BUILD()
|
2020-05-07 20:31:26 +00:00
|
|
|
crash_reporter::InitializeCrashKeys();
|
|
|
|
#endif
|
|
|
|
|
2018-10-23 12:16:13 +00:00
|
|
|
// 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.
|
|
|
|
if (SubprocessNeedsResourceBundle(process_type)) {
|
|
|
|
std::string locale = command_line->GetSwitchValueASCII(::switches::kLang);
|
|
|
|
LoadResourceBundle(locale);
|
|
|
|
}
|
|
|
|
|
2022-11-14 20:46:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_MAC) && !IS_MAS_BUILD())
|
2020-05-07 20:31:26 +00:00
|
|
|
// 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
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2021-07-19 17:11:10 +00:00
|
|
|
// Zygote needs to call InitCrashReporter() in RunZygote().
|
2020-10-16 01:30:41 +00:00
|
|
|
if (process_type != ::switches::kZygoteProcess && !process_type.empty()) {
|
2020-05-07 20:31:26 +00:00
|
|
|
ElectronCrashReporterClient::Create();
|
2022-10-17 14:22:24 +00:00
|
|
|
if (command_line->HasSwitch(
|
|
|
|
crash_reporter::switches::kCrashpadHandlerPid)) {
|
|
|
|
crash_reporter::InitializeCrashpad(false, process_type);
|
|
|
|
crash_reporter::SetFirstChanceExceptionHandler(
|
|
|
|
v8::TryHandleWebAssemblyTrapPosix);
|
2021-07-19 17:11:10 +00:00
|
|
|
}
|
2020-05-07 20:31:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-14 20:46:52 +00:00
|
|
|
#if !IS_MAS_BUILD()
|
2020-05-07 20:31:26 +00:00
|
|
|
crash_keys::SetCrashKeysFromCommandLine(*command_line);
|
|
|
|
crash_keys::SetPlatformCrashKey();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (IsBrowserProcess(command_line)) {
|
|
|
|
// Only append arguments for browser process.
|
2017-06-09 06:39:53 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
// Allow file:// URIs to read other file:// URIs by default.
|
|
|
|
command_line->AppendSwitch(::switches::kAllowFileAccessFromFiles);
|
2015-05-12 12:51:48 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-05-07 20:31:26 +00:00
|
|
|
// Enable AVFoundation.
|
|
|
|
command_line->AppendSwitch("enable-avfoundation");
|
2014-10-08 10:17:27 +00:00
|
|
|
#endif
|
2020-05-07 20:31:26 +00:00
|
|
|
}
|
2013-04-20 03:19:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 21:17:25 +00:00
|
|
|
void ElectronMainDelegate::SandboxInitialized(const std::string& process_type) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-06-17 21:17:25 +00:00
|
|
|
logging::InitElectronLogging(*base::CommandLine::ForCurrentProcess(),
|
|
|
|
/* is_preinit = */ process_type.empty());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:35:53 +00:00
|
|
|
absl::optional<int> ElectronMainDelegate::PreBrowserMain() {
|
2019-04-23 22:18:12 +00:00
|
|
|
// This is initialized early because the service manager reads some feature
|
|
|
|
// flags and we need to make sure the feature list is initialized before the
|
|
|
|
// service manager reads the features.
|
|
|
|
InitializeFeatureList();
|
2022-10-03 20:21:00 +00:00
|
|
|
// Initialize mojo core as soon as we have a valid feature list
|
|
|
|
content::InitializeMojoCore();
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-10-03 20:49:18 +00:00
|
|
|
RegisterAtomCrApp();
|
|
|
|
#endif
|
2022-08-17 18:35:53 +00:00
|
|
|
return absl::nullopt;
|
2018-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2022-09-15 20:21:16 +00:00
|
|
|
base::StringPiece ElectronMainDelegate::GetBrowserV8SnapshotFilename() {
|
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
std::string process_type =
|
|
|
|
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
|
|
bool load_browser_process_specific_v8_snapshot =
|
|
|
|
process_type.empty() &&
|
|
|
|
electron::fuses::IsLoadBrowserProcessSpecificV8SnapshotEnabled();
|
|
|
|
if (load_browser_process_specific_v8_snapshot) {
|
|
|
|
return "browser_v8_context_snapshot.bin";
|
|
|
|
}
|
|
|
|
return ContentMainDelegate::GetBrowserV8SnapshotFilename();
|
|
|
|
}
|
|
|
|
|
2022-10-10 14:48:44 +00:00
|
|
|
content::ContentClient* ElectronMainDelegate::CreateContentClient() {
|
|
|
|
content_client_ = std::make_unique<ElectronContentClient>();
|
|
|
|
return content_client_.get();
|
|
|
|
}
|
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
content::ContentBrowserClient*
|
|
|
|
ElectronMainDelegate::CreateContentBrowserClient() {
|
2019-09-16 22:12:00 +00:00
|
|
|
browser_client_ = std::make_unique<ElectronBrowserClient>();
|
2013-04-12 01:46:58 +00:00
|
|
|
return browser_client_.get();
|
|
|
|
}
|
|
|
|
|
2019-04-30 16:45:48 +00:00
|
|
|
content::ContentGpuClient* ElectronMainDelegate::CreateContentGpuClient() {
|
2019-09-16 22:12:00 +00:00
|
|
|
gpu_client_ = std::make_unique<ElectronGpuClient>();
|
2019-04-30 16:45:48 +00:00
|
|
|
return gpu_client_.get();
|
|
|
|
}
|
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
content::ContentRendererClient*
|
2018-04-18 01:55:30 +00:00
|
|
|
ElectronMainDelegate::CreateContentRendererClient() {
|
2019-06-20 10:10:56 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
if (IsSandboxEnabled(command_line)) {
|
2019-09-16 22:12:00 +00:00
|
|
|
renderer_client_ = std::make_unique<ElectronSandboxedRendererClient>();
|
2016-08-15 10:59:08 +00:00
|
|
|
} else {
|
2019-09-16 22:12:00 +00:00
|
|
|
renderer_client_ = std::make_unique<ElectronRendererClient>();
|
2016-08-15 10:59:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
return renderer_client_.get();
|
|
|
|
}
|
|
|
|
|
2015-04-30 03:31:17 +00:00
|
|
|
content::ContentUtilityClient*
|
|
|
|
ElectronMainDelegate::CreateContentUtilityClient() {
|
2019-09-16 22:12:00 +00:00
|
|
|
utility_client_ = std::make_unique<ElectronContentUtilityClient>();
|
2015-04-30 03:31:17 +00:00
|
|
|
return utility_client_.get();
|
|
|
|
}
|
|
|
|
|
2021-11-24 08:45:59 +00:00
|
|
|
absl::variant<int, content::MainFunctionParams>
|
|
|
|
ElectronMainDelegate::RunProcess(
|
2016-06-01 09:22:14 +00:00
|
|
|
const std::string& process_type,
|
2021-11-24 08:45:59 +00:00
|
|
|
content::MainFunctionParams main_function_params) {
|
2016-06-01 09:22:14 +00:00
|
|
|
if (process_type == kRelauncherProcess)
|
2016-06-02 07:23:46 +00:00
|
|
|
return relauncher::RelauncherMain(main_function_params);
|
2016-06-01 09:22:14 +00:00
|
|
|
else
|
2021-11-24 08:45:59 +00:00
|
|
|
return std::move(main_function_params);
|
2016-06-01 09:22:14 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 20:50:08 +00:00
|
|
|
bool ElectronMainDelegate::ShouldCreateFeatureList(InvokedIn invoked_in) {
|
2022-07-13 21:26:16 +00:00
|
|
|
return absl::holds_alternative<InvokedInChildProcess>(invoked_in);
|
2016-06-01 09:22:14 +00:00
|
|
|
}
|
|
|
|
|
2022-10-03 20:21:00 +00:00
|
|
|
bool ElectronMainDelegate::ShouldInitializeMojo(InvokedIn invoked_in) {
|
|
|
|
return ShouldCreateFeatureList(invoked_in);
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:35:05 +00:00
|
|
|
bool ElectronMainDelegate::ShouldLockSchemeRegistry() {
|
2019-01-12 01:00:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2020-05-07 20:31:26 +00:00
|
|
|
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);
|
2022-10-17 14:22:24 +00:00
|
|
|
if (command_line->HasSwitch(crash_reporter::switches::kCrashpadHandlerPid)) {
|
|
|
|
crash_reporter::InitializeCrashpad(false, process_type);
|
|
|
|
crash_reporter::SetFirstChanceExceptionHandler(
|
|
|
|
v8::TryHandleWebAssemblyTrapPosix);
|
2021-07-19 17:11:10 +00:00
|
|
|
}
|
2020-05-07 20:31:26 +00:00
|
|
|
|
|
|
|
// Reset the command line for the newly spawned process.
|
|
|
|
crash_keys::SetCrashKeysFromCommandLine(*command_line);
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#endif // BUILDFLAG(IS_LINUX)
|
2020-05-07 20:31:26 +00:00
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
} // namespace electron
|