1 #include "libcef/common/resource_bundle_delegate.h"
2
3 #include "libcef/common/app_manager.h"
4
GetPathForResourcePack(const base::FilePath & pack_path,ui::ResourceScaleFactor scale_factor)5 base::FilePath CefResourceBundleDelegate::GetPathForResourcePack(
6 const base::FilePath& pack_path,
7 ui::ResourceScaleFactor scale_factor) {
8 // Only allow the cef pack file to load.
9 if (!pack_loading_disabled_ && allow_pack_file_load_) {
10 return pack_path;
11 }
12 return base::FilePath();
13 }
14
GetPathForLocalePack(const base::FilePath & pack_path,const std::string & locale)15 base::FilePath CefResourceBundleDelegate::GetPathForLocalePack(
16 const base::FilePath& pack_path,
17 const std::string& locale) {
18 if (!pack_loading_disabled_)
19 return pack_path;
20 return base::FilePath();
21 }
22
GetImageNamed(int resource_id)23 gfx::Image CefResourceBundleDelegate::GetImageNamed(int resource_id) {
24 return gfx::Image();
25 }
26
GetNativeImageNamed(int resource_id)27 gfx::Image CefResourceBundleDelegate::GetNativeImageNamed(int resource_id) {
28 return gfx::Image();
29 }
30
LoadDataResourceBytes(int resource_id,ui::ResourceScaleFactor scale_factor)31 base::RefCountedStaticMemory* CefResourceBundleDelegate::LoadDataResourceBytes(
32 int resource_id,
33 ui::ResourceScaleFactor scale_factor) {
34 return nullptr;
35 }
36
LoadDataResourceString(int resource_id)37 absl::optional<std::string> CefResourceBundleDelegate::LoadDataResourceString(
38 int resource_id) {
39 return absl::nullopt;
40 }
41
GetRawDataResource(int resource_id,ui::ResourceScaleFactor scale_factor,base::StringPiece * value) const42 bool CefResourceBundleDelegate::GetRawDataResource(
43 int resource_id,
44 ui::ResourceScaleFactor scale_factor,
45 base::StringPiece* value) const {
46 auto application = CefAppManager::Get()->GetApplication();
47 if (application) {
48 CefRefPtr<CefResourceBundleHandler> handler =
49 application->GetResourceBundleHandler();
50 if (handler.get()) {
51 void* data = nullptr;
52 size_t data_size = 0;
53 if (scale_factor != ui::kScaleFactorNone) {
54 if (handler->GetDataResourceForScale(
55 resource_id, static_cast<cef_scale_factor_t>(scale_factor),
56 data, data_size)) {
57 *value = base::StringPiece(static_cast<char*>(data), data_size);
58 }
59 } else if (handler->GetDataResource(resource_id, data, data_size)) {
60 *value = base::StringPiece(static_cast<char*>(data), data_size);
61 }
62 }
63 }
64
65 return (pack_loading_disabled_ || !value->empty());
66 }
67
GetLocalizedString(int message_id,std::u16string * value) const68 bool CefResourceBundleDelegate::GetLocalizedString(
69 int message_id,
70 std::u16string* value) const {
71 auto application = CefAppManager::Get()->GetApplication();
72 if (application) {
73 CefRefPtr<CefResourceBundleHandler> handler =
74 application->GetResourceBundleHandler();
75 if (handler.get()) {
76 CefString cef_str;
77 if (handler->GetLocalizedString(message_id, cef_str))
78 *value = cef_str;
79 }
80 }
81
82 return (pack_loading_disabled_ || !value->empty());
83 }
84