2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/resource_bundle_delegate.h"
|
2019-09-04 17:13:32 +02:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/app_manager.h"
|
2024-05-03 18:50:23 +02:00
|
|
|
#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
|
|
|
|
}
|
2019-09-04 17:13:32 +02:00
|
|
|
|
|
|
|
base::FilePath CefResourceBundleDelegate::GetPathForResourcePack(
|
|
|
|
const base::FilePath& pack_path,
|
2021-08-20 01:40:49 +02:00
|
|
|
ui::ResourceScaleFactor scale_factor) {
|
2024-05-03 18:50:23 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2019-09-04 17:13:32 +02:00
|
|
|
// Only allow the cef pack file to load.
|
2020-06-28 23:05:36 +02:00
|
|
|
if (!pack_loading_disabled_ && allow_pack_file_load_) {
|
2019-09-04 17:13:32 +02:00
|
|
|
return pack_path;
|
|
|
|
}
|
|
|
|
return base::FilePath();
|
2024-05-03 18:50:23 +02:00
|
|
|
#else
|
|
|
|
return pack_path;
|
|
|
|
#endif
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
base::FilePath CefResourceBundleDelegate::GetPathForLocalePack(
|
|
|
|
const base::FilePath& pack_path,
|
|
|
|
const std::string& locale) {
|
2024-05-03 18:50:23 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!pack_loading_disabled_) {
|
2019-09-04 17:13:32 +02:00
|
|
|
return pack_path;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-09-04 17:13:32 +02:00
|
|
|
return base::FilePath();
|
2024-05-03 18:50:23 +02:00
|
|
|
#else
|
|
|
|
return pack_path;
|
|
|
|
#endif
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Image CefResourceBundleDelegate::GetImageNamed(int resource_id) {
|
|
|
|
return gfx::Image();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Image CefResourceBundleDelegate::GetNativeImageNamed(int resource_id) {
|
|
|
|
return gfx::Image();
|
|
|
|
}
|
|
|
|
|
2022-03-26 02:12:30 +01:00
|
|
|
base::RefCountedMemory* CefResourceBundleDelegate::LoadDataResourceBytes(
|
2019-09-04 17:13:32 +02:00
|
|
|
int resource_id,
|
2021-08-20 01:40:49 +02:00
|
|
|
ui::ResourceScaleFactor scale_factor) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|
|
|
|
|
2024-03-19 22:11:42 +01:00
|
|
|
std::optional<std::string> CefResourceBundleDelegate::LoadDataResourceString(
|
2020-12-02 23:31:49 +01:00
|
|
|
int resource_id) {
|
2024-03-19 22:11:42 +01:00
|
|
|
return std::nullopt;
|
2020-12-02 23:31:49 +01:00
|
|
|
}
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
bool CefResourceBundleDelegate::GetRawDataResource(
|
|
|
|
int resource_id,
|
2021-08-20 01:40:49 +02:00
|
|
|
ui::ResourceScaleFactor scale_factor,
|
2024-04-23 22:06:00 +02:00
|
|
|
std::string_view* value) const {
|
2020-06-28 23:05:36 +02:00
|
|
|
auto application = CefAppManager::Get()->GetApplication();
|
|
|
|
if (application) {
|
2019-09-04 17:13:32 +02:00
|
|
|
CefRefPtr<CefResourceBundleHandler> handler =
|
2020-06-28 23:05:36 +02:00
|
|
|
application->GetResourceBundleHandler();
|
2019-09-04 17:13:32 +02:00
|
|
|
if (handler.get()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
void* data = nullptr;
|
2019-09-04 17:13:32 +02:00
|
|
|
size_t data_size = 0;
|
2021-09-20 11:06:23 +02:00
|
|
|
if (scale_factor != ui::kScaleFactorNone) {
|
2019-09-04 17:13:32 +02:00
|
|
|
if (handler->GetDataResourceForScale(
|
|
|
|
resource_id, static_cast<cef_scale_factor_t>(scale_factor),
|
|
|
|
data, data_size)) {
|
2024-04-23 22:06:00 +02:00
|
|
|
*value = std::string_view(static_cast<char*>(data), data_size);
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|
|
|
|
} else if (handler->GetDataResource(resource_id, data, data_size)) {
|
2024-04-23 22:06:00 +02:00
|
|
|
*value = std::string_view(static_cast<char*>(data), data_size);
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 18:50:23 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
if (pack_loading_disabled_) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return !value->empty();
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
bool CefResourceBundleDelegate::GetLocalizedString(
|
|
|
|
int message_id,
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string* value) const {
|
2020-06-28 23:05:36 +02:00
|
|
|
auto application = CefAppManager::Get()->GetApplication();
|
|
|
|
if (application) {
|
2019-09-04 17:13:32 +02:00
|
|
|
CefRefPtr<CefResourceBundleHandler> handler =
|
2020-06-28 23:05:36 +02:00
|
|
|
application->GetResourceBundleHandler();
|
2019-09-04 17:13:32 +02:00
|
|
|
if (handler.get()) {
|
|
|
|
CefString cef_str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (handler->GetLocalizedString(message_id, cef_str)) {
|
2019-09-04 17:13:32 +02:00
|
|
|
*value = cef_str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 18:50:23 +02:00
|
|
|
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
|
|
|
if (pack_loading_disabled_) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return !value->empty();
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|