NativeWebInterfaceBrowserProxy.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // Engine/Source/Runtime/WebBrowser/Private/Native/NativeWebBrowserProxy.h
  2. #include "NativeWebInterfaceBrowserProxy.h"
  3. #include "NativeInterfaceJSScripting.h"
  4. #include "Misc/EmbeddedCommunication.h"
  5. FNativeWebInterfaceBrowserProxy::FNativeWebInterfaceBrowserProxy(bool bInJSBindingToLoweringEnabled)
  6. : bJSBindingToLoweringEnabled(bInJSBindingToLoweringEnabled)
  7. {
  8. }
  9. void FNativeWebInterfaceBrowserProxy::Initialize()
  10. {
  11. Scripting = MakeShareable(new FNativeInterfaceJSScripting(bJSBindingToLoweringEnabled, SharedThis(this)));
  12. FEmbeddedDelegates::GetNativeToEmbeddedParamsDelegateForSubsystem(TEXT("browserProxy")).AddRaw(this, &FNativeWebInterfaceBrowserProxy::HandleEmbeddedCommunication);
  13. }
  14. FNativeWebInterfaceBrowserProxy::~FNativeWebInterfaceBrowserProxy()
  15. {
  16. FEmbeddedDelegates::GetNativeToEmbeddedParamsDelegateForSubsystem(TEXT("browserProxy")).RemoveAll(this);
  17. }
  18. bool FNativeWebInterfaceBrowserProxy::OnJsMessageReceived(const FString& Message)
  19. {
  20. return Scripting->OnJsMessageReceived(Message);
  21. }
  22. void FNativeWebInterfaceBrowserProxy::HandleEmbeddedCommunication(const FEmbeddedCallParamsHelper& Params)
  23. {
  24. FString Error;
  25. if (Params.Command == "handlejs")
  26. {
  27. FString Message = Params.Parameters.FindRef(TEXT("script"));
  28. if (!Message.IsEmpty())
  29. {
  30. if (!OnJsMessageReceived(Message))
  31. {
  32. Error = TEXT("Command failed");
  33. }
  34. }
  35. }
  36. else if (Params.Command == "pageload")
  37. {
  38. Scripting->PageLoaded();
  39. }
  40. Params.OnCompleteDelegate(FEmbeddedCommunicationMap(), Error);
  41. }
  42. void FNativeWebInterfaceBrowserProxy::LoadURL(FString NewURL)
  43. {
  44. }
  45. void FNativeWebInterfaceBrowserProxy::LoadString(FString Contents, FString DummyURL)
  46. {
  47. }
  48. void FNativeWebInterfaceBrowserProxy::SetViewportSize(FIntPoint WindowSize, FIntPoint WindowPos)
  49. {
  50. }
  51. FIntPoint FNativeWebInterfaceBrowserProxy::GetViewportSize() const
  52. {
  53. return FIntPoint(ForceInitToZero);
  54. }
  55. FSlateShaderResource* FNativeWebInterfaceBrowserProxy::GetTexture(bool bIsPopup /*= false*/)
  56. {
  57. return nullptr;
  58. }
  59. bool FNativeWebInterfaceBrowserProxy::IsValid() const
  60. {
  61. return false;
  62. }
  63. bool FNativeWebInterfaceBrowserProxy::IsInitialized() const
  64. {
  65. return true;
  66. }
  67. bool FNativeWebInterfaceBrowserProxy::IsClosing() const
  68. {
  69. return false;
  70. }
  71. EWebInterfaceBrowserDocumentState FNativeWebInterfaceBrowserProxy::GetDocumentLoadingState() const
  72. {
  73. return EWebInterfaceBrowserDocumentState::Loading;
  74. }
  75. FString FNativeWebInterfaceBrowserProxy::GetTitle() const
  76. {
  77. return TEXT("");
  78. }
  79. FString FNativeWebInterfaceBrowserProxy::GetUrl() const
  80. {
  81. return TEXT("");
  82. }
  83. void FNativeWebInterfaceBrowserProxy::GetSource(TFunction<void(const FString&)> Callback) const
  84. {
  85. Callback(FString());
  86. }
  87. void FNativeWebInterfaceBrowserProxy::SetSupportsMouseWheel(bool bValue)
  88. {
  89. }
  90. bool FNativeWebInterfaceBrowserProxy::GetSupportsMouseWheel() const
  91. {
  92. return false;
  93. }
  94. bool FNativeWebInterfaceBrowserProxy::OnKeyDown(const FKeyEvent& InKeyEvent)
  95. {
  96. return false;
  97. }
  98. bool FNativeWebInterfaceBrowserProxy::OnKeyUp(const FKeyEvent& InKeyEvent)
  99. {
  100. return false;
  101. }
  102. bool FNativeWebInterfaceBrowserProxy::OnKeyChar(const FCharacterEvent& InCharacterEvent)
  103. {
  104. return false;
  105. }
  106. FReply FNativeWebInterfaceBrowserProxy::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup)
  107. {
  108. return FReply::Unhandled();
  109. }
  110. FReply FNativeWebInterfaceBrowserProxy::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup)
  111. {
  112. return FReply::Unhandled();
  113. }
  114. FReply FNativeWebInterfaceBrowserProxy::OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup)
  115. {
  116. return FReply::Unhandled();
  117. }
  118. FReply FNativeWebInterfaceBrowserProxy::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup)
  119. {
  120. return FReply::Unhandled();
  121. }
  122. void FNativeWebInterfaceBrowserProxy::OnMouseLeave(const FPointerEvent& MouseEvent)
  123. {
  124. }
  125. FReply FNativeWebInterfaceBrowserProxy::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup)
  126. {
  127. return FReply::Unhandled();
  128. }
  129. void FNativeWebInterfaceBrowserProxy::OnFocus(bool SetFocus, bool bIsPopup)
  130. {
  131. }
  132. void FNativeWebInterfaceBrowserProxy::OnCaptureLost()
  133. {
  134. }
  135. bool FNativeWebInterfaceBrowserProxy::CanGoBack() const
  136. {
  137. return false;
  138. }
  139. void FNativeWebInterfaceBrowserProxy::GoBack()
  140. {
  141. }
  142. bool FNativeWebInterfaceBrowserProxy::CanGoForward() const
  143. {
  144. return false;
  145. }
  146. void FNativeWebInterfaceBrowserProxy::GoForward()
  147. {
  148. }
  149. bool FNativeWebInterfaceBrowserProxy::IsLoading() const
  150. {
  151. return false;
  152. }
  153. void FNativeWebInterfaceBrowserProxy::Reload()
  154. {
  155. }
  156. void FNativeWebInterfaceBrowserProxy::StopLoad()
  157. {
  158. }
  159. void FNativeWebInterfaceBrowserProxy::ExecuteJavascript(const FString& Script)
  160. {
  161. FEmbeddedCallParamsHelper CallHelper;
  162. CallHelper.Command = TEXT("execjs");
  163. CallHelper.Parameters = { { TEXT("script"), Script } };
  164. FEmbeddedDelegates::GetEmbeddedToNativeParamsDelegateForSubsystem(TEXT("webview")).Broadcast(CallHelper);
  165. }
  166. void FNativeWebInterfaceBrowserProxy::CloseBrowser(bool bForce, bool bBlockTillClosed /* ignored */)
  167. {
  168. }
  169. void FNativeWebInterfaceBrowserProxy::BindUObject(const FString& Name, UObject* Object, bool bIsPermanent /*= true*/)
  170. {
  171. Scripting->BindUObject(Name, Object, bIsPermanent);
  172. }
  173. void FNativeWebInterfaceBrowserProxy::UnbindUObject(const FString& Name, UObject* Object /*= nullptr*/, bool bIsPermanent /*= true*/)
  174. {
  175. Scripting->UnbindUObject(Name, Object, bIsPermanent);
  176. }
  177. int FNativeWebInterfaceBrowserProxy::GetLoadError()
  178. {
  179. return 0;
  180. }
  181. void FNativeWebInterfaceBrowserProxy::SetIsDisabled(bool bValue)
  182. {
  183. }
  184. TSharedPtr<SWindow> FNativeWebInterfaceBrowserProxy::GetParentWindow() const
  185. {
  186. return nullptr;
  187. }
  188. void FNativeWebInterfaceBrowserProxy::SetParentWindow(TSharedPtr<SWindow> Window)
  189. {
  190. }