This source file includes following definitions.
- widgetNewParentMap
- performDeferredWidgetTreeOperations
- moveWidgetToParentSoon
- m_sandboxFlags
- renderPart
- setContentFrame
- clearContentFrame
- disconnectContentFrame
- contentDocument
- contentWindow
- setSandboxFlags
- isKeyboardFocusable
- getSVGDocument
- setWidget
- ownedWidget
- loadOrRedirectSubframe
#include "config.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "bindings/v8/ExceptionMessages.h"
#include "bindings/v8/ExceptionState.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/dom/ExceptionCode.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderPart.h"
#include "core/rendering/compositing/RenderLayerCompositor.h"
#include "core/svg/SVGDocument.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "platform/weborigin/SecurityPolicy.h"
namespace WebCore {
typedef HashMap<RefPtr<Widget>, FrameView*> WidgetToParentMap;
static WidgetToParentMap& widgetNewParentMap()
{
DEFINE_STATIC_LOCAL(WidgetToParentMap, map, ());
return map;
}
static unsigned s_updateSuspendCount = 0;
HTMLFrameOwnerElement::UpdateSuspendScope::UpdateSuspendScope()
{
++s_updateSuspendCount;
}
void HTMLFrameOwnerElement::UpdateSuspendScope::performDeferredWidgetTreeOperations()
{
WidgetToParentMap map;
widgetNewParentMap().swap(map);
WidgetToParentMap::iterator end = map.end();
for (WidgetToParentMap::iterator it = map.begin(); it != end; ++it) {
Widget* child = it->key.get();
ScrollView* currentParent = toScrollView(child->parent());
FrameView* newParent = it->value;
if (newParent != currentParent) {
if (currentParent)
currentParent->removeChild(child);
if (newParent)
newParent->addChild(child);
}
}
}
HTMLFrameOwnerElement::UpdateSuspendScope::~UpdateSuspendScope()
{
ASSERT(s_updateSuspendCount > 0);
if (s_updateSuspendCount == 1)
performDeferredWidgetTreeOperations();
--s_updateSuspendCount;
}
static void moveWidgetToParentSoon(Widget* child, FrameView* parent)
{
if (!s_updateSuspendCount) {
if (parent)
parent->addChild(child);
else if (toScrollView(child->parent()))
toScrollView(child->parent())->removeChild(child);
return;
}
widgetNewParentMap().set(child, parent);
}
HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Document& document)
: HTMLElement(tagName, document)
, m_contentFrame(0)
, m_widget(nullptr)
, m_sandboxFlags(SandboxNone)
{
}
RenderPart* HTMLFrameOwnerElement::renderPart() const
{
if (!renderer() || !renderer()->isRenderPart())
return 0;
return toRenderPart(renderer());
}
void HTMLFrameOwnerElement::setContentFrame(Frame& frame)
{
ASSERT(!m_contentFrame || m_contentFrame->ownerElement() != this);
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()) {
RefPtr<Frame> protect(frame);
if (frame->isLocalFrame())
toLocalFrame(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->domWindow() : 0;
}
void HTMLFrameOwnerElement::setSandboxFlags(SandboxFlags flags)
{
m_sandboxFlags = flags;
}
bool HTMLFrameOwnerElement::isKeyboardFocusable() const
{
return m_contentFrame && HTMLElement::isKeyboardFocusable();
}
SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionState& exceptionState) const
{
Document* doc = contentDocument();
if (doc && doc->isSVGDocument())
return toSVGDocument(doc);
return 0;
}
void HTMLFrameOwnerElement::setWidget(PassRefPtr<Widget> widget)
{
if (widget == m_widget)
return;
if (m_widget) {
if (m_widget->parent())
moveWidgetToParentSoon(m_widget.get(), 0);
m_widget = nullptr;
}
m_widget = widget;
RenderWidget* renderWidget = toRenderWidget(renderer());
if (!renderWidget)
return;
if (m_widget) {
renderWidget->updateOnWidgetChange();
ASSERT(document().view() == renderWidget->frameView());
ASSERT(renderWidget->frameView());
moveWidgetToParentSoon(m_widget.get(), renderWidget->frameView());
}
if (AXObjectCache* cache = document().existingAXObjectCache())
cache->childrenChanged(renderWidget);
}
Widget* HTMLFrameOwnerElement::ownedWidget() const
{
return m_widget.get();
}
bool HTMLFrameOwnerElement::loadOrRedirectSubframe(const KURL& url, const AtomicString& frameName, bool lockBackForwardList)
{
RefPtr<LocalFrame> parentFrame = document().frame();
if (contentFrame() && contentFrame()->isLocalFrame()) {
toLocalFrame(contentFrame())->navigationScheduler().scheduleLocationChange(&document(), url.string(), Referrer(document().outgoingReferrer(), document().referrerPolicy()), lockBackForwardList);
return true;
}
if (!document().securityOrigin()->canDisplay(url)) {
FrameLoader::reportLocalLoadFailed(parentFrame.get(), url.string());
return false;
}
if (!SubframeLoadingDisabler::canLoadFrame(*this))
return false;
String referrer = SecurityPolicy::generateReferrerHeader(document().referrerPolicy(), url, document().outgoingReferrer());
RefPtr<LocalFrame> childFrame = parentFrame->loader().client()->createFrame(url, frameName, Referrer(referrer, document().referrerPolicy()), this);
if (!childFrame) {
parentFrame->loader().checkCompleted();
return false;
}
childFrame->loader().started();
FrameView* view = childFrame->view();
RenderObject* renderObject = renderer();
if (renderObject && renderObject->isWidget() && view)
setWidget(view);
if (childFrame->loader().state() == FrameStateComplete && !childFrame->loader().policyDocumentLoader())
childFrame->loader().checkCompleted();
return true;
}
}