initial import
[vuplus_webkit] / Source / WebCore / html / HTMLIFrameElement.cpp
1 /*
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.
8  *
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.
13  *
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.
18  *
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.
23  */
24
25 #include "config.h"
26 #include "HTMLIFrameElement.h"
27
28 #include "Attribute.h"
29 #include "CSSPropertyNames.h"
30 #include "Frame.h"
31 #include "HTMLDocument.h"
32 #include "HTMLNames.h"
33 #include "NodeRenderingContext.h"
34 #include "RenderIFrame.h"
35
36 namespace WebCore {
37
38 using namespace HTMLNames;
39
40 inline HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
41     : HTMLFrameElementBase(tagName, document)
42 {
43     ASSERT(hasTagName(iframeTag));
44 }
45
46 PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(const QualifiedName& tagName, Document* document)
47 {
48     return adoptRef(new HTMLIFrameElement(tagName, document));
49 }
50
51 bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
52 {
53     if (attrName == widthAttr || attrName == heightAttr) {
54         result = eUniversal;
55         return false;
56     }
57     
58     if (attrName == alignAttr) {
59         result = eReplaced; // Share with <img> since the alignment behavior is the same.
60         return false;
61     }
62     
63     if (attrName == frameborderAttr) {
64         result = eReplaced;
65         return false;
66     }
67
68     return HTMLFrameElementBase::mapToEntry(attrName, result);
69 }
70
71 static SandboxFlags parseSandboxAttribute(Attribute* attribute)
72 {
73     if (attribute->isNull())
74         return SandboxNone;
75
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();
80     unsigned start = 0;
81     while (true) {
82         while (start < length && isASCIISpace(characters[start]))
83             ++start;
84         if (start >= length)
85             break;
86         unsigned end = start + 1;
87         while (end < length && !isASCIISpace(characters[end]))
88             ++end;
89
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;
100
101         start = end + 1;
102     }
103
104     return flags;
105 }
106
107 void HTMLIFrameElement::parseMappedAttribute(Attribute* attr)
108 {
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);
121         }
122         m_name = 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));
131     else
132         HTMLFrameElementBase::parseMappedAttribute(attr);
133 }
134
135 bool HTMLIFrameElement::rendererIsNeeded(const NodeRenderingContext& context)
136 {
137     return isURLAllowed() && context.style()->display() != NONE;
138 }
139
140 RenderObject* HTMLIFrameElement::createRenderer(RenderArena* arena, RenderStyle*)
141 {
142     return new (arena) RenderIFrame(this);
143 }
144
145 void HTMLIFrameElement::insertedIntoDocument()
146 {
147     if (document()->isHTMLDocument())
148         static_cast<HTMLDocument*>(document())->addExtraNamedItem(m_name);
149
150     HTMLFrameElementBase::insertedIntoDocument();
151 }
152
153 void HTMLIFrameElement::removedFromDocument()
154 {
155     if (document()->isHTMLDocument())
156         static_cast<HTMLDocument*>(document())->removeExtraNamedItem(m_name);
157
158     HTMLFrameElementBase::removedFromDocument();
159 }
160
161 bool HTMLIFrameElement::isURLAttribute(Attribute* attr) const
162 {
163     return attr->name() == srcAttr;
164 }
165
166 }