Files
UnrealEngineUWP/Engine/Source/Runtime/WebBrowser/Private/WebBrowserAdapter.cpp
Matthew Griffin bb70b349ce Merging CL 2804086 from //UE4/Release-4.11 to Dev-Main (//UE4/Dev-Main) to isolate copyright update
#lockdown Nick.Penwarden

[CL 2819020 by Matthew Griffin in Main branch]
2016-01-07 08:17:16 -05:00

97 lines
2.3 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "WebBrowserPrivatePCH.h"
#include "IWebBrowserAdapter.h"
#include "IWebBrowserWindow.h"
#include "CoreUObject.h"
#include "GCObject.h"
class FDefaultWebBrowserAdapter
: public IWebBrowserAdapter
, public FGCObject
{
public:
virtual FString GetName() const override
{
return Name;
}
virtual bool IsPermanent() const override
{
return bIsPermanent;
}
virtual void ConnectTo(const TSharedRef<IWebBrowserWindow>& BrowserWindow) override
{
if (JSBridge != nullptr)
{
BrowserWindow->BindUObject(Name, JSBridge, bIsPermanent);
}
if (!ConnectScriptText.IsEmpty())
{
BrowserWindow->ExecuteJavascript(ConnectScriptText);
}
}
virtual void DisconnectFrom(const TSharedRef<IWebBrowserWindow>& 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:
FDefaultWebBrowserAdapter(
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 FWebBrowserAdapterFactory;
};
TSharedRef<IWebBrowserAdapter> FWebBrowserAdapterFactory::Create(const FString& Name, UObject* JSBridge, bool IsPermanent)
{
return MakeShareable(new FDefaultWebBrowserAdapter(Name, FString(), FString(), JSBridge, IsPermanent));
}
TSharedRef<IWebBrowserAdapter> FWebBrowserAdapterFactory::Create(const FString& Name, UObject* JSBridge, bool IsPermanent, const FString& ConnectScriptText, const FString& DisconnectScriptText)
{
return MakeShareable(new FDefaultWebBrowserAdapter(Name, ConnectScriptText, DisconnectScriptText, JSBridge, IsPermanent));
}