WebInterfaceJSFunction.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Engine/Source/Runtime/WebBrowser/Private/WebJSFunction.cpp
  2. #include "WebInterfaceJSFunction.h"
  3. #include "WebInterfaceJSScripting.h"
  4. #include UE_INLINE_GENERATED_CPP_BY_NAME(WebInterfaceJSFunction)
  5. #if WITH_CEF3
  6. #if PLATFORM_WINDOWS
  7. #include "Windows/WindowsHWrapper.h"
  8. #include "Windows/AllowWindowsPlatformTypes.h"
  9. #include "Windows/AllowWindowsPlatformAtomics.h"
  10. #endif
  11. #pragma push_macro("OVERRIDE")
  12. #undef OVERRIDE // cef headers provide their own OVERRIDE macro
  13. THIRD_PARTY_INCLUDES_START
  14. #if PLATFORM_APPLE
  15. PRAGMA_DISABLE_DEPRECATION_WARNINGS
  16. #endif
  17. #include "include/cef_values.h"
  18. #if PLATFORM_APPLE
  19. PRAGMA_ENABLE_DEPRECATION_WARNINGS
  20. #endif
  21. THIRD_PARTY_INCLUDES_END
  22. #pragma pop_macro("OVERRIDE")
  23. #if PLATFORM_WINDOWS
  24. #include "Windows/HideWindowsPlatformAtomics.h"
  25. #include "Windows/HideWindowsPlatformTypes.h"
  26. #endif
  27. #endif
  28. FWebInterfaceJSParam::~FWebInterfaceJSParam()
  29. {
  30. // Since the FString, StructWrapper, TArray, and TMap members are in a union, they may or may not be valid, so we have to call the destructors manually.
  31. switch (Tag)
  32. {
  33. case PTYPE_STRING:
  34. delete StringValue;
  35. break;
  36. case PTYPE_STRUCT:
  37. delete StructValue;
  38. break;
  39. case PTYPE_ARRAY:
  40. delete ArrayValue;
  41. break;
  42. case PTYPE_MAP:
  43. delete MapValue;
  44. break;
  45. default:
  46. break;
  47. }
  48. }
  49. FWebInterfaceJSParam::FWebInterfaceJSParam(const FWebInterfaceJSParam& Other)
  50. : Tag(Other.Tag)
  51. {
  52. switch (Other.Tag)
  53. {
  54. case PTYPE_BOOL:
  55. BoolValue = Other.BoolValue;
  56. break;
  57. case PTYPE_DOUBLE:
  58. DoubleValue = Other.DoubleValue;
  59. break;
  60. case PTYPE_INT:
  61. IntValue = Other.IntValue;
  62. break;
  63. case PTYPE_STRING:
  64. StringValue = new FString(*Other.StringValue);
  65. break;
  66. case PTYPE_NULL:
  67. break;
  68. case PTYPE_OBJECT:
  69. ObjectValue = Other.ObjectValue;
  70. break;
  71. case PTYPE_STRUCT:
  72. StructValue = Other.StructValue->Clone();
  73. break;
  74. case PTYPE_ARRAY:
  75. ArrayValue = new TArray<FWebInterfaceJSParam>(*Other.ArrayValue);
  76. break;
  77. case PTYPE_MAP:
  78. MapValue = new TMap<FString, FWebInterfaceJSParam>(*Other.MapValue);
  79. break;
  80. }
  81. }
  82. FWebInterfaceJSParam::FWebInterfaceJSParam(FWebInterfaceJSParam&& Other)
  83. : Tag(Other.Tag)
  84. {
  85. switch (Other.Tag)
  86. {
  87. case PTYPE_BOOL:
  88. BoolValue = Other.BoolValue;
  89. break;
  90. case PTYPE_DOUBLE:
  91. DoubleValue = Other.DoubleValue;
  92. break;
  93. case PTYPE_INT:
  94. IntValue = Other.IntValue;
  95. break;
  96. case PTYPE_STRING:
  97. StringValue = Other.StringValue;
  98. Other.StringValue = nullptr;
  99. break;
  100. case PTYPE_NULL:
  101. break;
  102. case PTYPE_OBJECT:
  103. ObjectValue = Other.ObjectValue;
  104. Other.ObjectValue = nullptr;
  105. break;
  106. case PTYPE_STRUCT:
  107. StructValue = Other.StructValue;
  108. Other.StructValue = nullptr;
  109. break;
  110. case PTYPE_ARRAY:
  111. ArrayValue = Other.ArrayValue;
  112. Other.ArrayValue = nullptr;
  113. break;
  114. case PTYPE_MAP:
  115. MapValue = Other.MapValue;
  116. Other.MapValue = nullptr;
  117. break;
  118. }
  119. Other.Tag = PTYPE_NULL;
  120. }
  121. void FWebInterfaceJSCallbackBase::Invoke(int32 ArgCount, FWebInterfaceJSParam Arguments[], bool bIsError) const
  122. {
  123. TSharedPtr<FWebInterfaceJSScripting> Scripting = ScriptingPtr.Pin();
  124. if (Scripting.IsValid())
  125. {
  126. Scripting->InvokeJSFunction(CallbackId, ArgCount, Arguments, bIsError);
  127. }
  128. }