123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #pragma once
- #include "CoreMinimal.h"
- #if WITH_CEF3
- #include "WebInterfaceJSFunction.h"
- #include "WebInterfaceJSScripting.h"
- #if PLATFORM_WINDOWS
- #include "Windows/AllowWindowsPlatformTypes.h"
- #include "Windows/AllowWindowsPlatformAtomics.h"
- #endif
- #pragma push_macro("OVERRIDE")
- #undef OVERRIDE
- THIRD_PARTY_INCLUDES_START
- #if PLATFORM_APPLE
- PRAGMA_DISABLE_DEPRECATION_WARNINGS
- #endif
- #include "include/cef_client.h"
- #include "include/cef_values.h"
- #if PLATFORM_APPLE
- PRAGMA_ENABLE_DEPRECATION_WARNINGS
- #endif
- THIRD_PARTY_INCLUDES_END
- #pragma pop_macro("OVERRIDE")
- #if PLATFORM_WINDOWS
- #include "Windows/HideWindowsPlatformAtomics.h"
- #include "Windows/HideWindowsPlatformTypes.h"
- #endif
- #endif
- class Error;
- class FWebInterfaceJSScripting;
- struct FWebInterfaceJSParam;
- #if WITH_CEF3
- class FCEFInterfaceJSScripting
- : public FWebInterfaceJSScripting
- , public TSharedFromThis<FCEFInterfaceJSScripting>
- {
- public:
- FCEFInterfaceJSScripting(CefRefPtr<CefBrowser> Browser, bool bJSBindingToLoweringEnabled)
- : FWebInterfaceJSScripting(bJSBindingToLoweringEnabled)
- , InternalCefBrowser(Browser)
- {}
- void UnbindCefBrowser();
- virtual void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true) override;
- virtual void UnbindUObject(const FString& Name, UObject* Object = nullptr, bool bIsPermanent = true) override;
-
- bool OnProcessMessageReceived(CefRefPtr<CefBrowser> Browser, CefProcessId SourceProcess, CefRefPtr<CefProcessMessage> Message);
-
- void SendProcessMessage(CefRefPtr<CefProcessMessage> Message);
- CefRefPtr<CefDictionaryValue> ConvertStruct(UStruct* TypeInfo, const void* StructPtr);
- CefRefPtr<CefDictionaryValue> ConvertObject(UObject* Object);
-
- template<typename ContainerType, typename KeyType>
- bool SetConverted(CefRefPtr<ContainerType> Container, KeyType Key, FWebInterfaceJSParam& Param)
- {
- switch (Param.Tag)
- {
- case FWebInterfaceJSParam::PTYPE_NULL:
- return Container->SetNull(Key);
- case FWebInterfaceJSParam::PTYPE_BOOL:
- return Container->SetBool(Key, Param.BoolValue);
- case FWebInterfaceJSParam::PTYPE_DOUBLE:
- return Container->SetDouble(Key, Param.DoubleValue);
- case FWebInterfaceJSParam::PTYPE_INT:
- return Container->SetInt(Key, Param.IntValue);
- case FWebInterfaceJSParam::PTYPE_STRING:
- {
- CefString ConvertedString = TCHAR_TO_WCHAR(**Param.StringValue);
- return Container->SetString(Key, ConvertedString);
- }
- case FWebInterfaceJSParam::PTYPE_OBJECT:
- {
- if (Param.ObjectValue == nullptr)
- {
- return Container->SetNull(Key);
- }
- else
- {
- CefRefPtr<CefDictionaryValue> ConvertedObject = ConvertObject(Param.ObjectValue);
- return Container->SetDictionary(Key, ConvertedObject);
- }
- }
- case FWebInterfaceJSParam::PTYPE_STRUCT:
- {
- CefRefPtr<CefDictionaryValue> ConvertedStruct = ConvertStruct(Param.StructValue->GetTypeInfo(), Param.StructValue->GetData());
- return Container->SetDictionary(Key, ConvertedStruct);
- }
- case FWebInterfaceJSParam::PTYPE_ARRAY:
- {
- CefRefPtr<CefListValue> ConvertedArray = CefListValue::Create();
- for(int i=0; i < Param.ArrayValue->Num(); ++i)
- {
- SetConverted(ConvertedArray, i, (*Param.ArrayValue)[i]);
- }
- return Container->SetList(Key, ConvertedArray);
- }
- case FWebInterfaceJSParam::PTYPE_MAP:
- {
- CefRefPtr<CefDictionaryValue> ConvertedMap = CefDictionaryValue::Create();
- for(auto& Pair : *Param.MapValue)
- {
- SetConverted(ConvertedMap, TCHAR_TO_WCHAR(*Pair.Key), Pair.Value);
- }
- return Container->SetDictionary(Key, ConvertedMap);
- }
- default:
- return false;
- }
- }
- CefRefPtr<CefDictionaryValue> GetPermanentBindings();
- void InvokeJSFunction(FGuid FunctionId, int32 ArgCount, FWebInterfaceJSParam Arguments[], bool bIsError=false) override;
- void InvokeJSFunction(FGuid FunctionId, const CefRefPtr<CefListValue>& FunctionArguments, bool bIsError=false);
- void InvokeJSErrorResult(FGuid FunctionId, const FString& Error) override;
- private:
- bool ConvertStructArgImpl(uint8* Args, FProperty* Param, CefRefPtr<CefListValue> List, int32 Index);
- bool IsValid()
- {
- return InternalCefBrowser.get() != nullptr;
- }
-
- bool HandleExecuteUObjectMethodMessage(CefRefPtr<CefListValue> MessageArguments);
- bool HandleReleaseUObjectMessage(CefRefPtr<CefListValue> MessageArguments);
-
- CefRefPtr<CefBrowser> InternalCefBrowser;
- };
- #endif
|