1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-08-18 13:31:41 +02:00
Files
.github
.idea
bld
lib
linux
.idea
TweetDuck
TweetImpl.CefGlue
Adapters
Component
Dialogs
Handlers
Resources
Utils
BridgeObjectRegistry.cs
CefActionTask.cs
GtkUtils.cs
SchemeHandlerFactory.cs
Lib.cs
TweetImpl.CefGlue.csproj
.gitignore
Directory.Build.props
TweetDuck.Linux.sln
global.json
publish.sh
resources
windows
.gitattributes
.gitignore
LICENSE.md
README.md
TweetDuck.sln
TweetDuck.sln.DotSettings
Version.cs
global.json
2022-02-19 18:19:13 +01:00

40 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using TweetImpl.CefGlue.Adapters;
using TweetLib.Browser.CEF.Logic;
using TweetLib.Browser.Interfaces;
using Xilium.CefGlue;
namespace TweetImpl.CefGlue.Utils {
public sealed class SchemeHandlerFactory {
private static readonly Dictionary<string, SchemeHandlerFactory> Factories = new ();
internal static CefResourceHandler? TryGetHandler(CefRequest request) {
if (Uri.TryCreate(request.Url, UriKind.Absolute, out Uri? uri) && Factories.TryGetValue(uri.Scheme, out var factory)) {
return factory.Create(request);
}
else {
return null;
}
}
[SuppressMessage("ReSharper", "BitwiseOperatorOnEnumWithoutFlags")]
public static void Register(CefSchemeRegistrar registrar, ICustomSchemeHandler handler) {
string protocol = handler.Protocol;
Factories.Add(protocol, new SchemeHandlerFactory(handler));
registrar.AddCustomScheme(protocol, CefSchemeOptions.Secure | CefSchemeOptions.CorsEnabled | CefSchemeOptions.CspBypassing);
}
private readonly SchemeHandlerFactoryLogic<CefRequest, CefResourceHandler> logic;
private SchemeHandlerFactory(ICustomSchemeHandler handler) {
this.logic = new SchemeHandlerFactoryLogic<CefRequest, CefResourceHandler>(handler, CefRequestAdapter.Instance, CefResourceHandlerFactory.Instance);
}
private CefResourceHandler? Create(CefRequest request) {
return logic.Create(request);
}
}
}