Return decompressed values from CefResourceBundle (fixes issue #2976)

This commit is contained in:
Mike Wiedenbauer 2020-07-21 15:55:54 +00:00 committed by Marshall Greenblatt
parent ca1c00f95d
commit 034bd641de
8 changed files with 88 additions and 157 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=b9577b495df3990284d4e4a3db2824196175dc91$
// $hash=b0e2b63b467c6d4e990405d948908da3546ea1c7$
//
#ifndef CEF_INCLUDE_CAPI_CEF_RESOURCE_BUNDLE_CAPI_H_
@ -41,6 +41,7 @@
#pragma once
#include "include/capi/cef_base_capi.h"
#include "include/capi/cef_values_capi.h"
#ifdef __cplusplus
extern "C" {
@ -70,34 +71,25 @@ typedef struct _cef_resource_bundle_t {
int string_id);
///
// Retrieves the contents of the specified scale independent |resource_id|. If
// the value is found then |data| and |data_size| will be populated and this
// function will return true (1). If the value is not found then this function
// will return false (0). The returned |data| pointer will remain resident in
// memory and should not be freed. Include cef_pack_resources.h for a listing
// of valid resource ID values.
// Returns a cef_binary_value_t containing the decompressed contents of the
// specified scale independent |resource_id| or NULL if not found. Include
// cef_pack_resources.h for a listing of valid resource ID values.
///
int(CEF_CALLBACK* get_data_resource)(struct _cef_resource_bundle_t* self,
int resource_id,
void** data,
size_t* data_size);
struct _cef_binary_value_t*(CEF_CALLBACK* get_data_resource)(
struct _cef_resource_bundle_t* self,
int resource_id);
///
// Retrieves the contents of the specified |resource_id| nearest the scale
// factor |scale_factor|. Use a |scale_factor| value of SCALE_FACTOR_NONE for
// scale independent resources or call GetDataResource instead. If the value
// is found then |data| and |data_size| will be populated and this function
// will return true (1). If the value is not found then this function will
// return false (0). The returned |data| pointer will remain resident in
// memory and should not be freed. Include cef_pack_resources.h for a listing
// of valid resource ID values.
// Returns a cef_binary_value_t containing the decompressed contents of the
// specified |resource_id| nearest the scale factor |scale_factor| or NULL if
// not found. Use a |scale_factor| value of SCALE_FACTOR_NONE for scale
// independent resources or call GetDataResource instead.Include
// cef_pack_resources.h for a listing of valid resource ID values.
///
int(CEF_CALLBACK* get_data_resource_for_scale)(
struct _cef_binary_value_t*(CEF_CALLBACK* get_data_resource_for_scale)(
struct _cef_resource_bundle_t* self,
int resource_id,
cef_scale_factor_t scale_factor,
void** data,
size_t* data_size);
cef_scale_factor_t scale_factor);
} cef_resource_bundle_t;
///

View File

@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "20d95f0b54da45b2ced365aa92c784e348862bd3"
#define CEF_API_HASH_UNIVERSAL "3e1586373c83d1510dce730535167b8142a3ff84"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "fbe8ca0acbdc4b4050d5e44cbde930177be44edf"
#define CEF_API_HASH_PLATFORM "4598eb182560c405482ddf9c5b106a54260c7b92"
#elif defined(OS_MACOSX)
#define CEF_API_HASH_PLATFORM "68ba2cd3b110e52ef2d6b07412155b845b105177"
#define CEF_API_HASH_PLATFORM "4a22dc7529e4a0c6cd49f4004e742e924a2f4827"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "40e1cf30d708463e32bf65f9d033f98f22a321e8"
#define CEF_API_HASH_PLATFORM "27ba0b66cd1c5f7828455215fcdc824e0bfed656"
#endif
#ifdef __cplusplus

View File

@ -39,6 +39,7 @@
#pragma once
#include "include/cef_base.h"
#include "include/cef_values.h"
///
// Class used for retrieving resources from the resource bundle (*.pak) files
@ -67,33 +68,24 @@ class CefResourceBundle : public virtual CefBaseRefCounted {
virtual CefString GetLocalizedString(int string_id) = 0;
///
// Retrieves the contents of the specified scale independent |resource_id|.
// If the value is found then |data| and |data_size| will be populated and
// this method will return true. If the value is not found then this method
// will return false. The returned |data| pointer will remain resident in
// memory and should not be freed. Include cef_pack_resources.h for a listing
// of valid resource ID values.
// Returns a CefBinaryValue containing the decompressed contents of the
// specified scale independent |resource_id| or NULL if not found. Include
// cef_pack_resources.h for a listing of valid resource ID values.
///
/*--cef()--*/
virtual bool GetDataResource(int resource_id,
void*& data,
size_t& data_size) = 0;
virtual CefRefPtr<CefBinaryValue> GetDataResource(int resource_id) = 0;
///
// Retrieves the contents of the specified |resource_id| nearest the scale
// factor |scale_factor|. Use a |scale_factor| value of SCALE_FACTOR_NONE for
// scale independent resources or call GetDataResource instead. If the value
// is found then |data| and |data_size| will be populated and this method will
// return true. If the value is not found then this method will return false.
// The returned |data| pointer will remain resident in memory and should not
// be freed. Include cef_pack_resources.h for a listing of valid resource ID
// values.
// Returns a CefBinaryValue containing the decompressed contents of the
// specified |resource_id| nearest the scale factor |scale_factor| or NULL if
// not found. Use a |scale_factor| value of SCALE_FACTOR_NONE for scale
// independent resources or call GetDataResource instead.Include
// cef_pack_resources.h for a listing of valid resource ID values.
///
/*--cef()--*/
virtual bool GetDataResourceForScale(int resource_id,
ScaleFactor scale_factor,
void*& data,
size_t& data_size) = 0;
virtual CefRefPtr<CefBinaryValue> GetDataResourceForScale(
int resource_id,
ScaleFactor scale_factor) = 0;
};
#endif // CEF_INCLUDE_CEF_RESOURCE_BUNDLE_H_

View File

@ -4,6 +4,7 @@
#include "libcef/common/resource_bundle_impl.h"
#include "base/memory/ref_counted_memory.h"
#include "ui/base/resource/resource_bundle.h"
CefResourceBundleImpl::CefResourceBundleImpl() {}
@ -15,29 +16,24 @@ CefString CefResourceBundleImpl::GetLocalizedString(int string_id) {
return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(string_id);
}
bool CefResourceBundleImpl::GetDataResource(int resource_id,
void*& data,
size_t& data_size) {
return GetDataResourceForScale(resource_id, SCALE_FACTOR_NONE, data,
data_size);
CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResource(
int resource_id) {
return GetDataResourceForScale(resource_id, SCALE_FACTOR_NONE);
}
bool CefResourceBundleImpl::GetDataResourceForScale(int resource_id,
ScaleFactor scale_factor,
void*& data,
size_t& data_size) {
CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResourceForScale(
int resource_id,
ScaleFactor scale_factor) {
if (!ui::ResourceBundle::HasSharedInstance())
return false;
return nullptr;
const base::StringPiece& result =
ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
base::RefCountedMemory* result =
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
resource_id, static_cast<ui::ScaleFactor>(scale_factor));
if (result.empty())
return false;
if (!result)
return nullptr;
data = const_cast<char*>(result.data());
data_size = result.size();
return true;
return CefBinaryValue::Create(result->data(), result->size());
}
// static

View File

@ -14,13 +14,10 @@ class CefResourceBundleImpl : public CefResourceBundle {
// CefResourceBundle methods.
CefString GetLocalizedString(int string_id) override;
bool GetDataResource(int resource_id,
void*& data,
size_t& data_size) override;
bool GetDataResourceForScale(int resource_id,
ScaleFactor scale_factor,
void*& data,
size_t& data_size) override;
CefRefPtr<CefBinaryValue> GetDataResource(int resource_id) override;
CefRefPtr<CefBinaryValue> GetDataResourceForScale(
int resource_id,
ScaleFactor scale_factor) override;
private:
IMPLEMENT_REFCOUNTING(CefResourceBundleImpl);

View File

@ -9,10 +9,11 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=ba0a12367019906d32dae965d7d1b5245d02b442$
// $hash=0dc6766f75f9b051daf582009455efb08c969e9f$
//
#include "libcef_dll/cpptoc/resource_bundle_cpptoc.h"
#include "libcef_dll/cpptoc/binary_value_cpptoc.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
@ -47,83 +48,40 @@ resource_bundle_get_localized_string(struct _cef_resource_bundle_t* self,
return _retval.DetachToUserFree();
}
int CEF_CALLBACK
struct _cef_binary_value_t* CEF_CALLBACK
resource_bundle_get_data_resource(struct _cef_resource_bundle_t* self,
int resource_id,
void** data,
size_t* data_size) {
int resource_id) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: data; type: simple_byref
DCHECK(data);
if (!data)
return 0;
// Verify param: data_size; type: simple_byref
DCHECK(data_size);
if (!data_size)
return 0;
// Translate param: data; type: simple_byref
void* dataVal = data ? *data : NULL;
// Translate param: data_size; type: simple_byref
size_t data_sizeVal = data_size ? *data_size : 0;
return NULL;
// Execute
bool _retval = CefResourceBundleCppToC::Get(self)->GetDataResource(
resource_id, dataVal, data_sizeVal);
CefRefPtr<CefBinaryValue> _retval =
CefResourceBundleCppToC::Get(self)->GetDataResource(resource_id);
// Restore param: data; type: simple_byref
if (data)
*data = dataVal;
// Restore param: data_size; type: simple_byref
if (data_size)
*data_size = data_sizeVal;
// Return type: bool
return _retval;
// Return type: refptr_same
return CefBinaryValueCppToC::Wrap(_retval);
}
int CEF_CALLBACK
struct _cef_binary_value_t* CEF_CALLBACK
resource_bundle_get_data_resource_for_scale(struct _cef_resource_bundle_t* self,
int resource_id,
cef_scale_factor_t scale_factor,
void** data,
size_t* data_size) {
cef_scale_factor_t scale_factor) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: data; type: simple_byref
DCHECK(data);
if (!data)
return 0;
// Verify param: data_size; type: simple_byref
DCHECK(data_size);
if (!data_size)
return 0;
// Translate param: data; type: simple_byref
void* dataVal = data ? *data : NULL;
// Translate param: data_size; type: simple_byref
size_t data_sizeVal = data_size ? *data_size : 0;
return NULL;
// Execute
bool _retval = CefResourceBundleCppToC::Get(self)->GetDataResourceForScale(
resource_id, scale_factor, dataVal, data_sizeVal);
CefRefPtr<CefBinaryValue> _retval =
CefResourceBundleCppToC::Get(self)->GetDataResourceForScale(resource_id,
scale_factor);
// Restore param: data; type: simple_byref
if (data)
*data = dataVal;
// Restore param: data_size; type: simple_byref
if (data_size)
*data_size = data_sizeVal;
// Return type: bool
return _retval;
// Return type: refptr_same
return CefBinaryValueCppToC::Wrap(_retval);
}
} // namespace

View File

@ -9,10 +9,11 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=026dabca1d46cfbe911d71ede9d5bb79cb7c553d$
// $hash=12bfdabd19a9a90eb4c7b88cb0d8d225c8142115$
//
#include "libcef_dll/ctocpp/resource_bundle_ctocpp.h"
#include "libcef_dll/ctocpp/binary_value_ctocpp.h"
// STATIC METHODS - Body may be edited by hand.
@ -48,40 +49,38 @@ CefString CefResourceBundleCToCpp::GetLocalizedString(int string_id) {
}
NO_SANITIZE("cfi-icall")
bool CefResourceBundleCToCpp::GetDataResource(int resource_id,
void*& data,
size_t& data_size) {
CefRefPtr<CefBinaryValue> CefResourceBundleCToCpp::GetDataResource(
int resource_id) {
cef_resource_bundle_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_data_resource))
return false;
return nullptr;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
int _retval =
_struct->get_data_resource(_struct, resource_id, &data, &data_size);
cef_binary_value_t* _retval =
_struct->get_data_resource(_struct, resource_id);
// Return type: bool
return _retval ? true : false;
// Return type: refptr_same
return CefBinaryValueCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
bool CefResourceBundleCToCpp::GetDataResourceForScale(int resource_id,
ScaleFactor scale_factor,
void*& data,
size_t& data_size) {
CefRefPtr<CefBinaryValue> CefResourceBundleCToCpp::GetDataResourceForScale(
int resource_id,
ScaleFactor scale_factor) {
cef_resource_bundle_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_data_resource_for_scale))
return false;
return nullptr;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
int _retval = _struct->get_data_resource_for_scale(
_struct, resource_id, scale_factor, &data, &data_size);
cef_binary_value_t* _retval =
_struct->get_data_resource_for_scale(_struct, resource_id, scale_factor);
// Return type: bool
return _retval ? true : false;
// Return type: refptr_same
return CefBinaryValueCToCpp::Wrap(_retval);
}
// CONSTRUCTOR - Do not edit by hand.

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=c0d4e71c707c9d63a00ca1a497aaede3e429e970$
// $hash=7668efc00e13bb790df91f26c2a5683bd74ff677$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_RESOURCE_BUNDLE_CTOCPP_H_
@ -36,13 +36,10 @@ class CefResourceBundleCToCpp
// CefResourceBundle methods.
CefString GetLocalizedString(int string_id) OVERRIDE;
bool GetDataResource(int resource_id,
void*& data,
size_t& data_size) OVERRIDE;
bool GetDataResourceForScale(int resource_id,
ScaleFactor scale_factor,
void*& data,
size_t& data_size) OVERRIDE;
CefRefPtr<CefBinaryValue> GetDataResource(int resource_id) OVERRIDE;
CefRefPtr<CefBinaryValue> GetDataResourceForScale(
int resource_id,
ScaleFactor scale_factor) OVERRIDE;
};
#endif // CEF_LIBCEF_DLL_CTOCPP_RESOURCE_BUNDLE_CTOCPP_H_