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 "CSSPropertyNames.h"
30 #include "HTMLDocument.h"
31 #include "HTMLNames.h"
32 #include "MappedAttribute.h"
33 #include "RenderPartObject.h"
37 using namespace HTMLNames;
39 inline HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
40 : HTMLFrameElementBase(tagName, document)
42 ASSERT(hasTagName(iframeTag));
45 PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(const QualifiedName& tagName, Document* document)
47 return adoptRef(new HTMLIFrameElement(tagName, document));
50 bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
52 if (attrName == widthAttr || attrName == heightAttr) {
57 if (attrName == alignAttr) {
58 result = eReplaced; // Share with <img> since the alignment behavior is the same.
62 if (attrName == frameborderAttr) {
67 return HTMLFrameElementBase::mapToEntry(attrName, result);
70 static SandboxFlags parseSandboxAttribute(MappedAttribute* attribute)
72 if (attribute->isNull())
75 // Parse the unordered set of unique space-separated tokens.
76 SandboxFlags flags = SandboxAll;
77 const UChar* characters = attribute->value().characters();
78 unsigned length = attribute->value().length();
81 while (start < length && isASCIISpace(characters[start]))
85 unsigned end = start + 1;
86 while (end < length && !isASCIISpace(characters[end]))
89 // Turn off the corresponding sandbox flag if it's set as "allowed".
90 String sandboxToken = String(characters + start, end - start);
91 if (equalIgnoringCase(sandboxToken, "allow-same-origin"))
92 flags &= ~SandboxOrigin;
93 else if (equalIgnoringCase(sandboxToken, "allow-forms"))
94 flags &= ~SandboxForms;
95 else if (equalIgnoringCase(sandboxToken, "allow-scripts"))
96 flags &= ~SandboxScripts;
104 void HTMLIFrameElement::parseMappedAttribute(MappedAttribute* attr)
106 if (attr->name() == widthAttr)
107 addCSSLength(attr, CSSPropertyWidth, attr->value());
108 else if (attr->name() == heightAttr)
109 addCSSLength(attr, CSSPropertyHeight, attr->value());
110 else if (attr->name() == alignAttr)
111 addHTMLAlignment(attr);
112 else if (attr->name() == nameAttr) {
113 const AtomicString& newName = attr->value();
114 if (inDocument() && document()->isHTMLDocument()) {
115 HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
116 document->removeExtraNamedItem(m_name);
117 document->addExtraNamedItem(newName);
120 } else if (attr->name() == frameborderAttr) {
121 // Frame border doesn't really match the HTML4 spec definition for iframes. It simply adds
122 // a presentational hint that the border should be off if set to zero.
123 if (!attr->isNull() && !attr->value().toInt())
124 // Add a rule that nulls out our border width.
125 addCSSLength(attr, CSSPropertyBorderWidth, "0");
126 } else if (attr->name() == sandboxAttr)
127 setSandboxFlags(parseSandboxAttribute(attr));
129 HTMLFrameElementBase::parseMappedAttribute(attr);
132 bool HTMLIFrameElement::rendererIsNeeded(RenderStyle* style)
134 return isURLAllowed() && style->display() != NONE;
137 RenderObject* HTMLIFrameElement::createRenderer(RenderArena* arena, RenderStyle*)
139 return new (arena) RenderPartObject(this);
142 void HTMLIFrameElement::insertedIntoDocument()
144 if (document()->isHTMLDocument())
145 static_cast<HTMLDocument*>(document())->addExtraNamedItem(m_name);
147 HTMLFrameElementBase::insertedIntoDocument();
150 void HTMLIFrameElement::removedFromDocument()
152 if (document()->isHTMLDocument())
153 static_cast<HTMLDocument*>(document())->removeExtraNamedItem(m_name);
155 HTMLFrameElementBase::removedFromDocument();
158 bool HTMLIFrameElement::isURLAttribute(Attribute* attr) const
160 return attr->name() == srcAttr;