CEFInterfaceJSStructDeserializerBackend.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Engine/Source/Runtime/WebBrowser/Private/CEF/CEFJSStructDeserializerBackend.h
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #if WITH_CEF3
  5. #include "WebInterfaceBrowserSingleton.h"
  6. #include "UObject/UnrealType.h"
  7. #include "IStructDeserializerBackend.h"
  8. #include "CEFInterfaceJSScripting.h"
  9. #if PLATFORM_WINDOWS
  10. #include "Windows/AllowWindowsPlatformTypes.h"
  11. #include "Windows/AllowWindowsPlatformAtomics.h"
  12. #endif
  13. #pragma push_macro("OVERRIDE")
  14. #undef OVERRIDE // cef headers provide their own OVERRIDE macro
  15. THIRD_PARTY_INCLUDES_START
  16. #if PLATFORM_APPLE
  17. PRAGMA_DISABLE_DEPRECATION_WARNINGS
  18. #endif
  19. #include "include/cef_values.h"
  20. #if PLATFORM_APPLE
  21. PRAGMA_ENABLE_DEPRECATION_WARNINGS
  22. #endif
  23. THIRD_PARTY_INCLUDES_END
  24. #pragma pop_macro("OVERRIDE")
  25. #if PLATFORM_WINDOWS
  26. #include "Windows/HideWindowsPlatformAtomics.h"
  27. #include "Windows/HideWindowsPlatformTypes.h"
  28. #endif
  29. #endif
  30. class FCEFInterfaceJSScripting;
  31. class IStructDeserializerBackend;
  32. enum class EStructDeserializerBackendTokens;
  33. class FProperty;
  34. class UStruct;
  35. #if WITH_CEF3
  36. class ICefInterfaceContainerWalker
  37. : public TSharedFromThis<ICefInterfaceContainerWalker>
  38. {
  39. public:
  40. ICefInterfaceContainerWalker(TSharedPtr<ICefInterfaceContainerWalker> InParent)
  41. : Parent(InParent)
  42. {}
  43. virtual ~ICefInterfaceContainerWalker() {}
  44. virtual TSharedPtr<ICefInterfaceContainerWalker> GetNextToken( EStructDeserializerBackendTokens& OutToken, FString& PropertyName ) = 0;
  45. virtual bool ReadProperty(TSharedPtr<FCEFInterfaceJSScripting> Scripting, FProperty* Property, FProperty* Outer, void* Data, int32 ArrayIndex) = 0;
  46. TSharedPtr<ICefInterfaceContainerWalker> Parent;
  47. };
  48. class FCefInterfaceListValueWalker
  49. : public ICefInterfaceContainerWalker
  50. {
  51. public:
  52. FCefInterfaceListValueWalker(TSharedPtr<ICefInterfaceContainerWalker> InParent, CefRefPtr<CefListValue> InList)
  53. : ICefInterfaceContainerWalker(InParent)
  54. , List(InList)
  55. , Index(-2)
  56. {}
  57. virtual TSharedPtr<ICefInterfaceContainerWalker> GetNextToken( EStructDeserializerBackendTokens& OutToken, FString& PropertyName ) override;
  58. virtual bool ReadProperty(TSharedPtr<FCEFInterfaceJSScripting> Scripting, FProperty* Property, FProperty* Outer, void* Data, int32 ArrayIndex ) override;
  59. CefRefPtr<CefListValue> List;
  60. size_t Index;
  61. };
  62. class FCefInterfaceDictionaryValueWalker
  63. : public ICefInterfaceContainerWalker
  64. {
  65. public:
  66. FCefInterfaceDictionaryValueWalker(TSharedPtr<ICefInterfaceContainerWalker> InParent, CefRefPtr<CefDictionaryValue> InDictionary)
  67. : ICefInterfaceContainerWalker(InParent)
  68. , Dictionary(InDictionary)
  69. , Index(-2)
  70. {
  71. Dictionary->GetKeys(Keys);
  72. }
  73. virtual TSharedPtr<ICefInterfaceContainerWalker> GetNextToken( EStructDeserializerBackendTokens& OutToken, FString& PropertyName ) override;
  74. virtual bool ReadProperty(TSharedPtr<FCEFInterfaceJSScripting> Scripting, FProperty* Property, FProperty* Outer, void* Data, int32 ArrayIndex ) override;
  75. private:
  76. CefRefPtr<CefDictionaryValue> Dictionary;
  77. size_t Index;
  78. CefDictionaryValue::KeyList Keys;
  79. };
  80. /**
  81. * Implements a writer for UStruct serialization using CefDictionary.
  82. */
  83. class FCEFInterfaceJSStructDeserializerBackend
  84. : public IStructDeserializerBackend
  85. {
  86. public:
  87. /**
  88. * Creates and initializes a new instance.
  89. *
  90. * @param Archive The archive to deserialize from.
  91. */
  92. FCEFInterfaceJSStructDeserializerBackend(TSharedPtr<FCEFInterfaceJSScripting> InScripting, CefRefPtr<CefDictionaryValue> InDictionary)
  93. : Scripting(InScripting)
  94. , Walker(new FCefInterfaceDictionaryValueWalker(nullptr, InDictionary))
  95. , CurrentPropertyName()
  96. { }
  97. public:
  98. // IStructDeserializerBackend interface
  99. virtual const FString& GetCurrentPropertyName() const override;
  100. virtual FString GetDebugString() const override;
  101. virtual const FString& GetLastErrorMessage() const override;
  102. virtual bool GetNextToken( EStructDeserializerBackendTokens& OutToken ) override;
  103. virtual bool ReadProperty( FProperty* Property, FProperty* Outer, void* Data, int32 ArrayIndex ) override;
  104. virtual void SkipArray() override;
  105. virtual void SkipStructure() override;
  106. private:
  107. TSharedPtr<FCEFInterfaceJSScripting> Scripting;
  108. /** Holds the source CEF dictionary containing a serialized verion of the structure. */
  109. TSharedPtr<ICefInterfaceContainerWalker> Walker;
  110. FString CurrentPropertyName;
  111. };
  112. #endif