CEFWebInterfaceBrowserWindow.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. // Engine/Source/Runtime/WebBrowser/Private/CEF/CEFWebBrowserWindow.h
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Input/CursorReply.h"
  5. #include "Input/Events.h"
  6. #include "Input/Reply.h"
  7. #include "Widgets/SViewport.h"
  8. #include "WebInterfaceBrowserSingleton.h"
  9. #if WITH_CEF3
  10. #include "IWebInterfaceBrowserWindow.h"
  11. #include "CEFInterfaceBrowserHandler.h"
  12. #include "CEFInterfaceLibCefIncludes.h"
  13. #endif
  14. class FBrowserBufferedVideo;
  15. class FCEFInterfaceBrowserHandler;
  16. class FCEFInterfaceJSScripting;
  17. class FSlateUpdatableTexture;
  18. class IWebInterfaceBrowserPopupFeatures;
  19. class IWebInterfaceBrowserWindow;
  20. struct Rect;
  21. class FSlateShaderResource;
  22. enum class EWebInterfaceBrowserDocumentState;
  23. struct FGeometry;
  24. struct FPointerEvent;
  25. class UObject;
  26. struct FInputEvent;
  27. class FWebJSScripting;
  28. class FCEFInterfaceImeHandler;
  29. class ITextInputMethodSystem;
  30. class FCEFWebInterfaceBrowserWindowRHIHelper;
  31. #if WITH_CEF3
  32. /**
  33. * Helper for containing items required for CEF browser window creation.
  34. */
  35. struct FWebInterfaceBrowserWindowInfo
  36. {
  37. FWebInterfaceBrowserWindowInfo(CefRefPtr<CefBrowser> InBrowser, CefRefPtr<FCEFInterfaceBrowserHandler> InHandler)
  38. : Browser(InBrowser)
  39. , Handler(InHandler)
  40. {}
  41. CefRefPtr<CefBrowser> Browser;
  42. CefRefPtr<FCEFInterfaceBrowserHandler> Handler;
  43. };
  44. /**
  45. * Representation of a window drag region.
  46. */
  47. struct FWebInterfaceBrowserDragRegion
  48. {
  49. FWebInterfaceBrowserDragRegion(const FIntRect& InRect, bool bInDraggable)
  50. : Rect(InRect)
  51. , bDraggable(bInDraggable)
  52. {}
  53. FIntRect Rect;
  54. bool bDraggable;
  55. };
  56. /**
  57. * Implementation of interface for dealing with a Web Browser window.
  58. */
  59. class FCEFWebInterfaceBrowserWindow
  60. : public IWebInterfaceBrowserWindow
  61. , public TSharedFromThis<FCEFWebInterfaceBrowserWindow>
  62. {
  63. // Allow the Handler to access functions only it needs
  64. friend class FCEFInterfaceBrowserHandler;
  65. // The WebBrowserSingleton should be the only one creating instances of this class
  66. friend class FWebInterfaceBrowserSingleton;
  67. // CreateWidget should only be called by the WebBrowserView
  68. friend class SWebInterfaceBrowserView;
  69. private:
  70. /**
  71. * Creates and initializes a new instance.
  72. *
  73. * @param Browser The CefBrowser object representing this browser window.
  74. * @param Handler Pointer to the CEF handler for this window.
  75. * @param Url The Initial URL that will be loaded.
  76. * @param ContentsToLoad Optional string to load as a web page.
  77. * @param bShowErrorMessage Whether to show an error message in case of loading errors.
  78. * @param bThumbMouseButtonNavigation Whether to allow forward and back navigation via the mouse thumb buttons.
  79. * @param bUseTransparency Whether to enable transparency.
  80. * @param bJSBindingToLoweringEnabled Whether we ToLower all JavaScript member names.
  81. */
  82. FCEFWebInterfaceBrowserWindow(CefRefPtr<CefBrowser> Browser, CefRefPtr<FCEFInterfaceBrowserHandler> Handler, FString Url, TOptional<FString> ContentsToLoad, bool bShowErrorMessage, bool bThumbMouseButtonNavigation, bool bUseTransparency, bool bInUseNativeCursors, bool bJSBindingToLoweringEnabled, bool bUsingAcceleratedPaint);
  83. /**
  84. * Create the SWidget for this WebBrowserWindow
  85. */
  86. TSharedRef<SViewport> CreateWidget();
  87. public:
  88. /** Virtual Destructor. */
  89. virtual ~FCEFWebInterfaceBrowserWindow();
  90. bool IsShowingErrorMessages() const { return bShowErrorMessage; }
  91. bool IsThumbMouseButtonNavigationEnabled() const { return bThumbMouseButtonNavigation; }
  92. bool UseTransparency() const { return bUseTransparency; }
  93. bool UsingAcceleratedPaint() const { return bUsingAcceleratedPaint; }
  94. bool UseNativeCursors() { return bUseNativeCursors; }
  95. public:
  96. // IWebBrowserWindow Interface
  97. virtual void LoadURL(FString NewURL) override;
  98. virtual void LoadString(FString Contents, FString DummyURL) override;
  99. virtual void SetViewportSize(FIntPoint WindowSize, FIntPoint WindowPos) override;
  100. virtual FIntPoint GetViewportSize() const override { return FIntPoint::NoneValue; }
  101. virtual FSlateShaderResource* GetTexture(bool bIsPopup = false) override;
  102. virtual bool IsValid() const override;
  103. virtual bool IsInitialized() const override;
  104. virtual bool IsClosing() const override;
  105. virtual EWebInterfaceBrowserDocumentState GetDocumentLoadingState() const override;
  106. virtual FString GetTitle() const override;
  107. virtual FString GetUrl() const override;
  108. virtual void GetSource(TFunction<void (const FString&)> Callback) const override;
  109. virtual bool OnKeyDown(const FKeyEvent& InKeyEvent) override;
  110. virtual bool OnKeyUp(const FKeyEvent& InKeyEvent) override;
  111. virtual bool OnKeyChar(const FCharacterEvent& InCharacterEvent) override;
  112. virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  113. virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  114. virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  115. virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  116. virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
  117. virtual void SetSupportsMouseWheel(bool bValue) override;
  118. virtual bool GetSupportsMouseWheel() const override;
  119. virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
  120. virtual FReply OnTouchGesture(const FGeometry& MyGeometry, const FPointerEvent& GestureEvent, bool bIsPopup) override;
  121. virtual void OnFocus(bool SetFocus, bool bIsPopup) override;
  122. virtual void OnCaptureLost() override;
  123. virtual bool CanGoBack() const override;
  124. virtual void GoBack() override;
  125. virtual bool CanGoForward() const override;
  126. virtual void GoForward() override;
  127. virtual bool IsLoading() const override;
  128. virtual void Reload() override;
  129. virtual void StopLoad() override;
  130. virtual void ExecuteJavascript(const FString& Script) override;
  131. virtual void CloseBrowser(bool bForce, bool bBlockTillClosed) override;
  132. virtual void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true) override;
  133. virtual void UnbindUObject(const FString& Name, UObject* Object = nullptr, bool bIsPermanent = true) override;
  134. virtual void BindInputMethodSystem(ITextInputMethodSystem* TextInputMethodSystem) override;
  135. virtual void UnbindInputMethodSystem() override;
  136. virtual int GetLoadError() override;
  137. virtual void SetIsDisabled(bool bValue) override;
  138. virtual TSharedPtr<SWindow> GetParentWindow() const override;
  139. virtual void SetParentWindow(TSharedPtr<SWindow> Window) override;
  140. DECLARE_DERIVED_EVENT(FCEFWebInterfaceBrowserWindow, IWebInterfaceBrowserWindow::FOnDocumentStateChanged, FOnDocumentStateChanged);
  141. virtual FOnDocumentStateChanged& OnDocumentStateChanged() override
  142. {
  143. return DocumentStateChangedEvent;
  144. }
  145. DECLARE_DERIVED_EVENT(FCEFWebInterfaceBrowserWindow, IWebInterfaceBrowserWindow::FOnTitleChanged, FOnTitleChanged);
  146. virtual FOnTitleChanged& OnTitleChanged() override
  147. {
  148. return TitleChangedEvent;
  149. }
  150. DECLARE_DERIVED_EVENT(FCEFWebInterfaceBrowserWindow, IWebInterfaceBrowserWindow::FOnUrlChanged, FOnUrlChanged);
  151. virtual FOnUrlChanged& OnUrlChanged() override
  152. {
  153. return UrlChangedEvent;
  154. }
  155. DECLARE_DERIVED_EVENT(FCEFWebInterfaceBrowserWindow, IWebInterfaceBrowserWindow::FOnToolTip, FOnToolTip);
  156. virtual FOnToolTip& OnToolTip() override
  157. {
  158. return ToolTipEvent;
  159. }
  160. DECLARE_DERIVED_EVENT(FCEFWebInterfaceBrowserWindow, IWebInterfaceBrowserWindow::FOnNeedsRedraw, FOnNeedsRedraw);
  161. virtual FOnNeedsRedraw& OnNeedsRedraw() override
  162. {
  163. return NeedsRedrawEvent;
  164. }
  165. virtual FOnBeforeBrowse& OnBeforeBrowse() override
  166. {
  167. return BeforeBrowseDelegate;
  168. }
  169. virtual FOnLoadUrl& OnLoadUrl() override
  170. {
  171. return LoadUrlDelegate;
  172. }
  173. virtual FOnCreateWindow& OnCreateWindow() override
  174. {
  175. return WebBrowserHandler->OnCreateWindow();
  176. }
  177. virtual FOnCloseWindow& OnCloseWindow() override
  178. {
  179. return CloseWindowDelegate;
  180. }
  181. virtual FCursorReply OnCursorQuery( const FGeometry& MyGeometry, const FPointerEvent& CursorEvent ) override
  182. {
  183. return Cursor == EMouseCursor::Default ? FCursorReply::Unhandled() : FCursorReply::Cursor(Cursor);
  184. }
  185. virtual FOnBeforePopupDelegate& OnBeforePopup() override
  186. {
  187. return WebBrowserHandler->OnBeforePopup();
  188. }
  189. virtual FOnBeforeResourceLoadDelegate& OnBeforeResourceLoad() override
  190. {
  191. if (!WebBrowserHandler->OnBeforeResourceLoad().IsBoundToObject(this))
  192. {
  193. WebBrowserHandler->OnBeforeResourceLoad().BindSP(this, &FCEFWebInterfaceBrowserWindow::HandleOnBeforeResourceLoad);
  194. }
  195. return BeforeResourceLoadDelegate;
  196. }
  197. virtual FOnResourceLoadCompleteDelegate& OnResourceLoadComplete() override
  198. {
  199. if (!WebBrowserHandler->OnResourceLoadComplete().IsBoundToObject(this))
  200. {
  201. WebBrowserHandler->OnResourceLoadComplete().BindSP(this, &FCEFWebInterfaceBrowserWindow::HandleOnResourceLoadComplete);
  202. }
  203. return ResourceLoadCompleteDelegate;
  204. }
  205. virtual FOnConsoleMessageDelegate& OnConsoleMessage() override
  206. {
  207. if (!WebBrowserHandler->OnConsoleMessage().IsBoundToObject(this))
  208. {
  209. WebBrowserHandler->OnConsoleMessage().BindSP(this, &FCEFWebInterfaceBrowserWindow::HandleOnConsoleMessage);
  210. }
  211. return ConsoleMessageDelegate;
  212. }
  213. DECLARE_DERIVED_EVENT(FCEFWebInterfaceBrowserWindow, IWebInterfaceBrowserWindow::FOnShowPopup, FOnShowPopup);
  214. virtual FOnShowPopup& OnShowPopup() override
  215. {
  216. return ShowPopupEvent;
  217. }
  218. DECLARE_DERIVED_EVENT(FCEFWebInterfaceBrowserWindow, IWebInterfaceBrowserWindow::FOnDismissPopup, FOnDismissPopup);
  219. virtual FOnDismissPopup& OnDismissPopup() override
  220. {
  221. return DismissPopupEvent;
  222. }
  223. virtual FOnShowDialog& OnShowDialog() override
  224. {
  225. return ShowDialogDelegate;
  226. }
  227. virtual FOnDismissAllDialogs& OnDismissAllDialogs() override
  228. {
  229. return DismissAllDialogsDelegate;
  230. }
  231. virtual FOnSuppressContextMenu& OnSuppressContextMenu() override
  232. {
  233. return SuppressContextMenuDelgate;
  234. }
  235. virtual FOnDragWindow& OnDragWindow() override
  236. {
  237. return DragWindowDelegate;
  238. }
  239. virtual FOnUnhandledKeyDown& OnUnhandledKeyDown() override
  240. {
  241. return UnhandledKeyDownDelegate;
  242. }
  243. virtual FOnUnhandledKeyUp& OnUnhandledKeyUp() override
  244. {
  245. return UnhandledKeyUpDelegate;
  246. }
  247. virtual FOnUnhandledKeyChar& OnUnhandledKeyChar() override
  248. {
  249. return UnhandledKeyCharDelegate;
  250. }
  251. private:
  252. /**
  253. * Used to obtain the internal CEF browser.
  254. *
  255. * @return The bound CEF browser.
  256. */
  257. CefRefPtr<CefBrowser> GetCefBrowser();
  258. /**
  259. * Sets the Title of this window.
  260. *
  261. * @param InTitle The new title of this window.
  262. */
  263. void SetTitle(const CefString& InTitle);
  264. /**
  265. * Sets the url of this window.
  266. *
  267. * @param InUrl The new url of this window.
  268. */
  269. void SetUrl(const CefString& InUrl);
  270. /**
  271. * Sets the tool tip for this window.
  272. *
  273. * @param InToolTip The text to show in the ToolTip. Empty string for no tool tip.
  274. */
  275. void SetToolTip(const CefString& InToolTip);
  276. /**
  277. * Get the current proportions of this window.
  278. *
  279. * @param Rect Reference to CefRect to store sizes.
  280. * @return Whether Rect was set up correctly.
  281. */
  282. void GetViewRect(CefRect& Rect);
  283. /** Notifies when document loading has failed. */
  284. void NotifyDocumentError(CefLoadHandler::ErrorCode InErrorCode, const CefString& ErrorText, const CefString& FailedUrl);
  285. /** Notifies clients that document loading has failed. */
  286. void NotifyDocumentError(int ErrorCode);
  287. /**
  288. * Notifies clients that the loading state of the document has changed.
  289. *
  290. * @param IsLoading Whether the document is loading (false = completed).
  291. */
  292. void NotifyDocumentLoadingStateChange(bool IsLoading);
  293. /**
  294. * Called when there is an update to the rendered web page.
  295. *
  296. * @param Type Paint type.
  297. * @param DirtyRects List of image areas that have been changed.
  298. * @param Buffer Pointer to the raw texture data.
  299. * @param Width Width of the texture.
  300. * @param Height Height of the texture.
  301. */
  302. void OnPaint(CefRenderHandler::PaintElementType Type, const CefRenderHandler::RectList& DirtyRects, const void* Buffer, int Width, int Height);
  303. /**
  304. * Called when there is an update to the rendered web page.
  305. *
  306. * @param Type Paint type.
  307. * @param DirtyRects List of image areas that have been changed.
  308. * @param SharedHandle the handle for a D3D11 Texture2D that can be accessed via ID3D11Device using the OpenSharedResource method
  309. */
  310. void OnAcceleratedPaint(CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList& DirtyRects, void* SharedHandle);
  311. /**
  312. * Called when cursor would change due to web browser interaction.
  313. *
  314. * @param Cursor Handle to CEF mouse cursor.
  315. */
  316. bool OnCursorChange(CefCursorHandle Cursor, cef_cursor_type_t Type, const CefCursorInfo& CustomCursorInfo);
  317. /**
  318. * Called when a message was received from the renderer process.
  319. *
  320. * @param Browser The CefBrowser for this window.
  321. * @param SourceProcess The process id of the sender of the message. Currently always PID_RENDERER.
  322. * @param Message The actual message.
  323. * @return true if the message was handled, else false.
  324. */
  325. bool OnProcessMessageReceived(CefRefPtr<CefBrowser> Browser, CefRefPtr<CefFrame> frame, CefProcessId SourceProcess, CefRefPtr<CefProcessMessage> Message);
  326. /**
  327. * Called before browser navigation.
  328. *
  329. * @param Browser The CefBrowser for this window.
  330. * @param Frame The CefFrame the request came from.
  331. * @param Request The CefRequest containing web request info.
  332. * @param user_gesture true if the navigation was a result of a gesture, false otherwise.
  333. * @param bIsRedirect true if the navigation was a result of redirection, false otherwise.
  334. * @return true if the navigation was handled and no further processing of the navigation request should be disabled, false if the navigation should be handled by the default CEF implementation.
  335. */
  336. bool OnBeforeBrowse(CefRefPtr<CefBrowser> Browser, CefRefPtr<CefFrame> Frame, CefRefPtr<CefRequest> Request, bool user_gesture, bool bIsRedirect);
  337. void HandleOnBeforeResourceLoad(const CefString& URL, CefRequest::ResourceType Type, FRequestHeaders& AdditionalHeaders, const bool AllowUserCredentials);
  338. void HandleOnResourceLoadComplete(const CefString& URL, CefRequest::ResourceType Type, CefResourceRequestHandler::URLRequestStatus Status, int64 ContentLength);
  339. void HandleOnConsoleMessage(CefRefPtr<CefBrowser> Browser, cef_log_severity_t Level, const CefString& Message, const CefString& Source, int32 Line);
  340. /**
  341. * Called before loading a resource to allow overriding the content for a request.
  342. *
  343. * @return string content representing the content to show for the URL or an unset value to fetch the URL normally.
  344. */
  345. TOptional<FString> GetResourceContent( CefRefPtr< CefFrame > Frame, CefRefPtr< CefRequest > Request);
  346. /**
  347. * Convenience function to translate modifier keys from Cef keyboard event
  348. */
  349. FModifierKeysState SlateModifiersFromCefModifiers(const CefKeyEvent& CefEvent);
  350. /**
  351. * Called when browser reports a key event that was not handled by it
  352. */
  353. bool OnUnhandledKeyEvent(const CefKeyEvent& CefEvent);
  354. /**
  355. * Handle showing javascript dialogs
  356. */
  357. bool OnJSDialog(CefJSDialogHandler::JSDialogType DialogType, const CefString& MessageText, const CefString& DefaultPromptText, CefRefPtr<CefJSDialogCallback> Callback, bool& OutSuppressMessage);
  358. /**
  359. * Handle showing unload confirmation dialogs
  360. */
  361. bool OnBeforeUnloadDialog(const CefString& MessageText, bool IsReload, CefRefPtr<CefJSDialogCallback> Callback);
  362. /**
  363. * Notify when any and all pending dialogs should be canceled
  364. */
  365. void OnResetDialogState();
  366. /**
  367. * Called when render process was terminated abnormally.
  368. */
  369. void OnRenderProcessTerminated(CefRequestHandler::TerminationStatus Status);
  370. /** Called when the browser requests a new UI window
  371. *
  372. * @param NewBrowserWindow The web browser window to display in the new UI window.
  373. * @param BrowserPopupFeatures The popup features and settings for the browser window.
  374. * @return true if the UI window was created, false otherwise.
  375. */
  376. bool RequestCreateWindow(const TSharedRef<IWebInterfaceBrowserWindow>& NewBrowserWindow, const TSharedPtr<IWebInterfaceBrowserPopupFeatures>& BrowserPopupFeatures);
  377. //bool SupportsCloseWindows();
  378. //bool RequestCloseWindow(const TSharedRef<IWebInterfaceBrowserWindow>& BrowserWindow);
  379. /**
  380. * Called once the browser begins closing procedures.
  381. */
  382. void OnBrowserClosing();
  383. /**
  384. * Called once the browser is closed.
  385. */
  386. void OnBrowserClosed();
  387. /**
  388. * Called to set the popup menu location. Note that CEF also passes a size to this method,
  389. * which is ignored as the correct size is usually not known until inside OnPaint.
  390. *
  391. * @param PopupSize The location of the popup widget.
  392. */
  393. void SetPopupMenuPosition(CefRect PopupSize);
  394. /**
  395. * Called to request that the popup widget is shown or hidden.
  396. *
  397. * @param bShow true for showing the popup, false for hiding it.
  398. */
  399. void ShowPopupMenu(bool bShow);
  400. /**
  401. * Called when the IME composition DOM node has changed.
  402. * @param Browser The CefBrowser for this window.
  403. * @param SelectionRange The range of characters that have been selected.
  404. * @param CharacterBounds The bounds of each character in view coordinates.
  405. */
  406. void OnImeCompositionRangeChanged(
  407. CefRefPtr<CefBrowser> Browser,
  408. const CefRange& SelectionRange,
  409. const CefRenderHandler::RectList& CharacterBounds);
  410. void UpdateDragRegions(const TArray<FWebInterfaceBrowserDragRegion>& Regions);
  411. public:
  412. /**
  413. * Gets the Cef Keyboard Modifiers based on a Key Event.
  414. *
  415. * @param KeyEvent The Key event.
  416. * @return Bits representing keyboard modifiers.
  417. */
  418. static int32 GetCefKeyboardModifiers(const FKeyEvent& KeyEvent);
  419. /**
  420. * Gets the Cef Mouse Modifiers based on a Mouse Event.
  421. *
  422. * @param InMouseEvent The Mouse event.
  423. * @return Bits representing mouse modifiers.
  424. */
  425. static int32 GetCefMouseModifiers(const FPointerEvent& InMouseEvent);
  426. /**
  427. * Gets the Cef Input Modifiers based on an Input Event.
  428. *
  429. * @param InputEvent The Input event.
  430. * @return Bits representing input modifiers.
  431. */
  432. static int32 GetCefInputModifiers(const FInputEvent& InputEvent);
  433. /**
  434. * Is this platform able to support the accelerated paint path for CEF.
  435. *
  436. * @return true if supported AND enabled on this platform, false otherwise.
  437. */
  438. static bool CanSupportAcceleratedPaint();
  439. public:
  440. /**
  441. * Called from the WebBrowserViewport tick event. Allows us to cache the geometry and use it for coordinate transformations.
  442. */
  443. void UpdateCachedGeometry(const FGeometry& AllottedGeometry);
  444. /**
  445. * Called from the WebBrowserSingleton tick event. Should test wether the widget got a tick from Slate last frame and set the state to hidden if not.
  446. */
  447. void CheckTickActivity() override;
  448. /**
  449. * Called from the engine tick.
  450. */
  451. void UpdateVideoBuffering();
  452. /**
  453. * Called on every browser window when CEF launches a new render process.
  454. * Used to ensure global JS objects are registered as soon as possible.
  455. */
  456. CefRefPtr<CefDictionaryValue> GetProcessInfo();
  457. /**
  458. * Return true if this URL will support adding an Authorization header to it
  459. */
  460. bool URLRequestAllowsCredentials(const FString& URL) const { return WebBrowserHandler->URLRequestAllowsCredentials(URL); }
  461. private:
  462. /** @return the currently valid renderer, if available */
  463. FSlateRenderer* const GetRenderer();
  464. /**Checks whether an error with the renderer occurred and handles it if one has */
  465. void HandleRenderingError();
  466. /** Releases the updatable textures */
  467. void ReleaseTextures();
  468. /** Creates the initial updatable textures */
  469. bool CreateInitialTextures();
  470. /** Executes or defers a LoadUrl navigation */
  471. void RequestNavigationInternal(FString Url, FString Contents);
  472. /** Specifies whether or not we have a pending deferred navigation */
  473. bool HasPendingNavigation();
  474. /** Executes navigation on a pending deferred navigation */
  475. void ProcessPendingNavigation();
  476. /** Helper that calls WasHidden on the CEF host object when the value changes */
  477. void SetIsHidden(bool bValue);
  478. /** Used by the key down and up handlers to convert Slate key events to the CEF equivalent. */
  479. void PopulateCefKeyEvent(const FKeyEvent& InKeyEvent, CefKeyEvent& OutKeyEvent);
  480. /** Used to convert a FPointerEvent to a CefMouseEvent */
  481. CefMouseEvent GetCefMouseEvent(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup);
  482. /** Specifies whether or not a point falls within any tagged drag regions that are draggable. */
  483. bool IsInDragRegion(const FIntPoint& Point);
  484. /** Used to let us correctly render the web texture for the accelerated render path */
  485. TOptional<FSlateRenderTransform> GetWebBrowserRenderTransform() const;
  486. bool BlockInputInDirectHwndMode() const;
  487. #if PLATFORM_WINDOWS
  488. /** manually load cursor icons from the CEF3 dll if needed, working around a CEF3 bug */
  489. bool LoadCustomCEF3Cursor(cef_cursor_type_t Type);
  490. #endif
  491. private:
  492. /** Current state of the document being loaded. */
  493. EWebInterfaceBrowserDocumentState DocumentState;
  494. /** Interface to the texture we are rendering to. */
  495. FSlateUpdatableTexture* UpdatableTextures[2];
  496. /** Pointer to the CEF Browser for this window. */
  497. CefRefPtr<CefBrowser> InternalCefBrowser;
  498. /** Pointer to the CEF handler for this window. */
  499. CefRefPtr<FCEFInterfaceBrowserHandler> WebBrowserHandler;
  500. /** Current title of this window. */
  501. FString Title;
  502. /** Current Url of this window. */
  503. FString CurrentUrl;
  504. /** Current tool tip. */
  505. FString ToolTipText;
  506. /** Current size of this window. */
  507. FIntPoint ViewportSize;
  508. /** Current position of this window. */
  509. FIntPoint ViewportPos;
  510. /** Current DPI scale factor of this window. */
  511. float ViewportDPIScaleFactor;
  512. /** Whether this window is closing. */
  513. bool bIsClosing;
  514. /** Whether this window has been painted at least once. */
  515. bool bIsInitialized;
  516. /** Optional text to load as a web page. */
  517. TOptional<FString> ContentsToLoad;
  518. /** Delegate for broadcasting load state changes. */
  519. FOnDocumentStateChanged DocumentStateChangedEvent;
  520. /** Whether to show an error message in case of loading errors. */
  521. bool bShowErrorMessage;
  522. /** Whether to allow forward and back navigation via the mouse thumb buttons. */
  523. bool bThumbMouseButtonNavigation;
  524. /** Whether transparency is enabled. */
  525. bool bUseTransparency;
  526. /** Whether the accelerated paint path is enabled (i.e shared texture handles) */
  527. bool bUsingAcceleratedPaint;
  528. /** Whether native cursors are enabled. */
  529. bool bUseNativeCursors;
  530. /** Delegate for broadcasting title changes. */
  531. FOnTitleChanged TitleChangedEvent;
  532. /** Delegate for broadcasting address changes. */
  533. FOnUrlChanged UrlChangedEvent;
  534. /** Delegate for showing or hiding tool tips. */
  535. FOnToolTip ToolTipEvent;
  536. /** Delegate for notifying that the window needs refreshing. */
  537. FOnNeedsRedraw NeedsRedrawEvent;
  538. /** Delegate that is executed prior to browser navigation. */
  539. FOnBeforeBrowse BeforeBrowseDelegate;
  540. /** Delegate for overriding Url contents. */
  541. FOnLoadUrl LoadUrlDelegate;
  542. /** Delegate for handling requests to close new windows that were created. */
  543. FOnCloseWindow CloseWindowDelegate;
  544. /** Delegate for handling resource load requests */
  545. FOnBeforeResourceLoadDelegate BeforeResourceLoadDelegate;
  546. /** Delegate that allows for responses to resource loads */
  547. FOnResourceLoadCompleteDelegate ResourceLoadCompleteDelegate;
  548. /** Delegate that allows for response to console logs. Typically used to capture and mirror web logs in client application logs. */
  549. FOnConsoleMessageDelegate ConsoleMessageDelegate;
  550. /** Delegate for handling requests to show the popup menu. */
  551. FOnShowPopup ShowPopupEvent;
  552. /** Delegate for handling requests to dismiss the current popup menu. */
  553. FOnDismissPopup DismissPopupEvent;
  554. /** Delegate for showing dialogs. */
  555. FOnShowDialog ShowDialogDelegate;
  556. /** Delegate for dismissing all dialogs. */
  557. FOnDismissAllDialogs DismissAllDialogsDelegate;
  558. /** Delegate for suppressing context menu */
  559. FOnSuppressContextMenu SuppressContextMenuDelgate;
  560. /** Delegate that is executed when a drag event is detected in an area of the web page tagged as a drag region. */
  561. FOnDragWindow DragWindowDelegate;
  562. /** Delegate for handling key down events not handled by the browser. */
  563. FOnUnhandledKeyDown UnhandledKeyDownDelegate;
  564. /** Delegate for handling key up events not handled by the browser. */
  565. FOnUnhandledKeyUp UnhandledKeyUpDelegate;
  566. /** Delegate for handling key char events not handled by the browser. */
  567. FOnUnhandledKeyChar UnhandledKeyCharDelegate;
  568. /** Tracks the current mouse cursor */
  569. EMouseCursor::Type Cursor;
  570. /** Tracks whether the widget is currently disabled or not*/
  571. bool bIsDisabled;
  572. /** Tracks whether the widget is currently hidden or not*/
  573. bool bIsHidden;
  574. /** Used to detect when the widget is hidden*/
  575. bool bTickedLastFrame;
  576. /** Tracks whether the widget has been resized and needs to be refreshed */
  577. bool bNeedsResize;
  578. /** Tracks whether or not the user initiated a window drag by clicking on a page's drag region. */
  579. bool bDraggingWindow;
  580. /** Used for unhandled key events forwarding*/
  581. TOptional<FKeyEvent> PreviousKeyDownEvent;
  582. TOptional<FKeyEvent> PreviousKeyUpEvent;
  583. TOptional<FCharacterEvent> PreviousCharacterEvent;
  584. bool bIgnoreKeyDownEvent;
  585. bool bIgnoreKeyUpEvent;
  586. bool bIgnoreCharacterEvent;
  587. /** Used to ignore any popup menus when forwarding focus gained/lost events*/
  588. bool bMainHasFocus;
  589. bool bPopupHasFocus;
  590. bool bSupportsMouseWheel;
  591. FIntPoint PopupPosition;
  592. bool bShowPopupRequested;
  593. /** This is set to true when reloading after render process crash. */
  594. bool bRecoverFromRenderProcessCrash;
  595. int ErrorCode;
  596. /** Used to defer navigations */
  597. bool bDeferNavigations;
  598. /** Used to identify a navigation that needs to fully abort before we can stop deferring navigations. */
  599. FString PendingAbortUrl;
  600. /** Used to store the url of pending navigation requests while we need to defer navigations. */
  601. FString PendingLoadUrl;
  602. TUniquePtr<FBrowserBufferedVideo> BufferedVideo;
  603. #if PLATFORM_MAC
  604. void *LastPaintedSharedHandle;
  605. #endif
  606. /** Handling of passing and marshalling messages for JS integration is delegated to a helper class*/
  607. TSharedPtr<FCEFInterfaceJSScripting> Scripting;
  608. #if !PLATFORM_LINUX
  609. /** Handling of foreign language character input is delegated to a helper class */
  610. TSharedPtr<FCEFInterfaceImeHandler> Ime;
  611. #endif
  612. TArray<FWebInterfaceBrowserDragRegion> DragRegions;
  613. TWeakPtr<SWindow> ParentWindow;
  614. FCEFWebInterfaceBrowserWindowRHIHelper* RHIRenderHelper;
  615. #if PLATFORM_WINDOWS || PLATFORM_MAC
  616. bool bInDirectHwndMode;
  617. #endif
  618. };
  619. typedef FCEFWebInterfaceBrowserWindow FWebInterfaceBrowserWindow;
  620. #endif