2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Simon Hausmann (hausmann@kde.org)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2004, 2006, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2009 Ericsson AB. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #include "HTMLIFrameElement.h"
28 #include "Attribute.h"
29 #include "CSSPropertyNames.h"
31 #include "HTMLDocument.h"
32 #include "HTMLNames.h"
33 #include "NodeRenderingContext.h"
34 #include "RenderIFrame.h"
38 using namespace HTMLNames;
40 inline HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
41 : HTMLFrameElementBase(tagName, document)
43 ASSERT(hasTagName(iframeTag));
46 PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(const QualifiedName& tagName, Document* document)
48 return adoptRef(new HTMLIFrameElement(tagName, document));
51 bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
53 if (attrName == widthAttr || attrName == heightAttr) {
58 if (attrName == alignAttr) {
59 result = eReplaced; // Share with <img> since the alignment behavior is the same.
63 if (attrName == frameborderAttr) {
68 return HTMLFrameElementBase::mapToEntry(attrName, result);
71 static SandboxFlags parseSandboxAttribute(Attribute* attribute)
73 if (attribute->isNull())
76 // Parse the unordered set of unique space-separated tokens.
77 SandboxFlags flags = SandboxAll;
78 const UChar* characters = attribute->value().characters();
79 unsigned length = attribute->value().length();
82 while (start < length && isASCIISpace(characters[start]))
86 unsigned end = start + 1;
87 while (end < length && !isASCIISpace(characters[end]))
90 // Turn off the corresponding sandbox flag if it's set as "allowed".
91 String sandboxToken = String(characters + start, end - start);
92 if (equalIgnoringCase(sandboxToken, "allow-same-origin"))
93 flags &= ~SandboxOrigin;
94 else if (equalIgnoringCase(sandboxToken, "allow-forms"))
95 flags &= ~SandboxForms;
96 else if (equalIgnoringCase(sandboxToken, "allow-scripts"))
97 flags &= ~SandboxScripts;
98 else if (equalIgnoringCase(sandboxToken, "allow-top-navigation"))
99 flags &= ~SandboxTopNavigation;
107 void HTMLIFrameElement::parseMappedAttribute(Attribute* attr)
109 if (attr->name() == widthAttr)
110 addCSSLength(attr, CSSPropertyWidth, attr->value());
111 else if (attr->name() == heightAttr)
112 addCSSLength(attr, CSSPropertyHeight, attr->value());
113 else if (attr->name() == alignAttr)
114 addHTMLAlignment(attr);
115 else if (attr->name() == nameAttr) {
116 const AtomicString& newName = attr->value();
117 if (inDocument() && document()->isHTMLDocument()) {
118 HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
119 document->removeExtraNamedItem(m_name);
120 document->addExtraNamedItem(newName);
123 } else if (attr->name() == frameborderAttr) {
124 // Frame border doesn't really match the HTML4 spec definition for iframes. It simply adds
125 // a presentational hint that the border should be off if set to zero.
126 if (!attr->isNull() && !attr->value().toInt())
127 // Add a rule that nulls out our border width.
128 addCSSLength(attr, CSSPropertyBorderWidth, "0");
129 } else if (attr->name() == sandboxAttr)
130 setSandboxFlags(parseSandboxAttribute(attr));
132 HTMLFrameElementBase::parseMappedAttribute(attr);
135 bool HTMLIFrameElement::rendererIsNeeded(const NodeRenderingContext& context)
137 return isURLAllowed() && context.style()->display() != NONE;
140 RenderObject* HTMLIFrameElement::createRenderer(RenderArena* arena, RenderStyle*)
142 return new (arena) RenderIFrame(this);
145 void HTMLIFrameElement::insertedIntoDocument()
147 if (document()->isHTMLDocument())
148 static_cast<HTMLDocument*>(document())->addExtraNamedItem(m_name);
150 HTMLFrameElementBase::insertedIntoDocument();
153 void HTMLIFrameElement::removedFromDocument()
155 if (document()->isHTMLDocument())
156 static_cast<HTMLDocument*>(document())->removeExtraNamedItem(m_name);
158 HTMLFrameElementBase::removedFromDocument();
161 bool HTMLIFrameElement::isURLAttribute(Attribute* attr) const
163 return attr->name() == srcAttr;