2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 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.
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/common/alloy/alloy_main_delegate.h"
|
2019-03-07 23:04:32 +01:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
2022-01-25 20:40:24 +01:00
|
|
|
#include <tuple>
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_context.h"
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_content_browser_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/cef_switches.h"
|
|
|
|
#include "libcef/common/command_line_impl.h"
|
2016-12-12 11:05:29 +01:00
|
|
|
#include "libcef/common/crash_reporting.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2020-07-06 20:14:57 +02:00
|
|
|
#include "libcef/common/resource_util.h"
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/renderer/alloy/alloy_content_renderer_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-11-21 23:43:36 +01:00
|
|
|
#include "base/base_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/command_line.h"
|
2013-02-27 18:56:03 +01:00
|
|
|
#include "base/files/file_path.h"
|
2014-11-12 20:25:15 +01:00
|
|
|
#include "base/files/file_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/path_service.h"
|
2019-02-01 17:42:40 +01:00
|
|
|
#include "base/stl_util.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2023-08-07 18:58:24 +02:00
|
|
|
#include "base/strings/string_split.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_util.h"
|
2023-12-05 00:45:54 +01:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2012-04-11 20:00:55 +02:00
|
|
|
#include "base/synchronization/waitable_event.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2023-12-05 00:45:54 +01:00
|
|
|
#include "chrome/browser/chrome_process_singleton.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "chrome/child/pdf_child_init.h"
|
2015-08-14 16:41:08 +02:00
|
|
|
#include "chrome/common/chrome_constants.h"
|
2014-07-08 00:17:33 +02:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2023-12-05 00:45:54 +01:00
|
|
|
#include "chrome/common/chrome_result_codes.h"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2023-12-05 00:45:54 +01:00
|
|
|
#include "chrome/grit/generated_resources.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "chrome/utility/chrome_content_utility_client.h"
|
2021-08-09 23:18:43 +02:00
|
|
|
#include "components/component_updater/component_updater_paths.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "components/content_settings/core/common/content_settings_pattern.h"
|
2021-03-04 23:36:57 +01:00
|
|
|
#include "components/embedder_support/switches.h"
|
2023-12-05 00:45:54 +01:00
|
|
|
#include "components/metrics/persistent_histograms.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "components/viz/common/features.h"
|
2018-07-24 00:32:02 +02:00
|
|
|
#include "content/public/common/content_features.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2012-04-11 20:00:55 +02:00
|
|
|
#include "content/public/common/main_function_params.h"
|
2022-02-16 22:24:41 +01:00
|
|
|
#include "content/public/common/url_constants.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "extensions/common/constants.h"
|
2020-04-14 21:31:00 +02:00
|
|
|
#include "net/base/features.h"
|
2020-08-29 00:39:23 +02:00
|
|
|
#include "sandbox/policy/switches.h"
|
2019-07-16 19:59:21 +02:00
|
|
|
#include "services/network/public/cpp/features.h"
|
2023-09-19 20:24:56 +02:00
|
|
|
#include "third_party/blink/public/common/features.h"
|
2021-11-10 22:57:31 +01:00
|
|
|
#include "third_party/blink/public/common/switches.h"
|
2023-12-05 00:45:54 +01:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2023-12-05 00:45:54 +01:00
|
|
|
#include "ui/base/resource/scoped_startup_resource_bundle.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "ui/base/ui_base_features.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ui/base/ui_base_paths.h"
|
2012-10-22 22:56:38 +02:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2023-05-05 13:17:14 +02:00
|
|
|
#include "components/crash/core/common/objc_zombie.h"
|
2020-07-06 20:14:57 +02:00
|
|
|
#include "libcef/common/util_mac.h"
|
2022-03-15 20:42:15 +01:00
|
|
|
#elif BUILDFLAG(IS_POSIX)
|
|
|
|
#include "libcef/common/util_linux.h"
|
2020-07-06 20:14:57 +02:00
|
|
|
#endif
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2024-03-19 22:11:42 +01:00
|
|
|
#include "base/win/scoped_handle.h"
|
|
|
|
#include "base/win/win_util.h"
|
2021-09-22 11:17:27 +02:00
|
|
|
#include "ui/base/resource/resource_bundle_win.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
namespace {
|
2012-04-11 20:00:55 +02:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
const char* const kNonWildcardDomainNonPortSchemes[] = {
|
2022-02-16 22:24:41 +01:00
|
|
|
extensions::kExtensionScheme, content::kChromeDevToolsScheme,
|
|
|
|
content::kChromeUIScheme, content::kChromeUIUntrustedScheme};
|
2017-09-06 23:40:58 +02:00
|
|
|
const size_t kNonWildcardDomainNonPortSchemesSize =
|
2022-03-26 02:12:30 +01:00
|
|
|
std::size(kNonWildcardDomainNonPortSchemes);
|
2017-09-06 23:40:58 +02:00
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
std::optional<int> AcquireProcessSingleton(
|
2023-12-05 00:45:54 +01:00
|
|
|
const base::FilePath& user_data_dir) {
|
|
|
|
// Take the Chrome process singleton lock. The process can become the
|
|
|
|
// Browser process if it succeed to take the lock. Otherwise, the
|
|
|
|
// command-line is sent to the actual Browser process and the current
|
|
|
|
// process can be exited.
|
|
|
|
ChromeProcessSingleton::CreateInstance(user_data_dir);
|
|
|
|
|
|
|
|
ProcessSingleton::NotifyResult notify_result =
|
|
|
|
ChromeProcessSingleton::GetInstance()->NotifyOtherProcessOrCreate();
|
|
|
|
switch (notify_result) {
|
|
|
|
case ProcessSingleton::PROCESS_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProcessSingleton::PROCESS_NOTIFIED: {
|
|
|
|
// Ensure there is an instance of ResourceBundle that is initialized for
|
|
|
|
// localized string resource accesses.
|
|
|
|
ui::ScopedStartupResourceBundle startup_resource_bundle;
|
|
|
|
printf("%s\n", base::SysWideToNativeMB(
|
|
|
|
base::UTF16ToWide(l10n_util::GetStringUTF16(
|
|
|
|
IDS_USED_EXISTING_BROWSER)))
|
|
|
|
.c_str());
|
|
|
|
return chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ProcessSingleton::PROFILE_IN_USE:
|
|
|
|
return chrome::RESULT_CODE_PROFILE_IN_USE;
|
|
|
|
|
|
|
|
case ProcessSingleton::LOCK_ERROR:
|
|
|
|
LOG(ERROR) << "Failed to create a ProcessSingleton for your profile "
|
|
|
|
"directory. This means that running multiple instances "
|
|
|
|
"would start multiple browser processes rather than "
|
|
|
|
"opening a new window in the existing process. Aborting "
|
|
|
|
"now to avoid profile corruption.";
|
|
|
|
return chrome::RESULT_CODE_PROFILE_IN_USE;
|
|
|
|
}
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
return std::nullopt;
|
2023-12-05 00:45:54 +01:00
|
|
|
}
|
|
|
|
|
2019-03-13 22:27:37 +01:00
|
|
|
} // namespace
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyMainDelegate::AlloyMainDelegate(CefMainRunnerHandler* runner,
|
|
|
|
CefSettings* settings,
|
|
|
|
CefRefPtr<CefApp> application)
|
2020-06-28 23:05:36 +02:00
|
|
|
: runner_(runner), settings_(settings), application_(application) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2020-07-06 20:14:57 +02:00
|
|
|
resource_util::OverrideAssetPath();
|
2019-03-07 23:04:32 +01:00
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
AlloyMainDelegate::~AlloyMainDelegate() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
std::optional<int> AlloyMainDelegate::PreBrowserMain() {
|
2021-06-04 03:34:56 +02:00
|
|
|
runner_->PreBrowserMain();
|
2023-12-06 21:16:15 +01:00
|
|
|
return std::nullopt;
|
2018-09-06 14:40:36 +02:00
|
|
|
}
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
std::optional<int> AlloyMainDelegate::PostEarlyInitialization(
|
2023-12-05 00:45:54 +01:00
|
|
|
InvokedIn invoked_in) {
|
|
|
|
const auto* invoked_in_browser =
|
|
|
|
absl::get_if<InvokedInBrowserProcess>(&invoked_in);
|
|
|
|
if (!invoked_in_browser) {
|
2023-12-06 21:16:15 +01:00
|
|
|
return std::nullopt;
|
2023-12-05 00:45:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Based on ChromeMainDelegate::PostEarlyInitialization.
|
|
|
|
// The User Data dir is guaranteed to be valid as per PreSandboxStartup.
|
|
|
|
base::FilePath user_data_dir =
|
|
|
|
base::PathService::CheckedGet(chrome::DIR_USER_DATA);
|
|
|
|
|
|
|
|
// On platforms that support the process rendezvous, acquire the process
|
|
|
|
// singleton. In case of failure, it means there is already a running browser
|
|
|
|
// instance that handled the command-line.
|
|
|
|
if (auto process_singleton_result = AcquireProcessSingleton(user_data_dir);
|
|
|
|
process_singleton_result.has_value()) {
|
|
|
|
// To ensure that the histograms emitted in this process are reported in
|
|
|
|
// case of early exit, report the metrics accumulated this session with a
|
|
|
|
// future session's metrics.
|
|
|
|
DeferBrowserMetrics(user_data_dir);
|
|
|
|
|
|
|
|
return process_singleton_result;
|
|
|
|
}
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
return std::nullopt;
|
2023-12-05 00:45:54 +01:00
|
|
|
}
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
std::optional<int> AlloyMainDelegate::BasicStartupComplete() {
|
2015-01-09 18:22:10 +01:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string process_type =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_POSIX)
|
2022-03-15 20:42:15 +01:00
|
|
|
// Read the crash configuration file. On Windows this is done from chrome_elf.
|
2016-12-12 11:05:29 +01:00
|
|
|
crash_reporting::BasicStartupComplete(command_line);
|
|
|
|
#endif
|
|
|
|
|
2023-05-05 13:17:14 +02:00
|
|
|
const bool is_browser = process_type.empty();
|
|
|
|
if (is_browser) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// In the browser process. Populate the global command-line object.
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->command_line_args_disabled) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Remove any existing command-line arguments.
|
2015-01-09 18:22:10 +01:00
|
|
|
base::CommandLine::StringVector argv;
|
2012-04-03 03:34:16 +02:00
|
|
|
argv.push_back(command_line->GetProgram().value());
|
|
|
|
command_line->InitFromArgv(argv);
|
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine::SwitchMap& map = command_line->GetSwitches();
|
|
|
|
const_cast<base::CommandLine::SwitchMap*>(&map)->clear();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
bool no_sandbox = settings_->no_sandbox ? true : false;
|
2013-11-15 19:47:02 +01:00
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->browser_subprocess_path.length > 0) {
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath file_path =
|
2020-06-24 22:26:12 +02:00
|
|
|
base::FilePath(CefString(&settings_->browser_subprocess_path));
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!file_path.empty()) {
|
|
|
|
command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
|
|
|
|
file_path);
|
2013-11-15 19:47:02 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2013-11-15 19:47:02 +01:00
|
|
|
// The sandbox is not supported when using a separate subprocess
|
|
|
|
// executable on Windows.
|
|
|
|
no_sandbox = true;
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->framework_dir_path.length > 0) {
|
2017-01-27 01:14:56 +01:00
|
|
|
base::FilePath file_path =
|
2020-06-24 22:26:12 +02:00
|
|
|
base::FilePath(CefString(&settings_->framework_dir_path));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!file_path.empty()) {
|
2017-01-27 01:14:56 +01:00
|
|
|
command_line->AppendSwitchPath(switches::kFrameworkDirPath, file_path);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
}
|
2019-07-25 17:47:46 +02:00
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->main_bundle_path.length > 0) {
|
2019-07-25 17:47:46 +02:00
|
|
|
base::FilePath file_path =
|
2020-06-24 22:26:12 +02:00
|
|
|
base::FilePath(CefString(&settings_->main_bundle_path));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!file_path.empty()) {
|
2019-07-25 17:47:46 +02:00
|
|
|
command_line->AppendSwitchPath(switches::kMainBundlePath, file_path);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-07-25 17:47:46 +02:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
#endif
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (no_sandbox) {
|
2020-08-29 00:39:23 +02:00
|
|
|
command_line->AppendSwitch(sandbox::policy::switches::kNoSandbox);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-11-15 19:47:02 +01:00
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->user_agent.length > 0) {
|
2021-06-04 03:34:56 +02:00
|
|
|
command_line->AppendSwitchASCII(
|
|
|
|
embedder_support::kUserAgent,
|
|
|
|
CefString(&settings_->user_agent).ToString());
|
2021-04-27 18:39:09 +02:00
|
|
|
} else if (settings_->user_agent_product.length > 0) {
|
|
|
|
command_line->AppendSwitchASCII(
|
|
|
|
switches::kUserAgentProductAndVersion,
|
2021-06-04 03:34:56 +02:00
|
|
|
CefString(&settings_->user_agent_product).ToString());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->locale.length > 0) {
|
2012-10-22 22:56:38 +02:00
|
|
|
command_line->AppendSwitchASCII(switches::kLang,
|
2021-06-04 03:34:56 +02:00
|
|
|
CefString(&settings_->locale).ToString());
|
2012-10-22 22:56:38 +02:00
|
|
|
} else if (!command_line->HasSwitch(switches::kLang)) {
|
|
|
|
command_line->AppendSwitchASCII(switches::kLang, "en-US");
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 18:58:33 +02:00
|
|
|
base::FilePath log_file;
|
|
|
|
bool has_log_file_cmdline = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (settings_->log_file.length > 0) {
|
2020-06-24 22:26:12 +02:00
|
|
|
log_file = base::FilePath(CefString(&settings_->log_file));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-23 18:58:33 +02:00
|
|
|
if (log_file.empty() && command_line->HasSwitch(switches::kLogFile)) {
|
|
|
|
log_file = command_line->GetSwitchValuePath(switches::kLogFile);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!log_file.empty()) {
|
2015-10-23 18:58:33 +02:00
|
|
|
has_log_file_cmdline = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-25 19:52:54 +02:00
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (log_file.empty()) {
|
2020-07-06 20:14:57 +02:00
|
|
|
log_file = resource_util::GetDefaultLogFilePath();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-23 18:58:33 +02:00
|
|
|
DCHECK(!log_file.empty());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!has_log_file_cmdline) {
|
2015-10-23 18:58:33 +02:00
|
|
|
command_line->AppendSwitchPath(switches::kLogFile, log_file);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-25 19:52:54 +02:00
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->log_severity != LOGSEVERITY_DEFAULT) {
|
2012-06-25 19:52:54 +02:00
|
|
|
std::string log_severity;
|
2020-06-24 22:26:12 +02:00
|
|
|
switch (settings_->log_severity) {
|
2012-06-25 19:52:54 +02:00
|
|
|
case LOGSEVERITY_VERBOSE:
|
|
|
|
log_severity = switches::kLogSeverity_Verbose;
|
|
|
|
break;
|
|
|
|
case LOGSEVERITY_INFO:
|
|
|
|
log_severity = switches::kLogSeverity_Info;
|
|
|
|
break;
|
|
|
|
case LOGSEVERITY_WARNING:
|
|
|
|
log_severity = switches::kLogSeverity_Warning;
|
|
|
|
break;
|
|
|
|
case LOGSEVERITY_ERROR:
|
|
|
|
log_severity = switches::kLogSeverity_Error;
|
|
|
|
break;
|
2019-01-29 20:53:17 +01:00
|
|
|
case LOGSEVERITY_FATAL:
|
|
|
|
log_severity = switches::kLogSeverity_Fatal;
|
|
|
|
break;
|
2012-06-25 19:52:54 +02:00
|
|
|
case LOGSEVERITY_DISABLE:
|
|
|
|
log_severity = switches::kLogSeverity_Disable;
|
|
|
|
break;
|
2012-06-26 20:03:47 +02:00
|
|
|
default:
|
|
|
|
break;
|
2012-06-25 19:52:54 +02:00
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!log_severity.empty()) {
|
2012-06-25 19:52:54 +02:00
|
|
|
command_line->AppendSwitchASCII(switches::kLogSeverity, log_severity);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-25 19:52:54 +02:00
|
|
|
}
|
|
|
|
|
2023-08-07 18:58:24 +02:00
|
|
|
if (settings_->log_items != LOG_ITEMS_DEFAULT) {
|
|
|
|
std::string log_items_str;
|
|
|
|
if (settings_->log_items == LOG_ITEMS_NONE) {
|
|
|
|
log_items_str = std::string(switches::kLogItems_None);
|
|
|
|
} else {
|
|
|
|
std::vector<base::StringPiece> added_items;
|
|
|
|
if (settings_->log_items & LOG_ITEMS_FLAG_PROCESS_ID) {
|
2024-01-20 23:48:57 +01:00
|
|
|
added_items.emplace_back(switches::kLogItems_PId);
|
2023-08-07 18:58:24 +02:00
|
|
|
}
|
|
|
|
if (settings_->log_items & LOG_ITEMS_FLAG_THREAD_ID) {
|
2024-01-20 23:48:57 +01:00
|
|
|
added_items.emplace_back(switches::kLogItems_TId);
|
2023-08-07 18:58:24 +02:00
|
|
|
}
|
|
|
|
if (settings_->log_items & LOG_ITEMS_FLAG_TIME_STAMP) {
|
2024-01-20 23:48:57 +01:00
|
|
|
added_items.emplace_back(switches::kLogItems_TimeStamp);
|
2023-08-07 18:58:24 +02:00
|
|
|
}
|
|
|
|
if (settings_->log_items & LOG_ITEMS_FLAG_TICK_COUNT) {
|
2024-01-20 23:48:57 +01:00
|
|
|
added_items.emplace_back(switches::kLogItems_TickCount);
|
2023-08-07 18:58:24 +02:00
|
|
|
}
|
|
|
|
if (!added_items.empty()) {
|
|
|
|
log_items_str = base::JoinString(added_items, ",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!log_items_str.empty()) {
|
|
|
|
command_line->AppendSwitchASCII(switches::kLogItems, log_items_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->javascript_flags.length > 0) {
|
2021-06-04 03:34:56 +02:00
|
|
|
command_line->AppendSwitchASCII(
|
2021-11-10 22:57:31 +01:00
|
|
|
blink::switches::kJavaScriptFlags,
|
2021-06-04 03:34:56 +02:00
|
|
|
CefString(&settings_->javascript_flags).ToString());
|
2012-06-12 17:53:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->pack_loading_disabled) {
|
2013-02-07 20:59:40 +01:00
|
|
|
command_line->AppendSwitch(switches::kDisablePackLoading);
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->resources_dir_path.length > 0) {
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath file_path =
|
2020-06-24 22:26:12 +02:00
|
|
|
base::FilePath(CefString(&settings_->resources_dir_path));
|
2012-09-06 19:42:16 +02:00
|
|
|
if (!file_path.empty()) {
|
|
|
|
command_line->AppendSwitchPath(switches::kResourcesDirPath,
|
|
|
|
file_path);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->locales_dir_path.length > 0) {
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath file_path =
|
2020-06-24 22:26:12 +02:00
|
|
|
base::FilePath(CefString(&settings_->locales_dir_path));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!file_path.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
command_line->AppendSwitchPath(switches::kLocalesDirPath, file_path);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-15 02:02:20 +01:00
|
|
|
if (settings_->remote_debugging_port >= 1024 &&
|
|
|
|
settings_->remote_debugging_port <= 65535) {
|
2017-05-17 11:29:28 +02:00
|
|
|
command_line->AppendSwitchASCII(
|
|
|
|
switches::kRemoteDebuggingPort,
|
2020-06-24 22:26:12 +02:00
|
|
|
base::NumberToString(settings_->remote_debugging_port));
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
if (settings_->uncaught_exception_stack_size > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
command_line->AppendSwitchASCII(
|
|
|
|
switches::kUncaughtExceptionStackSize,
|
2020-06-24 22:26:12 +02:00
|
|
|
base::NumberToString(settings_->uncaught_exception_stack_size));
|
2012-11-02 19:16:28 +01:00
|
|
|
}
|
2019-01-17 10:56:52 +01:00
|
|
|
|
|
|
|
std::vector<std::string> disable_features;
|
|
|
|
|
2022-08-11 22:17:33 +02:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-11-12 17:11:44 +01:00
|
|
|
if (features::kCalculateNativeWinOcclusion.default_state ==
|
|
|
|
base::FEATURE_ENABLED_BY_DEFAULT) {
|
|
|
|
// TODO: Add support for occlusion detection in combination with native
|
|
|
|
// parent windows (see issue #2805).
|
|
|
|
disable_features.push_back(features::kCalculateNativeWinOcclusion.name);
|
|
|
|
}
|
2022-08-11 22:17:33 +02:00
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
|
|
|
if (features::kBackForwardCache.default_state ==
|
|
|
|
base::FEATURE_ENABLED_BY_DEFAULT) {
|
|
|
|
// Disable BackForwardCache globally so that
|
|
|
|
// blink::RuntimeEnabledFeatures::BackForwardCacheEnabled reports the
|
|
|
|
// correct value in the renderer process (see issue #3374).
|
|
|
|
disable_features.push_back(features::kBackForwardCache.name);
|
|
|
|
}
|
2021-10-04 12:02:05 +02:00
|
|
|
|
2023-09-19 20:24:56 +02:00
|
|
|
if (blink::features::kDocumentPictureInPictureAPI.default_state ==
|
|
|
|
base::FEATURE_ENABLED_BY_DEFAULT) {
|
|
|
|
// Disable DocumentPictureInPictureAPI globally so that
|
|
|
|
// blink::RuntimeEnabledFeatures::DocumentPictureInPictureAPIEnabled
|
|
|
|
// reports the correct value in the renderer process (see issue #3448).
|
|
|
|
disable_features.push_back(
|
|
|
|
blink::features::kDocumentPictureInPictureAPI.name);
|
|
|
|
}
|
|
|
|
|
2019-01-17 10:56:52 +01:00
|
|
|
if (!disable_features.empty()) {
|
|
|
|
DCHECK(!base::FeatureList::GetInstance());
|
|
|
|
std::string disable_features_str =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kDisableFeatures);
|
|
|
|
for (auto feature_str : disable_features) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!disable_features_str.empty()) {
|
2019-01-17 10:56:52 +01:00
|
|
|
disable_features_str += ",";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-01-17 10:56:52 +01:00
|
|
|
disable_features_str += feature_str;
|
|
|
|
}
|
|
|
|
command_line->AppendSwitchASCII(switches::kDisableFeatures,
|
|
|
|
disable_features_str);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
if (application_) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Give the application a chance to view/modify the command line.
|
|
|
|
CefRefPtr<CefCommandLineImpl> commandLinePtr(
|
|
|
|
new CefCommandLineImpl(command_line, false, false));
|
2020-06-28 23:05:36 +02:00
|
|
|
application_->OnBeforeCommandLineProcessing(CefString(process_type),
|
|
|
|
commandLinePtr.get());
|
2022-01-25 20:40:24 +01:00
|
|
|
std::ignore = commandLinePtr->Detach(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-05-05 13:17:14 +02:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
|
|
// Turns all deallocated Objective-C objects into zombies. Give the browser
|
|
|
|
// process a longer treadmill, since crashes there have more impact.
|
|
|
|
ObjcEvilDoers::ZombieEnable(true, is_browser ? 10000 : 1000);
|
|
|
|
#endif
|
|
|
|
|
2012-06-25 19:52:54 +02:00
|
|
|
// Initialize logging.
|
2013-07-19 00:37:02 +02:00
|
|
|
logging::LoggingSettings log_settings;
|
2015-10-23 18:58:33 +02:00
|
|
|
|
2024-03-19 22:11:42 +01:00
|
|
|
enum class LoggingDest {
|
|
|
|
kFile,
|
|
|
|
kStderr,
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
kHandle,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
LoggingDest dest = LoggingDest::kFile;
|
|
|
|
|
|
|
|
if (command_line->GetSwitchValueASCII(switches::kEnableLogging) == "stderr") {
|
|
|
|
dest = LoggingDest::kStderr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
// On Windows child process may be given a handle in the --log-file switch.
|
|
|
|
base::win::ScopedHandle log_handle;
|
|
|
|
if (command_line->GetSwitchValueASCII(switches::kEnableLogging) == "handle") {
|
|
|
|
auto handle_str = command_line->GetSwitchValueNative(switches::kLogFile);
|
|
|
|
uint32_t handle_value = 0;
|
|
|
|
if (base::StringToUint(handle_str, &handle_value)) {
|
|
|
|
// This handle is owned by the logging framework and is closed when the
|
|
|
|
// process exits.
|
|
|
|
HANDLE duplicate = nullptr;
|
|
|
|
if (::DuplicateHandle(GetCurrentProcess(),
|
|
|
|
base::win::Uint32ToHandle(handle_value),
|
|
|
|
GetCurrentProcess(), &duplicate, 0, FALSE,
|
|
|
|
DUPLICATE_SAME_ACCESS)) {
|
|
|
|
log_handle.Set(duplicate);
|
|
|
|
dest = LoggingDest::kHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
|
|
|
base::FilePath log_file;
|
|
|
|
if (dest == LoggingDest::kFile) {
|
|
|
|
log_file = command_line->GetSwitchValuePath(switches::kLogFile);
|
|
|
|
DCHECK(!log_file.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
if (dest == LoggingDest::kHandle) {
|
|
|
|
// TODO(crbug.com/328285906) Use a ScopedHandle in logging settings.
|
|
|
|
log_settings.log_file = log_handle.release();
|
|
|
|
} else {
|
|
|
|
log_settings.log_file = nullptr;
|
|
|
|
}
|
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
|
|
|
|
if (dest == LoggingDest::kFile) {
|
|
|
|
log_settings.log_file_path = log_file.value().c_str();
|
|
|
|
} else {
|
|
|
|
log_settings.log_file_path = nullptr;
|
|
|
|
}
|
2015-10-23 18:58:33 +02:00
|
|
|
|
2013-07-19 00:37:02 +02:00
|
|
|
log_settings.lock_log = logging::DONT_LOCK_LOG_FILE;
|
|
|
|
log_settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
|
2012-06-25 19:52:54 +02:00
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
logging::LogSeverity log_severity = logging::LOGGING_INFO;
|
2013-07-19 00:37:02 +02:00
|
|
|
|
|
|
|
std::string log_severity_str =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kLogSeverity);
|
2012-06-25 19:52:54 +02:00
|
|
|
if (!log_severity_str.empty()) {
|
2022-06-17 15:28:55 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(log_severity_str,
|
|
|
|
switches::kLogSeverity_Verbose)) {
|
2024-01-26 03:12:43 +01:00
|
|
|
log_severity = logging::LOGGING_VERBOSE;
|
2022-06-17 15:28:55 +02:00
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(
|
|
|
|
log_severity_str, switches::kLogSeverity_Warning)) {
|
2024-01-26 03:12:43 +01:00
|
|
|
log_severity = logging::LOGGING_WARNING;
|
2022-06-17 15:28:55 +02:00
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
|
|
|
|
switches::kLogSeverity_Error)) {
|
2024-01-26 03:12:43 +01:00
|
|
|
log_severity = logging::LOGGING_ERROR;
|
2022-06-17 15:28:55 +02:00
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
|
|
|
|
switches::kLogSeverity_Fatal)) {
|
2024-01-26 03:12:43 +01:00
|
|
|
log_severity = logging::LOGGING_FATAL;
|
2022-06-17 15:28:55 +02:00
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(
|
|
|
|
log_severity_str, switches::kLogSeverity_Disable)) {
|
2012-06-25 19:52:54 +02:00
|
|
|
log_severity = LOGSEVERITY_DISABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log_severity == LOGSEVERITY_DISABLE) {
|
2013-07-19 00:37:02 +02:00
|
|
|
log_settings.logging_dest = logging::LOG_NONE;
|
2019-01-29 20:53:17 +01:00
|
|
|
// By default, ERROR and FATAL messages will always be output to stderr due
|
|
|
|
// to the kAlwaysPrintErrorLevel value in base/logging.cc. We change the log
|
|
|
|
// level here so that only FATAL messages are output.
|
2024-01-26 03:12:43 +01:00
|
|
|
logging::SetMinLogLevel(logging::LOGGING_FATAL);
|
2012-06-25 19:52:54 +02:00
|
|
|
} else {
|
2024-03-19 22:11:42 +01:00
|
|
|
if (dest == LoggingDest::kStderr) {
|
|
|
|
log_settings.logging_dest =
|
|
|
|
logging::LOG_TO_STDERR | logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
|
|
|
} else {
|
|
|
|
// Includes both handle or provided filename on Windows.
|
|
|
|
log_settings.logging_dest = logging::LOG_TO_ALL;
|
|
|
|
}
|
2012-06-25 19:52:54 +02:00
|
|
|
logging::SetMinLogLevel(log_severity);
|
|
|
|
}
|
|
|
|
|
2023-08-07 18:58:24 +02:00
|
|
|
// Customization of items automatically prepended to log lines.
|
|
|
|
std::string log_items_str =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kLogItems);
|
|
|
|
if (!log_items_str.empty()) {
|
|
|
|
bool enable_log_of_process_id, enable_log_of_thread_id,
|
|
|
|
enable_log_of_time_stamp, enable_log_of_tick_count;
|
|
|
|
enable_log_of_process_id = enable_log_of_thread_id =
|
|
|
|
enable_log_of_time_stamp = enable_log_of_tick_count = false;
|
|
|
|
|
|
|
|
for (const auto& cur_item_to_log :
|
|
|
|
base::SplitStringPiece(log_items_str, ",", base::TRIM_WHITESPACE,
|
|
|
|
base::SPLIT_WANT_NONEMPTY)) {
|
|
|
|
// if "none" mode is present, all items are disabled.
|
|
|
|
if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
|
|
|
|
switches::kLogItems_None)) {
|
|
|
|
enable_log_of_process_id = enable_log_of_thread_id =
|
|
|
|
enable_log_of_time_stamp = enable_log_of_tick_count = false;
|
|
|
|
break;
|
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
|
|
|
|
switches::kLogItems_PId)) {
|
|
|
|
enable_log_of_process_id = true;
|
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
|
|
|
|
switches::kLogItems_TId)) {
|
|
|
|
enable_log_of_thread_id = true;
|
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(
|
|
|
|
cur_item_to_log, switches::kLogItems_TimeStamp)) {
|
|
|
|
enable_log_of_time_stamp = true;
|
|
|
|
} else if (base::EqualsCaseInsensitiveASCII(
|
|
|
|
cur_item_to_log, switches::kLogItems_TickCount)) {
|
|
|
|
enable_log_of_tick_count = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logging::SetLogItems(enable_log_of_process_id, enable_log_of_thread_id,
|
|
|
|
enable_log_of_time_stamp, enable_log_of_tick_count);
|
|
|
|
}
|
|
|
|
|
2013-07-19 00:37:02 +02:00
|
|
|
logging::InitLogging(log_settings);
|
2012-06-25 19:52:54 +02:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
ContentSettingsPattern::SetNonWildcardDomainNonPortSchemes(
|
|
|
|
kNonWildcardDomainNonPortSchemes, kNonWildcardDomainNonPortSchemesSize);
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
content::SetContentClient(&content_client_);
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-07-06 20:14:57 +02:00
|
|
|
util_mac::BasicStartupComplete();
|
2017-01-27 01:14:56 +01:00
|
|
|
#endif
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
return std::nullopt;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyMainDelegate::PreSandboxStartup() {
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
2014-07-03 20:34:58 +02:00
|
|
|
const std::string& process_type =
|
2015-01-09 18:22:10 +01:00
|
|
|
command_line->GetSwitchValueASCII(switches::kProcessType);
|
2013-08-14 18:36:50 +02:00
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
if (process_type.empty()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
// Only override these paths when executing the main process.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-07-06 20:14:57 +02:00
|
|
|
util_mac::PreSandboxStartup();
|
2022-03-15 20:42:15 +01:00
|
|
|
#elif BUILDFLAG(IS_POSIX)
|
|
|
|
util_linux::PreSandboxStartup();
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
|
|
|
|
2020-07-06 20:14:57 +02:00
|
|
|
resource_util::OverrideDefaultDownloadDir();
|
2014-10-07 22:44:33 +02:00
|
|
|
}
|
|
|
|
|
2021-08-09 23:18:43 +02:00
|
|
|
resource_util::OverrideUserDataDir(settings_, command_line);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (command_line->HasSwitch(switches::kDisablePackLoading)) {
|
2020-06-28 23:05:36 +02:00
|
|
|
resource_bundle_delegate_.set_pack_loading_disabled(true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-05-18 22:32:28 +02:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
// Initialize crash reporting state for this process/module.
|
|
|
|
// chrome::DIR_CRASH_DUMPS must be configured before calling this function.
|
|
|
|
crash_reporting::PreSandboxStartup(*command_line, process_type);
|
|
|
|
|
2021-08-09 23:18:43 +02:00
|
|
|
// Register the component_updater PathProvider.
|
|
|
|
component_updater::RegisterPathProvider(chrome::DIR_COMPONENTS,
|
|
|
|
chrome::DIR_INTERNAL_PLUGINS,
|
|
|
|
chrome::DIR_USER_DATA);
|
|
|
|
|
2012-05-18 22:32:28 +02:00
|
|
|
InitializeResourceBundle();
|
2021-09-20 11:06:23 +02:00
|
|
|
MaybePatchGdiGetFontData();
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2021-12-16 23:35:54 +01:00
|
|
|
absl::variant<int, content::MainFunctionParams> AlloyMainDelegate::RunProcess(
|
2012-04-03 03:34:16 +02:00
|
|
|
const std::string& process_type,
|
2021-12-16 23:35:54 +01:00
|
|
|
content::MainFunctionParams main_function_params) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (process_type.empty()) {
|
2021-12-16 23:35:54 +01:00
|
|
|
return runner_->RunMainProcess(std::move(main_function_params));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2021-12-16 23:35:54 +01:00
|
|
|
return std::move(main_function_params);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyMainDelegate::ProcessExiting(const std::string& process_type) {
|
2017-10-20 19:45:20 +02:00
|
|
|
ui::ResourceBundle::CleanupSharedInstance();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyMainDelegate::ZygoteForked() {
|
2017-05-17 11:29:28 +02:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
const std::string& process_type =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kProcessType);
|
2016-12-12 11:05:29 +01:00
|
|
|
// Initialize crash reporting state for the newly forked process.
|
|
|
|
crash_reporting::ZygoteForked(command_line, process_type);
|
2013-11-21 23:43:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
2012-06-22 00:50:34 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
content::ContentBrowserClient* AlloyMainDelegate::CreateContentBrowserClient() {
|
2024-01-20 23:48:57 +01:00
|
|
|
browser_client_ = std::make_unique<AlloyContentBrowserClient>();
|
2012-06-22 00:50:34 +02:00
|
|
|
return browser_client_.get();
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
content::ContentRendererClient*
|
|
|
|
AlloyMainDelegate::CreateContentRendererClient() {
|
2024-01-20 23:48:57 +01:00
|
|
|
renderer_client_ = std::make_unique<AlloyContentRendererClient>();
|
2012-06-22 00:50:34 +02:00
|
|
|
return renderer_client_.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
content::ContentUtilityClient* AlloyMainDelegate::CreateContentUtilityClient() {
|
2024-01-20 23:48:57 +01:00
|
|
|
utility_client_ = std::make_unique<ChromeContentUtilityClient>();
|
2014-07-03 20:34:58 +02:00
|
|
|
return utility_client_.get();
|
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
CefRefPtr<CefRequestContext> AlloyMainDelegate::GetGlobalRequestContext() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_client_) {
|
2020-06-28 23:05:36 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-28 23:05:36 +02:00
|
|
|
return browser_client_->request_context();
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
CefBrowserContext* AlloyMainDelegate::CreateNewBrowserContext(
|
2021-04-07 00:09:45 +02:00
|
|
|
const CefRequestContextSettings& settings,
|
|
|
|
base::OnceClosure initialized_cb) {
|
2020-07-01 02:57:00 +02:00
|
|
|
auto context = new AlloyBrowserContext(settings);
|
|
|
|
context->Initialize();
|
2021-04-07 00:09:45 +02:00
|
|
|
std::move(initialized_cb).Run();
|
2020-07-01 02:57:00 +02:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyMainDelegate::GetBackgroundTaskRunner() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_client_) {
|
2020-06-25 04:34:12 +02:00
|
|
|
return browser_client_->background_task_runner();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-25 04:34:12 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyMainDelegate::GetUserVisibleTaskRunner() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_client_) {
|
2020-06-25 04:34:12 +02:00
|
|
|
return browser_client_->user_visible_task_runner();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-25 04:34:12 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyMainDelegate::GetUserBlockingTaskRunner() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_client_) {
|
2020-06-25 04:34:12 +02:00
|
|
|
return browser_client_->user_blocking_task_runner();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-25 04:34:12 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyMainDelegate::GetRenderTaskRunner() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (renderer_client_) {
|
2020-06-25 04:34:12 +02:00
|
|
|
return renderer_client_->render_task_runner();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-25 04:34:12 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyMainDelegate::GetWebWorkerTaskRunner() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (renderer_client_) {
|
2020-06-25 04:34:12 +02:00
|
|
|
return renderer_client_->GetCurrentTaskRunner();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-25 04:34:12 +02:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyMainDelegate::InitializeResourceBundle() {
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
2021-02-28 21:23:42 +01:00
|
|
|
base::FilePath resources_pak_file, chrome_100_percent_pak_file,
|
|
|
|
chrome_200_percent_pak_file, locales_dir;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
base::FilePath resources_dir;
|
|
|
|
if (command_line->HasSwitch(switches::kResourcesDirPath)) {
|
|
|
|
resources_dir =
|
|
|
|
command_line->GetSwitchValuePath(switches::kResourcesDirPath);
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (resources_dir.empty()) {
|
2020-07-06 20:14:57 +02:00
|
|
|
resources_dir = resource_util::GetResourcesDir();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!resources_dir.empty()) {
|
2018-05-14 13:24:05 +02:00
|
|
|
base::PathService::Override(chrome::DIR_RESOURCES, resources_dir);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
if (!resource_bundle_delegate_.pack_loading_disabled()) {
|
2012-09-06 19:42:16 +02:00
|
|
|
if (!resources_dir.empty()) {
|
2015-07-29 18:13:14 +02:00
|
|
|
CHECK(resources_dir.IsAbsolute());
|
2021-02-28 21:23:42 +01:00
|
|
|
resources_pak_file =
|
|
|
|
resources_dir.Append(FILE_PATH_LITERAL("resources.pak"));
|
|
|
|
chrome_100_percent_pak_file =
|
|
|
|
resources_dir.Append(FILE_PATH_LITERAL("chrome_100_percent.pak"));
|
|
|
|
chrome_200_percent_pak_file =
|
|
|
|
resources_dir.Append(FILE_PATH_LITERAL("chrome_200_percent.pak"));
|
2012-09-06 19:42:16 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (command_line->HasSwitch(switches::kLocalesDirPath)) {
|
2015-01-09 18:22:10 +01:00
|
|
|
locales_dir = command_line->GetSwitchValuePath(switches::kLocalesDirPath);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!locales_dir.empty()) {
|
2018-05-14 13:24:05 +02:00
|
|
|
base::PathService::Override(ui::DIR_LOCALES, locales_dir);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-05-18 22:32:28 +02:00
|
|
|
}
|
2021-11-10 22:57:31 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-09-22 11:17:27 +02:00
|
|
|
// From chrome/app/chrome_main_delegate.cc
|
|
|
|
// Throbber icons and cursors are still stored in chrome.dll,
|
|
|
|
// this can be killed once those are merged into resources.pak. See
|
|
|
|
// GlassBrowserFrameView::InitThrobberIcons(), https://crbug.com/368327 and
|
|
|
|
// https://crbug.com/1178117.
|
|
|
|
auto module_handle =
|
|
|
|
::GetModuleHandle(CefAppManager::Get()->GetResourceDllName());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!module_handle) {
|
2024-01-20 23:48:57 +01:00
|
|
|
module_handle = ::GetModuleHandle(nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-09-22 11:17:27 +02:00
|
|
|
|
|
|
|
ui::SetResourcesDataDLL(module_handle);
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
std::string locale = command_line->GetSwitchValueASCII(switches::kLang);
|
2012-10-22 22:56:38 +02:00
|
|
|
DCHECK(!locale.empty());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
const std::string loaded_locale =
|
2014-09-04 19:53:40 +02:00
|
|
|
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
2020-06-28 23:05:36 +02:00
|
|
|
locale, &resource_bundle_delegate_,
|
2019-09-04 17:13:32 +02:00
|
|
|
ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!loaded_locale.empty() && g_browser_process) {
|
2015-10-17 02:44:00 +02:00
|
|
|
g_browser_process->SetApplicationLocale(loaded_locale);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-17 02:44:00 +02:00
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
|
2014-07-08 00:17:33 +02:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
if (!resource_bundle_delegate_.pack_loading_disabled()) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (loaded_locale.empty()) {
|
2014-07-08 00:17:33 +02:00
|
|
|
LOG(ERROR) << "Could not load locale pak for " << locale;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-05-18 22:32:28 +02:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
resource_bundle_delegate_.set_allow_pack_file_load(true);
|
2012-09-06 19:42:16 +02:00
|
|
|
|
2021-02-28 21:23:42 +01:00
|
|
|
if (base::PathExists(resources_pak_file)) {
|
|
|
|
resource_bundle.AddDataPackFromPath(resources_pak_file,
|
2021-09-20 11:06:23 +02:00
|
|
|
ui::kScaleFactorNone);
|
2012-05-18 22:32:28 +02:00
|
|
|
} else {
|
2021-02-28 21:23:42 +01:00
|
|
|
LOG(ERROR) << "Could not load resources.pak";
|
2014-07-08 00:17:33 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 21:23:42 +01:00
|
|
|
// Always load the 1x data pack first as the 2x data pack contains both 1x
|
|
|
|
// and 2x images. The 1x data pack only has 1x images, thus passes in an
|
|
|
|
// accurate scale factor to gfx::ImageSkia::AddRepresentation.
|
2021-09-20 11:06:23 +02:00
|
|
|
if (resource_util::IsScaleFactorSupported(ui::k100Percent)) {
|
2021-02-28 21:23:42 +01:00
|
|
|
if (base::PathExists(chrome_100_percent_pak_file)) {
|
|
|
|
resource_bundle.AddDataPackFromPath(chrome_100_percent_pak_file,
|
2021-09-20 11:06:23 +02:00
|
|
|
ui::k100Percent);
|
2014-07-08 00:17:33 +02:00
|
|
|
} else {
|
2021-02-28 21:23:42 +01:00
|
|
|
LOG(ERROR) << "Could not load chrome_100_percent.pak";
|
2014-07-08 00:17:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-20 11:06:23 +02:00
|
|
|
if (resource_util::IsScaleFactorSupported(ui::k200Percent)) {
|
2021-02-28 21:23:42 +01:00
|
|
|
if (base::PathExists(chrome_200_percent_pak_file)) {
|
|
|
|
resource_bundle.AddDataPackFromPath(chrome_200_percent_pak_file,
|
2021-09-20 11:06:23 +02:00
|
|
|
ui::k200Percent);
|
2014-07-08 00:17:33 +02:00
|
|
|
} else {
|
2021-02-28 21:23:42 +01:00
|
|
|
LOG(ERROR) << "Could not load chrome_200_percent.pak";
|
2014-07-08 00:17:33 +02:00
|
|
|
}
|
2012-05-18 22:32:28 +02:00
|
|
|
}
|
2012-09-06 19:42:16 +02:00
|
|
|
|
2021-02-28 21:23:42 +01:00
|
|
|
// Skip the default pak file loading that would otherwise occur in
|
|
|
|
// ResourceBundle::LoadChromeResources().
|
2020-06-28 23:05:36 +02:00
|
|
|
resource_bundle_delegate_.set_allow_pack_file_load(false);
|
2012-05-02 17:56:15 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|