2015-06-25 16:56:38 -04:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
# include "WebBrowserPrivatePCH.h"
# include "WebJSStructSerializerBackend.h"
2015-09-09 14:24:58 -04:00
2015-06-25 16:56:38 -04:00
# if WITH_CEF3
/* Private methods
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2015-09-09 14:24:58 -04:00
void FWebJSStructSerializerBackend : : AddNull ( const FStructSerializerState & State )
2015-06-25 16:56:38 -04:00
{
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
2015-09-09 14:24:58 -04:00
Current . DictionaryValue - > SetNull ( * State . ValueProperty - > GetName ( ) ) ;
2015-06-25 16:56:38 -04:00
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetNull ( Current . ListValue - > GetSize ( ) ) ;
break ;
}
}
2015-09-09 14:24:58 -04:00
void FWebJSStructSerializerBackend : : Add ( const FStructSerializerState & State , bool Value )
2015-06-25 16:56:38 -04:00
{
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
2015-09-09 14:24:58 -04:00
Current . DictionaryValue - > SetBool ( * State . ValueProperty - > GetName ( ) , Value ) ;
2015-06-25 16:56:38 -04:00
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetBool ( Current . ListValue - > GetSize ( ) , Value ) ;
break ;
}
}
2015-09-09 14:24:58 -04:00
void FWebJSStructSerializerBackend : : Add ( const FStructSerializerState & State , int32 Value )
2015-06-25 16:56:38 -04:00
{
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
2015-09-09 14:24:58 -04:00
Current . DictionaryValue - > SetInt ( * State . ValueProperty - > GetName ( ) , Value ) ;
2015-06-25 16:56:38 -04:00
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetInt ( Current . ListValue - > GetSize ( ) , Value ) ;
break ;
}
}
2015-09-09 14:24:58 -04:00
void FWebJSStructSerializerBackend : : Add ( const FStructSerializerState & State , double Value )
2015-06-25 16:56:38 -04:00
{
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
2015-09-09 14:24:58 -04:00
Current . DictionaryValue - > SetDouble ( * State . ValueProperty - > GetName ( ) , Value ) ;
2015-06-25 16:56:38 -04:00
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetDouble ( Current . ListValue - > GetSize ( ) , Value ) ;
break ;
}
}
2015-09-09 14:24:58 -04:00
void FWebJSStructSerializerBackend : : Add ( const FStructSerializerState & State , FString Value )
2015-06-25 16:56:38 -04:00
{
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
2015-09-09 14:24:58 -04:00
Current . DictionaryValue - > SetString ( * State . ValueProperty - > GetName ( ) , * Value ) ;
2015-06-25 16:56:38 -04:00
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetString ( Current . ListValue - > GetSize ( ) , * Value ) ;
break ;
}
}
2015-09-09 14:24:58 -04:00
void FWebJSStructSerializerBackend : : Add ( const FStructSerializerState & State , UObject * Value )
2015-06-25 16:56:38 -04:00
{
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
2015-09-09 14:24:58 -04:00
Current . DictionaryValue - > SetDictionary ( * State . ValueProperty - > GetName ( ) , Scripting - > ConvertObject ( Value ) ) ;
2015-06-25 16:56:38 -04:00
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetDictionary ( Current . ListValue - > GetSize ( ) , Scripting - > ConvertObject ( Value ) ) ;
break ;
}
}
2015-09-09 14:24:58 -04:00
2015-06-25 16:56:38 -04:00
/* IStructSerializerBackend interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2015-09-09 13:45:13 -04:00
void FWebJSStructSerializerBackend : : BeginArray ( const FStructSerializerState & State )
2015-06-25 16:56:38 -04:00
{
CefRefPtr < CefListValue > ListValue = CefListValue : : Create ( ) ;
2015-09-09 13:45:13 -04:00
Stack . Push ( StackItem ( State . ValueProperty - > GetName ( ) , ListValue ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 14:24:58 -04:00
2015-09-09 13:45:13 -04:00
void FWebJSStructSerializerBackend : : BeginStructure ( const FStructSerializerState & State )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
if ( State . KeyProperty ! = nullptr )
{
FString KeyString ;
State . KeyProperty - > ExportTextItem ( KeyString , State . KeyData , nullptr , nullptr , PPF_None ) ;
CefRefPtr < CefDictionaryValue > DictionaryValue = CefDictionaryValue : : Create ( ) ;
Stack . Push ( StackItem ( KeyString , DictionaryValue ) ) ;
}
else if ( State . ValueProperty ! = nullptr )
2015-09-09 13:45:13 -04:00
{
CefRefPtr < CefDictionaryValue > DictionaryValue = CefDictionaryValue : : Create ( ) ;
Stack . Push ( StackItem ( State . ValueProperty - > GetName ( ) , DictionaryValue ) ) ;
}
else
{
Result = CefDictionaryValue : : Create ( ) ;
Stack . Push ( StackItem ( FString ( ) , Result ) ) ;
}
2015-06-25 16:56:38 -04:00
}
2015-09-09 14:24:58 -04:00
2015-09-09 13:45:13 -04:00
void FWebJSStructSerializerBackend : : EndArray ( const FStructSerializerState & /*State*/ )
2015-06-25 16:56:38 -04:00
{
StackItem Previous = Stack . Pop ( ) ;
check ( Previous . Kind = = StackItem : : STYPE_LIST ) ;
check ( Stack . Num ( ) > 0 ) ; // The root level object is always a struct
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
Current . DictionaryValue - > SetList ( * Previous . Name , Previous . ListValue ) ;
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetList ( Current . ListValue - > GetSize ( ) , Previous . ListValue ) ;
break ;
}
}
2015-09-09 13:45:13 -04:00
void FWebJSStructSerializerBackend : : EndStructure ( const FStructSerializerState & /*State*/ )
2015-06-25 16:56:38 -04:00
{
StackItem Previous = Stack . Pop ( ) ;
check ( Previous . Kind = = StackItem : : STYPE_DICTIONARY ) ;
if ( Stack . Num ( ) > 0 )
{
StackItem & Current = Stack . Top ( ) ;
switch ( Current . Kind ) {
case StackItem : : STYPE_DICTIONARY :
Current . DictionaryValue - > SetDictionary ( * Previous . Name , Previous . DictionaryValue ) ;
break ;
case StackItem : : STYPE_LIST :
Current . ListValue - > SetDictionary ( Current . ListValue - > GetSize ( ) , Previous . DictionaryValue ) ;
break ;
}
}
else
{
check ( Result = = Previous . DictionaryValue ) ;
}
}
2015-09-09 13:45:13 -04:00
void FWebJSStructSerializerBackend : : WriteComment ( const FString & Comment )
2015-06-25 16:56:38 -04:00
{
// Cef values do not support comments
}
2015-09-09 13:45:13 -04:00
void FWebJSStructSerializerBackend : : WriteProperty ( const FStructSerializerState & State , int32 ArrayIndex )
2015-06-25 16:56:38 -04:00
{
// booleans
2015-09-09 13:45:13 -04:00
if ( State . ValueType = = UBoolProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UBoolProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
// unsigned bytes & enumerations
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UByteProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 13:45:13 -04:00
UByteProperty * ByteProperty = Cast < UByteProperty > ( State . ValueProperty ) ;
2015-06-25 16:56:38 -04:00
if ( ByteProperty - > IsEnum ( ) )
{
2015-09-09 14:24:58 -04:00
Add ( State , ByteProperty - > Enum - > GetEnumName ( ByteProperty - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ) ;
2015-06-25 16:56:38 -04:00
}
else
{
2015-09-09 14:24:58 -04:00
Add ( State , ( double ) Cast < UByteProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
}
// floating point numbers
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UDoubleProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UDoubleProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UFloatProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UFloatProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
// signed integers
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UIntProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , ( int32 ) Cast < UIntProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UInt8Property : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , ( int32 ) Cast < UInt8Property > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UInt16Property : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , ( int32 ) Cast < UInt16Property > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UInt64Property : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , ( double ) Cast < UInt64Property > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
// unsigned integers
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UUInt16Property : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , ( int32 ) Cast < UUInt16Property > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UUInt32Property : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , ( double ) Cast < UUInt32Property > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UUInt64Property : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , ( double ) Cast < UUInt64Property > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
// names & strings
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UNameProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UNameProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) . ToString ( ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UStrProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UStrProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UTextProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UTextProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) . ToString ( ) ) ;
2015-06-25 16:56:38 -04:00
}
// classes & objects
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UClassProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UClassProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) - > GetPathName ( ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
else if ( State . ValueType = = UObjectProperty : : StaticClass ( ) )
2015-06-25 16:56:38 -04:00
{
2015-09-09 14:24:58 -04:00
Add ( State , Cast < UObjectProperty > ( State . ValueProperty ) - > GetPropertyValue_InContainer ( State . ValueData , ArrayIndex ) ) ;
2015-06-25 16:56:38 -04:00
}
2015-09-09 13:45:13 -04:00
// unsupported property type
2015-06-25 16:56:38 -04:00
else
{
2015-09-09 13:45:13 -04:00
GLog - > Logf ( ELogVerbosity : : Warning , TEXT ( " FWebJSStructSerializerBackend: Property %s cannot be serialized, because its type (%s) is not supported " ) , * State . ValueProperty - > GetName ( ) , * State . ValueType - > GetName ( ) ) ;
2015-06-25 16:56:38 -04:00
}
}
2015-09-09 14:24:58 -04:00
2015-06-25 16:56:38 -04:00
# endif