UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ApplePlatformWebBrowser.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
7#if !WITH_CEF3 && (PLATFORM_IOS || PLATFORM_MAC)
8
9#include "IWebBrowserWindow.h"
10#include "Widgets/SWindow.h"
11
12#include "Engine/Texture2D.h"
14#include "WebBrowserTexture.h"
15#include "Misc/ConfigCacheIni.h"
16
18
19#if PLATFORM_IOS
20#import <UIKit/UIKit.h>
21#else
22#import <AppKit/AppKit.h>
23#endif
24
25#if !PLATFORM_TVOS
26#import "WebKit/WebKit.h"
27#endif
28
29
31
33class SWebBrowserView;
34
38#if !PLATFORM_TVOS
40
42#else
43@interface AppleWebViewWrapper : NSObject
44#endif
45{
49 bool bNeedsAddToView;
50 bool Is3DBrowser;
52}
53#if !PLATFORM_TVOS
54@property(strong) WKWebView* WebView;
55#if PLATFORM_MAC
56@property(strong) NSView* WebViewContainer;
57@property(strong) NSView* GameWindowView;
58#else
59@property(strong) WebViewCloseButton* CloseButton;
60@property(strong) UIView* WebViewContainer;
61#endif
63#endif
64@property(copy) NSURL* NextURL;
65@property(copy) NSString* NextContent;
66@property CGRect DesiredFrame;
67
68-(void)create:(SAppleWebBrowserWidget*)InWebBrowserWidget userAgentApplication: (NSString*)UserAgentApplication useTransparency : (bool)InUseTransparency
69enableFloatingCloseButton : (bool)bEnableFloatingCloseButton;
71-(void)close;
72-(void)showFloatingCloseButton:(BOOL)bShow setDraggable:(BOOL)bDraggable;
73-(void)dealloc;
74-(void)updateframe:(CGRect)InFrame window:(FGenericWindow*)EnclosedWindow;
75-(void)loadstring:(NSString*)InString dummyurl:(NSURL*)InURL;
76-(void)loadurl:(NSURL*)InURL;
77-(void)executejavascript:(NSString*)InJavaScript;
78-(void)set3D:(bool)InIs3DBrowser;
80-(void)setVisibility:(bool)InIsVisible;
82-(void)reload;
83-(void)goBack;
89-(void)SetVideoTextureValid:(bool)Condition;
91-(bool)UpdateVideoFrame:(void*)ptr;
95#if !PLATFORM_MAC
97#endif
98#if !PLATFORM_TVOS
99-(void)webView:(WKWebView*)InWebView decidePolicyForNavigationAction : (WKNavigationAction*)InNavigationAction decisionHandler : (void(^)(WKNavigationActionPolicy))InDecisionHandler;
100-(void)webView:(WKWebView*)InWebView didCommitNavigation : (WKNavigation*)InNavigation;
101#endif
102@end
103
105
110 : public IWebBrowserWindow
112{
113 // The WebBrowserSingleton should be the only one creating instances of this class
114 friend class FWebBrowserSingleton;
115 // CreateWidget should only be called by the WebBrowserView
116 friend class SWebBrowserView;
117
118private:
126 FWebBrowserWindow(FString InUrl, TOptional<FString> InContentsToLoad, bool ShowErrorMessage, bool bThumbMouseButtonNavigation, bool bUseTransparency, bool bInJSBindingToLoweringEnabled, FString InUserAgentApplication, bool bMobileJSReturnInDict);
127
132
133public:
135 virtual ~FWebBrowserWindow();
136
137public:
138
139 // IWebBrowserWindow Interface
140
141 virtual void LoadURL(FString NewURL) override;
142 virtual void LoadString(FString Contents, FString DummyURL) override;
143 virtual void SetViewportSize(FIntPoint ViewportWindowSize, FIntPoint WindowPos) override;
144 virtual FIntPoint GetViewportSize() const override;
145 virtual FSlateShaderResource* GetTexture(bool bIsPopup = false) override;
146 virtual bool IsValid() const override;
147 virtual bool IsInitialized() const override;
148 virtual bool IsClosing() const override;
149 virtual EWebBrowserDocumentState GetDocumentLoadingState() const override;
150 virtual FString GetTitle() const override;
151 virtual FString GetUrl() const override;
152 virtual bool OnKeyDown(const FKeyEvent& InKeyEvent) override;
153 virtual bool OnKeyUp(const FKeyEvent& InKeyEvent) override;
154 virtual bool OnKeyChar(const FCharacterEvent& InCharacterEvent) override;
155 virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
156 virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
157 virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
158 virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
159 virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
160 virtual void SetSupportsMouseWheel(bool bValue) override;
161 virtual bool GetSupportsMouseWheel() const override;
162 virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bIsPopup) override;
163 virtual FReply OnTouchGesture(const FGeometry& MyGeometry, const FPointerEvent& GestureEvent, bool bIsPopup) override;
164 virtual void OnFocus(bool SetFocus, bool bIsPopup) override;
165 virtual void OnCaptureLost() override;
166 virtual bool CanGoBack() const override;
167 virtual void GoBack() override;
168 virtual bool CanGoForward() const override;
169 virtual void GoForward() override;
170 virtual bool IsLoading() const override;
171 virtual void Reload() override;
172 virtual void StopLoad() override;
173 virtual void ExecuteJavascript(const FString& Script) override;
174 virtual void CloseBrowser(bool bForce, bool bBlockTillClosed) override;
175 virtual void BindUObject(const FString& Name, UObject* Object, bool bIsPermanent = true) override;
176 virtual void UnbindUObject(const FString& Name, UObject* Object = nullptr, bool bIsPermanent = true) override;
177 virtual void GetSource(TFunction<void (const FString&)> Callback) const;
178 virtual int GetLoadError() override;
179 virtual void SetIsDisabled(bool bValue) override;
180 virtual TSharedPtr<SWindow> GetParentWindow() const override;
181 virtual void SetParentWindow(TSharedPtr<SWindow> Window) override;
182 virtual void SetParentDockTab(TSharedPtr<SDockTab> DockTab) override;
183 virtual void ShowFloatingCloseButton(bool bShow, bool bDraggable) override;
184
185 // TODO: None of these events are actually called
186
187 DECLARE_DERIVED_EVENT(FWebBrowserWindow, IWebBrowserWindow::FOnDocumentStateChanged, FOnDocumentStateChanged);
188 virtual FOnDocumentStateChanged& OnDocumentStateChanged() override
189 {
190 return DocumentStateChangedEvent;
191 }
192
193 DECLARE_DERIVED_EVENT(FWebBrowserWindow, IWebBrowserWindow::FOnTitleChanged, FOnTitleChanged);
194 virtual FOnTitleChanged& OnTitleChanged() override
195 {
196 return TitleChangedEvent;
197 }
198
199 DECLARE_DERIVED_EVENT(FWebBrowserWindow, IWebBrowserWindow::FOnUrlChanged, FOnUrlChanged);
200 virtual FOnUrlChanged& OnUrlChanged() override
201 {
202 return UrlChangedEvent;
203 }
204
205 DECLARE_DERIVED_EVENT(FWebBrowserWindow, IWebBrowserWindow::FOnToolTip, FOnToolTip);
206 virtual FOnToolTip& OnToolTip() override
207 {
208 return ToolTipEvent;
209 }
210
211 DECLARE_DERIVED_EVENT(FWebBrowserWindow, IWebBrowserWindow::FOnNeedsRedraw, FOnNeedsRedraw);
212 virtual FOnNeedsRedraw& OnNeedsRedraw() override
213 {
214 return NeedsRedrawEvent;
215 }
216
217 virtual FOnBeforeBrowse& OnBeforeBrowse() override
218 {
219 return BeforeBrowseDelegate;
220 }
221
222 virtual FOnLoadUrl& OnLoadUrl() override
223 {
224 return LoadUrlDelegate;
225 }
226
227 virtual FOnCreateWindow& OnCreateWindow() override
228 {
229 return CreateWindowDelegate;
230 }
231
232 virtual FOnCloseWindow& OnCloseWindow() override
233 {
234 return CloseWindowDelegate;
235 }
236
237 virtual FOnFloatingCloseButtonPressed& OnFloatingCloseButtonPressed() override
238 {
239 return FloatingCloseButtonPressedDelegate;
240 }
241
242 virtual FCursorReply OnCursorQuery(const FGeometry& MyGeometry, const FPointerEvent& CursorEvent) override
243 {
244 //return Cursor == EMouseCursor::Default ? FCursorReply::Unhandled() : FCursorReply::Cursor(Cursor);
246 }
247
248 virtual FOnBeforeResourceLoadDelegate& OnBeforeResourceLoad() override
249 {
250 return BeforeResourceLoadDelegate;
251 }
252
253 virtual FOnResourceLoadCompleteDelegate& OnResourceLoadComplete() override
254 {
255 return ResourceLoadCompleteDelegate;
256 }
257
258 virtual FOnConsoleMessageDelegate& OnConsoleMessage() override
259 {
260 return ConsoleMessageDelegate;
261 }
262
263 virtual FOnBeforePopupDelegate& OnBeforePopup() override
264 {
265 return BeforePopupDelegate;
266 }
267
268 DECLARE_DERIVED_EVENT(FWebBrowserWindow, IWebBrowserWindow::FOnShowPopup, FOnShowPopup);
269 virtual FOnShowPopup& OnShowPopup() override
270 {
271 return ShowPopupEvent;
272 }
273
274 DECLARE_DERIVED_EVENT(FWebBrowserWindow, IWebBrowserWindow::FOnDismissPopup, FOnDismissPopup);
275 virtual FOnDismissPopup& OnDismissPopup() override
276 {
277 return DismissPopupEvent;
278 }
279
280 virtual FOnShowDialog& OnShowDialog() override
281 {
282 return ShowDialogDelegate;
283 }
284
285 virtual FOnDismissAllDialogs& OnDismissAllDialogs() override
286 {
287 return DismissAllDialogsDelegate;
288 }
289
290 virtual FOnSuppressContextMenu& OnSuppressContextMenu() override
291 {
292 return SuppressContextMenuDelgate;
293 }
294
295 virtual FOnDragWindow& OnDragWindow() override
296 {
297 return DragWindowDelegate;
298 }
299
301
302 void NotifyDocumentError(const FString& InCurrentUrl, int InErrorCode);
303
304 bool OnJsMessageReceived(const FString& Command, const TArray<FString>& Params, const FString& Origin);
305
306 virtual FOnUnhandledKeyDown& OnUnhandledKeyDown() override
307 {
308 return UnhandledKeyDownDelegate;
309 }
310
311 virtual FOnUnhandledKeyUp& OnUnhandledKeyUp() override
312 {
313 return UnhandledKeyUpDelegate;
314 }
315
316 virtual FOnUnhandledKeyChar& OnUnhandledKeyChar() override
317 {
318 return UnhandledKeyCharDelegate;
319 }
320
321 void NotifyUrlChanged(const FString& InCurrentUrl);
322public:
326 void CheckTickActivity() override;
327
331 void SetTickLastFrame();
332
336 bool IsVisible();
337
338 bool Is3D();
339
344
345
346 void SetTitle(const FString& InTitle)
347 {
348 Title = InTitle;
349 OnTitleChanged().Broadcast(Title);
350 }
351
352 void OnActiveTabChanged(TSharedPtr<SDockTab> ActiveTab, TSharedPtr<SDockTab> PreviouslyActiveTab);
353
355
356private:
357
359 void RedirectNSEvent();
360
362
364 FString Title;
365
367 FString CurrentUrl;
368
370 FString UserAgentApplication;
371
373 TOptional<FString> ContentsToLoad;
374
376 bool bUseTransparency;
377
378 // TODO: None of these events are actually called
379
381 FOnDocumentStateChanged DocumentStateChangedEvent;
382
384 FOnTitleChanged TitleChangedEvent;
385
387 FOnUrlChanged UrlChangedEvent;
388
390 FOnToolTip ToolTipEvent;
391
393 FOnNeedsRedraw NeedsRedrawEvent;
394
396 FOnBeforeBrowse BeforeBrowseDelegate;
397
399 FOnLoadUrl LoadUrlDelegate;
400
402 FOnBeforePopupDelegate BeforePopupDelegate;
403
405 FOnBeforeResourceLoadDelegate BeforeResourceLoadDelegate;
406
408 FOnResourceLoadCompleteDelegate ResourceLoadCompleteDelegate;
409
411 FOnConsoleMessageDelegate ConsoleMessageDelegate;
412
414 FOnCreateWindow CreateWindowDelegate;
415
417 FOnCloseWindow CloseWindowDelegate;
418
420 FOnFloatingCloseButtonPressed FloatingCloseButtonPressedDelegate;
421
423 FOnShowPopup ShowPopupEvent;
424
426 FOnDismissPopup DismissPopupEvent;
427
429 FOnShowDialog ShowDialogDelegate;
430
432 FOnDismissAllDialogs DismissAllDialogsDelegate;
433
435 FOnSuppressContextMenu SuppressContextMenuDelgate;
436
438 FOnDragWindow DragWindowDelegate;
439
442 int ErrorCode;
443
444 FMobileJSScriptingPtr Scripting;
446
447 mutable TOptional<TFunction<void(const FString&)>> GetPageSourceCallback;
449 FOnUnhandledKeyDown UnhandledKeyDownDelegate;
450
452 FOnUnhandledKeyUp UnhandledKeyUpDelegate;
453
455 FOnUnhandledKeyChar UnhandledKeyCharDelegate;
456
457 TWeakPtr<SWindow> ParentWindow;
460
461 FIntPoint WindowSize;
462
464 bool bIsDisabled;
465
467 bool bIsVisible;
468
470 bool bTickedLastFrame;
471};
472
473#endif
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
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
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
const bool
Definition NetworkReplayStreaming.h:178
virtual FReply OnMouseButtonDown(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent)
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 IDelegateInstance.h:14
Definition GenericWindow.h:94
Definition Reply.h:24
Definition SlateShaderResource.h:44
Definition WebBrowserSingleton.h:52
Definition WebView3DInputHandler.h:19
Definition IWebBrowserWindow.h:85
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 SharedPointer.h:1295
Definition Object.h:95
int32 BOOL
Definition MinimalWindowsApi.h:64
Definition Events.h:606
Definition Geometry.h:40
Definition Events.h:431
Definition Events.h:695
Definition Optional.h:131
Definition IntPoint.h:25