cef/libcef/common/resource_bundle_impl.cc

46 lines
1.4 KiB
C++
Raw Normal View History

// 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 "cef/libcef/common/resource_bundle_impl.h"
#include "base/memory/ref_counted_memory.h"
#include "ui/base/resource/resource_bundle.h"
CefResourceBundleImpl::CefResourceBundleImpl() = default;
CefString CefResourceBundleImpl::GetLocalizedString(int string_id) {
2023-01-02 23:59:03 +01:00
if (!ui::ResourceBundle::HasSharedInstance()) {
return CefString();
2023-01-02 23:59:03 +01:00
}
return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(string_id);
}
CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResource(
int resource_id) {
return GetDataResourceForScale(resource_id, SCALE_FACTOR_NONE);
}
CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResourceForScale(
int resource_id,
ScaleFactor scale_factor) {
2023-01-02 23:59:03 +01:00
if (!ui::ResourceBundle::HasSharedInstance()) {
return nullptr;
2023-01-02 23:59:03 +01:00
}
base::RefCountedMemory* result =
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
resource_id, static_cast<ui::ResourceScaleFactor>(scale_factor));
2023-01-02 23:59:03 +01:00
if (!result) {
return nullptr;
2023-01-02 23:59:03 +01:00
}
return CefBinaryValue::Create(result->data(), result->size());
}
// static
CefRefPtr<CefResourceBundle> CefResourceBundle::GetGlobal() {
return new CefResourceBundleImpl();
}