NativeWebInterfaceBrowserProxy.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. // Engine/Source/Runtime/WebBrowser/Private/Native/NativeWebBrowserProxy.h
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "IWebInterfaceBrowserWindow.h"
  5. #include "NativeInterfaceJSScripting.h"
  6. class FNativeWebInterfaceBrowserProxy
  7. : public IWebInterfaceBrowserWindow
  8. , public TSharedFromThis<FNativeWebInterfaceBrowserProxy>
  9. {
  10. // For creating instances of this class
  11. friend class FWebInterfaceBrowserSingleton;
  12. private:
  13. FNativeWebInterfaceBrowserProxy(bool bJSBindingToLoweringEnabled);
  14. void Initialize();
  15. void HandleEmbeddedCommunication(const struct FEmbeddedCallParamsHelper& Params);
  16. bool OnJsMessageReceived(const FString& Message);
  17. public:
  18. virtual ~FNativeWebInterfaceBrowserProxy();
  19. public:
  20. // IWebBrowserWindow Interface
  21. virtual void LoadURL(FString NewURL) override;
  22. virtual void LoadString(FString Contents, FString DummyURL) override;
  23. virtual void SetViewportSize(FIntPoint WindowSize, FIntPoint WindowPos) override;
  24. virtual FIntPoint GetViewportSize() const override;
  25. virtual class FSlateShaderResource* GetTexture(bool bIsPopup = false) override;
  26. virtual bool IsValid() const override;
  27. virtual bool IsInitialized() const override;
  28. virtual bool IsClosing() const override;
  29. virtual EWebInterfaceBrowserDocumentState GetDocumentLoadingState() const override;
  30. virtual FString GetTitle() const override;
  31. virtual FString GetUrl() const override;
  32. virtual void GetSource(TFunction<void(const FString&)> Callback) const override;
  33. virtual bool OnKeyDown(const FKeyEvent& InKeyEvent) override;
  34. virtual bool OnKeyUp(const FKeyEvent& InKeyEvent) override;
  35. virtual bool OnKeyChar(const FCharacterEvent& InCharacterEvent) override;
  36. virtual void SetSupportsMouseWheel(bool bValue) override;
  37. virtual bool GetSupportsMouseWheel() const override;
  38. virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  39. virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  40. virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  41. virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  42. virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
  43. virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  44. virtual FOnDragWindow& OnDragWindow() override
  45. {
  46. return DragWindowDelegate;
  47. }
  48. virtual void OnFocus(bool SetFocus, bool bIsPopup) override;
  49. virtual void OnCaptureLost() override;
  50. virtual bool CanGoBack() const override;
  51. virtual void GoBack() override;
  52. virtual bool CanGoForward() const override;
  53. virtual void GoForward() override;
  54. virtual bool IsLoading() const override;
  55. virtual void Reload() override;
  56. virtual void StopLoad() override;
  57. virtual void ExecuteJavascript(const FString& Script) override;
  58. virtual void CloseBrowser(bool bForce, bool bBlockTillClosed) override;
  59. virtual void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true) override;
  60. virtual void UnbindUObject(const FString& Name, UObject* Object = nullptr, bool bIsPermanent = true) override;
  61. virtual int GetLoadError() override;
  62. virtual void SetIsDisabled(bool bValue) override;
  63. virtual TSharedPtr<SWindow> GetParentWindow() const override;
  64. virtual void SetParentWindow(TSharedPtr<SWindow> Window) override;
  65. // @todo: None of these are actually called at the moment.
  66. DECLARE_DERIVED_EVENT(FNativeWebInterfaceBrowserProxy, IWebInterfaceBrowserWindow::FOnDocumentStateChanged, FOnDocumentStateChanged);
  67. virtual FOnDocumentStateChanged& OnDocumentStateChanged() override
  68. {
  69. return DocumentStateChangedEvent;
  70. }
  71. DECLARE_DERIVED_EVENT(FNativeWebInterfaceBrowserProxy, IWebInterfaceBrowserWindow::FOnTitleChanged, FOnTitleChanged);
  72. virtual FOnTitleChanged& OnTitleChanged() override
  73. {
  74. return TitleChangedEvent;
  75. }
  76. DECLARE_DERIVED_EVENT(FNativeWebInterfaceBrowserProxy, IWebInterfaceBrowserWindow::FOnUrlChanged, FOnUrlChanged);
  77. virtual FOnUrlChanged& OnUrlChanged() override
  78. {
  79. return UrlChangedEvent;
  80. }
  81. DECLARE_DERIVED_EVENT(FNativeWebInterfaceBrowserProxy, IWebInterfaceBrowserWindow::FOnToolTip, FOnToolTip);
  82. virtual FOnToolTip& OnToolTip() override
  83. {
  84. return ToolTipEvent;
  85. }
  86. DECLARE_DERIVED_EVENT(FNativeWebInterfaceBrowserProxy, IWebInterfaceBrowserWindow::FOnNeedsRedraw, FOnNeedsRedraw);
  87. virtual FOnNeedsRedraw& OnNeedsRedraw() override
  88. {
  89. return NeedsRedrawEvent;
  90. }
  91. virtual FOnBeforeBrowse& OnBeforeBrowse() override
  92. {
  93. return BeforeBrowseDelegate;
  94. }
  95. virtual FOnLoadUrl& OnLoadUrl() override
  96. {
  97. return LoadUrlDelegate;
  98. }
  99. virtual FOnCreateWindow& OnCreateWindow() override
  100. {
  101. return CreateWindowDelegate;
  102. }
  103. virtual FOnCloseWindow& OnCloseWindow() override
  104. {
  105. return CloseWindowDelegate;
  106. }
  107. virtual FCursorReply OnCursorQuery(const FGeometry& MyGeometry, const FPointerEvent& CursorEvent) override
  108. {
  109. return FCursorReply::Unhandled();
  110. }
  111. virtual FOnBeforePopupDelegate& OnBeforePopup() override
  112. {
  113. return BeforePopupDelegate;
  114. }
  115. virtual FOnBeforeResourceLoadDelegate& OnBeforeResourceLoad() override
  116. {
  117. return BeforeResourceLoadDelegate;
  118. }
  119. virtual FOnResourceLoadCompleteDelegate& OnResourceLoadComplete() override
  120. {
  121. return ResourceLoadCompleteDelegate;
  122. }
  123. virtual FOnConsoleMessageDelegate& OnConsoleMessage() override
  124. {
  125. return ConsoleMessageDelegate;
  126. }
  127. DECLARE_DERIVED_EVENT(FNativeWebInterfaceBrowserProxy, IWebInterfaceBrowserWindow::FOnShowPopup, FOnShowPopup);
  128. virtual FOnShowPopup& OnShowPopup() override
  129. {
  130. return ShowPopupEvent;
  131. }
  132. DECLARE_DERIVED_EVENT(FNativeWebInterfaceBrowserProxy, IWebInterfaceBrowserWindow::FOnDismissPopup, FOnDismissPopup);
  133. virtual FOnDismissPopup& OnDismissPopup() override
  134. {
  135. return DismissPopupEvent;
  136. }
  137. virtual FOnShowDialog& OnShowDialog() override
  138. {
  139. return ShowDialogDelegate;
  140. }
  141. virtual FOnDismissAllDialogs& OnDismissAllDialogs() override
  142. {
  143. return DismissAllDialogsDelegate;
  144. }
  145. virtual FOnSuppressContextMenu& OnSuppressContextMenu() override
  146. {
  147. return SuppressContextMenuDelgate;
  148. }
  149. virtual FOnUnhandledKeyDown& OnUnhandledKeyDown() override
  150. {
  151. return UnhandledKeyDownDelegate;
  152. }
  153. virtual FOnUnhandledKeyUp& OnUnhandledKeyUp() override
  154. {
  155. return UnhandledKeyUpDelegate;
  156. }
  157. virtual FOnUnhandledKeyChar& OnUnhandledKeyChar() override
  158. {
  159. return UnhandledKeyCharDelegate;
  160. }
  161. private:
  162. /** Delegate for broadcasting load state changes. */
  163. FOnDocumentStateChanged DocumentStateChangedEvent;
  164. /** Delegate for broadcasting title changes. */
  165. FOnTitleChanged TitleChangedEvent;
  166. /** Delegate for broadcasting address changes. */
  167. FOnUrlChanged UrlChangedEvent;
  168. /** Delegate for broadcasting when the browser wants to show a tool tip. */
  169. FOnToolTip ToolTipEvent;
  170. /** Delegate for notifying that the window needs refreshing. */
  171. FOnNeedsRedraw NeedsRedrawEvent;
  172. /** Delegate that is executed prior to browser navigation. */
  173. FOnBeforeBrowse BeforeBrowseDelegate;
  174. /** Delegate for overriding Url contents. */
  175. FOnLoadUrl LoadUrlDelegate;
  176. /** Delegate for notifying that a popup window is attempting to open. */
  177. FOnBeforePopupDelegate BeforePopupDelegate;
  178. /** Delegate that is invoked before the browser loads a resource. Its primary purpose is to inject headers into the request. */
  179. FOnBeforeResourceLoadDelegate BeforeResourceLoadDelegate;
  180. /** Delegate that is invoked on completion of browser resource loads. Its primary purpose is to allow response to failures. */
  181. FOnResourceLoadCompleteDelegate ResourceLoadCompleteDelegate;
  182. /** Delegate that is invoked for each console message */
  183. FOnConsoleMessageDelegate ConsoleMessageDelegate;
  184. /** Delegate for handling requests to create new windows. */
  185. FOnCreateWindow CreateWindowDelegate;
  186. /** Delegate for handling requests to close new windows that were created. */
  187. FOnCloseWindow CloseWindowDelegate;
  188. /** Delegate for handling requests to show the popup menu. */
  189. FOnShowPopup ShowPopupEvent;
  190. /** Delegate for handling requests to dismiss the current popup menu. */
  191. FOnDismissPopup DismissPopupEvent;
  192. /** Delegate for showing dialogs. */
  193. FOnShowDialog ShowDialogDelegate;
  194. /** Delegate for dismissing all dialogs. */
  195. FOnDismissAllDialogs DismissAllDialogsDelegate;
  196. /** Delegate for suppressing context menu */
  197. FOnSuppressContextMenu SuppressContextMenuDelgate;
  198. /** Delegate for handling key down events not handled by the browser. */
  199. FOnUnhandledKeyDown UnhandledKeyDownDelegate;
  200. /** Delegate for handling key up events not handled by the browser. */
  201. FOnUnhandledKeyUp UnhandledKeyUpDelegate;
  202. /** Delegate for handling key char events not handled by the browser. */
  203. FOnUnhandledKeyChar UnhandledKeyCharDelegate;
  204. FOnDragWindow DragWindowDelegate;
  205. bool bJSBindingToLoweringEnabled;
  206. FNativeInterfaceJSScriptingPtr Scripting;
  207. };