UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CEFWebBrowserWindow.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Input/CursorReply.h"
7#include "Input/Events.h"
8#include "Input/Reply.h"
9#include "Widgets/SViewport.h"
10#include "WebBrowserSingleton.h"
11
12#if WITH_CEF3
13
14#include "IWebBrowserWindow.h"
15#include "CEFBrowserHandler.h"
16
17#include "CEFLibCefIncludes.h"
18
19#include "CapturedCefBuffer.h"
20
21#endif
22
25class FCEFJSScripting;
29struct Rect;
32struct FGeometry;
33struct FPointerEvent;
34class UObject;
35struct FInputEvent;
36class FWebJSScripting;
37class FCEFImeHandler;
40
41#if WITH_CEF3
42
47{
50 , Handler(InHandler)
51 {}
54};
55
60{
62 : Rect(InRect)
64 {}
65
67 bool bDraggable;
68};
69
74 : public IWebBrowserWindow
75 , public TSharedFromThis<FCEFWebBrowserWindow>
76{
77 // Allow the Handler to access functions only it needs
78 friend class FCEFBrowserHandler;
79
80 // The WebBrowserSingleton should be the only one creating instances of this class
81 friend class FWebBrowserSingleton;
82
83 // CreateWidget should only be called by the WebBrowserView
84 friend class SWebBrowserView;
85
86private:
99 FCEFWebBrowserWindow(CefRefPtr<CefBrowser> Browser, CefRefPtr<FCEFBrowserHandler> Handler, FString Url, TOptional<FString> ContentsToLoad, bool bShowErrorMessage, bool bThumbMouseButtonNavigation, bool bUseTransparency, bool bJSBindingToLoweringEnabled, bool bUsingAcceleratedPaint);
100
105
106public:
108 virtual ~FCEFWebBrowserWindow();
109
110 bool IsShowingErrorMessages() const { return bShowErrorMessage; }
111 bool IsThumbMouseButtonNavigationEnabled() const { return bThumbMouseButtonNavigation; }
112 bool UseTransparency() const { return bUseTransparency; }
113 bool UsingAcceleratedPaint() const { return bUsingAcceleratedPaint; }
114
115public:
116
117 // IWebBrowserWindow Interface
118
119 virtual void LoadURL(FString NewURL) override;
120 virtual void LoadString(FString Contents, FString DummyURL) override;
121 virtual void SetViewportSize(FIntPoint WindowSize, FIntPoint WindowPos) override;
122 virtual FIntPoint GetViewportSize() const override { return FIntPoint::NoneValue; }
123 virtual FSlateShaderResource* GetTexture(bool bIsPopup = false) override;
124 virtual bool IsValid() const override;
125 virtual bool IsInitialized() const override;
126 virtual bool IsClosing() const override;
127 virtual EWebBrowserDocumentState GetDocumentLoadingState() const override;
128 virtual FString GetTitle() const override;
129 virtual FString GetUrl() const override;
130 virtual void GetSource(TFunction<void (const FString&)> Callback) const override;
131 virtual bool OnKeyDown(const FKeyEvent& InKeyEvent) override;
132 virtual bool OnKeyUp(const FKeyEvent& InKeyEvent) override;
133 virtual bool OnKeyChar(const FCharacterEvent& InCharacterEvent) override;
134 virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
135 virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
136 virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
137 virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
138 virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
139 virtual void SetSupportsMouseWheel(bool bValue) override;
140 virtual bool GetSupportsMouseWheel() const override;
141 virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
142 virtual FReply OnTouchGesture(const FGeometry& MyGeometry, const FPointerEvent& GestureEvent, bool bIsPopup) override;
143 virtual void OnFocus(bool SetFocus, bool bIsPopup) override;
144 virtual void OnCaptureLost() override;
145 virtual bool CanGoBack() const override;
146 virtual void GoBack() override;
147 virtual bool CanGoForward() const override;
148 virtual void GoForward() override;
149 virtual bool IsLoading() const override;
150 virtual void Reload() override;
151 virtual void StopLoad() override;
152 virtual void ExecuteJavascript(const FString& Script) override;
153 virtual void CloseBrowser(bool bForce, bool bBlockTillClosed) override;
154 virtual void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true) override;
155 virtual void UnbindUObject(const FString& Name, UObject* Object = nullptr, bool bIsPermanent = true) override;
156 virtual void BindInputMethodSystem(ITextInputMethodSystem* TextInputMethodSystem) override;
157 virtual void UnbindInputMethodSystem() override;
158 virtual int GetLoadError() override;
159 virtual void SetIsDisabled(bool bValue) override;
160 virtual TSharedPtr<SWindow> GetParentWindow() const override;
161 virtual void SetParentWindow(TSharedPtr<SWindow> Window) override;
162 virtual void ShowFloatingCloseButton(bool bShow, bool bDraggable) override
163 {
164 }
165
166 DECLARE_DERIVED_EVENT(FCEFWebBrowserWindow, IWebBrowserWindow::FOnDocumentStateChanged, FOnDocumentStateChanged);
168 {
169 return DocumentStateChangedEvent;
170 }
171
172 DECLARE_DERIVED_EVENT(FCEFWebBrowserWindow, IWebBrowserWindow::FOnTitleChanged, FOnTitleChanged);
173 virtual FOnTitleChanged& OnTitleChanged() override
174 {
175 return TitleChangedEvent;
176 }
177
178 DECLARE_DERIVED_EVENT(FCEFWebBrowserWindow, IWebBrowserWindow::FOnUrlChanged, FOnUrlChanged);
179 virtual FOnUrlChanged& OnUrlChanged() override
180 {
181 return UrlChangedEvent;
182 }
183
184 DECLARE_DERIVED_EVENT(FCEFWebBrowserWindow, IWebBrowserWindow::FOnToolTip, FOnToolTip);
185 virtual FOnToolTip& OnToolTip() override
186 {
187 return ToolTipEvent;
188 }
189
190 DECLARE_DERIVED_EVENT(FCEFWebBrowserWindow, IWebBrowserWindow::FOnNeedsRedraw, FOnNeedsRedraw);
191 virtual FOnNeedsRedraw& OnNeedsRedraw() override
192 {
193 return NeedsRedrawEvent;
194 }
195
196 virtual FOnBeforeBrowse& OnBeforeBrowse() override
197 {
198 return BeforeBrowseDelegate;
199 }
200
201 virtual FOnLoadUrl& OnLoadUrl() override
202 {
203 return LoadUrlDelegate;
204 }
205
206 virtual FOnCreateWindow& OnCreateWindow() override
207 {
208 return WebBrowserHandler->OnCreateWindow();
209 }
210
211 virtual FOnCloseWindow& OnCloseWindow() override
212 {
213 return CloseWindowDelegate;
214 }
215
217 {
218 return FloatingCloseButtonPressedDelegate;
219 }
220
222 {
223 return Cursor == EMouseCursor::Default ? FCursorReply::Unhandled() : FCursorReply::Cursor(Cursor);
224 }
225
226 virtual FOnBeforePopupDelegate& OnBeforePopup() override
227 {
228 return WebBrowserHandler->OnBeforePopup();
229 }
230
232 {
233 if (!WebBrowserHandler->OnBeforeResourceLoad().IsBoundToObject(this))
234 {
235 WebBrowserHandler->OnBeforeResourceLoad().BindSP(this, &FCEFWebBrowserWindow::HandleOnBeforeResourceLoad);
236 }
237
238 return BeforeResourceLoadDelegate;
239 }
240
242 {
243 if (!WebBrowserHandler->OnResourceLoadComplete().IsBoundToObject(this))
244 {
245 WebBrowserHandler->OnResourceLoadComplete().BindSP(this, &FCEFWebBrowserWindow::HandleOnResourceLoadComplete);
246 }
247
248 return ResourceLoadCompleteDelegate;
249 }
250
252 {
253 if (!WebBrowserHandler->OnConsoleMessage().IsBoundToObject(this))
254 {
255 WebBrowserHandler->OnConsoleMessage().BindSP(this, &FCEFWebBrowserWindow::HandleOnConsoleMessage);
256 }
257
258 return ConsoleMessageDelegate;
259 }
260
261 DECLARE_DERIVED_EVENT(FCEFWebBrowserWindow, IWebBrowserWindow::FOnShowPopup, FOnShowPopup);
262 virtual FOnShowPopup& OnShowPopup() override
263 {
264 return ShowPopupEvent;
265 }
266
267 DECLARE_DERIVED_EVENT(FCEFWebBrowserWindow, IWebBrowserWindow::FOnDismissPopup, FOnDismissPopup);
268 virtual FOnDismissPopup& OnDismissPopup() override
269 {
270 return DismissPopupEvent;
271 }
272
273 virtual FOnShowDialog& OnShowDialog() override
274 {
275 return ShowDialogDelegate;
276 }
277
278 virtual FOnDismissAllDialogs& OnDismissAllDialogs() override
279 {
280 return DismissAllDialogsDelegate;
281 }
282
284 {
285 return SuppressContextMenuDelgate;
286 }
287
288 virtual FOnDragWindow& OnDragWindow() override
289 {
290 return DragWindowDelegate;
291 }
292
293 virtual FOnUnhandledKeyDown& OnUnhandledKeyDown() override
294 {
295 return UnhandledKeyDownDelegate;
296 }
297
298 virtual FOnUnhandledKeyUp& OnUnhandledKeyUp() override
299 {
300 return UnhandledKeyUpDelegate;
301 }
302
303 virtual FOnUnhandledKeyChar& OnUnhandledKeyChar() override
304 {
305 return UnhandledKeyCharDelegate;
306 }
307
308private:
309
316
322 void SetTitle(const CefString& InTitle);
323
329 void SetUrl(const CefString& InUrl);
330
336 void SetToolTip(const CefString& InToolTip);
337
344 void GetViewRect(CefRect& Rect);
345
347 void NotifyDocumentError(CefLoadHandler::ErrorCode InErrorCode, const CefString& ErrorText, const CefString& FailedUrl);
348
350 void NotifyDocumentError(int ErrorCode);
351
358
368 void OnPaint(CefRenderHandler::PaintElementType Type, const CefRenderHandler::RectList& DirtyRects, const void* Buffer, int Width, int Height);
369
377 void OnAcceleratedPaint(CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList& DirtyRects,
378#if CEF_VERSION_MAJOR < 128
379 void* SharedHandle);
380#else
382#endif
383
390
400
411 bool OnBeforeBrowse(CefRefPtr<CefBrowser> Browser, CefRefPtr<CefFrame> Frame, CefRefPtr<CefRequest> Request, bool user_gesture, bool bIsRedirect);
412
413 void HandleOnBeforeResourceLoad(const CefString& URL, CefRequest::ResourceType Type, FRequestHeaders& AdditionalHeaders, const bool AllowUserCredentials);
414 void HandleOnResourceLoadComplete(const CefString& URL, CefRequest::ResourceType Type, CefResourceRequestHandler::URLRequestStatus Status, int64 ContentLength);
416
423
428
433
437 bool OnJSDialog(CefJSDialogHandler::JSDialogType DialogType, const CefString& MessageText, const CefString& DefaultPromptText, CefRefPtr<CefJSDialogCallback> Callback, bool& OutSuppressMessage);
438
442 bool OnFileDialog(CefDialogHandler::FileDialogMode Mode, const CefString& DialogTitle, const CefString& DefaultFilePath, const std::vector<CefString>& AcceptFilters,
443#if CEF_VERSION_MAJOR < 128
445#else
446 const std::vector<CefString>& AcceptExtensions,
447 const std::vector<CefString>& AcceptDescriptions,
448#endif
450
454 bool OnBeforeUnloadDialog(const CefString& MessageText, bool IsReload, CefRefPtr<CefJSDialogCallback> Callback);
455
459 void OnResetDialogState();
460
464 void OnRenderProcessTerminated(CefRequestHandler::TerminationStatus Status);
465
466
474
475 //bool SupportsCloseWindows();
476 //bool RequestCloseWindow(const TSharedRef<IWebBrowserWindow>& BrowserWindow);
477
478
482 void OnBrowserClosing();
483
487 void OnBrowserClosed();
488
496
502 void ShowPopupMenu(bool bShow);
503
512 const CefRange& SelectionRange,
513 const CefRenderHandler::RectList& CharacterBounds);
514
516
517public:
518
525 static int32 GetCefKeyboardModifiers(const FKeyEvent& KeyEvent);
526
534
541 static int32 GetCefInputModifiers(const FInputEvent& InputEvent);
542
543
549 static bool CanSupportAcceleratedPaint();
550public:
551
555 void UpdateCachedGeometry(const FGeometry& AllottedGeometry);
556
557
561 void CheckTickActivity() override;
562
567
572 CefRefPtr<CefDictionaryValue> GetProcessInfo();
573
577 bool URLRequestAllowsCredentials(const FString& URL) const { return WebBrowserHandler->URLRequestAllowsCredentials(URL); }
578
583
588 WEBBROWSER_API void SetUseCapturedCefBuffer(const bool bValue);
589
593 WEBBROWSER_API bool HasResizeBug() const;
594
599
603 WEBBROWSER_API void SetNeedsResize(const bool bInValue);
604
605private:
606
608 FSlateRenderer* const GetRenderer();
609
612
614 void ReleaseTextures();
615
618
620 void RequestNavigationInternal(FString Url, FString Contents);
621
624
627
629 void SetIsHidden(bool bValue);
630
633
636
638 bool IsInDragRegion(const FIntPoint& Point);
639
640 bool BlockInputInDirectHwndMode() const;
641
642#if PLATFORM_WINDOWS
645#endif
646private:
647
650
653
656
659
661 FString Title;
662
664 FString CurrentUrl;
665
667 FString ToolTipText;
668
670 FIntPoint ViewportSize;
671
674
677
679 bool bIsClosing;
680
682 bool bIsInitialized;
683
685 TOptional<FString> ContentsToLoad;
686
688 FOnDocumentStateChanged DocumentStateChangedEvent;
689
691 bool bShowErrorMessage;
692
694 bool bThumbMouseButtonNavigation;
695
697 bool bUseTransparency;
698
701
703 FOnTitleChanged TitleChangedEvent;
704
706 FOnUrlChanged UrlChangedEvent;
707
709 FOnToolTip ToolTipEvent;
710
712 FOnNeedsRedraw NeedsRedrawEvent;
713
715 FOnBeforeBrowse BeforeBrowseDelegate;
716
718 FOnLoadUrl LoadUrlDelegate;
719
721 FOnCloseWindow CloseWindowDelegate;
722
724 FOnFloatingCloseButtonPressed FloatingCloseButtonPressedDelegate;
725
727 FOnBeforeResourceLoadDelegate BeforeResourceLoadDelegate;
728
730 FOnResourceLoadCompleteDelegate ResourceLoadCompleteDelegate;
731
733 FOnConsoleMessageDelegate ConsoleMessageDelegate;
734
736 FOnShowPopup ShowPopupEvent;
737
739 FOnDismissPopup DismissPopupEvent;
740
742 FOnShowDialog ShowDialogDelegate;
743
745 FOnDismissAllDialogs DismissAllDialogsDelegate;
746
748 FOnSuppressContextMenu SuppressContextMenuDelgate;
749
751 FOnDragWindow DragWindowDelegate;
752
754 FOnUnhandledKeyDown UnhandledKeyDownDelegate;
755
757 FOnUnhandledKeyUp UnhandledKeyUpDelegate;
758
760 FOnUnhandledKeyChar UnhandledKeyCharDelegate;
761
763 EMouseCursor::Type Cursor;
764
766 bool bIsDisabled;
767
769 bool bIsHidden;
770
772 bool bTickedLastFrame;
773
775 bool bNeedsResize;
776
778 bool bDraggingWindow;
779
787
789 bool bMainHasFocus;
790 bool bPopupHasFocus;
791
793
796
799
800 int ErrorCode;
801
804
806 FString PendingAbortUrl;
807
809 FString PendingLoadUrl;
810
812#if PLATFORM_MAC
814#endif
815
818
819#if !PLATFORM_LINUX
822#endif
823
825
826 TWeakPtr<SWindow> ParentWindow;
827
829
830#if PLATFORM_WINDOWS || PLATFORM_MAC
832#endif
833
834 bool bHasCorrectNativeCefBuffer = true;
836};
837
839
840#endif
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DERIVED_EVENT(OwningType, BaseTypeEvent, EventName)
Definition Delegate.h:231
EWebBrowserDocumentState
Definition IWebBrowserWindow.h:18
bool IsLoading()
Definition UObjectGlobals.cpp:2087
WidgetT * CreateWidget(OwnerType OwningObject, TSubclassOf< UUserWidget > UserWidgetClass=WidgetT::StaticClass(), FName WidgetName=NAME_None)
Definition UserWidget.h:1811
Definition CursorReply.h:16
static FCursorReply Unhandled()
Definition CursorReply.h:24
Definition GenericApplication.h:75
Definition Reply.h:24
Definition SlateRenderer.h:173
Definition SlateShaderResource.h:44
Definition SlateUpdatableTexture.h:15
Definition WebBrowserSingleton.h:52
Definition WebJSScripting.h:17
Definition ITextInputMethodSystem.h:169
Definition IWebBrowserPopupFeatures.h:8
Definition IWebBrowserWindow.h:85
virtual bool GetSupportsMouseWheel() const =0
virtual void UnbindInputMethodSystem()
Definition IWebBrowserWindow.h:345
virtual FReply OnMouseButtonUp(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent, bool bIsPopup)=0
virtual bool OnKeyUp(const FKeyEvent &InKeyEvent)=0
virtual FOnSuppressContextMenu & OnSuppressContextMenu()=0
virtual void CloseBrowser(bool bForce, bool bBlockTillClosed=false)=0
virtual bool OnKeyDown(const FKeyEvent &InKeyEvent)=0
virtual FIntPoint GetViewportSize() const =0
virtual FOnTitleChanged & OnTitleChanged()=0
virtual bool CanGoForward() const =0
virtual bool OnKeyChar(const FCharacterEvent &InCharacterEvent)=0
virtual bool CanGoBack() const =0
virtual FOnUnhandledKeyUp & OnUnhandledKeyUp()=0
virtual void LoadURL(FString NewURL)=0
virtual FOnDismissPopup & OnDismissPopup()=0
virtual void SetIsDisabled(bool bValue)=0
virtual void ExecuteJavascript(const FString &Script)=0
virtual bool IsValid() const =0
virtual void GoForward()=0
virtual TSharedPtr< class SWindow > GetParentWindow() const =0
virtual void SetViewportSize(FIntPoint WindowSize, FIntPoint WindowPos=FIntPoint::NoneValue)=0
virtual FOnUrlChanged & OnUrlChanged()=0
virtual void OnMouseLeave(const FPointerEvent &MouseEvent)=0
virtual void StopLoad()=0
virtual FString GetUrl() const =0
virtual FOnConsoleMessageDelegate & OnConsoleMessage()=0
virtual void OnFocus(bool SetFocus, bool bIsPopup)=0
virtual void ShowFloatingCloseButton(bool bShow, bool bDraggable)=0
virtual FReply OnMouseWheel(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent, bool bIsPopup)=0
virtual void OnCaptureLost()=0
virtual FOnBeforeResourceLoadDelegate & OnBeforeResourceLoad()=0
virtual FOnDismissAllDialogs & OnDismissAllDialogs()=0
virtual bool IsClosing() const =0
virtual FSlateShaderResource * GetTexture(bool bIsPopup=false)=0
virtual void GetSource(TFunction< void(const FString &)> Callback) const =0
virtual FReply OnMouseButtonDown(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent, bool bIsPopup)=0
virtual void SetParentWindow(TSharedPtr< class SWindow > Window)=0
virtual void BindUObject(const FString &Name, UObject *Object, bool bIsPermanent=true)=0
virtual FOnNeedsRedraw & OnNeedsRedraw()=0
virtual void SetSupportsMouseWheel(bool bValue)=0
virtual EWebBrowserDocumentState GetDocumentLoadingState() const =0
virtual void BindInputMethodSystem(ITextInputMethodSystem *TextInputMethodSystem)
Definition IWebBrowserWindow.h:343
virtual FOnFloatingCloseButtonPressed & OnFloatingCloseButtonPressed()=0
virtual void GoBack()=0
virtual FCursorReply OnCursorQuery(const FGeometry &MyGeometry, const FPointerEvent &CursorEvent)=0
virtual void UnbindUObject(const FString &Name, UObject *Object, bool bIsPermanent=true)=0
virtual FReply OnTouchGesture(const FGeometry &MyGeometry, const FPointerEvent &GestureEvent, bool bIsPopup)=0
virtual bool IsLoading() const =0
virtual void CheckTickActivity()
Definition IWebBrowserWindow.h:376
virtual FOnBeforePopupDelegate & OnBeforePopup()=0
virtual FOnDocumentStateChanged & OnDocumentStateChanged()=0
virtual void LoadString(FString Contents, FString DummyURL)=0
virtual FOnUnhandledKeyChar & OnUnhandledKeyChar()=0
virtual bool IsInitialized() const =0
virtual FString GetTitle() const =0
virtual int GetLoadError()=0
virtual FReply OnMouseMove(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent, bool bIsPopup)=0
virtual FOnToolTip & OnToolTip()=0
virtual void Reload()=0
virtual FReply OnMouseButtonDoubleClick(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent, bool bIsPopup)=0
virtual FOnResourceLoadCompleteDelegate & OnResourceLoadComplete()=0
virtual FOnUnhandledKeyDown & OnUnhandledKeyDown()=0
Definition SWebBrowserView.h:39
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition SharedPointer.h:1640
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Definition UniquePtr.h:107
Definition SharedPointer.h:1295
Definition Object.h:95
Type
Definition ICursor.h:18
@ Default
Definition ICursor.h:23
Definition Events.h:606
Definition Geometry.h:40
Definition Events.h:155
Definition Events.h:431
Definition Events.h:695
Definition LinuxPlatformSplash.cpp:43
Definition Optional.h:131
Definition IntPoint.h:25
static const TIntPoint NoneValue
Definition IntPoint.h:48