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/frame/UseCounter.h"
32 #include "core/html/HTMLDocument.h"
33 #include "core/inspector/ConsoleMessage.h"
34 #include "core/layout/LayoutIFrame.h"
38 using namespace HTMLNames
;
40 inline HTMLIFrameElement::HTMLIFrameElement(Document
& document
)
41 : HTMLFrameElementBase(iframeTag
, document
)
42 , m_didLoadNonEmptyDocument(false)
43 , m_sandbox(DOMSettableTokenList::create(this))
44 , m_referrerPolicy(ReferrerPolicyDefault
)
48 DEFINE_NODE_FACTORY(HTMLIFrameElement
)
50 DEFINE_TRACE(HTMLIFrameElement
)
52 visitor
->trace(m_sandbox
);
53 HTMLFrameElementBase::trace(visitor
);
54 DOMSettableTokenListObserver::trace(visitor
);
57 HTMLIFrameElement::~HTMLIFrameElement()
60 m_sandbox
->setObserver(nullptr);
64 DOMSettableTokenList
* HTMLIFrameElement::sandbox() const
66 return m_sandbox
.get();
69 bool HTMLIFrameElement::isPresentationAttribute(const QualifiedName
& name
) const
71 if (name
== widthAttr
|| name
== heightAttr
|| name
== alignAttr
|| name
== frameborderAttr
)
73 return HTMLFrameElementBase::isPresentationAttribute(name
);
76 void HTMLIFrameElement::collectStyleForPresentationAttribute(const QualifiedName
& name
, const AtomicString
& value
, MutableStylePropertySet
* style
)
78 if (name
== widthAttr
) {
79 addHTMLLengthToStyle(style
, CSSPropertyWidth
, value
);
80 } else if (name
== heightAttr
) {
81 addHTMLLengthToStyle(style
, CSSPropertyHeight
, value
);
82 } else if (name
== alignAttr
) {
83 applyAlignmentAttributeToStyle(value
, style
);
84 } else if (name
== frameborderAttr
) {
85 // LocalFrame border doesn't really match the HTML4 spec definition for iframes. It simply adds
86 // a presentational hint that the border should be off if set to zero.
88 // Add a rule that nulls out our border width.
89 addPropertyToPresentationAttributeStyle(style
, CSSPropertyBorderWidth
, 0, CSSPrimitiveValue::UnitType::Pixels
);
92 HTMLFrameElementBase::collectStyleForPresentationAttribute(name
, value
, style
);
96 void HTMLIFrameElement::attributeWillChange(const QualifiedName
& name
, const AtomicString
& oldValue
, const AtomicString
& newValue
)
98 if (name
== srcAttr
&& inDocument()) {
99 V8DOMActivityLogger
* activityLogger
= V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld();
100 if (activityLogger
) {
102 argv
.append("iframe");
103 argv
.append(srcAttr
.toString());
104 argv
.append(oldValue
);
105 argv
.append(newValue
);
106 activityLogger
->logEvent("blinkSetAttribute", argv
.size(), argv
.data());
109 HTMLFrameElementBase::attributeWillChange(name
, oldValue
, newValue
);
112 void HTMLIFrameElement::parseAttribute(const QualifiedName
& name
, const AtomicString
& value
)
114 if (name
== nameAttr
) {
115 if (inDocument() && document().isHTMLDocument() && !isInShadowTree()) {
116 HTMLDocument
& document
= toHTMLDocument(this->document());
117 document
.removeExtraNamedItem(m_name
);
118 document
.addExtraNamedItem(value
);
121 } else if (name
== sandboxAttr
) {
122 m_sandbox
->setValue(value
);
123 UseCounter::count(document(), UseCounter::SandboxViaIFrame
);
124 } else if (RuntimeEnabledFeatures::referrerPolicyAttributeEnabled() && name
== referrerpolicyAttr
) {
125 m_referrerPolicy
= ReferrerPolicyDefault
;
127 SecurityPolicy::referrerPolicyFromString(value
, &m_referrerPolicy
);
129 HTMLFrameElementBase::parseAttribute(name
, value
);
133 bool HTMLIFrameElement::layoutObjectIsNeeded(const ComputedStyle
& style
)
135 return isURLAllowed() && HTMLElement::layoutObjectIsNeeded(style
);
138 LayoutObject
* HTMLIFrameElement::createLayoutObject(const ComputedStyle
&)
140 return new LayoutIFrame(this);
143 Node::InsertionNotificationRequest
HTMLIFrameElement::insertedInto(ContainerNode
* insertionPoint
)
145 if (insertionPoint
->inDocument()) {
146 V8DOMActivityLogger
* activityLogger
= V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld();
147 if (activityLogger
) {
149 argv
.append("iframe");
150 argv
.append(fastGetAttribute(srcAttr
));
151 activityLogger
->logEvent("blinkAddElement", argv
.size(), argv
.data());
154 InsertionNotificationRequest result
= HTMLFrameElementBase::insertedInto(insertionPoint
);
155 if (insertionPoint
->inDocument() && document().isHTMLDocument() && !insertionPoint
->isInShadowTree())
156 toHTMLDocument(document()).addExtraNamedItem(m_name
);
160 void HTMLIFrameElement::removedFrom(ContainerNode
* insertionPoint
)
162 HTMLFrameElementBase::removedFrom(insertionPoint
);
163 if (insertionPoint
->inDocument() && document().isHTMLDocument() && !insertionPoint
->isInShadowTree())
164 toHTMLDocument(document()).removeExtraNamedItem(m_name
);
167 bool HTMLIFrameElement::isInteractiveContent() const
172 void HTMLIFrameElement::valueChanged()
174 String invalidTokens
;
175 setSandboxFlags(m_sandbox
->value().isNull() ? SandboxNone
: parseSandboxPolicy(m_sandbox
->tokens(), invalidTokens
));
176 if (!invalidTokens
.isNull())
177 document().addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, ErrorMessageLevel
, "Error while parsing the 'sandbox' attribute: " + invalidTokens
));
178 setSynchronizedLazyAttribute(sandboxAttr
, m_sandbox
->value());
181 ReferrerPolicy
HTMLIFrameElement::referrerPolicyAttribute()
183 return m_referrerPolicy
;