mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
CEF cookie fixes (#2934)
* Trying to get res:// and usr:// cookies to wrok * Update CefGlue * Bump CEF * Seal types in WebView Fixes warnings * Move most of client cleanup to game thread. This used to run in the windowing thread which broke CEF shutdown, most notably cookie saving. * "flushcookies" command for CEF. * Remove unecessary res:// code. * Fix tests * More request handler fixes. * Good thing I don't have to care about commit quality in PRs like this.
This commit is contained in:
committed by
GitHub
parent
776669b789
commit
05bb361eb2
@@ -144,3 +144,10 @@ cmd-hint-loadmap-x-position = [x-position]
|
||||
cmd-hint-loadmap-y-position = [y-position]
|
||||
cmd-hint-loadmap-rotation = [rotation]
|
||||
cmd-hint-loadmap-uids = [float]
|
||||
|
||||
## 'flushcookies' command
|
||||
# Note: the flushcookies command is from Robust.Client.WebView, it's not in the main engine code.
|
||||
|
||||
cmd-flushcookies-desc = Flush CEF cookie storage to disk
|
||||
cmd-flushcookies-help = This ensure cookies are properly saved to disk in the event of unclean shutdowns.
|
||||
Note that the actual operation is asynchronous.
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
@@ -19,24 +16,11 @@ namespace Robust.Client.WebView.Cef
|
||||
Array.Copy(args, 0, argv, 1, args.Length);
|
||||
argv[0] = "-";
|
||||
}
|
||||
/*
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
// Chromium tries to load libEGL.so and libGLESv2.so relative to the process executable on Linux.
|
||||
// (Compared to Windows where it is relative to Chromium's *module*)
|
||||
// There is a TODO "is this correct?" in the Chromium code for this.
|
||||
// Great.
|
||||
|
||||
//CopyDllToExecutableDir("libEGL.so");
|
||||
//CopyDllToExecutableDir("libGLESv2.so");
|
||||
|
||||
// System.Threading.Thread.Sleep(200000);
|
||||
}
|
||||
*/
|
||||
var mainArgs = new CefMainArgs(argv);
|
||||
|
||||
// This will block executing until the subprocess is shut down.
|
||||
var code = CefRuntime.ExecuteProcess(mainArgs, null, IntPtr.Zero);
|
||||
var code = CefRuntime.ExecuteProcess(mainArgs, new RobustCefApp(), IntPtr.Zero);
|
||||
|
||||
if (code != 0)
|
||||
{
|
||||
@@ -45,44 +29,5 @@ namespace Robust.Client.WebView.Cef
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/* private static void CopyDllToExecutableDir(string dllName)
|
||||
{
|
||||
var executableDir = PathHelpers.GetExecutableDirectory();
|
||||
var targetPath = Path.Combine(executableDir, dllName);
|
||||
if (File.Exists(targetPath))
|
||||
return;
|
||||
|
||||
// Find source file.
|
||||
string? srcFile = null;
|
||||
foreach (var searchDir in WebViewManagerCef.NativeDllSearchDirectories())
|
||||
{
|
||||
var searchPath = Path.Combine(searchDir, dllName);
|
||||
if (File.Exists(searchPath))
|
||||
{
|
||||
srcFile = searchPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (srcFile == null)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(targetPath))
|
||||
return;
|
||||
|
||||
File.Copy(srcFile, targetPath);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Catching race condition lock errors and stuff I guess.
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal class RobustCefApp : CefApp
|
||||
internal sealed class RobustCefApp : CefApp
|
||||
{
|
||||
private readonly BrowserProcessHandler _browserProcessHandler = new();
|
||||
private readonly RenderProcessHandler _renderProcessHandler = new();
|
||||
@@ -24,12 +24,12 @@ namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
// Disable zygote on Linux.
|
||||
commandLine.AppendSwitch("--no-zygote");
|
||||
|
||||
|
||||
// Work around https://bitbucket.org/chromiumembedded/cef/issues/3213/ozone-egl-initialization-does-not-have
|
||||
// Desktop GL force makes Chromium not try to load its own ANGLE/Swiftshader so load paths aren't problematic.
|
||||
if (OperatingSystem.IsLinux())
|
||||
commandLine.AppendSwitch("--use-gl", "desktop");
|
||||
|
||||
|
||||
// commandLine.AppendSwitch("--single-process");
|
||||
|
||||
//commandLine.AppendSwitch("--disable-gpu");
|
||||
@@ -43,12 +43,18 @@ namespace Robust.Client.WebView.Cef
|
||||
Logger.Debug($"{commandLine}");
|
||||
}
|
||||
|
||||
private class BrowserProcessHandler : CefBrowserProcessHandler
|
||||
protected override void OnRegisterCustomSchemes(CefSchemeRegistrar registrar)
|
||||
{
|
||||
registrar.AddCustomScheme("res", CefSchemeOptions.Secure | CefSchemeOptions.Standard);
|
||||
registrar.AddCustomScheme("usr", CefSchemeOptions.Secure | CefSchemeOptions.Standard);
|
||||
}
|
||||
|
||||
private sealed class BrowserProcessHandler : CefBrowserProcessHandler
|
||||
{
|
||||
}
|
||||
|
||||
// TODO CEF: Research - Is this even needed?
|
||||
private class RenderProcessHandler : CefRenderProcessHandler
|
||||
private sealed class RenderProcessHandler : CefRenderProcessHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Xilium.CefGlue;
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
// Simple CEF client.
|
||||
internal class RobustCefClient : CefClient
|
||||
internal sealed class RobustCefClient : CefClient
|
||||
{
|
||||
private readonly CefRenderHandler _renderHandler;
|
||||
private readonly CefRequestHandler _requestHandler;
|
||||
|
||||
@@ -57,6 +57,14 @@ namespace Robust.Client.WebView.Cef
|
||||
string requestInitiator,
|
||||
ref bool disableDefaultHandling)
|
||||
{
|
||||
var url = new Uri(request.Url);
|
||||
if (url.Scheme == "file")
|
||||
{
|
||||
// Deny file:// access.
|
||||
disableDefaultHandling = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (_resourceRequestHandlers)
|
||||
{
|
||||
_sawmill.Debug($"HANDLING REQUEST: {request.Url}");
|
||||
@@ -113,7 +121,7 @@ namespace Robust.Client.WebView.Cef
|
||||
CefFrame frame,
|
||||
CefRequest request)
|
||||
{
|
||||
return null;
|
||||
return new CookieHandler();
|
||||
}
|
||||
|
||||
protected override CefResourceHandler GetResourceHandler(
|
||||
@@ -124,5 +132,18 @@ namespace Robust.Client.WebView.Cef
|
||||
return _handler;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class CookieHandler : CefCookieAccessFilter
|
||||
{
|
||||
protected override bool CanSendCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefCookie cookie)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool CanSaveCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, CefCookie cookie)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal partial class WebViewManagerCef : IWebViewManagerImpl
|
||||
internal sealed partial class WebViewManagerCef : IWebViewManagerImpl
|
||||
{
|
||||
private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location!)!;
|
||||
|
||||
@@ -17,11 +21,18 @@ namespace Robust.Client.WebView.Cef
|
||||
|
||||
[Dependency] private readonly IDependencyCollection _dependencyCollection = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IResourceManagerInternal _resourceManager = default!;
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
IoCManager.Instance!.InjectDependencies(this, oneOff: true);
|
||||
|
||||
_consoleHost.RegisterCommand("flushcookies", Loc.GetString("cmd-flushcookies-desc"), Loc.GetString("cmd-flushcookies-help"), (_, _, _) =>
|
||||
{
|
||||
CefCookieManager.GetGlobal(null).FlushStore(null);
|
||||
});
|
||||
|
||||
string subProcessName;
|
||||
if (OperatingSystem.IsWindows())
|
||||
subProcessName = "Robust.Client.WebView.exe";
|
||||
@@ -38,6 +49,10 @@ namespace Robust.Client.WebView.Cef
|
||||
if (cefResourcesPath == null)
|
||||
throw new InvalidOperationException("Unable to locate cef_resources directory!");
|
||||
|
||||
var cachePath = "";
|
||||
if (_resourceManager.UserData is WritableDirProvider userData)
|
||||
cachePath = userData.GetFullPath(new ResourcePath("/cef_cache"));
|
||||
|
||||
var settings = new CefSettings()
|
||||
{
|
||||
WindowlessRenderingEnabled = true, // So we can render to our UI controls.
|
||||
@@ -47,6 +62,8 @@ namespace Robust.Client.WebView.Cef
|
||||
LocalesDirPath = Path.Combine(cefResourcesPath, "locales"),
|
||||
ResourcesDirPath = cefResourcesPath,
|
||||
RemoteDebuggingPort = 9222,
|
||||
CookieableSchemesList = "usr,res",
|
||||
CachePath = cachePath,
|
||||
};
|
||||
|
||||
Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}");
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
|
||||
<PackageReference Include="Robust.Natives.Cef" Version="95.7.14" />
|
||||
<PackageReference Include="Robust.Natives.Cef" Version="102.0.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Robust.Client
|
||||
ContinueStartupAndLoop(mode);
|
||||
}
|
||||
|
||||
Cleanup();
|
||||
CleanupWindowThread();
|
||||
|
||||
Logger.Debug("Goodbye");
|
||||
IoCManager.Clear();
|
||||
@@ -127,6 +127,8 @@ namespace Robust.Client
|
||||
|
||||
DebugTools.AssertNotNull(_mainLoop);
|
||||
_mainLoop!.Run();
|
||||
|
||||
CleanupGameThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,15 +659,20 @@ namespace Robust.Client
|
||||
Clyde,
|
||||
}
|
||||
|
||||
internal void Cleanup()
|
||||
internal void CleanupGameThread()
|
||||
{
|
||||
_modLoader.Shutdown();
|
||||
|
||||
// CEF specifically makes a massive silent stink of it if we don't shut it down from the correct thread.
|
||||
_webViewHook?.Shutdown();
|
||||
|
||||
_networkManager.Shutdown("Client shutting down");
|
||||
_midiManager.Shutdown();
|
||||
_entityManager.Shutdown();
|
||||
}
|
||||
|
||||
internal void CleanupWindowThread()
|
||||
{
|
||||
_clyde.Shutdown();
|
||||
_clydeAudio.Shutdown();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -114,7 +114,7 @@ namespace Robust.Shared.ContentPack
|
||||
|
||||
#endregion
|
||||
|
||||
private string GetFullPath(ResourcePath path)
|
||||
public string GetFullPath(ResourcePath path)
|
||||
{
|
||||
if (!path.IsRooted)
|
||||
{
|
||||
|
||||
@@ -706,7 +706,8 @@ namespace Robust.UnitTesting
|
||||
{
|
||||
var client = Init();
|
||||
GameLoop.Run();
|
||||
client.Cleanup();
|
||||
client.CleanupGameThread();
|
||||
client.CleanupWindowThread();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
2
cefglue
2
cefglue
Submodule cefglue updated: bf474fc395...dec642a10f
Reference in New Issue
Block a user