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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/resource_bundle_impl.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
|
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"
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefResourceBundleImpl::CefResourceBundleImpl() = default;
|
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();
|
|
|
|
}
|