mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:47:43 +00:00
LibWeb: Delay sub-Frame construction until host Document is attached
While we're parsing a new document, we don't have a Frame to grab at. We now use the Node::document_did_attach_to_frame() notification hook to delay subframe construction. With this, subframes now always have a valid reference to their enclosing main frame.
This commit is contained in:
parent
285a4165f3
commit
38ada2d102
4 changed files with 31 additions and 15 deletions
|
@ -44,7 +44,6 @@ namespace Web {
|
||||||
HTMLIFrameElement::HTMLIFrameElement(Document& document, const FlyString& tag_name)
|
HTMLIFrameElement::HTMLIFrameElement(Document& document, const FlyString& tag_name)
|
||||||
: HTMLElement(document, tag_name)
|
: HTMLElement(document, tag_name)
|
||||||
{
|
{
|
||||||
m_hosted_frame = Frame::create_subframe();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLIFrameElement::~HTMLIFrameElement()
|
HTMLIFrameElement::~HTMLIFrameElement()
|
||||||
|
@ -57,14 +56,18 @@ RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const StyleProperties*
|
||||||
return adopt(*new LayoutFrame(*this, move(style)));
|
return adopt(*new LayoutFrame(*this, move(style)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& value)
|
void HTMLIFrameElement::document_did_attach_to_frame(Frame& frame)
|
||||||
{
|
{
|
||||||
HTMLElement::parse_attribute(name, value);
|
ASSERT(!m_hosted_frame);
|
||||||
|
m_hosted_frame = Frame::create_subframe(*this, frame.main_frame());
|
||||||
if (name == HTML::AttributeNames::src) {
|
auto src = attribute(HTML::AttributeNames::src);
|
||||||
load_src(value);
|
if (src.is_null())
|
||||||
return;
|
return;
|
||||||
}
|
load_src(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLIFrameElement::document_will_detach_from_frame(Frame&)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLIFrameElement::load_src(const String& value)
|
void HTMLIFrameElement::load_src(const String& value)
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
|
||||||
class HTMLIFrameElement : public HTMLElement {
|
class HTMLIFrameElement final : public HTMLElement {
|
||||||
public:
|
public:
|
||||||
HTMLIFrameElement(Document&, const FlyString& tag_name);
|
HTMLIFrameElement(Document&, const FlyString& tag_name);
|
||||||
virtual ~HTMLIFrameElement() override;
|
virtual ~HTMLIFrameElement() override;
|
||||||
|
@ -40,9 +40,10 @@ public:
|
||||||
Frame* hosted_frame() { return m_hosted_frame; }
|
Frame* hosted_frame() { return m_hosted_frame; }
|
||||||
const Frame* hosted_frame() const { return m_hosted_frame; }
|
const Frame* hosted_frame() const { return m_hosted_frame; }
|
||||||
|
|
||||||
virtual void parse_attribute(const FlyString& name, const String& value) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void document_did_attach_to_frame(Frame&) override;
|
||||||
|
virtual void document_will_detach_from_frame(Frame&) override;
|
||||||
|
|
||||||
void load_src(const String&);
|
void load_src(const String&);
|
||||||
|
|
||||||
RefPtr<Frame> m_hosted_frame;
|
RefPtr<Frame> m_hosted_frame;
|
||||||
|
|
|
@ -32,13 +32,16 @@
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
|
||||||
Frame::Frame()
|
Frame::Frame(Element& host_element, Frame& main_frame)
|
||||||
: m_loader(*this)
|
: m_main_frame(main_frame)
|
||||||
|
, m_loader(*this)
|
||||||
|
, m_host_element(host_element.make_weak_ptr())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame::Frame(PageView& page_view)
|
Frame::Frame(PageView& page_view)
|
||||||
: m_loader(*this)
|
: m_main_frame(*this)
|
||||||
|
, m_loader(*this)
|
||||||
, m_page_view(page_view.make_weak_ptr())
|
, m_page_view(page_view.make_weak_ptr())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class PageView;
|
||||||
|
|
||||||
class Frame : public TreeNode<Frame> {
|
class Frame : public TreeNode<Frame> {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<Frame> create_subframe() { return adopt(*new Frame); }
|
static NonnullRefPtr<Frame> create_subframe(Element& host_element, Frame& main_frame) { return adopt(*new Frame(host_element, main_frame)); }
|
||||||
static NonnullRefPtr<Frame> create(PageView& page_view) { return adopt(*new Frame(page_view)); }
|
static NonnullRefPtr<Frame> create(PageView& page_view) { return adopt(*new Frame(page_view)); }
|
||||||
~Frame();
|
~Frame();
|
||||||
|
|
||||||
|
@ -76,12 +76,21 @@ public:
|
||||||
|
|
||||||
void scroll_to_anchor(const String&);
|
void scroll_to_anchor(const String&);
|
||||||
|
|
||||||
|
Frame& main_frame() { return m_main_frame; }
|
||||||
|
const Frame& main_frame() const { return m_main_frame; }
|
||||||
|
|
||||||
|
Element* host_element() { return m_host_element; }
|
||||||
|
const Element* host_element() const { return m_host_element; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Frame();
|
explicit Frame(Element& host_element, Frame& main_frame);
|
||||||
explicit Frame(PageView&);
|
explicit Frame(PageView&);
|
||||||
|
|
||||||
|
Frame& m_main_frame;
|
||||||
|
|
||||||
FrameLoader m_loader;
|
FrameLoader m_loader;
|
||||||
|
|
||||||
|
WeakPtr<Element> m_host_element;
|
||||||
WeakPtr<PageView> m_page_view;
|
WeakPtr<PageView> m_page_view;
|
||||||
RefPtr<Document> m_document;
|
RefPtr<Document> m_document;
|
||||||
Gfx::Size m_size;
|
Gfx::Size m_size;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue