mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
Follow up to #2010
ResourceFactoryItem renamed to DefaultResourceHandlerFactory - it's only used in the context of that class Change persist to OneTimeUse and invert logic (false is the default) Remove unnecessary RegisterHandler overload - user default value instead
This commit is contained in:
@@ -199,7 +199,7 @@
|
||||
<Compile Include="PdfPrintSettings.cs" />
|
||||
<Compile Include="ICookieManager.cs" />
|
||||
<Compile Include="IMenuModel.cs" />
|
||||
<Compile Include="ResourceFactoryItem.cs" />
|
||||
<Compile Include="DefaultResourceHandlerFactoryItem.cs" />
|
||||
<Compile Include="Structs\ViewRect.cs" />
|
||||
<Compile Include="ISslInfo.cs" />
|
||||
<Compile Include="Structs\KeyEvent.cs" />
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CefSharp
|
||||
/// <summary>
|
||||
/// Resource handler thread safe dictionary
|
||||
/// </summary>
|
||||
public ConcurrentDictionary<string, ResourceFactoryItem> Handlers { get; private set; }
|
||||
public ConcurrentDictionary<string, DefaultResourceHandlerFactoryItem> Handlers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance of DefaultResourceHandlerFactory
|
||||
@@ -26,7 +26,7 @@ namespace CefSharp
|
||||
/// <param name="comparer">string equality comparer</param>
|
||||
public DefaultResourceHandlerFactory(IEqualityComparer<string> comparer = null)
|
||||
{
|
||||
Handlers = new ConcurrentDictionary<string, ResourceFactoryItem>(comparer ?? StringComparer.OrdinalIgnoreCase);
|
||||
Handlers = new ConcurrentDictionary<string, DefaultResourceHandlerFactoryItem>(comparer ?? StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -34,14 +34,14 @@ namespace CefSharp
|
||||
/// </summary>
|
||||
/// <param name="url">url</param>
|
||||
/// <param name="handler">handler</param>
|
||||
/// <param name="persist">Whether or not the handler should be used once (false) or until manually unregistered (true)</param>
|
||||
/// <param name="oneTimeUse">Whether or not the handler should be used once (true) or until manually unregistered (false)</param>
|
||||
/// <returns>returns true if the Url was successfully parsed into a Uri otherwise false</returns>
|
||||
public virtual bool RegisterHandler(string url, IResourceHandler handler, bool persist)
|
||||
public virtual bool RegisterHandler(string url, IResourceHandler handler, bool oneTimeUse = false)
|
||||
{
|
||||
Uri uri;
|
||||
if (Uri.TryCreate(url, UriKind.Absolute, out uri))
|
||||
{
|
||||
ResourceFactoryItem entry = new ResourceFactoryItem(handler, persist);
|
||||
var entry = new DefaultResourceHandlerFactoryItem(handler, oneTimeUse);
|
||||
|
||||
Handlers.AddOrUpdate(uri.AbsoluteUri, entry, (k, v) => entry);
|
||||
return true;
|
||||
@@ -49,17 +49,6 @@ namespace CefSharp
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a persistant handler for the specified Url
|
||||
/// </summary>
|
||||
/// <param name="url">url</param>
|
||||
/// <param name="handler">handler</param>
|
||||
/// <returns>returns true if the Url was successfully parsed into a Uri otherwise false</returns>
|
||||
public virtual bool RegisterHandler(string url, IResourceHandler handler)
|
||||
{
|
||||
return RegisterHandler(url, handler, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister a handler for the specified Url
|
||||
/// </summary>
|
||||
@@ -67,7 +56,7 @@ namespace CefSharp
|
||||
/// <returns>returns true if successfully removed</returns>
|
||||
public virtual bool UnregisterHandler(string url)
|
||||
{
|
||||
ResourceFactoryItem entry;
|
||||
DefaultResourceHandlerFactoryItem entry;
|
||||
return Handlers.TryRemove(url, out entry);
|
||||
}
|
||||
|
||||
@@ -91,11 +80,11 @@ namespace CefSharp
|
||||
{
|
||||
try
|
||||
{
|
||||
ResourceFactoryItem entry;
|
||||
DefaultResourceHandlerFactoryItem entry;
|
||||
|
||||
if (Handlers.TryGetValue(request.Url, out entry))
|
||||
{
|
||||
if (!entry.Persist)
|
||||
if (entry.OneTimeUse)
|
||||
{
|
||||
Handlers.TryRemove(request.Url, out entry);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
public class ResourceFactoryItem
|
||||
public class DefaultResourceHandlerFactoryItem
|
||||
{
|
||||
/// <summary>
|
||||
/// The handler for a specific Url
|
||||
@@ -12,16 +12,16 @@ namespace CefSharp
|
||||
public IResourceHandler Handler { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the handler should be used once (false) or until manually unregistered (true)
|
||||
/// Whether or not the handler should be used once (true) or until manually unregistered (false)
|
||||
/// </summary>
|
||||
public bool Persist { get; private set; }
|
||||
public bool OneTimeUse { get; private set; }
|
||||
|
||||
/// <param name="handler">The handler for a specific Url</param>
|
||||
/// <param name="persist">Whether or not the handler should be used once (false) or until manually unregistered (true)</param>
|
||||
public ResourceFactoryItem(IResourceHandler handler, bool persist)
|
||||
/// <param name="oneTimeUse">Whether or not the handler should be used once (true) or until manually unregistered (false)</param>
|
||||
public DefaultResourceHandlerFactoryItem(IResourceHandler handler, bool oneTimeUse)
|
||||
{
|
||||
Handler = handler;
|
||||
Persist = persist;
|
||||
OneTimeUse = oneTimeUse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,8 +293,9 @@ namespace CefSharp
|
||||
/// <param name="html">The HTML content.</param>
|
||||
/// <param name="url">The URL that will be treated as the address of the content.</param>
|
||||
/// <param name="encoding">Character Encoding</param>
|
||||
/// <param name="oneTimeUse">Whether or not the handler should be used once (true) or until manually unregistered (false)</param>
|
||||
/// <returns>returns false if the Url was not successfully parsed into a Uri</returns>
|
||||
public static bool LoadHtml(this IWebBrowser browser, string html, string url, Encoding encoding)
|
||||
public static bool LoadHtml(this IWebBrowser browser, string html, string url, Encoding encoding, bool oneTimeUse = false)
|
||||
{
|
||||
var handler = browser.ResourceHandlerFactory;
|
||||
if (handler == null)
|
||||
@@ -309,7 +310,7 @@ namespace CefSharp
|
||||
throw new Exception("LoadHtml can only be used with the default IResourceHandlerFactory(DefaultResourceHandlerFactory) implementation");
|
||||
}
|
||||
|
||||
if (resourceHandler.RegisterHandler(url, ResourceHandler.FromString(html, encoding, true), false))
|
||||
if (resourceHandler.RegisterHandler(url, ResourceHandler.FromString(html, encoding, true), oneTimeUse))
|
||||
{
|
||||
browser.Load(url);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user