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 "core/html/HTMLIFrameElement.h"
28 #include "bindings/core/v8/V8DOMActivityLogger.h"
29 #include "core/CSSPropertyNames.h"
30 #include "core/HTMLNames.h"
31 #include "core/html/HTMLDocument.h"
32 #include "core/inspector/ConsoleMessage.h"
33 #include "core/rendering/RenderIFrame.h"
37 using namespace HTMLNames;
39 inline HTMLIFrameElement::HTMLIFrameElement(Document& document)
40 : HTMLFrameElementBase(iframeTag, document)
41 , m_didLoadNonEmptyDocument(false)
45 DEFINE_NODE_FACTORY(HTMLIFrameElement)
47 bool HTMLIFrameElement::isPresentationAttribute(const QualifiedName& name) const
49 if (name == widthAttr || name == heightAttr || name == alignAttr || name == frameborderAttr)
51 return HTMLFrameElementBase::isPresentationAttribute(name);
54 void HTMLIFrameElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
56 if (name == widthAttr)
57 addHTMLLengthToStyle(style, CSSPropertyWidth, value);
58 else if (name == heightAttr)
59 addHTMLLengthToStyle(style, CSSPropertyHeight, value);
60 else if (name == alignAttr)
61 applyAlignmentAttributeToStyle(value, style);
62 else if (name == frameborderAttr) {
63 // LocalFrame border doesn't really match the HTML4 spec definition for iframes. It simply adds
64 // a presentational hint that the border should be off if set to zero.
66 // Add a rule that nulls out our border width.
67 addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, 0, CSSPrimitiveValue::CSS_PX);
70 HTMLFrameElementBase::collectStyleForPresentationAttribute(name, value, style);
73 void HTMLIFrameElement::attributeWillChange(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
75 if (name == srcAttr && inDocument()) {
76 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld();
79 argv.append("iframe");
80 argv.append(srcAttr.toString());
81 argv.append(oldValue);
82 argv.append(newValue);
83 activityLogger->logEvent("blinkSetAttribute", argv.size(), argv.data());
86 HTMLFrameElementBase::attributeWillChange(name, oldValue, newValue);
89 void HTMLIFrameElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
91 if (name == nameAttr) {
92 if (inDocument() && document().isHTMLDocument() && !isInShadowTree()) {
93 HTMLDocument& document = toHTMLDocument(this->document());
94 document.removeExtraNamedItem(m_name);
95 document.addExtraNamedItem(value);
98 } else if (name == sandboxAttr) {
100 setSandboxFlags(value.isNull() ? SandboxNone : parseSandboxPolicy(value, invalidTokens));
101 if (!invalidTokens.isNull())
102 document().addConsoleMessage(ConsoleMessage::create(OtherMessageSource, ErrorMessageLevel, "Error while parsing the 'sandbox' attribute: " + invalidTokens));
104 HTMLFrameElementBase::parseAttribute(name, value);
108 bool HTMLIFrameElement::rendererIsNeeded(const RenderStyle& style)
110 return isURLAllowed() && HTMLElement::rendererIsNeeded(style);
113 RenderObject* HTMLIFrameElement::createRenderer(RenderStyle*)
115 return new RenderIFrame(this);
118 Node::InsertionNotificationRequest HTMLIFrameElement::insertedInto(ContainerNode* insertionPoint)
120 if (insertionPoint->inDocument()) {
121 V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld();
122 if (activityLogger) {
124 argv.append("iframe");
125 argv.append(fastGetAttribute(srcAttr));
126 activityLogger->logEvent("blinkAddElement", argv.size(), argv.data());
129 InsertionNotificationRequest result = HTMLFrameElementBase::insertedInto(insertionPoint);
130 if (insertionPoint->inDocument() && document().isHTMLDocument() && !insertionPoint->isInShadowTree())
131 toHTMLDocument(document()).addExtraNamedItem(m_name);
135 void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint)
137 HTMLFrameElementBase::removedFrom(insertionPoint);
138 if (insertionPoint->inDocument() && document().isHTMLDocument() && !insertionPoint->isInShadowTree())
139 toHTMLDocument(document()).removeExtraNamedItem(m_name);
142 bool HTMLIFrameElement::isInteractiveContent() const