ContextFactory
THe default browsing context factory.
using AngleSharp.Dom;
using System;
using System.Collections.Generic;
namespace AngleSharp.Services.Default
{
public class ContextFactory : IContextFactory
{
private readonly Dictionary<string, WeakReference<IBrowsingContext>> _cache = new Dictionary<string, WeakReference<IBrowsingContext>>();
public IBrowsingContext Create(IConfiguration configuration, Sandboxes security)
{
return new BrowsingContext(configuration, security);
}
public IBrowsingContext Create(IBrowsingContext parent, string name, Sandboxes security)
{
BrowsingContext browsingContext = new BrowsingContext(parent, security);
_cache[name] = new WeakReference<IBrowsingContext>(browsingContext);
return browsingContext;
}
public IBrowsingContext Find(string name)
{
WeakReference<IBrowsingContext> value = null;
IBrowsingContext target = null;
if (_cache.TryGetValue(name, out value))
value.TryGetTarget(out target);
return target;
}
}
}