NativeInterfaceJSScripting.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Engine/Source/Runtime/WebBrowser/Private/Native/NativeJSScripting.h
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "WebInterfaceJSFunction.h"
  5. #include "WebInterfaceJSScripting.h"
  6. typedef TSharedRef<class FNativeInterfaceJSScripting> FNativeInterfaceJSScriptingRef;
  7. typedef TSharedPtr<class FNativeInterfaceJSScripting> FNativeInterfaceJSScriptingPtr;
  8. class FNativeWebInterfaceBrowserProxy;
  9. /**
  10. * Implements handling of bridging UObjects client side with JavaScript renderer side.
  11. */
  12. class FNativeInterfaceJSScripting
  13. : public FWebInterfaceJSScripting
  14. , public TSharedFromThis<FNativeInterfaceJSScripting>
  15. {
  16. public:
  17. //static const FString JSMessageTag;
  18. FNativeInterfaceJSScripting(bool bJSBindingToLoweringEnabled, TSharedRef<FNativeWebInterfaceBrowserProxy> Window);
  19. virtual void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true) override;
  20. virtual void UnbindUObject(const FString& Name, UObject* Object = nullptr, bool bIsPermanent = true) override;
  21. bool OnJsMessageReceived(const FString& Message);
  22. FString ConvertStruct(UStruct* TypeInfo, const void* StructPtr);
  23. FString ConvertObject(UObject* Object);
  24. virtual void InvokeJSFunction(FGuid FunctionId, int32 ArgCount, FWebInterfaceJSParam Arguments[], bool bIsError=false) override;
  25. virtual void InvokeJSErrorResult(FGuid FunctionId, const FString& Error) override;
  26. void PageLoaded();
  27. private:
  28. FString GetInitializeScript();
  29. void InvokeJSFunctionRaw(FGuid FunctionId, const FString& JSValue, bool bIsError=false);
  30. bool IsValid()
  31. {
  32. return WindowPtr.Pin().IsValid();
  33. }
  34. /** Message handling helpers */
  35. bool HandleExecuteUObjectMethodMessage(const TArray<FString>& Params);
  36. void ExecuteJavascript(const FString& Javascript);
  37. TWeakPtr<FNativeWebInterfaceBrowserProxy> WindowPtr;
  38. bool bLoaded;
  39. };