2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 09:46:58 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/app/atom_main_delegate.h"
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2015-10-10 06:39:02 +03:00
|
|
|
#include <iostream>
|
2018-09-12 19:25:56 -05:00
|
|
|
#include <memory>
|
2016-08-26 15:30:02 -07:00
|
|
|
#include <string>
|
2014-03-16 09:13:06 +08:00
|
|
|
|
2019-01-10 17:41:49 -08:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include <glib.h> // for g_setenv()
|
|
|
|
#endif
|
|
|
|
|
2014-08-27 20:48:49 +08:00
|
|
|
#include "atom/app/atom_content_client.h"
|
2014-06-30 12:15:59 +08:00
|
|
|
#include "atom/browser/atom_browser_client.h"
|
2016-06-01 22:04:20 +09:00
|
|
|
#include "atom/browser/relauncher.h"
|
2016-08-15 07:59:08 -03:00
|
|
|
#include "atom/common/options_switches.h"
|
2014-06-30 12:15:59 +08:00
|
|
|
#include "atom/renderer/atom_renderer_client.h"
|
2016-08-19 08:47:32 -03:00
|
|
|
#include "atom/renderer/atom_sandboxed_renderer_client.h"
|
2015-05-04 20:58:48 +08:00
|
|
|
#include "atom/utility/atom_content_utility_client.h"
|
2013-04-20 11:19:25 +08:00
|
|
|
#include "base/command_line.h"
|
2014-02-19 19:07:52 +08:00
|
|
|
#include "base/debug/stack_trace.h"
|
2014-10-08 18:27:39 +08:00
|
|
|
#include "base/environment.h"
|
2013-07-08 11:09:53 +08:00
|
|
|
#include "base/logging.h"
|
2018-10-23 14:16:13 +02:00
|
|
|
#include "base/mac/bundle_locations.h"
|
|
|
|
#include "base/path_service.h"
|
2015-11-13 13:05:16 +08:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2013-04-20 11:19:25 +08:00
|
|
|
#include "content/public/common/content_switches.h"
|
2018-10-23 14:16:13 +02:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2018-07-21 14:30:16 +02:00
|
|
|
#include "ipc/ipc_buildflags.h"
|
2018-10-23 14:16:13 +02:00
|
|
|
#include "services/service_manager/embedder/switches.h"
|
2018-04-10 20:54:22 +02:00
|
|
|
#include "services/service_manager/sandbox/switches.h"
|
2016-01-08 12:06:06 +08:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2014-07-16 15:05:02 +08:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2018-10-23 14:16:13 +02:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
2013-09-12 15:42:36 +08:00
|
|
|
|
2018-02-09 18:01:14 -08:00
|
|
|
#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
|
|
|
|
#define IPC_MESSAGE_MACROS_LOG_ENABLED
|
|
|
|
#include "content/public/common/content_ipc_logging.h"
|
|
|
|
#define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \
|
|
|
|
content::RegisterIPCLogger(msg_id, logger)
|
2018-02-11 10:25:11 -08:00
|
|
|
#include "atom/common/common_message_generator.h"
|
2018-02-09 18:01:14 -08:00
|
|
|
#endif
|
|
|
|
|
2018-10-03 13:49:18 -07:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#include "atom/app/atom_main_delegate_mac.h"
|
|
|
|
#endif
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
namespace atom {
|
|
|
|
|
2015-10-15 12:44:55 +08:00
|
|
|
namespace {
|
|
|
|
|
2016-06-01 18:22:14 +09:00
|
|
|
const char* kRelauncherProcess = "relauncher";
|
|
|
|
|
2015-10-15 12:44:55 +08:00
|
|
|
bool IsBrowserProcess(base::CommandLine* cmd) {
|
2016-08-15 07:59:08 -03:00
|
|
|
std::string process_type = cmd->GetSwitchValueASCII(::switches::kProcessType);
|
2015-10-15 12:44:55 +08:00
|
|
|
return process_type.empty();
|
|
|
|
}
|
|
|
|
|
2018-10-23 14:16:13 +02:00
|
|
|
// Returns true if this subprocess type needs the ResourceBundle initialized
|
|
|
|
// and resources loaded.
|
|
|
|
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
|
|
|
|
return
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
// The zygote process opens the resources for the renderers.
|
|
|
|
process_type == service_manager::switches::kZygoteProcess ||
|
|
|
|
#endif
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
// Mac needs them too for scrollbar related images and for sandbox
|
|
|
|
// profiles.
|
|
|
|
process_type == ::switches::kPpapiPluginProcess ||
|
|
|
|
process_type == ::switches::kPpapiBrokerProcess ||
|
|
|
|
process_type == ::switches::kGpuProcess ||
|
|
|
|
#endif
|
|
|
|
process_type == ::switches::kRendererProcess ||
|
|
|
|
process_type == ::switches::kUtilityProcess;
|
|
|
|
}
|
|
|
|
|
2016-05-25 13:45:25 +09:00
|
|
|
#if defined(OS_WIN)
|
2018-04-17 21:55:30 -04:00
|
|
|
void InvalidParameterHandler(const wchar_t*,
|
|
|
|
const wchar_t*,
|
|
|
|
const wchar_t*,
|
|
|
|
unsigned int,
|
|
|
|
uintptr_t) {
|
2016-05-25 13:45:25 +09:00
|
|
|
// noop.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-15 12:44:55 +08:00
|
|
|
} // namespace
|
|
|
|
|
2018-10-23 14:16:13 +02:00
|
|
|
void LoadResourceBundle(const std::string& locale) {
|
|
|
|
const bool initialized = ui::ResourceBundle::HasSharedInstance();
|
|
|
|
if (initialized)
|
|
|
|
ui::ResourceBundle::CleanupSharedInstance();
|
|
|
|
|
|
|
|
// Load other resource files.
|
|
|
|
base::FilePath pak_dir;
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
pak_dir =
|
|
|
|
base::mac::FrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
|
|
|
#else
|
|
|
|
base::PathService::Get(base::DIR_MODULE, &pak_dir);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
|
|
|
locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
|
|
|
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
|
|
|
bundle.ReloadLocaleResources(locale);
|
|
|
|
bundle.AddDataPackFromPath(pak_dir.Append(FILE_PATH_LITERAL("resources.pak")),
|
|
|
|
ui::SCALE_FACTOR_NONE);
|
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
|
|
NOTIMPLEMENTED()
|
|
|
|
<< "Hi, whoever's fixing PDF support! Thanks! The pdf "
|
|
|
|
"viewer resources haven't been ported over to the GN build yet, so "
|
|
|
|
"you'll probably need to change this bit of code.";
|
|
|
|
bundle.AddDataPackFromPath(
|
|
|
|
pak_dir.Append(FILE_PATH_LITERAL("pdf_viewer_resources.pak")),
|
|
|
|
ui::GetSupportedScaleFactors()[0]);
|
|
|
|
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
|
|
}
|
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
AtomMainDelegate::AtomMainDelegate() {}
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
AtomMainDelegate::~AtomMainDelegate() {}
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2013-07-08 11:09:53 +08:00
|
|
|
bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
2018-04-17 15:41:47 -07:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2015-10-15 12:44:55 +08:00
|
|
|
|
2013-12-17 14:01:40 +08:00
|
|
|
logging::LoggingSettings settings;
|
2015-03-25 17:51:56 +05:30
|
|
|
#if defined(OS_WIN)
|
2015-10-10 06:39:02 +03: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 12:44:55 +08:00
|
|
|
if (IsBrowserProcess(command_line))
|
|
|
|
std::wcout << std::endl;
|
2013-07-23 16:37:00 +08:00
|
|
|
#if defined(DEBUG)
|
2015-10-03 15:33:55 +08:00
|
|
|
// Print logging to debug.log on Windows
|
2013-12-17 14:01:40 +08:00
|
|
|
settings.logging_dest = logging::LOG_TO_ALL;
|
|
|
|
settings.log_file = L"debug.log";
|
|
|
|
settings.lock_log = logging::LOCK_LOG_FILE;
|
|
|
|
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
|
2013-07-23 16:37:00 +08:00
|
|
|
#else
|
2013-12-17 14:01:40 +08:00
|
|
|
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
2015-03-26 11:27:06 +08:00
|
|
|
#endif // defined(DEBUG)
|
2018-04-17 21:55:30 -04:00
|
|
|
#else // defined(OS_WIN)
|
2015-09-07 21:44:03 +08:00
|
|
|
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
|
|
|
#endif // !defined(OS_WIN)
|
2015-10-03 15:33:55 +08:00
|
|
|
|
|
|
|
// Only enable logging when --enable-logging is specified.
|
2018-06-18 09:32:55 +02:00
|
|
|
auto env = base::Environment::Create();
|
2016-08-15 07:59:08 -03:00
|
|
|
if (!command_line->HasSwitch(::switches::kEnableLogging) &&
|
2015-10-20 13:00:28 +08:00
|
|
|
!env->HasVar("ELECTRON_ENABLE_LOGGING")) {
|
2015-10-03 15:33:55 +08:00
|
|
|
settings.logging_dest = logging::LOG_NONE;
|
2015-10-10 20:44:22 +03:00
|
|
|
logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES);
|
|
|
|
}
|
2015-10-03 15:33:55 +08:00
|
|
|
|
2015-03-25 17:51:56 +05:30
|
|
|
logging::InitLogging(settings);
|
|
|
|
|
2013-12-23 22:04:49 +08:00
|
|
|
// Logging with pid and timestamp.
|
|
|
|
logging::SetLogItems(true, false, true, false);
|
|
|
|
|
2018-11-28 22:23:41 -08:00
|
|
|
// Enable convient stack printing. This is enabled by default in non-official
|
|
|
|
// builds.
|
|
|
|
if (env->HasVar("ELECTRON_ENABLE_STACK_DUMPING"))
|
2015-10-20 13:02:48 +08:00
|
|
|
base::debug::EnableInProcessStackDumping();
|
2014-02-19 19:07:52 +08:00
|
|
|
|
2019-01-28 22:30:17 -08:00
|
|
|
if (env->HasVar("ELECTRON_DISABLE_SANDBOX"))
|
|
|
|
command_line->AppendSwitch(service_manager::switches::kNoSandbox);
|
|
|
|
|
2015-11-13 13:05:16 +08:00
|
|
|
chrome::RegisterPathProvider();
|
|
|
|
|
2016-05-18 16:42:26 +09:00
|
|
|
#if defined(OS_MACOSX)
|
2018-10-23 14:16:13 +02:00
|
|
|
OverrideChildProcessPath();
|
|
|
|
OverrideFrameworkBundlePath();
|
2016-05-18 16:42:26 +09:00
|
|
|
SetUpBundleOverrides();
|
|
|
|
#endif
|
|
|
|
|
2016-05-25 13:45:25 +09:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Ignore invalid parameter errors.
|
|
|
|
_set_invalid_parameter_handler(InvalidParameterHandler);
|
2017-02-14 17:23:20 +09:00
|
|
|
// Disable the ActiveVerifier, which is used by Chrome to track possible
|
|
|
|
// bugs, but no use in Electron.
|
|
|
|
base::win::DisableHandleVerifier();
|
2016-05-25 13:45:25 +09:00
|
|
|
#endif
|
|
|
|
|
2018-10-22 19:04:23 +02:00
|
|
|
content_client_ = std::make_unique<AtomContentClient>();
|
|
|
|
SetContentClient(content_client_.get());
|
|
|
|
|
2018-10-23 14:16:13 +02:00
|
|
|
return false;
|
2013-07-08 11:09:53 +08:00
|
|
|
}
|
|
|
|
|
2019-01-10 21:49:25 +05:30
|
|
|
void AtomMainDelegate::PostEarlyInitialization(bool is_running_tests) {
|
|
|
|
std::string custom_locale;
|
|
|
|
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
|
|
|
custom_locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
|
|
|
auto* cmd_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
if (cmd_line->HasSwitch(::switches::kLang)) {
|
|
|
|
const std::string locale = cmd_line->GetSwitchValueASCII(::switches::kLang);
|
|
|
|
const base::FilePath locale_file_path =
|
|
|
|
ui::ResourceBundle::GetSharedInstance().GetLocaleFilePath(locale, true);
|
|
|
|
if (!locale_file_path.empty()) {
|
|
|
|
custom_locale = locale;
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
/* When built with USE_GLIB, libcc's GetApplicationLocaleInternal() uses
|
|
|
|
* glib's g_get_language_names(), which keys off of getenv("LC_ALL") */
|
|
|
|
g_setenv("LC_ALL", custom_locale.c_str(), TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
if (custom_locale.empty())
|
|
|
|
l10n_util::OverrideLocaleWithCocoaLocale();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LoadResourceBundle(custom_locale);
|
|
|
|
|
|
|
|
AtomBrowserClient::SetApplicationLocale(
|
|
|
|
l10n_util::GetApplicationLocale(custom_locale));
|
|
|
|
}
|
|
|
|
|
2013-04-20 11:19:25 +08:00
|
|
|
void AtomMainDelegate::PreSandboxStartup() {
|
2018-04-17 15:41:47 -07:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2014-01-30 21:06:56 +08:00
|
|
|
|
2018-10-23 14:16:13 +02:00
|
|
|
std::string process_type =
|
|
|
|
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2014-02-21 01:04:27 +08:00
|
|
|
// Only append arguments for browser process.
|
2015-10-15 12:44:55 +08:00
|
|
|
if (!IsBrowserProcess(command_line))
|
2014-01-30 21:06:56 +08:00
|
|
|
return;
|
2017-06-08 23:39:53 -07:00
|
|
|
|
2018-11-15 13:27:56 -08:00
|
|
|
// Disable setuid sandbox since it is not longer required on
|
|
|
|
// linux (namespace sandbox is available on most distros).
|
|
|
|
command_line->AppendSwitch(service_manager::switches::kDisableSetuidSandbox);
|
|
|
|
|
2015-05-12 18:21:48 +05:30
|
|
|
// Allow file:// URIs to read other file:// URIs by default.
|
2016-08-15 07:59:08 -03:00
|
|
|
command_line->AppendSwitch(::switches::kAllowFileAccessFromFiles);
|
2015-05-12 18:21:48 +05:30
|
|
|
|
2014-10-08 18:17:27 +08:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
// Enable AVFoundation.
|
|
|
|
command_line->AppendSwitch("enable-avfoundation");
|
|
|
|
#endif
|
2013-04-20 11:19:25 +08:00
|
|
|
}
|
|
|
|
|
2018-10-25 17:02:58 +11:00
|
|
|
void AtomMainDelegate::PreCreateMainMessageLoop() {
|
2018-10-03 13:49:18 -07:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
RegisterAtomCrApp();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
|
|
|
|
browser_client_.reset(new AtomBrowserClient);
|
|
|
|
return browser_client_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::ContentRendererClient*
|
2018-04-17 21:55:30 -04:00
|
|
|
AtomMainDelegate::CreateContentRendererClient() {
|
2016-08-15 07:59:08 -03:00
|
|
|
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
2018-04-17 21:55:30 -04:00
|
|
|
switches::kEnableSandbox) ||
|
2017-07-11 18:18:36 -07:00
|
|
|
!base::CommandLine::ForCurrentProcess()->HasSwitch(
|
2018-09-14 17:07:49 -07:00
|
|
|
service_manager::switches::kNoSandbox)) {
|
2016-08-19 08:47:32 -03:00
|
|
|
renderer_client_.reset(new AtomSandboxedRendererClient);
|
2016-08-15 07:59:08 -03:00
|
|
|
} else {
|
|
|
|
renderer_client_.reset(new AtomRendererClient);
|
|
|
|
}
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
return renderer_client_.get();
|
|
|
|
}
|
|
|
|
|
2015-04-30 11:31:17 +08:00
|
|
|
content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
|
|
|
|
utility_client_.reset(new AtomContentUtilityClient);
|
|
|
|
return utility_client_.get();
|
|
|
|
}
|
|
|
|
|
2016-06-01 18:22:14 +09:00
|
|
|
int AtomMainDelegate::RunProcess(
|
|
|
|
const std::string& process_type,
|
|
|
|
const content::MainFunctionParams& main_function_params) {
|
|
|
|
if (process_type == kRelauncherProcess)
|
2016-06-02 16:23:46 +09:00
|
|
|
return relauncher::RelauncherMain(main_function_params);
|
2016-06-01 18:22:14 +09:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:54:21 +09:00
|
|
|
#if defined(OS_MACOSX)
|
2016-06-01 18:22:14 +09:00
|
|
|
bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) {
|
|
|
|
return process_type != kRelauncherProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomMainDelegate::DelaySandboxInitialization(
|
|
|
|
const std::string& process_type) {
|
|
|
|
return process_type == kRelauncherProcess;
|
|
|
|
}
|
2016-06-02 16:54:21 +09:00
|
|
|
#endif
|
2016-06-01 18:22:14 +09:00
|
|
|
|
2018-11-22 09:02:52 -08:00
|
|
|
bool AtomMainDelegate::ShouldLockSchemeRegistry() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-12 06:30:43 +05:30
|
|
|
bool AtomMainDelegate::ShouldCreateFeatureList() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
} // namespace atom
|