AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="0.9.2" />

.NET API 1,213,440 bytes

 HtmlIFrameElement

Represents the HTML iframe element.
using AngleSharp.Dom.Collections; using AngleSharp.Dom.Css; using AngleSharp.Extensions; using AngleSharp.Html; using AngleSharp.Network; 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 { private readonly IBrowsingContext _context; private SettableTokenList _sandbox; 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)); CreateBindings(_sandbox, AttributeNames.Sandbox); } return _sandbox; } } public bool IsSeamless { get { return HasOwnAttribute(AttributeNames.SrcDoc); } set { SetOwnAttribute(AttributeNames.SrcDoc, value ? string.Empty : null); } } public bool IsFullscreenAllowed { get { return HasOwnAttribute(AttributeNames.AllowFullscreen); } 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); RegisterAttributeObserver(AttributeNames.SrcDoc, UpdateSource); } private void UpdateSource(string _) { this.CancelTasks(); string content = ContentHtml; string source = base.Source; if (content != null) this.CreateTask((CancellationToken cancel) => _context.OpenAsync(delegate(BrowsingContextExtensions.VirtualResponse m) { m.Content(content).Address(base.Owner.DocumentUri); }, cancel)).ContinueWith(Finished); else if (!string.IsNullOrEmpty(source) && !source.Is(base.BaseUri)) { Url target = this.HyperReference(source); DocumentRequest request = DocumentRequest.Get(target, this, base.Owner.DocumentUri); this.CreateTask((CancellationToken cancel) => _context.OpenAsync(request, cancel)).ContinueWith(Finished); } } private void Finished(Task<IDocument> task) { if (!task.IsFaulted) base.ContentDocument = task.Result; this.FireLoadOrErrorEvent(task); } } }