blob: 33561ce92e0c7198c5dd93677abae45249b3f79e [file] [log] [blame]
darincb3524a2006-12-11 23:40:47 +00001/*
darin@apple.com4c71dea2019-07-17 20:02:37 +00002 * Copyright (C) 2006-2019 Apple Inc. All rights reserved.
darincb3524a2006-12-11 23:40:47 +00003 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
ddkilzerc8eccec2007-09-26 02:29:57 +000016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
darincb3524a2006-12-11 23:40:47 +000018 *
19 */
20
21#include "config.h"
22#include "HTMLFrameOwnerElement.h"
23
weinig6d162e72007-07-17 17:46:39 +000024#include "DOMWindow.h"
darincb3524a2006-12-11 23:40:47 +000025#include "Frame.h"
weinig15901862007-10-26 21:44:49 +000026#include "FrameLoader.h"
akling@apple.comb95111f2013-09-12 05:21:14 +000027#include "RenderWidget.h"
jer.noble@apple.com872903d2021-10-08 23:31:51 +000028#include "SVGDocument.h"
29#include "SVGElementTypeHelpers.h"
darin@apple.com4c71dea2019-07-17 20:02:37 +000030#include "ScriptController.h"
antti@apple.comf269b272013-08-16 06:33:51 +000031#include "ShadowRoot.h"
antti@apple.com2098dc82016-01-07 08:16:49 +000032#include "StyleTreeResolver.h"
fpizlo@apple.com197cd322018-03-17 06:11:00 +000033#include <wtf/IsoMallocInlines.h>
ossy@webkit.org66d8c0a2014-02-05 11:42:35 +000034#include <wtf/Ref.h>
eric@webkit.org346b6362008-02-01 09:35:00 +000035
darincb3524a2006-12-11 23:40:47 +000036namespace WebCore {
37
fpizlo@apple.com197cd322018-03-17 06:11:00 +000038WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLFrameOwnerElement);
39
weinig@apple.comdedf67e2013-09-15 05:23:01 +000040HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Document& document)
esprehn@chromium.org941a2422013-02-16 02:36:29 +000041 : HTMLElement(tagName, document)
darincb3524a2006-12-11 23:40:47 +000042{
43}
44
akling@apple.comb95111f2013-09-12 05:21:14 +000045RenderWidget* HTMLFrameOwnerElement::renderWidget() const
eric@webkit.org4eeaef72010-09-02 02:11:45 +000046{
47 // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers
48 // when using fallback content.
cdumez@apple.com3abcc792014-10-20 03:42:03 +000049 if (!is<RenderWidget>(renderer()))
50 return nullptr;
51 return downcast<RenderWidget>(renderer());
eric@webkit.org4eeaef72010-09-02 02:11:45 +000052}
53
achristensen@apple.com2ace43d2020-11-05 16:54:48 +000054void HTMLFrameOwnerElement::setContentFrame(Frame& frame)
commit-queue@webkit.org8d4344a2012-11-13 04:44:20 +000055{
56 // Make sure we will not end up with two frames referencing the same owner element.
57 ASSERT(!m_contentFrame || m_contentFrame->ownerElement() != this);
commit-queue@webkit.org8d4344a2012-11-13 04:44:20 +000058 // Disconnected frames should not be allowed to load.
cdumez@apple.com85cc2622017-02-02 21:29:15 +000059 ASSERT(isConnected());
cdumez@apple.comf440d4c2021-10-13 15:37:52 +000060 m_contentFrame = frame;
esprehn@chromium.org64fc1e82013-01-18 03:22:00 +000061
jiewen_tan@apple.com147b9342017-10-19 01:01:21 +000062 for (RefPtr<ContainerNode> node = this; node; node = node->parentOrShadowHostNode())
esprehn@chromium.org64fc1e82013-01-18 03:22:00 +000063 node->incrementConnectedSubframeCount();
commit-queue@webkit.org8d4344a2012-11-13 04:44:20 +000064}
65
commit-queue@webkit.orgbe321c02013-01-25 10:48:14 +000066void HTMLFrameOwnerElement::clearContentFrame()
67{
68 if (!m_contentFrame)
69 return;
70
darin@apple.com4c71dea2019-07-17 20:02:37 +000071 m_contentFrame = nullptr;
commit-queue@webkit.orgbe321c02013-01-25 10:48:14 +000072
jiewen_tan@apple.com147b9342017-10-19 01:01:21 +000073 for (RefPtr<ContainerNode> node = this; node; node = node->parentOrShadowHostNode())
commit-queue@webkit.orgbe321c02013-01-25 10:48:14 +000074 node->decrementConnectedSubframeCount();
75}
76
morrita@google.com1b44b4d2012-05-10 11:37:09 +000077void HTMLFrameOwnerElement::disconnectContentFrame()
weinig15901862007-10-26 21:44:49 +000078{
achristensen@apple.com2ace43d2020-11-05 16:54:48 +000079 if (RefPtr<Frame> frame = m_contentFrame.get()) {
andersca@apple.comdf550b92013-08-15 22:17:17 +000080 frame->loader().frameDetached();
eric@webkit.org8cc44242010-09-10 09:12:11 +000081 frame->disconnectOwnerElement();
weinig15901862007-10-26 21:44:49 +000082 }
weinig15901862007-10-26 21:44:49 +000083}
84
darincb3524a2006-12-11 23:40:47 +000085HTMLFrameOwnerElement::~HTMLFrameOwnerElement()
86{
87 if (m_contentFrame)
88 m_contentFrame->disconnectOwnerElement();
89}
90
91Document* HTMLFrameOwnerElement::contentDocument() const
92{
bfulgham@apple.com81c797a2017-11-17 23:34:09 +000093 return m_contentFrame ? m_contentFrame->document() : nullptr;
darincb3524a2006-12-11 23:40:47 +000094}
95
cdumez@apple.com240d0172018-04-27 22:11:00 +000096WindowProxy* HTMLFrameOwnerElement::contentWindow() const
weinig6d162e72007-07-17 17:46:39 +000097{
cdumez@apple.com240d0172018-04-27 22:11:00 +000098 return m_contentFrame ? &m_contentFrame->windowProxy() : nullptr;
darincb3524a2006-12-11 23:40:47 +000099}
weinig6d162e72007-07-17 17:46:39 +0000100
abarth@webkit.orgb8a10552009-12-02 02:40:35 +0000101void HTMLFrameOwnerElement::setSandboxFlags(SandboxFlags flags)
102{
abarth@webkit.orgb8a10552009-12-02 02:40:35 +0000103 m_sandboxFlags = flags;
abarth@webkit.orgb8a10552009-12-02 02:40:35 +0000104}
105
darin@apple.com0b38bee2018-02-08 06:06:29 +0000106bool HTMLFrameOwnerElement::isKeyboardFocusable(KeyboardEvent* event) const
arv@chromium.org2cdc7502011-04-08 23:37:33 +0000107{
108 return m_contentFrame && HTMLElement::isKeyboardFocusable(event);
109}
110
darin@apple.comf412fd12016-10-31 15:54:51 +0000111ExceptionOr<Document&> HTMLFrameOwnerElement::getSVGDocument() const
eric@webkit.org346b6362008-02-01 09:35:00 +0000112{
bfulgham@apple.com81c797a2017-11-17 23:34:09 +0000113 auto* document = contentDocument();
cdumez@apple.coma9c60c92014-10-02 19:39:41 +0000114 if (is<SVGDocument>(document))
bfulgham@apple.com81c797a2017-11-17 23:34:09 +0000115 return *document;
eric@webkit.org346b6362008-02-01 09:35:00 +0000116 // Spec: http://www.w3.org/TR/SVG/struct.html#InterfaceGetSVGDocument
cdumez@apple.com750df372017-07-25 03:59:12 +0000117 return Exception { NotSupportedError };
eric@webkit.org346b6362008-02-01 09:35:00 +0000118}
eric@webkit.org346b6362008-02-01 09:35:00 +0000119
simon.fraser@apple.comc65f2632017-09-05 18:17:29 +0000120void HTMLFrameOwnerElement::scheduleInvalidateStyleAndLayerComposition()
andersca@apple.com20bdec42013-12-20 22:34:31 +0000121{
darin@apple.comcdcb72f2014-04-06 20:27:07 +0000122 if (Style::postResolutionCallbacksAreSuspended()) {
123 RefPtr<HTMLFrameOwnerElement> element = this;
ntim@apple.com49ac4102021-09-27 21:21:37 +0000124 Style::deprecatedQueuePostResolutionCallback([element] {
antti@apple.com1c455832016-10-18 12:28:55 +0000125 element->invalidateStyleAndLayerComposition();
darin@apple.comcdcb72f2014-04-06 20:27:07 +0000126 });
127 } else
antti@apple.com1c455832016-10-18 12:28:55 +0000128 invalidateStyleAndLayerComposition();
andersca@apple.com20bdec42013-12-20 22:34:31 +0000129}
130
darin@apple.com4c71dea2019-07-17 20:02:37 +0000131bool HTMLFrameOwnerElement::isProhibitedSelfReference(const URL& completeURL) const
132{
133 // We allow one level of self-reference because some websites depend on that, but we don't allow more than one.
134 bool foundOneSelfReference = false;
135 for (auto* frame = document().frame(); frame; frame = frame->tree().parent()) {
136 if (equalIgnoringFragmentIdentifier(frame->document()->url(), completeURL)) {
137 if (foundOneSelfReference)
138 return true;
139 foundOneSelfReference = true;
140 }
141 }
142 return false;
143}
144
weinig@apple.com2e067212013-09-23 03:40:47 +0000145bool SubframeLoadingDisabler::canLoadFrame(HTMLFrameOwnerElement& owner)
antti@apple.comf269b272013-08-16 06:33:51 +0000146{
jiewen_tan@apple.com147b9342017-10-19 01:01:21 +0000147 for (RefPtr<ContainerNode> node = &owner; node; node = node->parentOrShadowHostNode()) {
148 if (disabledSubtreeRoots().contains(node.get()))
antti@apple.comf269b272013-08-16 06:33:51 +0000149 return false;
150 }
151 return true;
152}
153
weinig6d162e72007-07-17 17:46:39 +0000154} // namespace WebCore