HtmlFrameElementBase
Represents the base class for frame elements.
using AngleSharp.Extensions;
using AngleSharp.Html;
using AngleSharp.Network;
using AngleSharp.Network.RequestProcessors;
namespace AngleSharp.Dom.Html
{
internal abstract class HtmlFrameElementBase : HtmlFrameOwnerElement
{
private IBrowsingContext _context;
private FrameRequestProcessor _request;
public IDownload CurrentDownload => _request?.Download;
public string Name {
get {
return this.GetOwnAttribute(AttributeNames.Name);
}
set {
this.SetOwnAttribute(AttributeNames.Name, value, false);
}
}
public string Source {
get {
return this.GetUrlAttribute(AttributeNames.Src);
}
set {
this.SetOwnAttribute(AttributeNames.Src, value, false);
}
}
public string Scrolling {
get {
return this.GetOwnAttribute(AttributeNames.Scrolling);
}
set {
this.SetOwnAttribute(AttributeNames.Scrolling, value, false);
}
}
public IDocument ContentDocument => _request?.Document;
public string LongDesc {
get {
return this.GetOwnAttribute(AttributeNames.LongDesc);
}
set {
this.SetOwnAttribute(AttributeNames.LongDesc, value, false);
}
}
public string FrameBorder {
get {
return this.GetOwnAttribute(AttributeNames.FrameBorder);
}
set {
this.SetOwnAttribute(AttributeNames.FrameBorder, value, false);
}
}
public IBrowsingContext NestedContext => _context ?? (_context = base.Owner.NewChildContext(Sandboxes.None));
static HtmlFrameElementBase()
{
Element.RegisterCallback(AttributeNames.Src, delegate(HtmlFrameElementBase element, string value) {
element.UpdateSource();
});
}
public HtmlFrameElementBase(Document owner, string name, string prefix, NodeFlags flags = NodeFlags.None)
: base(owner, name, prefix, flags | NodeFlags.Special)
{
_request = FrameRequestProcessor.Create(this);
}
protected void UpdateSource()
{
string contentHtml = GetContentHtml();
string source = Source;
if (source != null || contentHtml != null) {
Url url = this.HyperReference(source);
this.Process(_request, url);
}
}
internal virtual string GetContentHtml()
{
return null;
}
internal override void SetupElement()
{
base.SetupElement();
if (this.GetOwnAttribute(AttributeNames.Src) != null)
UpdateSource();
}
}
}