HTMLFrameOwnerElement.cpp [plain text]
#include "config.h"
#include "HTMLFrameOwnerElement.h"
#include "DOMWindow.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "RenderWidget.h"
#include "ShadowRoot.h"
#include "SVGDocument.h"
#include <wtf/Ref.h>
namespace WebCore {
HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Document& document)
: HTMLElement(tagName, document)
, m_contentFrame(0)
, m_sandboxFlags(SandboxNone)
{
}
RenderWidget* HTMLFrameOwnerElement::renderWidget() const
{
if (!renderer() || !renderer()->isWidget())
return 0;
return toRenderWidget(renderer());
}
void HTMLFrameOwnerElement::setContentFrame(Frame* frame)
{
ASSERT(!m_contentFrame || m_contentFrame->ownerElement() != this);
ASSERT(frame);
ASSERT(inDocument());
m_contentFrame = frame;
for (ContainerNode* node = this; node; node = node->parentOrShadowHostNode())
node->incrementConnectedSubframeCount();
}
void HTMLFrameOwnerElement::clearContentFrame()
{
if (!m_contentFrame)
return;
m_contentFrame = 0;
for (ContainerNode* node = this; node; node = node->parentOrShadowHostNode())
node->decrementConnectedSubframeCount();
}
void HTMLFrameOwnerElement::disconnectContentFrame()
{
if (Frame* frame = contentFrame()) {
Ref<Frame> protect(*frame);
frame->loader().frameDetached();
frame->disconnectOwnerElement();
}
}
HTMLFrameOwnerElement::~HTMLFrameOwnerElement()
{
if (m_contentFrame)
m_contentFrame->disconnectOwnerElement();
}
Document* HTMLFrameOwnerElement::contentDocument() const
{
return m_contentFrame ? m_contentFrame->document() : 0;
}
DOMWindow* HTMLFrameOwnerElement::contentWindow() const
{
return m_contentFrame ? m_contentFrame->document()->domWindow() : 0;
}
void HTMLFrameOwnerElement::setSandboxFlags(SandboxFlags flags)
{
m_sandboxFlags = flags;
}
bool HTMLFrameOwnerElement::isKeyboardFocusable(KeyboardEvent* event) const
{
return m_contentFrame && HTMLElement::isKeyboardFocusable(event);
}
SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionCode& ec) const
{
Document* doc = contentDocument();
if (doc && doc->isSVGDocument())
return toSVGDocument(doc);
ec = NOT_SUPPORTED_ERR;
return 0;
}
void HTMLFrameOwnerElement::scheduleSetNeedsStyleRecalc(StyleChangeType changeType)
{
if (Style::postResolutionCallbacksAreSuspended()) {
RefPtr<HTMLFrameOwnerElement> element = this;
Style::queuePostResolutionCallback([element, changeType]{
element->setNeedsStyleRecalc(changeType);
});
} else
setNeedsStyleRecalc(changeType);
}
bool SubframeLoadingDisabler::canLoadFrame(HTMLFrameOwnerElement& owner)
{
for (ContainerNode* node = &owner; node; node = node->parentOrShadowHostNode()) {
if (disabledSubtreeRoots().contains(node))
return false;
}
return true;
}
}