summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp
blob: 19d5d6a560e220e6609d0b91138a58f15a8c9f81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/FrameHostElement.h>
#include <LibWeb/Origin.h>
#include <LibWeb/Page/Frame.h>

namespace Web::HTML {

FrameHostElement::FrameHostElement(DOM::Document& document, QualifiedName qualified_name)
    : HTMLElement(document, move(qualified_name))
{
}

FrameHostElement::~FrameHostElement()
{
}

void FrameHostElement::inserted()
{
    HTMLElement::inserted();
    if (!is_connected())
        return;
    if (auto* frame = document().frame())
        m_content_frame = Frame::create_subframe(*this, frame->main_frame());
}

Origin FrameHostElement::content_origin() const
{
    if (!m_content_frame || !m_content_frame->document())
        return {};
    return m_content_frame->document()->origin();
}

bool FrameHostElement::may_access_from_origin(const Origin& origin) const
{
    return origin.is_same(content_origin());
}

const DOM::Document* FrameHostElement::content_document() const
{
    return m_content_frame ? m_content_frame->document() : nullptr;
}

void FrameHostElement::content_frame_did_load(Badge<FrameLoader>)
{
    dispatch_event(DOM::Event::create(EventNames::load));
}

}