HtmlIFrameElement
sealed class HtmlIFrameElement : HtmlFrameElementBase, IHtmlInlineFrameElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IDisposable
Represents the HTML iframe element.
using AngleSharp.Dom.Collections;
using AngleSharp.Dom.Css;
using AngleSharp.Extensions;
using AngleSharp.Html;
using AngleSharp.Network;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace AngleSharp.Dom.Html
{
internal sealed class HtmlIFrameElement : HtmlFrameElementBase, IHtmlInlineFrameElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IDisposable
{
private readonly IBrowsingContext _context;
private CancellationTokenSource _cts;
private SettableTokenList _sandbox;
private Task _docTask;
public Alignment Align {
get {
return GetOwnAttribute(AttributeNames.Align).ToEnum(Alignment.Bottom);
}
set {
SetOwnAttribute(AttributeNames.Align, value.ToString());
}
}
public string ContentHtml {
get {
return GetOwnAttribute(AttributeNames.SrcDoc);
}
set {
SetOwnAttribute(AttributeNames.SrcDoc, value);
}
}
public ISettableTokenList Sandbox {
get {
if (_sandbox == null) {
_sandbox = new SettableTokenList(GetOwnAttribute(AttributeNames.Sandbox));
_sandbox.Changed += delegate {
UpdateAttribute(AttributeNames.Sandbox, _sandbox.Value);
};
}
return _sandbox;
}
}
public bool IsSeamless {
get {
return GetOwnAttribute(AttributeNames.SrcDoc) != null;
}
set {
SetOwnAttribute(AttributeNames.SrcDoc, value ? string.Empty : null);
}
}
public bool IsFullscreenAllowed {
get {
return GetOwnAttribute(AttributeNames.AllowFullscreen) != null;
}
set {
SetOwnAttribute(AttributeNames.AllowFullscreen, value ? string.Empty : null);
}
}
public IWindow ContentWindow => _context.Current;
public HtmlIFrameElement(Document owner, string prefix = null)
: base(owner, Tags.Iframe, prefix, NodeFlags.LiteralText)
{
_context = owner.NewChildContext(Sandboxes.None);
RegisterAttributeObserver(AttributeNames.Src, UpdateSource);
}
public void Dispose()
{
if (_cts != null)
_cts.Cancel();
_docTask = null;
_cts = null;
}
private void UpdateSource(string src)
{
if (_cts != null)
_cts.Cancel();
if (!string.IsNullOrEmpty(src)) {
DocumentRequest request = new DocumentRequest(this.HyperReference(src)) {
Source = this,
Referer = base.Owner.DocumentUri
};
_cts = new CancellationTokenSource();
_docTask = _context.OpenAsync(request, _cts.Token);
}
}
}
}