chrome: Support CefSettings path config (see #3685)
This commit is contained in:
parent
7328b9e40d
commit
29381355ef
|
@ -120,6 +120,12 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
|
|||
// Propagate the following switches to all command lines (along with any
|
||||
// associated values) if present in the browser command line.
|
||||
static const char* const kSwitchNames[] = {
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
switches::kFrameworkDirPath,
|
||||
switches::kMainBundlePath,
|
||||
#endif
|
||||
switches::kLocalesDirPath,
|
||||
switches::kResourcesDirPath,
|
||||
switches::kUserAgentProductAndVersion,
|
||||
};
|
||||
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames);
|
||||
|
@ -127,6 +133,19 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
|
|||
|
||||
const std::string& process_type =
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
|
||||
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
|
||||
if (process_type == switches::kZygoteProcess &&
|
||||
browser_cmd->HasSwitch(switches::kBrowserSubprocessPath)) {
|
||||
// Force use of the sub-process executable path for the zygote process.
|
||||
const base::FilePath& subprocess_path =
|
||||
browser_cmd->GetSwitchValuePath(switches::kBrowserSubprocessPath);
|
||||
if (!subprocess_path.empty()) {
|
||||
command_line->SetProgram(subprocess_path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (process_type == switches::kRendererProcess) {
|
||||
// Propagate the following switches to the renderer command line (along with
|
||||
// any associated values) if present in the browser command line.
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "base/base_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/threading/threading_features.h"
|
||||
#include "cef/libcef/browser/chrome/chrome_browser_context.h"
|
||||
#include "cef/libcef/browser/chrome/chrome_content_browser_client_cef.h"
|
||||
|
@ -20,12 +21,14 @@
|
|||
#include "cef/libcef/renderer/chrome/chrome_content_renderer_client_cef.h"
|
||||
#include "chrome/browser/metrics/chrome_feature_list_creator.h"
|
||||
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/embedder_support/switches.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "sandbox/policy/switches.h"
|
||||
#include "third_party/blink/public/common/switches.h"
|
||||
#include "ui/base/ui_base_paths.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
|
@ -86,6 +89,39 @@ std::optional<int> ChromeMainDelegateCef::BasicStartupComplete() {
|
|||
|
||||
bool no_sandbox = settings_->no_sandbox ? true : false;
|
||||
|
||||
if (settings_->browser_subprocess_path.length > 0) {
|
||||
base::FilePath file_path =
|
||||
base::FilePath(CefString(&settings_->browser_subprocess_path));
|
||||
if (!file_path.empty()) {
|
||||
command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
|
||||
file_path);
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// The sandbox is not supported when using a separate subprocess
|
||||
// executable on Windows.
|
||||
no_sandbox = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
if (settings_->framework_dir_path.length > 0) {
|
||||
base::FilePath file_path =
|
||||
base::FilePath(CefString(&settings_->framework_dir_path));
|
||||
if (!file_path.empty()) {
|
||||
command_line->AppendSwitchPath(switches::kFrameworkDirPath, file_path);
|
||||
}
|
||||
}
|
||||
|
||||
if (settings_->main_bundle_path.length > 0) {
|
||||
base::FilePath file_path =
|
||||
base::FilePath(CefString(&settings_->main_bundle_path));
|
||||
if (!file_path.empty()) {
|
||||
command_line->AppendSwitchPath(switches::kMainBundlePath, file_path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (no_sandbox) {
|
||||
command_line->AppendSwitch(sandbox::policy::switches::kNoSandbox);
|
||||
}
|
||||
|
@ -113,6 +149,22 @@ std::optional<int> ChromeMainDelegateCef::BasicStartupComplete() {
|
|||
CefString(&settings_->javascript_flags).ToString());
|
||||
}
|
||||
|
||||
if (settings_->resources_dir_path.length > 0) {
|
||||
base::FilePath file_path =
|
||||
base::FilePath(CefString(&settings_->resources_dir_path));
|
||||
if (!file_path.empty()) {
|
||||
command_line->AppendSwitchPath(switches::kResourcesDirPath, file_path);
|
||||
}
|
||||
}
|
||||
|
||||
if (settings_->locales_dir_path.length > 0) {
|
||||
base::FilePath file_path =
|
||||
base::FilePath(CefString(&settings_->locales_dir_path));
|
||||
if (!file_path.empty()) {
|
||||
command_line->AppendSwitchPath(switches::kLocalesDirPath, file_path);
|
||||
}
|
||||
}
|
||||
|
||||
if (settings_->remote_debugging_port >= 1024 &&
|
||||
settings_->remote_debugging_port <= 65535) {
|
||||
command_line->AppendSwitchASCII(
|
||||
|
@ -192,6 +244,26 @@ void ChromeMainDelegateCef::PreSandboxStartup() {
|
|||
// 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);
|
||||
|
||||
base::FilePath resources_dir;
|
||||
if (command_line->HasSwitch(switches::kResourcesDirPath)) {
|
||||
resources_dir =
|
||||
command_line->GetSwitchValuePath(switches::kResourcesDirPath);
|
||||
}
|
||||
if (resources_dir.empty()) {
|
||||
resources_dir = resource_util::GetResourcesDir();
|
||||
}
|
||||
if (!resources_dir.empty()) {
|
||||
base::PathService::Override(chrome::DIR_RESOURCES, resources_dir);
|
||||
}
|
||||
|
||||
if (command_line->HasSwitch(switches::kLocalesDirPath)) {
|
||||
const auto& locales_dir =
|
||||
command_line->GetSwitchValuePath(switches::kLocalesDirPath);
|
||||
if (!locales_dir.empty()) {
|
||||
base::PathService::Override(ui::DIR_LOCALES, locales_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<int> ChromeMainDelegateCef::PreBrowserMain() {
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
#include "base/nix/xdg_util.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#include "cef/libcef/common/util_mac.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/notreached.h"
|
||||
|
@ -30,7 +34,6 @@
|
|||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#include "base/apple/foundation_util.h"
|
||||
#include "cef/libcef/common/util_mac.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
|
@ -171,10 +174,6 @@ bool GetDefaultDownloadSafeDirectory(base::FilePath* result) {
|
|||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
|
||||
base::FilePath GetResourcesDir() {
|
||||
return util_mac::GetFrameworkResourcesDirectory();
|
||||
}
|
||||
|
||||
// Use a "~/Library/Logs/<app name>_debug.log" file where <app name> is the name
|
||||
// of the running executable.
|
||||
base::FilePath GetDefaultLogFilePath() {
|
||||
|
@ -186,12 +185,6 @@ base::FilePath GetDefaultLogFilePath() {
|
|||
|
||||
#else // !BUILDFLAG(IS_MAC)
|
||||
|
||||
base::FilePath GetResourcesDir() {
|
||||
base::FilePath pak_dir;
|
||||
base::PathService::Get(base::DIR_ASSETS, &pak_dir);
|
||||
return pak_dir;
|
||||
}
|
||||
|
||||
// Use a "debug.log" file in the running executable's directory.
|
||||
base::FilePath GetDefaultLogFilePath() {
|
||||
base::FilePath log_path;
|
||||
|
@ -224,6 +217,22 @@ bool IsScaleFactorSupported(ui::ResourceScaleFactor scale_factor) {
|
|||
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
|
||||
base::FilePath GetResourcesDir() {
|
||||
return util_mac::GetFrameworkResourcesDirectory();
|
||||
}
|
||||
|
||||
#else // !BUILDFLAG(IS_MAC)
|
||||
|
||||
base::FilePath GetResourcesDir() {
|
||||
base::FilePath pak_dir;
|
||||
base::PathService::Get(base::DIR_ASSETS, &pak_dir);
|
||||
return pak_dir;
|
||||
}
|
||||
|
||||
#endif // !BUILDFLAG(IS_MAC)
|
||||
|
||||
void OverrideUserDataDir(CefSettings* settings,
|
||||
const base::CommandLine* command_line) {
|
||||
const base::FilePath& user_data_path =
|
||||
|
|
|
@ -23,10 +23,6 @@ class FilePath;
|
|||
namespace resource_util {
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// Returns the directory that contains resource files (*.bin, *.dat, *.pak,
|
||||
// etc).
|
||||
base::FilePath GetResourcesDir();
|
||||
|
||||
// Returns the default path for the debug.log file.
|
||||
base::FilePath GetDefaultLogFilePath();
|
||||
|
||||
|
@ -37,6 +33,10 @@ void OverrideDefaultDownloadDir();
|
|||
bool IsScaleFactorSupported(ui::ResourceScaleFactor scale_factor);
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
// Returns the directory that contains resource files (*.bin, *.dat, *.pak,
|
||||
// etc).
|
||||
base::FilePath GetResourcesDir();
|
||||
|
||||
void OverrideUserDataDir(CefSettings* settings,
|
||||
const base::CommandLine* command_line);
|
||||
|
||||
|
|
Loading…
Reference in New Issue