2019-09-04 17:13:32 +02:00
|
|
|
#include "libcef/common/resource_bundle_delegate.h"
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
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) {
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
base::FilePath CefResourceBundleDelegate::GetPathForLocalePack(
|
|
|
|
const base::FilePath& pack_path,
|
|
|
|
const std::string& locale) {
|
2020-06-28 23:05:36 +02:00
|
|
|
if (!pack_loading_disabled_)
|
2019-09-04 17:13:32 +02:00
|
|
|
return pack_path;
|
|
|
|
return base::FilePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Image CefResourceBundleDelegate::GetImageNamed(int resource_id) {
|
|
|
|
return gfx::Image();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Image CefResourceBundleDelegate::GetNativeImageNamed(int resource_id) {
|
|
|
|
return gfx::Image();
|
|
|
|
}
|
|
|
|
|
|
|
|
base::RefCountedStaticMemory* CefResourceBundleDelegate::LoadDataResourceBytes(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-06-04 03:34:56 +02:00
|
|
|
absl::optional<std::string> CefResourceBundleDelegate::LoadDataResourceString(
|
2020-12-02 23:31:49 +01:00
|
|
|
int resource_id) {
|
2021-06-04 03:34:56 +02:00
|
|
|
return absl::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,
|
2020-10-08 21:54:42 +02:00
|
|
|
base::StringPiece* 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;
|
|
|
|
if (scale_factor != ui::SCALE_FACTOR_NONE) {
|
|
|
|
if (handler->GetDataResourceForScale(
|
|
|
|
resource_id, static_cast<cef_scale_factor_t>(scale_factor),
|
|
|
|
data, data_size)) {
|
|
|
|
*value = base::StringPiece(static_cast<char*>(data), data_size);
|
|
|
|
}
|
|
|
|
} else if (handler->GetDataResource(resource_id, data, data_size)) {
|
|
|
|
*value = base::StringPiece(static_cast<char*>(data), data_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
return (pack_loading_disabled_ || !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;
|
|
|
|
if (handler->GetLocalizedString(message_id, cef_str))
|
|
|
|
*value = cef_str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
return (pack_loading_disabled_ || !value->empty());
|
2019-09-04 17:13:32 +02:00
|
|
|
}
|