CEF3启用Flash和WebGL

UE4 CEFBrowserApp.cpp里修改这些代码

void FCEFBrowserApp::OnBeforeCommandLineProcessing(const CefString& ProcessType, CefRefPtr< CefCommandLine > CommandLine)
{
	//加载Flash
	FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::RootDir()) + TEXT("Engine/Binaries/ThirdParty/CEF3/Win64/pepflashplayer.dll");
	std::string MyStdString(TCHAR_TO_UTF8(*ThePath));
	CefString cef_str(MyStdString);
	CommandLine->AppendSwitchWithValue("ppapi-flash-path",cef_str);
	CommandLine->AppendSwitchWithValue("ppapi-flash-version", "30.0.0.154");

	//使用系统的Flash
	/*CommandLine->AppendSwitch("--disable-web-security");
	CommandLine->AppendSwitch("--enable-system-flash");*/

	//使用单线程
	//CommandLine->AppendSwitch("single-process");

	CommandLine->AppendSwitch("enable-gpu");
	CommandLine->AppendSwitch("enable-gpu-compositing");
#if !PLATFORM_MAC
	CommandLine->AppendSwitch("enable-begin-frame-scheduling");
#endif
}

注意需要把Flash的Dll拷贝到相应的目录,使用64位Dll,使用中国特供版Flash dll   不然会出现你的dll在当前地区不可用的提示 然后强制停止

找到E:\UE4.19\Engine\Source\ThirdParty\CEF3\CEF3.build.cs

添加dll

Dlls.Add("pepflashplayer.dll");

t

WebBrowserSingleton.cpp里修改这些代码


FWebBrowserSingleton::FWebBrowserSingleton(const FWebBrowserInitSettings& WebBrowserInitSettings)
#if WITH_CEF3
	: WebBrowserWindowFactory(MakeShareable(new FWebBrowserWindowFactory()))
#else
	: WebBrowserWindowFactory(MakeShareable(new FNoWebBrowserWindowFactory()))
#endif
	, bDevToolsShortcutEnabled(UE_BUILD_DEBUG)
	, bJSBindingsToLoweringEnabled(true)
{
#if WITH_CEF3
	// The FWebBrowserSingleton must be initialized on the game thread
	check(IsInGameThread());

	// Provide CEF with command-line arguments.
#if PLATFORM_WINDOWS
	CefMainArgs MainArgs(hInstance);
#else
	CefMainArgs MainArgs;
#endif

	bool bVerboseLogging = FParse::Param(FCommandLine::Get(), TEXT("cefverbose")) || FParse::Param(FCommandLine::Get(), TEXT("debuglog"));
	// CEFBrowserApp implements application-level callbacks.
	CEFBrowserApp = new FCEFBrowserApp;

	//构造Flash
	//CefRefPtr command_line = CefCommandLine::CreateCommandLine();
	//command_line->AppendSwitchWithValue("ppapi-flash-path", "pepflashplayer.dll");
	//command_line->AppendSwitchWithValue("ppapi-flash-version", "30.0 r0");
	//command_line->AppendSwitchWithValue("plugin-policy", "allow");
	//command_line->AppendSwitchWithValue("enable-system-flash", "1");
    //FCommandLine::Append(TEXT(" --enable-system-flash=1 --plugin-policy=allow "));

	CEFBrowserApp->OnRenderProcessThreadCreated().BindRaw(this, &FWebBrowserSingleton::HandleRenderProcessCreated);

	// Specify CEF global settings here.
	CefSettings Settings;
	Settings.no_sandbox = true;
	Settings.command_line_args_disabled = true;
	Settings.single_process = true;


	FString CefLogFile(FPaths::Combine(*FPaths::ProjectLogDir(), TEXT("cef3.log")));
	CefLogFile = FPaths::ConvertRelativePathToFull(CefLogFile);
	CefString(&Settings.log_file) = *CefLogFile;
	Settings.log_severity = bVerboseLogging ? LOGSEVERITY_VERBOSE : LOGSEVERITY_WARNING;

	uint16 DebugPort;
	if(FParse::Value(FCommandLine::Get(), TEXT("cefdebug="), DebugPort))
	{
		Settings.remote_debugging_port = DebugPort;
	}

	// Specify locale from our settings
	FString LocaleCode = GetCurrentLocaleCode();
	CefString(&Settings.locale) = *LocaleCode;

	// Append engine version to the user agent string.
	CefString(&Settings.product_version) = *WebBrowserInitSettings.ProductVersion;

#if CEF3_DEFAULT_CACHE
	// Enable on disk cache
	FString CachePath(FPaths::Combine(ApplicationCacheDir(), TEXT("webcache")));
	CachePath = FPaths::ConvertRelativePathToFull(CachePath);
	CefString(&Settings.cache_path) = *CachePath;

	//改变缓存路径
	//CefString(&Settings.cache_path) = "C:\\test";
#endif

	// Specify path to resources
	FString ResourcesPath(FPaths::Combine(*FPaths::EngineDir(), CEF3_RESOURCES_DIR));
	ResourcesPath = FPaths::ConvertRelativePathToFull(ResourcesPath);
	if (!FPaths::DirectoryExists(ResourcesPath))
	{
		UE_LOG(LogWebBrowser, Error, TEXT("Chromium Resources information not found at: %s."), *ResourcesPath);
	}
	CefString(&Settings.resources_dir_path) = *ResourcesPath;

#if !PLATFORM_MAC
	// On Mac Chromium ignores custom locales dir. Files need to be stored in Resources folder in the app bundle
	FString LocalesPath(FPaths::Combine(*ResourcesPath, TEXT("locales")));
	LocalesPath = FPaths::ConvertRelativePathToFull(LocalesPath);
	if (!FPaths::DirectoryExists(LocalesPath))
	{
		UE_LOG(LogWebBrowser, Error, TEXT("Chromium Locales information not found at: %s."), *LocalesPath);
	}
	CefString(&Settings.locales_dir_path) = *LocalesPath;
#endif

	// Specify path to sub process exe
	FString SubProcessPath(FPaths::Combine(*FPaths::EngineDir(), CEF3_SUBPROCES_EXE));
	SubProcessPath = FPaths::ConvertRelativePathToFull(SubProcessPath);

	if (!IPlatformFile::GetPlatformPhysical().FileExists(*SubProcessPath))
	{
		UE_LOG(LogWebBrowser, Error, TEXT("UnrealCEFSubProcess.exe not found, check that this program has been built and is placed in: %s."), *SubProcessPath);
	}
	CefString(&Settings.browser_subprocess_path) = *SubProcessPath;

	// Initialize CEF.
	bool bSuccess = CefInitialize(MainArgs, Settings, CEFBrowserApp.get(), nullptr);
	check(bSuccess);

	// Set the thread name back to GameThread.
	SetCurrentThreadName(TCHAR_TO_ANSI( *(FName( NAME_GameThread ).GetPlainNameString()) ));

	DefaultCookieManager = FCefWebBrowserCookieManagerFactory::Create(CefCookieManager::GetGlobalManager(nullptr));
#endif
}

CefSettings Settings注意这里面有很多CEF3属性设置

关于CEF3的文章可以参考https://blog.csdn.net/zhangzq86/article/details/70171121

 

      在CreateBrowserWindow函数里开启
        BrowserSettings.plugins = STATE_ENABLED;
        BrowserSettings.webgl = STATE_ENABLED;
        BrowserSettings.windowless_frame_rate = 60;

 

 

 

 

 

天真的以为现在就结束了,发现调用Flash的时候会跳出黑框弹窗 ,很讨厌。

解决办法:

用二进制编辑软件,比如winhex,我这儿采用UltraEdit,用UltraEdit打开flash插件dll文件 pepflashplayer.dll

搜索comspec修改为somspec,(修改的名字只要和comspec不相同即可)修改cmd.exe为cm1.exe (修改的名字只要和cmd.exe不相同即可)

然后保存即可,这时打开flash就不会有dos黑框闪一下了!

你可能感兴趣的:(CEF3启用Flash和WebGL)