This source file includes following definitions.
- m_marginHeight
- isURLAllowed
- openURL
- parseAttribute
- setNameAndOpenURL
- insertedInto
- didNotifySubtreeInsertionsToDocument
- attach
- setLocation
- supportsFocus
- setFocus
- isURLAttribute
- hasLegalLinkAttribute
- isHTMLContentAttribute
- width
- height
#include "config.h"
#include "core/html/HTMLFrameElementBase.h"
#include "HTMLNames.h"
#include "bindings/v8/ScriptController.h"
#include "bindings/v8/ScriptEventListener.h"
#include "core/dom/Attribute.h"
#include "core/dom/Document.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/loader/FrameLoader.h"
#include "core/page/FocusController.h"
#include "core/page/Page.h"
#include "core/rendering/RenderPart.h"
namespace WebCore {
using namespace HTMLNames;
HTMLFrameElementBase::HTMLFrameElementBase(const QualifiedName& tagName, Document& document)
: HTMLFrameOwnerElement(tagName, document)
, m_scrolling(ScrollbarAuto)
, m_marginWidth(-1)
, m_marginHeight(-1)
{
}
bool HTMLFrameElementBase::isURLAllowed() const
{
if (m_URL.isEmpty())
return true;
const KURL& completeURL = document().completeURL(m_URL);
if (protocolIsJavaScript(completeURL)) {
Document* contentDoc = this->contentDocument();
if (contentDoc && !ScriptController::canAccessFromCurrentOrigin(contentDoc->frame()))
return false;
}
LocalFrame* parentFrame = document().frame();
if (parentFrame)
return parentFrame->isURLAllowed(completeURL);
return true;
}
void HTMLFrameElementBase::openURL(bool lockBackForwardList)
{
if (!isURLAllowed())
return;
if (m_URL.isEmpty())
m_URL = AtomicString(blankURL().string());
LocalFrame* parentFrame = document().frame();
if (!parentFrame)
return;
KURL scriptURL;
KURL url = document().completeURL(m_URL);
if (protocolIsJavaScript(m_URL)) {
scriptURL = url;
url = blankURL();
}
if (!loadOrRedirectSubframe(url, m_frameName, lockBackForwardList))
return;
if (!contentFrame() || scriptURL.isEmpty() || !contentFrame()->isLocalFrame())
return;
toLocalFrame(contentFrame())->script().executeScriptIfJavaScriptURL(scriptURL);
}
void HTMLFrameElementBase::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == srcdocAttr)
setLocation("about:srcdoc");
else if (name == srcAttr && !fastHasAttribute(srcdocAttr))
setLocation(stripLeadingAndTrailingHTMLSpaces(value));
else if (isIdAttributeName(name)) {
HTMLFrameOwnerElement::parseAttribute(name, value);
m_frameName = value;
} else if (name == nameAttr) {
m_frameName = value;
} else if (name == marginwidthAttr) {
m_marginWidth = value.toInt();
} else if (name == marginheightAttr) {
m_marginHeight = value.toInt();
} else if (name == scrollingAttr) {
if (equalIgnoringCase(value, "auto") || equalIgnoringCase(value, "yes"))
m_scrolling = ScrollbarAuto;
else if (equalIgnoringCase(value, "no"))
m_scrolling = ScrollbarAlwaysOff;
} else if (name == onbeforeunloadAttr) {
setAttributeEventListener(EventTypeNames::beforeunload, createAttributeEventListener(this, name, value));
} else
HTMLFrameOwnerElement::parseAttribute(name, value);
}
void HTMLFrameElementBase::setNameAndOpenURL()
{
m_frameName = getNameAttribute();
openURL();
}
Node::InsertionNotificationRequest HTMLFrameElementBase::insertedInto(ContainerNode* insertionPoint)
{
HTMLFrameOwnerElement::insertedInto(insertionPoint);
return InsertionShouldCallDidNotifySubtreeInsertions;
}
void HTMLFrameElementBase::didNotifySubtreeInsertionsToDocument()
{
if (!document().frame())
return;
if (!SubframeLoadingDisabler::canLoadFrame(*this))
return;
setNameAndOpenURL();
}
void HTMLFrameElementBase::attach(const AttachContext& context)
{
HTMLFrameOwnerElement::attach(context);
if (renderPart()) {
if (Frame* frame = contentFrame()) {
if (frame->isLocalFrame())
setWidget(toLocalFrame(frame)->view());
}
}
}
void HTMLFrameElementBase::setLocation(const String& str)
{
m_URL = AtomicString(str);
if (inDocument())
openURL(false);
}
bool HTMLFrameElementBase::supportsFocus() const
{
return true;
}
void HTMLFrameElementBase::setFocus(bool received)
{
HTMLFrameOwnerElement::setFocus(received);
if (Page* page = document().page()) {
if (received)
page->focusController().setFocusedFrame(contentFrame());
else if (page->focusController().focusedFrame() == contentFrame())
page->focusController().setFocusedFrame(nullptr);
}
}
bool HTMLFrameElementBase::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == longdescAttr || attribute.name() == srcAttr
|| HTMLFrameOwnerElement::isURLAttribute(attribute);
}
bool HTMLFrameElementBase::hasLegalLinkAttribute(const QualifiedName& name) const
{
return name == hrefAttr || HTMLFrameOwnerElement::hasLegalLinkAttribute(name);
}
bool HTMLFrameElementBase::isHTMLContentAttribute(const Attribute& attribute) const
{
return attribute.name() == srcdocAttr || HTMLFrameOwnerElement::isHTMLContentAttribute(attribute);
}
int HTMLFrameElementBase::width()
{
document().updateLayoutIgnorePendingStylesheets();
if (!renderBox())
return 0;
return renderBox()->width();
}
int HTMLFrameElementBase::height()
{
document().updateLayoutIgnorePendingStylesheets();
if (!renderBox())
return 0;
return renderBox()->height();
}
}