DocumentRequestProcessor
using AngleSharp.Dom;
using System.Threading;
using System.Threading.Tasks;
namespace AngleSharp.Network.RequestProcessors
{
internal class DocumentRequestProcessor : BaseRequestProcessor
{
private readonly IDocument _parentDocument;
private readonly IConfiguration _options;
private IDocument _childDocument;
public IDocument Document => _childDocument;
private DocumentRequestProcessor(IDocument document, IConfiguration options, IResourceLoader loader)
: base(loader)
{
_parentDocument = document;
_options = options;
}
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, _options) {
ImportAncestor = _parentDocument
};
_childDocument = await context.OpenAsync(options, CancellationToken.None).ConfigureAwait(false);
}
}
}