Files
UnrealEngineUWP/Engine/Source/Runtime/WebBrowser/Private/WebBrowserModule.cpp
alfred reynolds e003c8a69d - Disable accelerated rendering on macOS for the web browser control as we lack RHI support for it right now
- Fix crash when enabling the WebBrowser plugin on macOS. CEF uses a dylib scoped function pointer table for its API, so we need to enable it in the WebBrowser module, doing it in the CEF3Utils module doesn't help here.

#jira UE-113510
#lockdown simon.tourangeau

#ROBOMERGE-SOURCE: CL 16031887 in //UE5/Release-5.0-EarlyAccess/...
#ROBOMERGE-BOT: STARSHIP (Release-5.0-EarlyAccess -> Main) (v789-15992632)

[CL 16031906 by alfred reynolds in ue5-main branch]
2021-04-16 08:19:38 -04:00

118 lines
3.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "WebBrowserModule.h"
#include "WebBrowserLog.h"
#include "WebBrowserSingleton.h"
#include "Misc/App.h"
#include "Misc/EngineVersion.h"
#if WITH_CEF3
# include "CEF3Utils.h"
# if PLATFORM_MAC
# include "include/wrapper/cef_library_loader.h"
# define CEF3_BIN_DIR TEXT("Binaries/ThirdParty/CEF3")
# define CEF3_FRAMEWORK_DIR CEF3_BIN_DIR TEXT("/Mac/Chromium Embedded Framework.framework")
# define CEF3_FRAMEWORK_EXE CEF3_FRAMEWORK_DIR TEXT("/Chromium Embedded Framework")
# endif
#endif
DEFINE_LOG_CATEGORY(LogWebBrowser);
static FWebBrowserSingleton* WebBrowserSingleton = nullptr;
FWebBrowserInitSettings::FWebBrowserInitSettings()
: ProductVersion(FString::Printf(TEXT("%s/%s UnrealEngine/%s Chrome/84.0.4147.38"), FApp::GetProjectName(), FApp::GetBuildVersion(), *FEngineVersion::Current().ToString()))
{
}
class FWebBrowserModule : public IWebBrowserModule
{
private:
// IModuleInterface Interface
virtual void StartupModule() override;
virtual void ShutdownModule() override;
public:
virtual bool IsWebModuleAvailable() const override;
virtual IWebBrowserSingleton* GetSingleton() override;
virtual bool CustomInitialize(const FWebBrowserInitSettings& WebBrowserInitSettings) override;
private:
#if WITH_CEF3
bool bLoadedCEFModule = false;
#if PLATFORM_MAC
// Dynamically load the CEF framework library.
CefScopedLibraryLoader *CEFLibraryLoader = nullptr;
#endif
#endif
};
IMPLEMENT_MODULE( FWebBrowserModule, WebBrowser );
void FWebBrowserModule::StartupModule()
{
#if WITH_CEF3
bLoadedCEFModule = CEF3Utils::LoadCEF3Modules(true);
#if PLATFORM_MAC
// Dynamically load the CEF framework library into this dylibs memory space.
// CEF now loads function pointers at runtime so we need this to be dylib specific.
CEFLibraryLoader = new CefScopedLibraryLoader();
FString CefFrameworkPath(FPaths::Combine(*FPaths::EngineDir(), CEF3_FRAMEWORK_EXE));
CefFrameworkPath = FPaths::ConvertRelativePathToFull(CefFrameworkPath);
bool bLoaderInitialized = false;
if (!CEFLibraryLoader->LoadInMain(TCHAR_TO_ANSI(*CefFrameworkPath)))
{
UE_LOG(LogWebBrowser, Error, TEXT("Chromium loader initialization failed"));
}
#endif // PLATFORM_MAC
#endif
}
void FWebBrowserModule::ShutdownModule()
{
if (WebBrowserSingleton != nullptr)
{
delete WebBrowserSingleton;
WebBrowserSingleton = nullptr;
}
#if WITH_CEF3
CEF3Utils::UnloadCEF3Modules();
#if PLATFORM_MAC
delete CEFLibraryLoader;
CEFLibraryLoader = nullptr;
#endif // PLATFORM_MAC
#endif
}
bool FWebBrowserModule::CustomInitialize(const FWebBrowserInitSettings& WebBrowserInitSettings)
{
if (WebBrowserSingleton == nullptr)
{
WebBrowserSingleton = new FWebBrowserSingleton(WebBrowserInitSettings);
return true;
}
return false;
}
IWebBrowserSingleton* FWebBrowserModule::GetSingleton()
{
if (WebBrowserSingleton == nullptr)
{
WebBrowserSingleton = new FWebBrowserSingleton(FWebBrowserInitSettings());
}
return WebBrowserSingleton;
}
bool FWebBrowserModule::IsWebModuleAvailable() const
{
#if WITH_CEF3
return bLoadedCEFModule;
#else
return true;
#endif
}