DocumentRequestProcessor
using AngleSharp.Dom;
using AngleSharp.Extensions;
using AngleSharp.Services;
using System.Threading;
using System.Threading.Tasks;
namespace AngleSharp.Network.RequestProcessors
{
internal class DocumentRequestProcessor : BaseRequestProcessor
{
private readonly IDocument _parentDocument;
private readonly IConfiguration _configuration;
private IDocument _childDocument;
public IDocument Document => _childDocument;
private DocumentRequestProcessor(IDocument document, IConfiguration configuration, IResourceLoader loader)
: base(loader)
{
_parentDocument = document;
_configuration = configuration;
}
internal static DocumentRequestProcessor Create(Element element)
{
Document owner = element.Owner;
IConfiguration options = owner.Options;
IResourceLoader loader = owner.Loader;
if (options == null || loader == null)
return null;
return new DocumentRequestProcessor(owner, options, loader);
}
protected override async Task ProcessResponseAsync(IResponse response)
{
BrowsingContext context = new BrowsingContext(_parentDocument.Context, Sandboxes.None);
CreateDocumentOptions options = new CreateDocumentOptions(response, _configuration, _parentDocument);
IDocumentFactory factory = _configuration.GetFactory<IDocumentFactory>();
IDocument childDocument = _childDocument;
IDocument document = _childDocument = await factory.CreateAsync(context, options, CancellationToken.None).ConfigureAwait(false);
}
}
}