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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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