WebInterfaceBrowserAdapter.cpp
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Engine/Source/Runtime/WebBrowser/Private/WebBrowserAdapter.cpp
#include "CoreMinimal.h"
#include "UObject/GCObject.h"
#include "IWebInterfaceBrowserWindow.h"
#include "IWebInterfaceBrowserAdapter.h"
class FDefaultWebInterfaceBrowserAdapter
: public IWebInterfaceBrowserAdapter
, public FGCObject
{
public:
virtual FString GetName() const override
{
return Name;
}
virtual bool IsPermanent() const override
{
return bIsPermanent;
}
virtual void ConnectTo(const TSharedRef<IWebInterfaceBrowserWindow>& BrowserWindow) override
{
if (JSBridge != nullptr)
{
BrowserWindow->BindUObject(Name, JSBridge, bIsPermanent);
}
if (!ConnectScriptText.IsEmpty())
{
BrowserWindow->ExecuteJavascript(ConnectScriptText);
}
}
virtual void DisconnectFrom(const TSharedRef<IWebInterfaceBrowserWindow>& BrowserWindow) override
{
if (!DisconnectScriptText.IsEmpty())
{
BrowserWindow->ExecuteJavascript(DisconnectScriptText);
}
if (JSBridge != nullptr)
{
BrowserWindow->UnbindUObject(Name, JSBridge, bIsPermanent);
}
}
// FGCObject API
virtual void AddReferencedObjects(FReferenceCollector& Collector) override
{
if (JSBridge != nullptr)
{
Collector.AddReferencedObject(JSBridge);
}
}
private:
FDefaultWebInterfaceBrowserAdapter(
const FString InName,
const FString InConnectScriptText,
const FString InDisconnectScriptText,
UObject* InJSBridge,
const bool InIsPermanent)
: Name(InName)
, ConnectScriptText(InConnectScriptText)
, DisconnectScriptText(InDisconnectScriptText)
, JSBridge(InJSBridge)
, bIsPermanent(InIsPermanent)
{ }
private:
const FString Name;
const FString ConnectScriptText;
const FString DisconnectScriptText;
UObject* JSBridge;
const bool bIsPermanent;
friend FWebInterfaceBrowserAdapterFactory;
};
TSharedRef<IWebInterfaceBrowserAdapter> FWebInterfaceBrowserAdapterFactory::Create(const FString& Name, UObject* JSBridge, bool IsPermanent)
{
return MakeShareable(new FDefaultWebInterfaceBrowserAdapter(Name, FString(), FString(), JSBridge, IsPermanent));
}
TSharedRef<IWebInterfaceBrowserAdapter> FWebInterfaceBrowserAdapterFactory::Create(const FString& Name, UObject* JSBridge, bool IsPermanent, const FString& ConnectScriptText, const FString& DisconnectScriptText)
{
return MakeShareable(new FDefaultWebInterfaceBrowserAdapter(Name, ConnectScriptText, DisconnectScriptText, JSBridge, IsPermanent));
}