You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Removes depency on WebBrowser project from Slate, it now depends on Slate instead. Removed functions from Singleton interface that are no longer needed. Get the Slate renderer when needed instead of keeping reference. Added call to FTicker::Tick function in Slate viewer app so that Web Browser will continue to work. [CL 2330030 by Matthew Griffin in Main branch]
132 lines
3.7 KiB
C++
132 lines
3.7 KiB
C++
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "WebBrowserPrivatePCH.h"
|
|
#include "WebBrowserSingleton.h"
|
|
#include "WebBrowserApp.h"
|
|
#include "WebBrowserHandler.h"
|
|
#include "WebBrowserWindow.h"
|
|
|
|
#if WITH_CEF3
|
|
#if PLATFORM_WINDOWS
|
|
#include "AllowWindowsPlatformTypes.h"
|
|
#endif
|
|
#include "include/cef_app.h"
|
|
#if PLATFORM_WINDOWS
|
|
#include "HideWindowsPlatformTypes.h"
|
|
#endif
|
|
#endif
|
|
|
|
FWebBrowserSingleton::FWebBrowserSingleton()
|
|
{
|
|
#if WITH_CEF3
|
|
// Provide CEF with command-line arguments.
|
|
CefMainArgs MainArgs(hInstance);
|
|
|
|
// WebBrowserApp implements application-level callbacks.
|
|
WebBrowserApp = new FWebBrowserApp;
|
|
|
|
// Specify CEF global settings here.
|
|
CefSettings Settings;
|
|
Settings.no_sandbox = true;
|
|
Settings.command_line_args_disabled = true;
|
|
|
|
// Specify locale from our settings
|
|
FString LocaleCode = GetCurrentLocaleCode();
|
|
CefString(&Settings.locale) = *LocaleCode;
|
|
|
|
// Specify path to resources
|
|
FString ResourcesPath(FPaths::Combine(*FPaths::EngineDir(), TEXT("Binaries/ThirdParty/CEF3/Win64/Resources")));
|
|
FString LocalesPath(FPaths::Combine(*FPaths::EngineDir(), TEXT("Binaries/ThirdParty/CEF3/Win64/Resources/locales")));
|
|
CefString(&Settings.locales_dir_path) = *LocalesPath;
|
|
CefString(&Settings.resources_dir_path) = *ResourcesPath;
|
|
|
|
// Specify path to sub process exe
|
|
FString SubProcessPath(TEXT("UnrealCEFSubProcess.exe"));
|
|
CefString(&Settings.browser_subprocess_path) = *SubProcessPath;
|
|
|
|
// Initialize CEF.
|
|
bool bSuccess = CefInitialize(MainArgs, Settings, WebBrowserApp.get(), nullptr);
|
|
check(bSuccess);
|
|
#endif
|
|
}
|
|
|
|
FWebBrowserSingleton::~FWebBrowserSingleton()
|
|
{
|
|
#if WITH_CEF3
|
|
// Force all existing browsers to close in case any haven't been deleted
|
|
for (int32 Index = 0; Index < WindowInterfaces.Num(); ++Index)
|
|
{
|
|
if (WindowInterfaces[Index].IsValid())
|
|
{
|
|
WindowInterfaces[Index].Pin()->CloseBrowser();
|
|
}
|
|
}
|
|
|
|
// CefRefPtr takes care of delete
|
|
WebBrowserApp = nullptr;
|
|
// Shut down CEF.
|
|
CefShutdown();
|
|
#endif
|
|
}
|
|
|
|
TSharedPtr<IWebBrowserWindow> FWebBrowserSingleton::CreateBrowserWindow(void* OSWindowHandle, FString InitialURL, uint32 Width, uint32 Height, bool bUseTransparency)
|
|
{
|
|
#if WITH_CEF3
|
|
// Create new window
|
|
TSharedPtr<FWebBrowserWindow> NewWindow(new FWebBrowserWindow(FIntPoint(Width, Height)));
|
|
|
|
// WebBrowserHandler implements browser-level callbacks.
|
|
CefRefPtr<FWebBrowserHandler> NewHandler(new FWebBrowserHandler);
|
|
NewWindow->SetHandler(NewHandler);
|
|
|
|
// Information used when creating the native window.
|
|
CefWindowHandle WindowHandle = (CefWindowHandle)OSWindowHandle; // TODO: check this is correct for all platforms
|
|
CefWindowInfo WindowInfo;
|
|
|
|
// Always use off screen rendering so we can integrate with our windows
|
|
WindowInfo.SetAsOffScreen(WindowHandle);
|
|
WindowInfo.SetTransparentPainting(bUseTransparency);
|
|
|
|
// Specify CEF browser settings here.
|
|
CefBrowserSettings BrowserSettings;
|
|
|
|
CefString URL = *InitialURL;
|
|
|
|
// Create the CEF browser window.
|
|
if (CefBrowserHost::CreateBrowser(WindowInfo, NewHandler.get(), URL, BrowserSettings, NULL))
|
|
{
|
|
WindowInterfaces.Add(NewWindow);
|
|
return NewWindow;
|
|
}
|
|
#endif
|
|
return NULL;
|
|
}
|
|
|
|
bool FWebBrowserSingleton::Tick(float DeltaTime)
|
|
{
|
|
#if WITH_CEF3
|
|
// Remove any windows that have been deleted
|
|
for (int32 Index = WindowInterfaces.Num() - 1; Index >= 0; --Index)
|
|
{
|
|
if (!WindowInterfaces[Index].IsValid())
|
|
{
|
|
WindowInterfaces.RemoveAtSwap(Index);
|
|
}
|
|
}
|
|
CefDoMessageLoopWork();
|
|
#endif
|
|
return true;
|
|
}
|
|
|
|
FString FWebBrowserSingleton::GetCurrentLocaleCode()
|
|
{
|
|
FCultureRef Culture = FInternationalization::Get().GetCurrentCulture();
|
|
FString LocaleCode = Culture->GetTwoLetterISOLanguageName();
|
|
FString Country = Culture->GetRegion();
|
|
if (!Country.IsEmpty())
|
|
{
|
|
LocaleCode = LocaleCode + TEXT("-") + Country;
|
|
}
|
|
return LocaleCode;
|
|
}
|