HTMLFrameElementBase.cpp [plain text]
#include "config.h"
#include "HTMLFrameElementBase.h"
#include "Attribute.h"
#include "Document.h"
#include "EventNames.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameView.h"
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
#include "URL.h"
#include "Page.h"
#include "RenderWidget.h"
#include "ScriptController.h"
#include "Settings.h"
#include "SubframeLoader.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)
{
setHasCustomStyleResolveCallbacks();
}
bool HTMLFrameElementBase::isURLAllowed() const
{
if (document().page() && document().page()->subframeCount() >= Page::maxNumberOfFrames)
return false;
if (m_URL.isEmpty())
return true;
const URL& completeURL = document().completeURL(m_URL);
if (protocolIsJavaScript(completeURL)) {
Document* contentDoc = this->contentDocument();
if (contentDoc && !ScriptController::canAccessFromCurrentOrigin(contentDoc->frame()))
return false;
}
Frame* parentFrame = document().frame();
if (parentFrame)
return parentFrame->isURLAllowed(completeURL);
return true;
}
void HTMLFrameElementBase::openURL(LockHistory lockHistory, LockBackForwardList lockBackForwardList)
{
if (!isURLAllowed())
return;
if (m_URL.isEmpty())
m_URL = blankURL().string();
Frame* parentFrame = document().frame();
if (!parentFrame)
return;
parentFrame->loader().subframeLoader().requestFrame(*this, m_URL, m_frameName, lockHistory, lockBackForwardList);
}
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 (name == HTMLNames::idAttr) {
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 = document().frameElementsShouldIgnoreScrolling() ? ScrollbarAlwaysOff : ScrollbarAuto;
else if (equalIgnoringCase(value, "no"))
m_scrolling = ScrollbarAlwaysOff;
} else if (name == onbeforeloadAttr)
setAttributeEventListener(eventNames().beforeloadEvent, name, value);
else if (name == onbeforeunloadAttr) {
setAttributeEventListener(eventNames().beforeunloadEvent, name, value);
} else
HTMLFrameOwnerElement::parseAttribute(name, value);
}
void HTMLFrameElementBase::setNameAndOpenURL()
{
m_frameName = getNameAttribute();
if (m_frameName.isNull())
m_frameName = getIdAttribute();
openURL();
}
Node::InsertionNotificationRequest HTMLFrameElementBase::insertedInto(ContainerNode& insertionPoint)
{
HTMLFrameOwnerElement::insertedInto(insertionPoint);
if (insertionPoint.inDocument())
return InsertionShouldCallDidNotifySubtreeInsertions;
return InsertionDone;
}
void HTMLFrameElementBase::didNotifySubtreeInsertions(ContainerNode*)
{
if (!inDocument())
return;
if (!document().frame())
return;
if (!SubframeLoadingDisabler::canLoadFrame(*this))
return;
if (!renderer())
setNeedsStyleRecalc(ReconstructRenderTree);
setNameAndOpenURL();
}
void HTMLFrameElementBase::didAttachRenderers()
{
if (RenderWidget* part = renderWidget()) {
if (Frame* frame = contentFrame())
part->setWidget(frame->view());
}
}
URL HTMLFrameElementBase::location() const
{
if (fastHasAttribute(srcdocAttr))
return URL(ParsedURLString, "about:srcdoc");
return document().completeURL(getAttribute(srcAttr));
}
void HTMLFrameElementBase::setLocation(const String& str)
{
Settings* settings = document().settings();
if (settings && settings->needsAcrobatFrameReloadingQuirk() && m_URL == str)
return;
m_URL = AtomicString(str);
if (inDocument())
openURL(LockHistory::No, LockBackForwardList::No);
}
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(0);
}
}
bool HTMLFrameElementBase::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == srcAttr || HTMLFrameOwnerElement::isURLAttribute(attribute);
}
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();
}
}