2015-09-09 16:05:39 +02:00
|
|
|
// Copyright (c) 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 "libcef/common/resource_bundle_impl.h"
|
|
|
|
|
2020-07-21 17:55:54 +02:00
|
|
|
#include "base/memory/ref_counted_memory.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefResourceBundleImpl::CefResourceBundleImpl() {}
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
CefString CefResourceBundleImpl::GetLocalizedString(int string_id) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!ui::ResourceBundle::HasSharedInstance()) {
|
2015-09-09 16:05:39 +02:00
|
|
|
return CefString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(string_id);
|
|
|
|
}
|
|
|
|
|
2020-07-21 17:55:54 +02:00
|
|
|
CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResource(
|
|
|
|
int resource_id) {
|
|
|
|
return GetDataResourceForScale(resource_id, SCALE_FACTOR_NONE);
|
2015-09-09 16:05:39 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 17:55:54 +02:00
|
|
|
CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResourceForScale(
|
|
|
|
int resource_id,
|
|
|
|
ScaleFactor scale_factor) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!ui::ResourceBundle::HasSharedInstance()) {
|
2020-07-21 17:55:54 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2020-07-21 17:55:54 +02:00
|
|
|
base::RefCountedMemory* result =
|
|
|
|
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
|
2021-08-20 01:40:49 +02:00
|
|
|
resource_id, static_cast<ui::ResourceScaleFactor>(scale_factor));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!result) {
|
2020-07-21 17:55:54 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2020-07-21 17:55:54 +02:00
|
|
|
return CefBinaryValue::Create(result->data(), result->size());
|
2015-09-09 16:05:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefResourceBundle> CefResourceBundle::GetGlobal() {
|
|
|
|
return new CefResourceBundleImpl();
|
|
|
|
}
|