mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Bring CEF up to snuff (#4760)
This commit is contained in:
committed by
GitHub
parent
7b171b2212
commit
2d3379d7f4
85
Robust.Client.WebView/Cef/BaseRobustCefClient.cs
Normal file
85
Robust.Client.WebView/Cef/BaseRobustCefClient.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using Xilium.CefGlue;
|
||||||
|
|
||||||
|
namespace Robust.Client.WebView.Cef;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shared functionality for all <see cref="CefClient"/> implementations.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Locks down a bunch of CEF functionality we absolutely do not need content to do right now.
|
||||||
|
/// </remarks>
|
||||||
|
internal abstract class BaseRobustCefClient : CefClient
|
||||||
|
{
|
||||||
|
private readonly RobustCefPrintHandler _printHandler = new();
|
||||||
|
private readonly RobustCefPermissionHandler _permissionHandler = new();
|
||||||
|
private readonly RobustCefDialogHandler _dialogHandler = new();
|
||||||
|
private readonly RobustCefDragHandler _dragHandler = new();
|
||||||
|
|
||||||
|
protected override CefPrintHandler GetPrintHandler() => _printHandler;
|
||||||
|
protected override CefPermissionHandler GetPermissionHandler() => _permissionHandler;
|
||||||
|
protected override CefDialogHandler GetDialogHandler() => _dialogHandler;
|
||||||
|
protected override CefDragHandler GetDragHandler() => _dragHandler;
|
||||||
|
|
||||||
|
private sealed class RobustCefPrintHandler : CefPrintHandler
|
||||||
|
{
|
||||||
|
protected override void OnPrintSettings(CefBrowser browser, CefPrintSettings settings, bool getDefaults)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnPrintDialog(CefBrowser browser, bool hasSelection, CefPrintDialogCallback callback)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnPrintJob(CefBrowser browser, string documentName, string pdfFilePath, CefPrintJobCallback callback)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPrintReset(CefBrowser browser)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class RobustCefPermissionHandler : CefPermissionHandler
|
||||||
|
{
|
||||||
|
protected override bool OnRequestMediaAccessPermission(
|
||||||
|
CefBrowser browser,
|
||||||
|
CefFrame frame,
|
||||||
|
string requestingOrigin,
|
||||||
|
CefMediaAccessPermissionTypes requestedPermissions,
|
||||||
|
CefMediaAccessCallback callback)
|
||||||
|
{
|
||||||
|
callback.Cancel();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class RobustCefDialogHandler : CefDialogHandler
|
||||||
|
{
|
||||||
|
protected override bool OnFileDialog(
|
||||||
|
CefBrowser browser,
|
||||||
|
CefFileDialogMode mode,
|
||||||
|
string title,
|
||||||
|
string defaultFilePath,
|
||||||
|
string[] acceptFilters,
|
||||||
|
CefFileDialogCallback callback)
|
||||||
|
{
|
||||||
|
callback.Cancel();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class RobustCefDragHandler : CefDragHandler
|
||||||
|
{
|
||||||
|
protected override bool OnDragEnter(CefBrowser browser, CefDragData dragData, CefDragOperationsMask mask)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDraggableRegionsChanged(CefBrowser browser, CefFrame frame, CefDraggableRegion[] regions)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -76,12 +76,9 @@ namespace Robust.Client.WebView.Cef
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override unsafe bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback)
|
protected override bool Read(Span<byte> response, out int bytesRead, CefResourceReadCallback callback)
|
||||||
{
|
{
|
||||||
var byteSpan = new Span<byte>((void*) dataOut, bytesToRead);
|
bytesRead = _stream.Read(response);
|
||||||
|
|
||||||
bytesRead = _stream.Read(byteSpan);
|
|
||||||
|
|
||||||
return bytesRead != 0;
|
return bytesRead != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,12 @@ namespace Robust.Client.WebView.Cef
|
|||||||
// Disable zygote on Linux.
|
// Disable zygote on Linux.
|
||||||
commandLine.AppendSwitch("--no-zygote");
|
commandLine.AppendSwitch("--no-zygote");
|
||||||
|
|
||||||
// Work around https://bitbucket.org/chromiumembedded/cef/issues/3213/ozone-egl-initialization-does-not-have
|
// Work around https://github.com/chromiumembedded/cef/issues/3213
|
||||||
// Desktop GL force makes Chromium not try to load its own ANGLE/Swiftshader so load paths aren't problematic.
|
// Desktop GL force makes Chromium not try to load its own ANGLE/Swiftshader so load paths aren't problematic.
|
||||||
if (OperatingSystem.IsLinux())
|
// UPDATE: That bug got fixed and now this workaround breaks CEF.
|
||||||
commandLine.AppendSwitch("--use-gl", "desktop");
|
// Keeping all this comment history in case I ever wanan remember what the `--use-gl` flag is.
|
||||||
|
//if (OperatingSystem.IsLinux())
|
||||||
|
// commandLine.AppendSwitch("--use-gl", "desktop");
|
||||||
|
|
||||||
// commandLine.AppendSwitch("--single-process");
|
// commandLine.AppendSwitch("--single-process");
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using Xilium.CefGlue;
|
|||||||
namespace Robust.Client.WebView.Cef
|
namespace Robust.Client.WebView.Cef
|
||||||
{
|
{
|
||||||
// Simple CEF client.
|
// Simple CEF client.
|
||||||
internal sealed class RobustCefClient : CefClient
|
internal sealed class RobustCefClient : BaseRobustCefClient
|
||||||
{
|
{
|
||||||
private readonly CefRenderHandler _renderHandler;
|
private readonly CefRenderHandler _renderHandler;
|
||||||
private readonly CefRequestHandler _requestHandler;
|
private readonly CefRequestHandler _requestHandler;
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ namespace Robust.Client.WebView.Cef
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class WindowCefClient : CefClient
|
private sealed class WindowCefClient : BaseRobustCefClient
|
||||||
{
|
{
|
||||||
private readonly CefLifeSpanHandler _lifeSpanHandler;
|
private readonly CefLifeSpanHandler _lifeSpanHandler;
|
||||||
private readonly CefRequestHandler _requestHandler;
|
private readonly CefRequestHandler _requestHandler;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
|
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
|
||||||
<PackageReference Include="Robust.Natives.Cef" Version="102.0.9" />
|
<PackageReference Include="Robust.Natives.Cef" Version="120.1.9" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
28
Robust.Client.WebView/TestBrowseWindow.cs
Normal file
28
Robust.Client.WebView/TestBrowseWindow.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Numerics;
|
||||||
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
|
namespace Robust.Client.WebView;
|
||||||
|
|
||||||
|
internal sealed class TestBrowseWindow : DefaultWindow
|
||||||
|
{
|
||||||
|
protected override Vector2 ContentsMinimumSize => new Vector2(640, 480);
|
||||||
|
|
||||||
|
public TestBrowseWindow()
|
||||||
|
{
|
||||||
|
var wv = new WebViewControl();
|
||||||
|
wv.Url = "https://spacestation14.io";
|
||||||
|
|
||||||
|
Contents.AddChild(wv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class TestBrowseWindowCommand : LocalizedCommands
|
||||||
|
{
|
||||||
|
public override string Command => "test_browse_window";
|
||||||
|
|
||||||
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
|
{
|
||||||
|
new TestBrowseWindow().Open();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using Robust.Client.WebView.Headless;
|
|||||||
using Robust.Client.WebViewHook;
|
using Robust.Client.WebViewHook;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Reflection;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
[assembly: WebViewManagerImpl(typeof(WebViewManager))]
|
[assembly: WebViewManagerImpl(typeof(WebViewManager))]
|
||||||
@@ -22,6 +23,9 @@ namespace Robust.Client.WebView
|
|||||||
var cfg = dependencies.Resolve<IConfigurationManagerInternal>();
|
var cfg = dependencies.Resolve<IConfigurationManagerInternal>();
|
||||||
cfg.LoadCVarsFromAssembly(typeof(WebViewManager).Assembly);
|
cfg.LoadCVarsFromAssembly(typeof(WebViewManager).Assembly);
|
||||||
|
|
||||||
|
var refl = dependencies.Resolve<IReflectionManager>();
|
||||||
|
refl.LoadAssemblies(typeof(WebViewManager).Assembly);
|
||||||
|
|
||||||
dependencies.RegisterInstance<IWebViewManager>(this);
|
dependencies.RegisterInstance<IWebViewManager>(this);
|
||||||
dependencies.RegisterInstance<IWebViewManagerInternal>(this);
|
dependencies.RegisterInstance<IWebViewManagerInternal>(this);
|
||||||
|
|
||||||
|
|||||||
@@ -109,9 +109,15 @@ namespace Robust.Client
|
|||||||
{
|
{
|
||||||
IsBackground = false,
|
IsBackground = false,
|
||||||
Priority = priority,
|
Priority = priority,
|
||||||
Name = "Game thread",
|
Name = "Game thread"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
// Necessary for CEF to not complain when using CEF debug binaries.
|
||||||
|
_gameThread.SetApartmentState(ApartmentState.STA);
|
||||||
|
}
|
||||||
|
|
||||||
_gameThread.Start();
|
_gameThread.Start();
|
||||||
|
|
||||||
// Will block until game exit
|
// Will block until game exit
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
import argparse
|
import argparse
|
||||||
|
import glob
|
||||||
|
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
@@ -101,10 +102,12 @@ def main() -> None:
|
|||||||
|
|
||||||
if os.path.exists("release"):
|
if os.path.exists("release"):
|
||||||
print(Fore.BLUE + Style.DIM +
|
print(Fore.BLUE + Style.DIM +
|
||||||
"Cleaning old release packages (release/)..." + Style.RESET_ALL)
|
"Cleaning old release packages (release/Robust.Client_*)..." + Style.RESET_ALL)
|
||||||
shutil.rmtree("release")
|
for past in glob.glob("release/Robust.Client_*"):
|
||||||
|
os.remove(past)
|
||||||
|
else:
|
||||||
|
os.mkdir("release")
|
||||||
|
|
||||||
os.mkdir("release")
|
|
||||||
|
|
||||||
if PLATFORM_WINDOWS in platforms:
|
if PLATFORM_WINDOWS in platforms:
|
||||||
if not skip_build:
|
if not skip_build:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
import argparse
|
import argparse
|
||||||
|
import glob
|
||||||
|
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
@@ -55,10 +56,11 @@ def main() -> None:
|
|||||||
|
|
||||||
if os.path.exists("release"):
|
if os.path.exists("release"):
|
||||||
print(Fore.BLUE + Style.DIM +
|
print(Fore.BLUE + Style.DIM +
|
||||||
"Cleaning old release packages (release/)..." + Style.RESET_ALL)
|
"Cleaning old release packages (release/Robust.Client.WebView_*)..." + Style.RESET_ALL)
|
||||||
shutil.rmtree("release")
|
for past in glob.glob("release/Robust.Client.WebView_*"):
|
||||||
|
os.remove(past)
|
||||||
os.mkdir("release")
|
else:
|
||||||
|
os.mkdir("release")
|
||||||
|
|
||||||
if PLATFORM_WINDOWS in platforms:
|
if PLATFORM_WINDOWS in platforms:
|
||||||
if not skip_build:
|
if not skip_build:
|
||||||
@@ -83,7 +85,7 @@ def build_windows(skip_build: bool) -> None:
|
|||||||
# Run a full build.
|
# Run a full build.
|
||||||
print(Fore.GREEN + "Building project for Windows x64..." + Style.RESET_ALL)
|
print(Fore.GREEN + "Building project for Windows x64..." + Style.RESET_ALL)
|
||||||
|
|
||||||
base_bin = p("Robust.Client.WebView", "bin", "Release", "net7.0")
|
base_bin = p("Robust.Client.WebView", "bin", "Release", "net8.0")
|
||||||
|
|
||||||
if not skip_build:
|
if not skip_build:
|
||||||
build_client_rid("Windows", "win-x64")
|
build_client_rid("Windows", "win-x64")
|
||||||
@@ -142,7 +144,7 @@ def build_linux(skip_build: bool) -> None:
|
|||||||
# Run a full build.
|
# Run a full build.
|
||||||
print(Fore.GREEN + "Building project for Linux x64..." + Style.RESET_ALL)
|
print(Fore.GREEN + "Building project for Linux x64..." + Style.RESET_ALL)
|
||||||
|
|
||||||
base_bin = p("Robust.Client.WebView", "bin", "Release", "net7.0")
|
base_bin = p("Robust.Client.WebView", "bin", "Release", "net8.0")
|
||||||
|
|
||||||
if not skip_build:
|
if not skip_build:
|
||||||
build_client_rid("Linux", "linux-x64")
|
build_client_rid("Linux", "linux-x64")
|
||||||
|
|||||||
2
cefglue
2
cefglue
Submodule cefglue updated: dec642a10f...e265d67a21
Reference in New Issue
Block a user