Delete Alloy bootstrap (fixes #3685)

This commit is contained in:
Marshall Greenblatt
2024-06-25 20:12:37 -04:00
parent b95b3e6fd5
commit a461a89728
282 changed files with 360 additions and 22399 deletions

View File

@@ -1,160 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 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.
#include "cef/libcef/common/alloy/alloy_content_client.h"
#include <stdint.h>
#include <string_view>
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "cef/include/cef_stream.h"
#include "cef/include/cef_version.h"
#include "cef/libcef/common/app_manager.h"
#include "cef/libcef/common/cef_switches.h"
#include "cef/libcef/common/extensions/extensions_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/media/cdm_registration.h"
#include "components/pdf/common/constants.h"
#include "content/public/common/cdm_info.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_plugin_info.h"
#include "content/public/common/content_switches.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
#include "third_party/widevine/cdm/buildflags.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
#include "cef/libcef/common/cdm_host_file_path.h"
#endif
namespace {
// The following plugin-related methods are from
// chrome/common/chrome_content_client.cc
constexpr char kPDFPluginName[] = "Chromium PDF Plugin";
constexpr char kPDFPluginExtension[] = "pdf";
constexpr char kPDFPluginDescription[] = "Portable Document Format";
constexpr uint32_t kPDFPluginPermissions =
ppapi::PERMISSION_PDF | ppapi::PERMISSION_DEV;
// Appends the known built-in plugins to the given vector. Some built-in
// plugins are "internal" which means they are compiled into the Chrome binary,
// and some are extra shared libraries distributed with the browser (these are
// not marked internal, aside from being automatically registered, they're just
// regular plugins).
void ComputeBuiltInPlugins(std::vector<content::ContentPluginInfo>* plugins) {
if (extensions::PdfExtensionEnabled()) {
content::ContentPluginInfo pdf_info;
pdf_info.is_internal = true;
pdf_info.is_out_of_process = true;
pdf_info.name = kPDFPluginName;
pdf_info.description = kPDFPluginDescription;
pdf_info.path = base::FilePath(ChromeContentClient::kPDFInternalPluginPath);
content::WebPluginMimeType pdf_mime_type(pdf::kInternalPluginMimeType,
kPDFPluginExtension,
kPDFPluginDescription);
pdf_info.mime_types.push_back(pdf_mime_type);
pdf_info.permissions = kPDFPluginPermissions;
plugins->push_back(pdf_info);
}
}
} // namespace
AlloyContentClient::AlloyContentClient() = default;
AlloyContentClient::~AlloyContentClient() = default;
void AlloyContentClient::AddPlugins(
std::vector<content::ContentPluginInfo>* plugins) {
ComputeBuiltInPlugins(plugins);
}
void AlloyContentClient::AddContentDecryptionModules(
std::vector<content::CdmInfo>* cdms,
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
if (cdms) {
RegisterCdmInfo(cdms);
}
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
if (cdm_host_file_paths) {
cef::AddCdmHostFilePaths(cdm_host_file_paths);
}
#endif
}
void AlloyContentClient::AddAdditionalSchemes(Schemes* schemes) {
CefAppManager::Get()->AddAdditionalSchemes(schemes);
}
std::u16string AlloyContentClient::GetLocalizedString(int message_id) {
std::u16string value =
ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
if (value.empty()) {
LOG(ERROR) << "No localized string available for id " << message_id;
}
return value;
}
std::u16string AlloyContentClient::GetLocalizedString(
int message_id,
const std::u16string& replacement) {
std::u16string value = l10n_util::GetStringFUTF16(message_id, replacement);
if (value.empty()) {
LOG(ERROR) << "No localized string available for id " << message_id;
}
return value;
}
std::string_view AlloyContentClient::GetDataResource(
int resource_id,
ui::ResourceScaleFactor scale_factor) {
auto value =
ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
resource_id, scale_factor);
if (value.empty()) {
LOG(ERROR) << "No data resource available for id " << resource_id;
}
return value;
}
base::RefCountedMemory* AlloyContentClient::GetDataResourceBytes(
int resource_id) {
base::RefCountedMemory* value =
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
resource_id);
if (!value) {
LOG(ERROR) << "No data resource bytes available for id " << resource_id;
}
return value;
}
gfx::Image& AlloyContentClient::GetNativeImageNamed(int resource_id) {
gfx::Image& value =
ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
if (value.IsEmpty()) {
LOG(ERROR) << "No native image available for id " << resource_id;
}
return value;
}

View File

@@ -1,33 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 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.
#ifndef CEF_LIBCEF_COMMON_ALLOY_ALLOY_CONTENT_CLIENT_H_
#define CEF_LIBCEF_COMMON_ALLOY_ALLOY_CONTENT_CLIENT_H_
#pragma once
#include "content/public/common/content_client.h"
class AlloyContentClient : public content::ContentClient {
public:
AlloyContentClient();
~AlloyContentClient() override;
// content::ContentClient overrides.
void AddPlugins(std::vector<content::ContentPluginInfo>* plugins) override;
void AddContentDecryptionModules(
std::vector<content::CdmInfo>* cdms,
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) override;
void AddAdditionalSchemes(Schemes* schemes) override;
std::u16string GetLocalizedString(int message_id) override;
std::u16string GetLocalizedString(int message_id,
const std::u16string& replacement) override;
std::string_view GetDataResource(
int resource_id,
ui::ResourceScaleFactor scale_factor) override;
base::RefCountedMemory* GetDataResourceBytes(int resource_id) override;
gfx::Image& GetNativeImageNamed(int resource_id) override;
};
#endif // CEF_LIBCEF_COMMON_ALLOY_ALLOY_CONTENT_CLIENT_H_

View File

@@ -1,813 +0,0 @@
// 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.
#include "cef/libcef/common/alloy/alloy_main_delegate.h"
#include <memory>
#include <tuple>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "cef/libcef/browser/alloy/alloy_browser_context.h"
#include "cef/libcef/browser/alloy/alloy_content_browser_client.h"
#include "cef/libcef/common/cef_switches.h"
#include "cef/libcef/common/command_line_impl.h"
#include "cef/libcef/common/crash_reporting.h"
#include "cef/libcef/common/extensions/extensions_util.h"
#include "cef/libcef/common/resource_util.h"
#include "cef/libcef/renderer/alloy/alloy_content_renderer_client.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_process_singleton.h"
#include "chrome/child/pdf_child_init.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_result_codes.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/utility/chrome_content_utility_client.h"
#include "components/component_updater/component_updater_paths.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/embedder_support/switches.h"
#include "components/metrics/persistent_histograms.h"
#include "components/viz/common/features.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "net/base/features.h"
#include "sandbox/policy/switches.h"
#include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/switches.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/scoped_startup_resource_bundle.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_paths.h"
#include "ui/base/ui_base_switches.h"
#if BUILDFLAG(IS_MAC)
#include "cef/libcef/common/util_mac.h"
#include "components/crash/core/common/objc_zombie.h"
#elif BUILDFLAG(IS_POSIX)
#include "cef/libcef/common/util_linux.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/scoped_handle.h"
#include "base/win/win_util.h"
#include "ui/base/resource/resource_bundle_win.h"
#endif
namespace {
const char* const kNonWildcardDomainNonPortSchemes[] = {
extensions::kExtensionScheme, content::kChromeDevToolsScheme,
content::kChromeUIScheme, content::kChromeUIUntrustedScheme};
const size_t kNonWildcardDomainNonPortSchemesSize =
std::size(kNonWildcardDomainNonPortSchemes);
std::optional<int> AcquireProcessSingleton(
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;
}
return std::nullopt;
}
} // namespace
AlloyMainDelegate::AlloyMainDelegate(CefMainRunnerHandler* runner,
CefSettings* settings,
CefRefPtr<CefApp> application)
: runner_(runner), settings_(settings), application_(application) {
#if BUILDFLAG(IS_LINUX)
resource_util::OverrideAssetPath();
#endif
}
AlloyMainDelegate::~AlloyMainDelegate() = default;
std::optional<int> AlloyMainDelegate::PreBrowserMain() {
runner_->PreBrowserMain();
return std::nullopt;
}
std::optional<int> AlloyMainDelegate::PostEarlyInitialization(
InvokedIn invoked_in) {
const auto* invoked_in_browser =
absl::get_if<InvokedInBrowserProcess>(&invoked_in);
if (!invoked_in_browser) {
return std::nullopt;
}
// 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;
}
return std::nullopt;
}
std::optional<int> AlloyMainDelegate::BasicStartupComplete() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
std::string process_type =
command_line->GetSwitchValueASCII(switches::kProcessType);
#if BUILDFLAG(IS_POSIX)
// Read the crash configuration file. On Windows this is done from chrome_elf.
crash_reporting::BasicStartupComplete(command_line);
#endif
const bool is_browser = process_type.empty();
if (is_browser) {
// In the browser process. Populate the global command-line object.
if (settings_->command_line_args_disabled) {
// Remove any existing command-line arguments.
base::CommandLine::StringVector argv;
argv.push_back(command_line->GetProgram().value());
command_line->InitFromArgv(argv);
const base::CommandLine::SwitchMap& map = command_line->GetSwitches();
const_cast<base::CommandLine::SwitchMap*>(&map)->clear();
}
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);
}
if (settings_->user_agent.length > 0) {
command_line->AppendSwitchASCII(
embedder_support::kUserAgent,
CefString(&settings_->user_agent).ToString());
} else if (settings_->user_agent_product.length > 0) {
command_line->AppendSwitchASCII(
switches::kUserAgentProductAndVersion,
CefString(&settings_->user_agent_product).ToString());
}
if (settings_->locale.length > 0) {
command_line->AppendSwitchASCII(switches::kLang,
CefString(&settings_->locale).ToString());
} else if (!command_line->HasSwitch(switches::kLang)) {
command_line->AppendSwitchASCII(switches::kLang, "en-US");
}
base::FilePath log_file;
bool has_log_file_cmdline = false;
if (settings_->log_file.length > 0) {
log_file = base::FilePath(CefString(&settings_->log_file));
}
if (log_file.empty() && command_line->HasSwitch(switches::kLogFile)) {
log_file = command_line->GetSwitchValuePath(switches::kLogFile);
if (!log_file.empty()) {
has_log_file_cmdline = true;
}
}
if (log_file.empty()) {
log_file = resource_util::GetDefaultLogFilePath();
}
DCHECK(!log_file.empty());
if (!has_log_file_cmdline) {
command_line->AppendSwitchPath(switches::kLogFile, log_file);
}
if (settings_->log_severity != LOGSEVERITY_DEFAULT) {
std::string log_severity;
switch (settings_->log_severity) {
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;
case LOGSEVERITY_FATAL:
log_severity = switches::kLogSeverity_Fatal;
break;
case LOGSEVERITY_DISABLE:
log_severity = switches::kLogSeverity_Disable;
break;
default:
break;
}
if (!log_severity.empty()) {
command_line->AppendSwitchASCII(switches::kLogSeverity, log_severity);
}
}
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<std::string_view> added_items;
if (settings_->log_items & LOG_ITEMS_FLAG_PROCESS_ID) {
added_items.emplace_back(switches::kLogItems_PId);
}
if (settings_->log_items & LOG_ITEMS_FLAG_THREAD_ID) {
added_items.emplace_back(switches::kLogItems_TId);
}
if (settings_->log_items & LOG_ITEMS_FLAG_TIME_STAMP) {
added_items.emplace_back(switches::kLogItems_TimeStamp);
}
if (settings_->log_items & LOG_ITEMS_FLAG_TICK_COUNT) {
added_items.emplace_back(switches::kLogItems_TickCount);
}
if (!added_items.empty()) {
log_items_str = base::JoinString(added_items, ",");
}
}
if (!log_items_str.empty()) {
command_line->AppendSwitchASCII(switches::kLogItems, log_items_str);
}
}
if (settings_->javascript_flags.length > 0) {
command_line->AppendSwitchASCII(
blink::switches::kJavaScriptFlags,
CefString(&settings_->javascript_flags).ToString());
}
if (settings_->pack_loading_disabled) {
command_line->AppendSwitch(switches::kDisablePackLoading);
} else {
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(
switches::kRemoteDebuggingPort,
base::NumberToString(settings_->remote_debugging_port));
}
if (settings_->uncaught_exception_stack_size > 0) {
command_line->AppendSwitchASCII(
switches::kUncaughtExceptionStackSize,
base::NumberToString(settings_->uncaught_exception_stack_size));
}
std::vector<std::string> disable_features;
#if BUILDFLAG(IS_WIN)
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);
}
#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);
}
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);
}
if (!disable_features.empty()) {
DCHECK(!base::FeatureList::GetInstance());
std::string disable_features_str =
command_line->GetSwitchValueASCII(switches::kDisableFeatures);
for (auto feature_str : disable_features) {
if (!disable_features_str.empty()) {
disable_features_str += ",";
}
disable_features_str += feature_str;
}
command_line->AppendSwitchASCII(switches::kDisableFeatures,
disable_features_str);
}
}
if (application_) {
// Give the application a chance to view/modify the command line.
CefRefPtr<CefCommandLineImpl> commandLinePtr(
new CefCommandLineImpl(command_line, false, false));
application_->OnBeforeCommandLineProcessing(CefString(process_type),
commandLinePtr.get());
std::ignore = commandLinePtr->Detach(nullptr);
}
#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
// Initialize logging.
logging::LoggingSettings log_settings;
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();
}
log_settings.lock_log = logging::DONT_LOCK_LOG_FILE;
log_settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
logging::LogSeverity log_severity = logging::LOGGING_INFO;
std::string log_severity_str =
command_line->GetSwitchValueASCII(switches::kLogSeverity);
if (!log_severity_str.empty()) {
if (base::EqualsCaseInsensitiveASCII(log_severity_str,
switches::kLogSeverity_Verbose)) {
log_severity = logging::LOGGING_VERBOSE;
} else if (base::EqualsCaseInsensitiveASCII(
log_severity_str, switches::kLogSeverity_Warning)) {
log_severity = logging::LOGGING_WARNING;
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
switches::kLogSeverity_Error)) {
log_severity = logging::LOGGING_ERROR;
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
switches::kLogSeverity_Fatal)) {
log_severity = logging::LOGGING_FATAL;
} else if (base::EqualsCaseInsensitiveASCII(
log_severity_str, switches::kLogSeverity_Disable)) {
log_severity = LOGSEVERITY_DISABLE;
}
}
if (log_severity == LOGSEVERITY_DISABLE) {
log_settings.logging_dest = logging::LOG_NONE;
// 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.
logging::SetMinLogLevel(logging::LOGGING_FATAL);
} else {
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;
}
logging::SetMinLogLevel(log_severity);
}
// 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);
}
logging::InitLogging(log_settings);
if (is_browser) {
LOG(WARNING)
<< "Alloy bootstrap is deprecated and will be removed in ~M127. See "
"https://github.com/chromiumembedded/cef/issues/3685";
}
ContentSettingsPattern::SetNonWildcardDomainNonPortSchemes(
kNonWildcardDomainNonPortSchemes, kNonWildcardDomainNonPortSchemesSize);
content::SetContentClient(&content_client_);
#if BUILDFLAG(IS_MAC)
util_mac::BasicStartupComplete();
#endif
return std::nullopt;
}
void AlloyMainDelegate::PreSandboxStartup() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
const std::string& process_type =
command_line->GetSwitchValueASCII(switches::kProcessType);
if (process_type.empty()) {
// Only override these paths when executing the main process.
#if BUILDFLAG(IS_MAC)
util_mac::PreSandboxStartup();
#elif BUILDFLAG(IS_POSIX)
util_linux::PreSandboxStartup();
#endif
resource_util::OverrideDefaultDownloadDir();
}
resource_util::OverrideUserDataDir(settings_, command_line);
if (command_line->HasSwitch(switches::kDisablePackLoading)) {
resource_bundle_delegate_.set_pack_loading_disabled(true);
}
// 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);
// Register the component_updater PathProvider.
component_updater::RegisterPathProvider(chrome::DIR_COMPONENTS,
chrome::DIR_INTERNAL_PLUGINS,
chrome::DIR_USER_DATA);
InitializeResourceBundle();
MaybePatchGdiGetFontData();
}
absl::variant<int, content::MainFunctionParams> AlloyMainDelegate::RunProcess(
const std::string& process_type,
content::MainFunctionParams main_function_params) {
if (process_type.empty()) {
return runner_->RunMainProcess(std::move(main_function_params));
}
return std::move(main_function_params);
}
void AlloyMainDelegate::ProcessExiting(const std::string& process_type) {
ui::ResourceBundle::CleanupSharedInstance();
}
#if BUILDFLAG(IS_LINUX)
void AlloyMainDelegate::ZygoteForked() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
const std::string& process_type =
command_line->GetSwitchValueASCII(switches::kProcessType);
// Initialize crash reporting state for the newly forked process.
crash_reporting::ZygoteForked(command_line, process_type);
}
#endif
content::ContentBrowserClient* AlloyMainDelegate::CreateContentBrowserClient() {
browser_client_ = std::make_unique<AlloyContentBrowserClient>();
return browser_client_.get();
}
content::ContentRendererClient*
AlloyMainDelegate::CreateContentRendererClient() {
renderer_client_ = std::make_unique<AlloyContentRendererClient>();
return renderer_client_.get();
}
content::ContentUtilityClient* AlloyMainDelegate::CreateContentUtilityClient() {
utility_client_ = std::make_unique<ChromeContentUtilityClient>();
return utility_client_.get();
}
CefRefPtr<CefRequestContext> AlloyMainDelegate::GetGlobalRequestContext() {
if (!browser_client_) {
return nullptr;
}
return browser_client_->request_context();
}
CefBrowserContext* AlloyMainDelegate::CreateNewBrowserContext(
const CefRequestContextSettings& settings,
base::OnceClosure initialized_cb) {
auto context = new AlloyBrowserContext(settings);
context->Initialize();
std::move(initialized_cb).Run();
return context;
}
scoped_refptr<base::SingleThreadTaskRunner>
AlloyMainDelegate::GetBackgroundTaskRunner() {
if (browser_client_) {
return browser_client_->background_task_runner();
}
return nullptr;
}
scoped_refptr<base::SingleThreadTaskRunner>
AlloyMainDelegate::GetUserVisibleTaskRunner() {
if (browser_client_) {
return browser_client_->user_visible_task_runner();
}
return nullptr;
}
scoped_refptr<base::SingleThreadTaskRunner>
AlloyMainDelegate::GetUserBlockingTaskRunner() {
if (browser_client_) {
return browser_client_->user_blocking_task_runner();
}
return nullptr;
}
scoped_refptr<base::SingleThreadTaskRunner>
AlloyMainDelegate::GetRenderTaskRunner() {
if (renderer_client_) {
return renderer_client_->render_task_runner();
}
return nullptr;
}
scoped_refptr<base::SingleThreadTaskRunner>
AlloyMainDelegate::GetWebWorkerTaskRunner() {
if (renderer_client_) {
return renderer_client_->GetCurrentTaskRunner();
}
return nullptr;
}
void AlloyMainDelegate::InitializeResourceBundle() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
base::FilePath resources_pak_file, chrome_100_percent_pak_file,
chrome_200_percent_pak_file, locales_dir;
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 (!resource_bundle_delegate_.pack_loading_disabled()) {
if (!resources_dir.empty()) {
CHECK(resources_dir.IsAbsolute());
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"));
}
if (command_line->HasSwitch(switches::kLocalesDirPath)) {
locales_dir = command_line->GetSwitchValuePath(switches::kLocalesDirPath);
}
if (!locales_dir.empty()) {
base::PathService::Override(ui::DIR_LOCALES, locales_dir);
}
}
#if BUILDFLAG(IS_WIN)
// 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());
if (!module_handle) {
module_handle = ::GetModuleHandle(nullptr);
}
ui::SetResourcesDataDLL(module_handle);
#endif
std::string locale = command_line->GetSwitchValueASCII(switches::kLang);
DCHECK(!locale.empty());
const std::string loaded_locale =
ui::ResourceBundle::InitSharedInstanceWithLocale(
locale, &resource_bundle_delegate_,
ui::ResourceBundle::LOAD_COMMON_RESOURCES);
if (!loaded_locale.empty() && g_browser_process) {
g_browser_process->SetApplicationLocale(loaded_locale);
}
ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
if (!resource_bundle_delegate_.pack_loading_disabled()) {
if (loaded_locale.empty()) {
LOG(ERROR) << "Could not load locale pak for " << locale;
}
resource_bundle_delegate_.set_allow_pack_file_load(true);
if (base::PathExists(resources_pak_file)) {
resource_bundle.AddDataPackFromPath(resources_pak_file,
ui::kScaleFactorNone);
} else {
LOG(ERROR) << "Could not load resources.pak";
}
// 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.
if (resource_util::IsScaleFactorSupported(ui::k100Percent)) {
if (base::PathExists(chrome_100_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(chrome_100_percent_pak_file,
ui::k100Percent);
} else {
LOG(ERROR) << "Could not load chrome_100_percent.pak";
}
}
if (resource_util::IsScaleFactorSupported(ui::k200Percent)) {
if (base::PathExists(chrome_200_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(chrome_200_percent_pak_file,
ui::k200Percent);
} else {
LOG(ERROR) << "Could not load chrome_200_percent.pak";
}
}
// Skip the default pak file loading that would otherwise occur in
// ResourceBundle::LoadChromeResources().
resource_bundle_delegate_.set_allow_pack_file_load(false);
}
}

View File

@@ -1,106 +0,0 @@
// Copyright (c) 2011 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.
#ifndef CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_DELEGATE_H_
#define CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_DELEGATE_H_
#pragma once
#include <string>
#include "base/memory/raw_ptr.h"
#include "cef/include/cef_app.h"
#include "cef/libcef/common/alloy/alloy_content_client.h"
#include "cef/libcef/common/app_manager.h"
#include "cef/libcef/common/main_runner_handler.h"
#include "cef/libcef/common/resource_bundle_delegate.h"
#include "cef/libcef/common/task_runner_manager.h"
#include "content/public/app/content_main_delegate.h"
#if BUILDFLAG(IS_WIN)
#include "components/spellcheck/common/spellcheck_features.h"
#endif
namespace base {
class CommandLine;
}
class AlloyContentBrowserClient;
class AlloyContentRendererClient;
class ChromeContentUtilityClient;
// Manages state specific to the CEF runtime.
class AlloyMainDelegate : public content::ContentMainDelegate,
public CefAppManager,
public CefTaskRunnerManager {
public:
// |runner| and |settings| will be non-nullptr for the main process only,
// and will outlive this object.
AlloyMainDelegate(CefMainRunnerHandler* runner,
CefSettings* settings,
CefRefPtr<CefApp> application);
AlloyMainDelegate(const AlloyMainDelegate&) = delete;
AlloyMainDelegate& operator=(const AlloyMainDelegate&) = delete;
~AlloyMainDelegate() override;
// content::ContentMainDelegate overrides.
std::optional<int> PreBrowserMain() override;
std::optional<int> PostEarlyInitialization(InvokedIn invoked_in) override;
std::optional<int> BasicStartupComplete() override;
void PreSandboxStartup() override;
absl::variant<int, content::MainFunctionParams> RunProcess(
const std::string& process_type,
content::MainFunctionParams main_function_params) override;
void ProcessExiting(const std::string& process_type) override;
#if BUILDFLAG(IS_LINUX)
void ZygoteForked() override;
#endif
content::ContentBrowserClient* CreateContentBrowserClient() override;
content::ContentRendererClient* CreateContentRendererClient() override;
content::ContentUtilityClient* CreateContentUtilityClient() override;
protected:
// CefAppManager overrides.
CefRefPtr<CefApp> GetApplication() override { return application_; }
content::ContentClient* GetContentClient() override {
return &content_client_;
}
CefRefPtr<CefRequestContext> GetGlobalRequestContext() override;
CefBrowserContext* CreateNewBrowserContext(
const CefRequestContextSettings& settings,
base::OnceClosure initialized_cb) override;
// CefTaskRunnerManager overrides.
scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner()
override;
scoped_refptr<base::SingleThreadTaskRunner> GetUserVisibleTaskRunner()
override;
scoped_refptr<base::SingleThreadTaskRunner> GetUserBlockingTaskRunner()
override;
scoped_refptr<base::SingleThreadTaskRunner> GetRenderTaskRunner() override;
scoped_refptr<base::SingleThreadTaskRunner> GetWebWorkerTaskRunner() override;
private:
void InitializeResourceBundle();
const raw_ptr<CefMainRunnerHandler> runner_;
const raw_ptr<CefSettings> settings_;
CefRefPtr<CefApp> application_;
std::unique_ptr<AlloyContentBrowserClient> browser_client_;
std::unique_ptr<AlloyContentRendererClient> renderer_client_;
std::unique_ptr<ChromeContentUtilityClient> utility_client_;
AlloyContentClient content_client_;
CefResourceBundleDelegate resource_bundle_delegate_;
#if BUILDFLAG(IS_WIN)
// TODO: Add support for windows spellcheck service (see issue #3055).
spellcheck::ScopedDisableBrowserSpellCheckerForTesting
disable_browser_spellchecker_;
#endif
};
#endif // CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_DELEGATE_H_

View File

@@ -1,72 +0,0 @@
// Copyright 2020 The Chromium Embedded Framework Authors.
// Portions copyright 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.
#include "cef/libcef/common/alloy/alloy_main_runner_delegate.h"
#include "cef/libcef/browser/alloy/alloy_content_browser_client.h"
#include "cef/libcef/browser/alloy/chrome_browser_process_alloy.h"
#include "cef/libcef/common/alloy/alloy_main_delegate.h"
#include "cef/libcef/renderer/alloy/alloy_content_renderer_client.h"
#include "chrome/browser/chrome_process_singleton.h"
#include "content/public/browser/render_process_host.h"
#include "ui/base/resource/resource_bundle.h"
AlloyMainRunnerDelegate::AlloyMainRunnerDelegate(CefMainRunnerHandler* runner,
CefSettings* settings,
CefRefPtr<CefApp> application)
: runner_(runner), settings_(settings), application_(application) {}
AlloyMainRunnerDelegate::~AlloyMainRunnerDelegate() = default;
content::ContentMainDelegate*
AlloyMainRunnerDelegate::GetContentMainDelegate() {
if (!main_delegate_) {
main_delegate_ =
std::make_unique<AlloyMainDelegate>(runner_, settings_, application_);
}
return main_delegate_.get();
}
void AlloyMainRunnerDelegate::BeforeMainThreadInitialize(
const CefMainArgs& args) {
g_browser_process = new ChromeBrowserProcessAlloy();
}
void AlloyMainRunnerDelegate::BeforeMainThreadRun(
bool multi_threaded_message_loop) {
static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)->Initialize();
}
void AlloyMainRunnerDelegate::AfterUIThreadInitialize() {
static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)
->OnContextInitialized();
}
void AlloyMainRunnerDelegate::BeforeUIThreadShutdown() {
static_cast<AlloyContentBrowserClient*>(
CefAppManager::Get()->GetContentClient()->browser())
->CleanupOnUIThread();
static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)
->CleanupOnUIThread();
ui::ResourceBundle::GetSharedInstance().CleanupOnUIThread();
}
void AlloyMainRunnerDelegate::AfterUIThreadShutdown() {
ChromeProcessSingleton::DeleteInstance();
}
void AlloyMainRunnerDelegate::BeforeMainThreadShutdown() {
if (content::RenderProcessHost::run_renderer_in_process()) {
// Blocks until RenderProcess cleanup is complete.
AlloyContentRendererClient::Get()->RunSingleProcessCleanup();
}
}
void AlloyMainRunnerDelegate::AfterMainThreadShutdown() {
if (g_browser_process) {
delete g_browser_process;
g_browser_process = nullptr;
}
}

View File

@@ -1,50 +0,0 @@
// Copyright 2020 The Chromium Embedded Framework Authors.
// Portions copyright 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.
#ifndef CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_RUNNER_DELEGATE_
#define CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_RUNNER_DELEGATE_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "cef/include/cef_base.h"
#include "cef/libcef/common/main_runner_delegate.h"
#include "cef/libcef/common/main_runner_handler.h"
class AlloyMainDelegate;
class AlloyMainRunnerDelegate : public CefMainRunnerDelegate {
public:
// |runner| and |settings| will be non-nullptr for the main process only, and
// will outlive this object.
AlloyMainRunnerDelegate(CefMainRunnerHandler* runner,
CefSettings* settings,
CefRefPtr<CefApp> application);
AlloyMainRunnerDelegate(const AlloyMainRunnerDelegate&) = delete;
AlloyMainRunnerDelegate& operator=(const AlloyMainRunnerDelegate&) = delete;
~AlloyMainRunnerDelegate() override;
protected:
// CefMainRunnerDelegate overrides.
content::ContentMainDelegate* GetContentMainDelegate() override;
void BeforeMainThreadInitialize(const CefMainArgs& args) override;
void BeforeMainThreadRun(bool multi_threaded_message_loop) override;
void AfterUIThreadInitialize() override;
void BeforeUIThreadShutdown() override;
void AfterUIThreadShutdown() override;
void BeforeMainThreadShutdown() override;
void AfterMainThreadShutdown() override;
private:
std::unique_ptr<AlloyMainDelegate> main_delegate_;
const raw_ptr<CefMainRunnerHandler> runner_;
const raw_ptr<CefSettings> settings_;
CefRefPtr<CefApp> application_;
};
#endif // CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_RUNNER_DELEGATE_

View File

@@ -17,10 +17,6 @@
#include "base/path_service.h"
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "cef/libcef/common/net/scheme_registration.h"
#endif
namespace {
CefAppManager* g_manager = nullptr;
@@ -91,10 +87,6 @@ void CefAppManager::AddAdditionalSchemes(
schemeRegistrar.GetSchemes(schemes);
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
scheme::AddInternalSchemes(schemes);
#endif
scheme_info_list_locked_ = true;
}

View File

@@ -29,9 +29,6 @@ const char kResourcesDirPath[] = "resources-dir-path";
// Path to locales directory.
const char kLocalesDirPath[] = "locales-dir-path";
// Path to locales directory.
const char kDisablePackLoading[] = "disable-pack-loading";
// Stack size for uncaught exceptions.
const char kUncaughtExceptionStackSize[] = "uncaught-exception-stack-size";
@@ -72,9 +69,6 @@ const char kDisableTabToLinks[] = "disable-tab-to-links";
// Persist session cookies.
const char kPersistSessionCookies[] = "persist-session-cookies";
// Persist user preferences.
const char kPersistUserPreferences[] = "persist-user-preferences";
// Enable media (WebRTC audio/video) streaming.
const char kEnableMediaStream[] = "enable-media-stream";
@@ -108,13 +102,7 @@ const char kDisableNewBrowserInfoTimeout[] = "disable-new-browser-info-timeout";
// File used for logging DevTools protocol messages.
const char kDevToolsProtocolLogFile[] = "devtools-protocol-log-file";
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Enable use of the Chrome runtime in CEF. See issue #2969 for details.
const char kEnableChromeRuntime[] = "enable-chrome-runtime";
#endif
// Delegate all login requests to the client GetAuthCredentials callback when
// using the Chrome runtime.
// Delegate all login requests to the client GetAuthCredentials callback.
const char kDisableChromeLoginPrompt[] = "disable-chrome-login-prompt";
// Override the product component of the default User-Agent string.

View File

@@ -9,7 +9,6 @@
#pragma once
#include "build/build_config.h"
#include "cef/libcef/features/features.h"
namespace switches {
@@ -28,7 +27,6 @@ extern const char kLogItems_TimeStamp[];
extern const char kLogItems_TickCount[];
extern const char kResourcesDirPath[];
extern const char kLocalesDirPath[];
extern const char kDisablePackLoading[];
extern const char kUncaughtExceptionStackSize[];
extern const char kDefaultEncoding[];
extern const char kDisableJavascript[];
@@ -41,7 +39,6 @@ extern const char kImageShrinkStandaloneToFit[];
extern const char kDisableTextAreaResize[];
extern const char kDisableTabToLinks[];
extern const char kPersistSessionCookies[];
extern const char kPersistUserPreferences[];
extern const char kEnableMediaStream[];
extern const char kEnableSpeechInput[];
extern const char kEnableProfanityFilter[];
@@ -53,9 +50,6 @@ extern const char kDisablePdfExtension[];
extern const char kEnablePrintPreview[];
extern const char kDisableNewBrowserInfoTimeout[];
extern const char kDevToolsProtocolLogFile[];
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
extern const char kEnableChromeRuntime[];
#endif
extern const char kDisableChromeLoginPrompt[];
extern const char kUserAgentProductAndVersion[];
extern const char kDisableRequestHandlingForTesting[];

View File

@@ -1,39 +0,0 @@
# Copyright 2016 The Chromium Embedded Framework Authors. Portions copyright
# 2014 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.
import("//tools/json_schema_compiler/json_features.gni")
json_features("cef_api_features") {
feature_type = "APIFeature"
method_name = "AddCEFAPIFeatures"
sources = [
"_api_features.json",
]
}
json_features("cef_permission_features") {
feature_type = "PermissionFeature"
method_name = "AddCEFPermissionFeatures"
sources = [
"_permission_features.json",
]
}
json_features("cef_manifest_features") {
feature_type = "ManifestFeature"
method_name = "AddCEFManifestFeatures"
sources = [
# Use the same manifest features as Chrome.
"//chrome/common/extensions/api/_manifest_features.json",
]
}
group("extensions_features") {
public_deps = [
":cef_api_features",
":cef_manifest_features",
":cef_permission_features",
"//extensions/common/api:extensions_features",
]
}

View File

@@ -1,66 +0,0 @@
This directory provides API definitions for CEF. Some extensions are implemented
using Mojo and others use an older JSON-based format.
<api> is the name of the API definition (e.g. 'alarms').
<class> is the name of the class implementation (e.g. 'AlarmManager').
To add a new extension API implemented only in CEF ***:
1. Add libcef/common/extensions/api/<api>.idl or .json file which defines the
API.
2. Add <api>.idl or .json to the 'schema_sources' list in
libcef/common/extensions/api/BUILD.gn. Serialization code will be
generated based on this list in step 4.
3. Add libcef/browser/extensions/api/<api>/<api>_api.[h|cc] class implementation
files and associated entries to the 'libcef_static' target in BUILD.gn.
4. Run the cef_create_projects script and build to generate the
cef/libcef/common/extensions/api/<api>.h file and other serialization code
required by the extensions system.
5. Add an entry in the libcef/common/extensions/api/_*_features.json files if
necessary [1].
6. Add an entry in the libcef/common/extensions/api/*_manifest_overlay.json
files if necessary [2].
7. Call `<class>::GetInstance();` or `<class>Factory::GetFactoryInstance();` [3]
from EnsureBrowserContextKeyedServiceFactoriesBuilt in
libcef/browser/browser_context_keyed_service_factories.cc.
8. Call `DependsOn(<class>Factory::GetInstance());` from
CefExtensionSystemFactory::CefExtensionSystemFactory in
libcef/browser/extensions/extension_system_factory.cc if necessary [3].
*** Note that CEF does not currently expose its own Mojo APIs. Related code is
commented out in:
cef/BUILD.gn
cef/libcef/common/extensions/api/BUILD.gn
CefExtensionsBrowserClient::RegisterExtensionFunctions
CefExtensionsClient::IsAPISchemaGenerated
CefExtensionsClient::GetAPISchema
To add a new extension API implemented in Chrome:
1. Register the API in libcef/browser/extensions/chrome_api_registration.cc
2. Perform steps 5 through 8 above.
See https://www.chromium.org/developers/design-documents/mojo for more
information.
[1] A feature can optionally express requirements for where it can be accessed.
See the _api_features.json and _permission_features.json files for
additional details. For Chrome extensions this should match the definitions
in the chrome/common/extensions/api/_*_features.json files.
[2] Service Manifest InterfaceProviderSpecs control interfaces exposed between
processes. Mojo interfaces exposed at the frame level are controlled by the
"navigation:frame" dictionary. Those exposed at the process level are
controlled by the "service_manager:connector" dictionary. Failure to specify
this correctly may result in a console error like the following:
InterfaceProviderSpec "navigation:frame" prevented service:
service:content_renderer from binding interface:
mojom::Foo exposed by: service:content_browser
[3] Some Mojo APIs use singleton Factory objects that create a one-to-one
relationship between a service and a BrowserContext. This is used primarily
to control shutdown/destruction order and implementors must explicitly state
which services are depended on. See comments in
components/keyed_service/content/browser_context_keyed_service_factory.h
for additional details.

View File

@@ -1,46 +0,0 @@
// Copyright 2014 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.
// This file defines extension APIs implemented in CEF.
// See extensions/common/features/* to understand this file, in particular
// feature.h, simple_feature.h, and feature_provider.h.
// If APIs are defined in chrome then entries must also be added in
// libcef/browser/extensions/chrome_api_registration.cc.
{
// From chrome/common/extensions/api/_api_features.json.
// Required by the PDF extension which is hosted in a guest view.
"contentSettings": {
"dependencies": ["permission:contentSettings"],
"contexts": ["privileged_extension"]
},
"mimeHandlerViewGuestInternal": {
"internal": true,
"contexts": "all",
"channel": "stable",
"matches": ["<all_urls>"]
},
"pdfViewerPrivate": {
"dependencies": ["permission:pdfViewerPrivate"],
"contexts": ["privileged_extension"]
},
"resourcesPrivate": [
{
"dependencies": ["permission:resourcesPrivate"],
"contexts": ["privileged_extension"]
},
{
"channel": "stable",
"contexts": ["webui"],
"matches": ["chrome://print/*"]
}
],
"tabs": {
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"],
"contexts": ["privileged_extension"],
"disallow_for_service_workers": false
}
}

View File

@@ -1,43 +0,0 @@
// 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.
// This file defines permissions for extension APIs implemented by CEF.
// See extensions/common/features/* to understand this file, in particular
// feature.h, simple_feature.h, and feature_provider.h.
// If APIs are defined in chrome then entries must also be added in
// libcef/browser/extensions/chrome_api_registration.cc.
{
// From chrome/common/extensions/api/_permission_features.json.
// Required by the PDF extension which is hosted in a guest view.
"contentSettings": {
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"]
},
"pdfViewerPrivate": {
"channel": "stable",
"extension_types": ["extension"],
"allowlist": [
"CBCC42ABED43A4B58FE3810E62AFFA010EB0349F" // PDF Viewer
]
},
"resourcesPrivate": {
"channel": "stable",
"extension_types": [
"extension", "legacy_packaged_app", "platform_app"
],
"location": "component"
},
"tabs": [
{
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"]
},
{
"channel": "stable",
"extension_types": ["platform_app"]
}
]
}

View File

@@ -1,28 +0,0 @@
// Copyright (c) 2016 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.
#include "cef/libcef/common/extensions/chrome_generated_schemas.h"
#include "cef/libcef/browser/extensions/chrome_api_registration.h"
#include "chrome/common/extensions/api/generated_schemas.h"
namespace extensions::api::cef {
// static
std::string_view ChromeGeneratedSchemas::Get(const std::string& name) {
if (!ChromeFunctionRegistry::IsSupported(name)) {
return std::string_view();
}
return extensions::api::ChromeGeneratedSchemas::Get(name);
}
// static
bool ChromeGeneratedSchemas::IsGenerated(std::string name) {
if (!ChromeFunctionRegistry::IsSupported(name)) {
return false;
}
return extensions::api::ChromeGeneratedSchemas::IsGenerated(name);
}
} // namespace extensions::api::cef

View File

@@ -1,29 +0,0 @@
// Copyright (c) 2016 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.
// GENERATED FROM THE API DEFINITIONS IN
// chrome\common\extensions\api
// DO NOT EDIT.
#ifndef CEF_LIBCEF_COMMON_EXTENSIONS_CHROME_GENERATED_SCHEMAS_H_
#define CEF_LIBCEF_COMMON_EXTENSIONS_CHROME_GENERATED_SCHEMAS_H_
#include <map>
#include <string>
#include <string_view>
namespace extensions::api::cef {
class ChromeGeneratedSchemas {
public:
// Determines if schema named |name| is generated.
static bool IsGenerated(std::string name);
// Gets the API schema named |name|.
static std::string_view Get(const std::string& name);
};
} // namespace extensions::api::cef
#endif // CEF_LIBCEF_COMMON_EXTENSIONS_CHROME_GENERATED_SCHEMAS_H_

View File

@@ -1,88 +0,0 @@
// Copyright 2018 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.
#include "cef/libcef/common/extensions/extensions_api_provider.h"
#include "cef/grit/cef_resources.h"
#include "cef/libcef/common/extensions/chrome_generated_schemas.h"
// #include "cef/libcef/common/extensions/api/generated_schemas.h"
#include "cef/libcef/common/extensions/api/cef_api_features.h"
#include "cef/libcef/common/extensions/api/cef_manifest_features.h"
#include "cef/libcef/common/extensions/api/cef_permission_features.h"
#include "chrome/common/extensions/chrome_manifest_handlers.h"
#include "chrome/common/extensions/permissions/chrome_api_permissions.h"
#include "extensions/common/features/json_feature_provider_source.h"
#include "extensions/common/permissions/permissions_info.h"
namespace extensions {
CefExtensionsAPIProvider::CefExtensionsAPIProvider() = default;
void CefExtensionsAPIProvider::AddAPIFeatures(FeatureProvider* provider) {
AddCEFAPIFeatures(provider);
}
void CefExtensionsAPIProvider::AddManifestFeatures(FeatureProvider* provider) {
AddCEFManifestFeatures(provider);
}
void CefExtensionsAPIProvider::AddPermissionFeatures(
FeatureProvider* provider) {
AddCEFPermissionFeatures(provider);
}
void CefExtensionsAPIProvider::AddBehaviorFeatures(FeatureProvider* provider) {
// No CEF-specific behavior features.
}
void CefExtensionsAPIProvider::AddAPIJSONSources(
JSONFeatureProviderSource* json_source) {
// Extension API features specific to CEF. See
// libcef/common/extensions/api/README.txt for additional details.
json_source->LoadJSON(IDR_CEF_EXTENSION_API_FEATURES);
}
bool CefExtensionsAPIProvider::IsAPISchemaGenerated(const std::string& name) {
// Schema for CEF-only APIs.
// TODO(cef): Enable if/when CEF exposes its own Mojo APIs. See
// libcef/common/extensions/api/README.txt for details.
// if (api::cef::CefGeneratedSchemas::IsGenerated(name))
// return true;
// Chrome APIs whitelisted by CEF.
if (api::cef::ChromeGeneratedSchemas::IsGenerated(name)) {
return true;
}
return false;
}
std::string_view CefExtensionsAPIProvider::GetAPISchema(
const std::string& name) {
// Schema for CEF-only APIs.
// TODO(cef): Enable if/when CEF exposes its own Mojo APIs. See
// libcef/common/extensions/api/README.txt for details.
// if (api::cef::CefGeneratedSchemas::IsGenerated(name))
// return api::cef::CefGeneratedSchemas::Get(name);
// Chrome APIs whitelisted by CEF.
if (api::cef::ChromeGeneratedSchemas::IsGenerated(name)) {
return api::cef::ChromeGeneratedSchemas::Get(name);
}
return std::string_view();
}
void CefExtensionsAPIProvider::RegisterPermissions(
PermissionsInfo* permissions_info) {
permissions_info->RegisterPermissions(
chrome_api_permissions::GetPermissionInfos(),
chrome_api_permissions::GetPermissionAliases());
}
void CefExtensionsAPIProvider::RegisterManifestHandlers() {
RegisterChromeManifestHandlers();
}
} // namespace extensions

View File

@@ -1,33 +0,0 @@
// Copyright 2018 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.
#ifndef CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_API_PROVIDER_H_
#define CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_API_PROVIDER_H_
#include "extensions/common/extensions_api_provider.h"
namespace extensions {
class CefExtensionsAPIProvider : public ExtensionsAPIProvider {
public:
CefExtensionsAPIProvider();
CefExtensionsAPIProvider(const CefExtensionsAPIProvider&) = delete;
CefExtensionsAPIProvider& operator=(const CefExtensionsAPIProvider&) = delete;
// ExtensionsAPIProvider:
void AddAPIFeatures(FeatureProvider* provider) override;
void AddManifestFeatures(FeatureProvider* provider) override;
void AddPermissionFeatures(FeatureProvider* provider) override;
void AddBehaviorFeatures(FeatureProvider* provider) override;
void AddAPIJSONSources(JSONFeatureProviderSource* json_source) override;
bool IsAPISchemaGenerated(const std::string& name) override;
std::string_view GetAPISchema(const std::string& name) override;
void RegisterPermissions(PermissionsInfo* permissions_info) override;
void RegisterManifestHandlers() override;
};
} // namespace extensions
#endif // CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_API_PROVIDER_H_

View File

@@ -1,101 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 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.
#include "cef/libcef/common/extensions/extensions_client.h"
#include <utility>
#include "base/logging.h"
#include "cef/libcef/common/cef_switches.h"
#include "cef/libcef/common/extensions/extensions_api_provider.h"
#include "extensions/common/core_extensions_api_provider.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/features/simple_feature.h"
#include "extensions/common/permissions/permission_message_provider.h"
#include "extensions/common/url_pattern_set.h"
namespace extensions {
namespace {
template <class FeatureClass>
SimpleFeature* CreateFeature() {
return new FeatureClass;
}
} // namespace
CefExtensionsClient::CefExtensionsClient()
: webstore_base_url_(extension_urls::kChromeWebstoreBaseURL),
new_webstore_base_url_(extension_urls::kNewChromeWebstoreBaseURL),
webstore_update_url_(extension_urls::kChromeWebstoreUpdateURL) {
AddAPIProvider(std::make_unique<CoreExtensionsAPIProvider>());
AddAPIProvider(std::make_unique<CefExtensionsAPIProvider>());
}
CefExtensionsClient::~CefExtensionsClient() = default;
void CefExtensionsClient::Initialize() {}
void CefExtensionsClient::InitializeWebStoreUrls(
base::CommandLine* command_line) {}
const PermissionMessageProvider&
CefExtensionsClient::GetPermissionMessageProvider() const {
return permission_message_provider_;
}
const std::string CefExtensionsClient::GetProductName() {
return "cef";
}
void CefExtensionsClient::FilterHostPermissions(
const URLPatternSet& hosts,
URLPatternSet* new_hosts,
PermissionIDSet* permissions) const {
NOTIMPLEMENTED();
}
void CefExtensionsClient::SetScriptingAllowlist(
const ScriptingAllowlist& allowlist) {
scripting_allowlist_ = allowlist;
}
const ExtensionsClient::ScriptingAllowlist&
CefExtensionsClient::GetScriptingAllowlist() const {
// TODO(jamescook): Real allowlist.
return scripting_allowlist_;
}
URLPatternSet CefExtensionsClient::GetPermittedChromeSchemeHosts(
const Extension* extension,
const APIPermissionSet& api_permissions) const {
return URLPatternSet();
}
bool CefExtensionsClient::IsScriptableURL(const GURL& url,
std::string* error) const {
return true;
}
const GURL& CefExtensionsClient::GetWebstoreBaseURL() const {
return webstore_base_url_;
}
const GURL& CefExtensionsClient::GetNewWebstoreBaseURL() const {
return new_webstore_base_url_;
}
const GURL& CefExtensionsClient::GetWebstoreUpdateURL() const {
return webstore_update_url_;
}
bool CefExtensionsClient::IsBlocklistUpdateURL(const GURL& url) const {
// TODO(rockot): Maybe we want to do something else here. For now we accept
// any URL as a blocklist URL because we don't really care.
return true;
}
} // namespace extensions

View File

@@ -1,58 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 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.
#ifndef CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_CLIENT_H_
#define CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_CLIENT_H_
#include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
#include "extensions/common/extensions_client.h"
#include "url/gurl.h"
namespace extensions {
// The CEF implementation of ExtensionsClient.
class CefExtensionsClient : public ExtensionsClient {
public:
CefExtensionsClient();
CefExtensionsClient(const CefExtensionsClient&) = delete;
CefExtensionsClient& operator=(const CefExtensionsClient&) = delete;
~CefExtensionsClient() override;
// ExtensionsClient overrides:
void Initialize() override;
void InitializeWebStoreUrls(base::CommandLine* command_line) override;
const PermissionMessageProvider& GetPermissionMessageProvider()
const override;
const std::string GetProductName() override;
void FilterHostPermissions(const URLPatternSet& hosts,
URLPatternSet* new_hosts,
PermissionIDSet* permissions) const override;
void SetScriptingAllowlist(const ScriptingAllowlist& allowlist) override;
const ScriptingAllowlist& GetScriptingAllowlist() const override;
URLPatternSet GetPermittedChromeSchemeHosts(
const Extension* extension,
const APIPermissionSet& api_permissions) const override;
bool IsScriptableURL(const GURL& url, std::string* error) const override;
const GURL& GetWebstoreBaseURL() const override;
const GURL& GetNewWebstoreBaseURL() const override;
const GURL& GetWebstoreUpdateURL() const override;
bool IsBlocklistUpdateURL(const GURL& url) const override;
private:
const ChromePermissionMessageProvider permission_message_provider_;
ScriptingAllowlist scripting_allowlist_;
// Mutable to allow caching in a const method.
const GURL webstore_base_url_;
const GURL new_webstore_base_url_;
const GURL webstore_update_url_;
};
} // namespace extensions
#endif // CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_CLIENT_H_

View File

@@ -1,28 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
#include "cef/libcef/common/extensions/extensions_util.h"
#include "base/command_line.h"
#include "cef/libcef/common/cef_switches.h"
#include "cef/libcef/features/runtime.h"
#include "chrome/common/chrome_switches.h"
namespace extensions {
bool ExtensionsEnabled() {
static bool enabled = cef::IsAlloyRuntimeEnabled() &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableExtensions);
return enabled;
}
bool PdfExtensionEnabled() {
static bool enabled =
ExtensionsEnabled() && !base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisablePdfExtension);
return enabled;
}
} // namespace extensions

View File

@@ -1,22 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
#ifndef CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_UTIL_H_
#define CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_UTIL_H_
#include "cef/libcef/features/runtime.h"
namespace extensions {
// Returns true if extensions have not been disabled via the command-line.
// Always returns false with Chrome runtime even if Alloy style is used.
bool ExtensionsEnabled();
// Returns true if the PDF extension has not been disabled via the command-line.
// Always returns false with Chrome runtime even if Alloy style is used.
bool PdfExtensionEnabled();
} // namespace extensions
#endif // CEF_LIBCEF_COMMON_EXTENSIONS_EXTENSIONS_UTIL_H_

View File

@@ -1,17 +0,0 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cef/libcef/common/net/net_resource_provider.h"
#include "base/logging.h"
#include "chrome/common/net/net_resource_provider.h"
scoped_refptr<base::RefCountedMemory> NetResourceProvider(int key) {
// Chrome performs substitution of localized strings for directory listings.
scoped_refptr<base::RefCountedMemory> value = ChromeNetResourceProvider(key);
if (!value) {
LOG(ERROR) << "No data resource available for id " << key;
}
return value;
}

View File

@@ -1,14 +0,0 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_LIBCEF_COMMON_NET_RESOURCE_PROVIDER_H_
#define CEF_LIBCEF_COMMON_NET_RESOURCE_PROVIDER_H_
#pragma once
#include "base/memory/ref_counted_memory.h"
// This is called indirectly by the network layer to access resources.
scoped_refptr<base::RefCountedMemory> NetResourceProvider(int key);
#endif // CEF_LIBCEF_COMMON_NET_RESOURCE_PROVIDER_H_

View File

@@ -5,66 +5,13 @@
#include "cef/libcef/common/net/scheme_registration.h"
#include "base/containers/contains.h"
#include "cef/libcef/features/runtime.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "url/url_constants.h"
#include "url/url_util.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "cef/libcef/common/app_manager.h"
#include "cef/libcef/common/net/scheme_info.h"
#endif
namespace scheme {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void AddInternalSchemes(content::ContentClient::Schemes* schemes) {
if (!cef::IsAlloyRuntimeEnabled()) {
return;
}
// chrome: and chrome-devtools: schemes are registered in
// RenderThreadImpl::RegisterSchemes().
// Access restrictions for chrome-extension: and chrome-extension-resource:
// schemes will be applied in AlloyContentRendererClient::WillSendRequest().
static CefSchemeInfo internal_schemes[] = {
{
extensions::kExtensionScheme, true, /* is_standard */
false, /* is_local */
false, /* is_display_isolated */
true, /* is_secure */
true, /* is_cors_enabled */
true, /* is_csp_bypassing */
},
};
// The |is_display_isolated| value is excluded here because it's registered
// with Blink only.
for (const auto& scheme : internal_schemes) {
if (scheme.is_standard) {
schemes->standard_schemes.push_back(scheme.scheme_name);
if (!scheme.is_local && !scheme.is_display_isolated) {
schemes->referrer_schemes.push_back(scheme.scheme_name);
}
}
if (scheme.is_local) {
schemes->local_schemes.push_back(scheme.scheme_name);
}
if (scheme.is_secure) {
schemes->secure_schemes.push_back(scheme.scheme_name);
}
if (scheme.is_cors_enabled) {
schemes->cors_enabled_schemes.push_back(scheme.scheme_name);
}
if (scheme.is_csp_bypassing) {
schemes->csp_bypassing_schemes.push_back(scheme.scheme_name);
}
CefAppManager::Get()->AddCustomScheme(&scheme);
}
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
bool IsInternalHandledScheme(const std::string& scheme) {
static const char* schemes[] = {
url::kAboutScheme,

View File

@@ -9,19 +9,8 @@
#include <string>
#include <vector>
#include "cef/libcef/features/features.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "content/public/common/content_client.h"
#endif
namespace scheme {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Add internal schemes.
void AddInternalSchemes(content::ContentClient::Schemes* schemes);
#endif
// Returns true if the specified |scheme| is handled internally.
bool IsInternalHandledScheme(const std::string& scheme);

View File

@@ -1,42 +1,19 @@
#include "cef/libcef/common/resource_bundle_delegate.h"
#include "cef/libcef/common/app_manager.h"
#include "cef/libcef/features/runtime.h"
CefResourceBundleDelegate::CefResourceBundleDelegate() {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Alloy bootstrap explicitly enables pack file loading in
// AlloyMainDelegate::InitializeResourceBundle, and it is otherwise disabled
// by default. Chrome bootstrap does not support this.
allow_pack_file_load_ = cef::IsChromeRuntimeEnabled();
#endif
}
CefResourceBundleDelegate::CefResourceBundleDelegate() = default;
base::FilePath CefResourceBundleDelegate::GetPathForResourcePack(
const base::FilePath& pack_path,
ui::ResourceScaleFactor scale_factor) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Only allow the cef pack file to load.
if (!pack_loading_disabled_ && allow_pack_file_load_) {
return pack_path;
}
return base::FilePath();
#else
return pack_path;
#endif
}
base::FilePath CefResourceBundleDelegate::GetPathForLocalePack(
const base::FilePath& pack_path,
const std::string& locale) {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (!pack_loading_disabled_) {
return pack_path;
}
return base::FilePath();
#else
return pack_path;
#endif
}
gfx::Image CefResourceBundleDelegate::GetImageNamed(int resource_id) {
@@ -81,12 +58,6 @@ bool CefResourceBundleDelegate::GetRawDataResource(
}
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (pack_loading_disabled_) {
return true;
}
#endif
return !value->empty();
}
@@ -105,11 +76,5 @@ bool CefResourceBundleDelegate::GetLocalizedString(
}
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
if (pack_loading_disabled_) {
return true;
}
#endif
return !value->empty();
}

View File

@@ -7,7 +7,6 @@
#define CEF_LIBCEF_COMMON_RESOURCE_BUNDLE_DELEGATE_H_
#pragma once
#include "cef/libcef/features/features.h"
#include "ui/base/resource/resource_bundle.h"
class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate {
@@ -18,13 +17,6 @@ class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate {
CefResourceBundleDelegate& operator=(const CefResourceBundleDelegate&) =
delete;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void set_pack_loading_disabled(bool val) { pack_loading_disabled_ = val; }
bool pack_loading_disabled() const { return pack_loading_disabled_; }
void set_allow_pack_file_load(bool val) { allow_pack_file_load_ = val; }
bool allow_pack_file_load() const { return allow_pack_file_load_; }
#endif
private:
// ui::ResourceBundle::Delegate methods.
base::FilePath GetPathForResourcePack(
@@ -42,12 +34,6 @@ class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate {
ui::ResourceScaleFactor scale_factor,
std::string_view* value) const override;
bool GetLocalizedString(int message_id, std::u16string* value) const override;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
private:
bool pack_loading_disabled_ = false;
bool allow_pack_file_load_;
#endif
};
#endif // CEF_LIBCEF_COMMON_RESOURCE_BUNDLE_DELEGATE_H_

View File

@@ -25,22 +25,6 @@
#include "cef/libcef/common/util_mac.h"
#endif
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "base/files/file_util.h"
#include "base/notreached.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "ui/base/layout.h"
#if BUILDFLAG(IS_MAC)
#include "base/apple/foundation_util.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/registry.h"
#endif
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace resource_util {
namespace {
@@ -123,100 +107,6 @@ base::FilePath GetUserDataPath(CefSettings* settings,
} // namespace
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace {
// Consider downloads 'dangerous' if they go to the home directory on Linux and
// to the desktop on any platform.
// From chrome/browser/download/download_prefs.cc.
bool DownloadPathIsDangerous(const base::FilePath& download_path) {
#if BUILDFLAG(IS_LINUX)
base::FilePath home_dir = base::GetHomeDir();
if (download_path == home_dir) {
return true;
}
#endif
base::FilePath desktop_dir;
if (!base::PathService::Get(base::DIR_USER_DESKTOP, &desktop_dir)) {
DCHECK(false);
return false;
}
return (download_path == desktop_dir);
}
bool GetDefaultDownloadDirectory(base::FilePath* result) {
// This will return the safe download directory if necessary.
return chrome::GetUserDownloadsDirectory(result);
}
bool GetDefaultDownloadSafeDirectory(base::FilePath* result) {
// Start with the default download directory.
if (!GetDefaultDownloadDirectory(result)) {
return false;
}
if (DownloadPathIsDangerous(*result)) {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
// Explicitly switch to the safe download directory.
return chrome::GetUserDownloadsDirectorySafe(result);
#else
// No viable alternative on macOS.
return false;
#endif
}
return true;
}
} // namespace
#if BUILDFLAG(IS_MAC)
// Use a "~/Library/Logs/<app name>_debug.log" file where <app name> is the name
// of the running executable.
base::FilePath GetDefaultLogFilePath() {
std::string exe_name = util_mac::GetMainProcessPath().BaseName().value();
return base::apple::GetUserLibraryPath()
.Append(FILE_PATH_LITERAL("Logs"))
.Append(FILE_PATH_LITERAL(exe_name + "_debug.log"));
}
#else // !BUILDFLAG(IS_MAC)
// Use a "debug.log" file in the running executable's directory.
base::FilePath GetDefaultLogFilePath() {
base::FilePath log_path;
base::PathService::Get(base::DIR_EXE, &log_path);
return log_path.Append(FILE_PATH_LITERAL("debug.log"));
}
#endif // !BUILDFLAG(IS_MAC)
void OverrideDefaultDownloadDir() {
base::FilePath dir_default_download;
base::FilePath dir_default_download_safe;
if (GetDefaultDownloadDirectory(&dir_default_download)) {
base::PathService::Override(chrome::DIR_DEFAULT_DOWNLOADS,
dir_default_download);
}
if (GetDefaultDownloadSafeDirectory(&dir_default_download_safe)) {
base::PathService::Override(chrome::DIR_DEFAULT_DOWNLOADS_SAFE,
dir_default_download_safe);
}
}
// Same as ui::ResourceBundle::IsScaleFactorSupported.
bool IsScaleFactorSupported(ui::ResourceScaleFactor scale_factor) {
const auto& supported_scale_factors = ui::GetSupportedResourceScaleFactors();
return std::find(supported_scale_factors.begin(),
supported_scale_factors.end(),
scale_factor) != supported_scale_factors.end();
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#if BUILDFLAG(IS_MAC)
base::FilePath GetResourcesDir() {

View File

@@ -7,32 +7,13 @@
#pragma once
#include "cef/include/cef_base.h"
#include "cef/libcef/features/features.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "ui/base/resource/resource_scale_factor.h"
#endif
namespace base {
class CommandLine;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
class FilePath;
#endif
} // namespace base
namespace resource_util {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Returns the default path for the debug.log file.
base::FilePath GetDefaultLogFilePath();
// Called from MainDelegate::PreSandboxStartup.
void OverrideDefaultDownloadDir();
// Returns true if |scale_factor| is supported by this platform.
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();