darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 1 | /* |
darin@apple.com | 4c71dea | 2019-07-17 20:02:37 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006-2019 Apple Inc. All rights reserved. |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 3 | * |
| 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | #include "HTMLFrameOwnerElement.h" |
| 23 | |
weinig | 6d162e7 | 2007-07-17 17:46:39 +0000 | [diff] [blame] | 24 | #include "DOMWindow.h" |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 25 | #include "Frame.h" |
weinig | 1590186 | 2007-10-26 21:44:49 +0000 | [diff] [blame] | 26 | #include "FrameLoader.h" |
akling@apple.com | b95111f | 2013-09-12 05:21:14 +0000 | [diff] [blame] | 27 | #include "RenderWidget.h" |
jer.noble@apple.com | 872903d | 2021-10-08 23:31:51 +0000 | [diff] [blame] | 28 | #include "SVGDocument.h" |
| 29 | #include "SVGElementTypeHelpers.h" |
darin@apple.com | 4c71dea | 2019-07-17 20:02:37 +0000 | [diff] [blame] | 30 | #include "ScriptController.h" |
antti@apple.com | f269b27 | 2013-08-16 06:33:51 +0000 | [diff] [blame] | 31 | #include "ShadowRoot.h" |
antti@apple.com | 2098dc8 | 2016-01-07 08:16:49 +0000 | [diff] [blame] | 32 | #include "StyleTreeResolver.h" |
fpizlo@apple.com | 197cd32 | 2018-03-17 06:11:00 +0000 | [diff] [blame] | 33 | #include <wtf/IsoMallocInlines.h> |
ossy@webkit.org | 66d8c0a | 2014-02-05 11:42:35 +0000 | [diff] [blame] | 34 | #include <wtf/Ref.h> |
eric@webkit.org | 346b636 | 2008-02-01 09:35:00 +0000 | [diff] [blame] | 35 | |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 36 | namespace WebCore { |
| 37 | |
fpizlo@apple.com | 197cd32 | 2018-03-17 06:11:00 +0000 | [diff] [blame] | 38 | WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLFrameOwnerElement); |
| 39 | |
weinig@apple.com | dedf67e | 2013-09-15 05:23:01 +0000 | [diff] [blame] | 40 | HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Document& document) |
esprehn@chromium.org | 941a242 | 2013-02-16 02:36:29 +0000 | [diff] [blame] | 41 | : HTMLElement(tagName, document) |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
akling@apple.com | b95111f | 2013-09-12 05:21:14 +0000 | [diff] [blame] | 45 | RenderWidget* HTMLFrameOwnerElement::renderWidget() const |
eric@webkit.org | 4eeaef7 | 2010-09-02 02:11:45 +0000 | [diff] [blame] | 46 | { |
| 47 | // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers |
| 48 | // when using fallback content. |
cdumez@apple.com | 3abcc79 | 2014-10-20 03:42:03 +0000 | [diff] [blame] | 49 | if (!is<RenderWidget>(renderer())) |
| 50 | return nullptr; |
| 51 | return downcast<RenderWidget>(renderer()); |
eric@webkit.org | 4eeaef7 | 2010-09-02 02:11:45 +0000 | [diff] [blame] | 52 | } |
| 53 | |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 54 | void HTMLFrameOwnerElement::setContentFrame(Frame& frame) |
commit-queue@webkit.org | 8d4344a | 2012-11-13 04:44:20 +0000 | [diff] [blame] | 55 | { |
| 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.org | 8d4344a | 2012-11-13 04:44:20 +0000 | [diff] [blame] | 58 | // Disconnected frames should not be allowed to load. |
cdumez@apple.com | 85cc262 | 2017-02-02 21:29:15 +0000 | [diff] [blame] | 59 | ASSERT(isConnected()); |
cdumez@apple.com | f440d4c | 2021-10-13 15:37:52 +0000 | [diff] [blame] | 60 | m_contentFrame = frame; |
esprehn@chromium.org | 64fc1e8 | 2013-01-18 03:22:00 +0000 | [diff] [blame] | 61 | |
jiewen_tan@apple.com | 147b934 | 2017-10-19 01:01:21 +0000 | [diff] [blame] | 62 | for (RefPtr<ContainerNode> node = this; node; node = node->parentOrShadowHostNode()) |
esprehn@chromium.org | 64fc1e8 | 2013-01-18 03:22:00 +0000 | [diff] [blame] | 63 | node->incrementConnectedSubframeCount(); |
commit-queue@webkit.org | 8d4344a | 2012-11-13 04:44:20 +0000 | [diff] [blame] | 64 | } |
| 65 | |
commit-queue@webkit.org | be321c0 | 2013-01-25 10:48:14 +0000 | [diff] [blame] | 66 | void HTMLFrameOwnerElement::clearContentFrame() |
| 67 | { |
| 68 | if (!m_contentFrame) |
| 69 | return; |
| 70 | |
darin@apple.com | 4c71dea | 2019-07-17 20:02:37 +0000 | [diff] [blame] | 71 | m_contentFrame = nullptr; |
commit-queue@webkit.org | be321c0 | 2013-01-25 10:48:14 +0000 | [diff] [blame] | 72 | |
jiewen_tan@apple.com | 147b934 | 2017-10-19 01:01:21 +0000 | [diff] [blame] | 73 | for (RefPtr<ContainerNode> node = this; node; node = node->parentOrShadowHostNode()) |
commit-queue@webkit.org | be321c0 | 2013-01-25 10:48:14 +0000 | [diff] [blame] | 74 | node->decrementConnectedSubframeCount(); |
| 75 | } |
| 76 | |
morrita@google.com | 1b44b4d | 2012-05-10 11:37:09 +0000 | [diff] [blame] | 77 | void HTMLFrameOwnerElement::disconnectContentFrame() |
weinig | 1590186 | 2007-10-26 21:44:49 +0000 | [diff] [blame] | 78 | { |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 79 | if (RefPtr<Frame> frame = m_contentFrame.get()) { |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 80 | frame->loader().frameDetached(); |
eric@webkit.org | 8cc4424 | 2010-09-10 09:12:11 +0000 | [diff] [blame] | 81 | frame->disconnectOwnerElement(); |
weinig | 1590186 | 2007-10-26 21:44:49 +0000 | [diff] [blame] | 82 | } |
weinig | 1590186 | 2007-10-26 21:44:49 +0000 | [diff] [blame] | 83 | } |
| 84 | |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 85 | HTMLFrameOwnerElement::~HTMLFrameOwnerElement() |
| 86 | { |
| 87 | if (m_contentFrame) |
| 88 | m_contentFrame->disconnectOwnerElement(); |
| 89 | } |
| 90 | |
| 91 | Document* HTMLFrameOwnerElement::contentDocument() const |
| 92 | { |
bfulgham@apple.com | 81c797a | 2017-11-17 23:34:09 +0000 | [diff] [blame] | 93 | return m_contentFrame ? m_contentFrame->document() : nullptr; |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 94 | } |
| 95 | |
cdumez@apple.com | 240d017 | 2018-04-27 22:11:00 +0000 | [diff] [blame] | 96 | WindowProxy* HTMLFrameOwnerElement::contentWindow() const |
weinig | 6d162e7 | 2007-07-17 17:46:39 +0000 | [diff] [blame] | 97 | { |
cdumez@apple.com | 240d017 | 2018-04-27 22:11:00 +0000 | [diff] [blame] | 98 | return m_contentFrame ? &m_contentFrame->windowProxy() : nullptr; |
darin | cb3524a | 2006-12-11 23:40:47 +0000 | [diff] [blame] | 99 | } |
weinig | 6d162e7 | 2007-07-17 17:46:39 +0000 | [diff] [blame] | 100 | |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 101 | void HTMLFrameOwnerElement::setSandboxFlags(SandboxFlags flags) |
| 102 | { |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 103 | m_sandboxFlags = flags; |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 104 | } |
| 105 | |
darin@apple.com | 0b38bee | 2018-02-08 06:06:29 +0000 | [diff] [blame] | 106 | bool HTMLFrameOwnerElement::isKeyboardFocusable(KeyboardEvent* event) const |
arv@chromium.org | 2cdc750 | 2011-04-08 23:37:33 +0000 | [diff] [blame] | 107 | { |
| 108 | return m_contentFrame && HTMLElement::isKeyboardFocusable(event); |
| 109 | } |
| 110 | |
darin@apple.com | f412fd1 | 2016-10-31 15:54:51 +0000 | [diff] [blame] | 111 | ExceptionOr<Document&> HTMLFrameOwnerElement::getSVGDocument() const |
eric@webkit.org | 346b636 | 2008-02-01 09:35:00 +0000 | [diff] [blame] | 112 | { |
bfulgham@apple.com | 81c797a | 2017-11-17 23:34:09 +0000 | [diff] [blame] | 113 | auto* document = contentDocument(); |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 114 | if (is<SVGDocument>(document)) |
bfulgham@apple.com | 81c797a | 2017-11-17 23:34:09 +0000 | [diff] [blame] | 115 | return *document; |
eric@webkit.org | 346b636 | 2008-02-01 09:35:00 +0000 | [diff] [blame] | 116 | // Spec: http://www.w3.org/TR/SVG/struct.html#InterfaceGetSVGDocument |
cdumez@apple.com | 750df37 | 2017-07-25 03:59:12 +0000 | [diff] [blame] | 117 | return Exception { NotSupportedError }; |
eric@webkit.org | 346b636 | 2008-02-01 09:35:00 +0000 | [diff] [blame] | 118 | } |
eric@webkit.org | 346b636 | 2008-02-01 09:35:00 +0000 | [diff] [blame] | 119 | |
simon.fraser@apple.com | c65f263 | 2017-09-05 18:17:29 +0000 | [diff] [blame] | 120 | void HTMLFrameOwnerElement::scheduleInvalidateStyleAndLayerComposition() |
andersca@apple.com | 20bdec4 | 2013-12-20 22:34:31 +0000 | [diff] [blame] | 121 | { |
darin@apple.com | cdcb72f | 2014-04-06 20:27:07 +0000 | [diff] [blame] | 122 | if (Style::postResolutionCallbacksAreSuspended()) { |
| 123 | RefPtr<HTMLFrameOwnerElement> element = this; |
ntim@apple.com | 49ac410 | 2021-09-27 21:21:37 +0000 | [diff] [blame] | 124 | Style::deprecatedQueuePostResolutionCallback([element] { |
antti@apple.com | 1c45583 | 2016-10-18 12:28:55 +0000 | [diff] [blame] | 125 | element->invalidateStyleAndLayerComposition(); |
darin@apple.com | cdcb72f | 2014-04-06 20:27:07 +0000 | [diff] [blame] | 126 | }); |
| 127 | } else |
antti@apple.com | 1c45583 | 2016-10-18 12:28:55 +0000 | [diff] [blame] | 128 | invalidateStyleAndLayerComposition(); |
andersca@apple.com | 20bdec4 | 2013-12-20 22:34:31 +0000 | [diff] [blame] | 129 | } |
| 130 | |
darin@apple.com | 4c71dea | 2019-07-17 20:02:37 +0000 | [diff] [blame] | 131 | bool 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.com | 2e06721 | 2013-09-23 03:40:47 +0000 | [diff] [blame] | 145 | bool SubframeLoadingDisabler::canLoadFrame(HTMLFrameOwnerElement& owner) |
antti@apple.com | f269b27 | 2013-08-16 06:33:51 +0000 | [diff] [blame] | 146 | { |
jiewen_tan@apple.com | 147b934 | 2017-10-19 01:01:21 +0000 | [diff] [blame] | 147 | for (RefPtr<ContainerNode> node = &owner; node; node = node->parentOrShadowHostNode()) { |
| 148 | if (disabledSubtreeRoots().contains(node.get())) |
antti@apple.com | f269b27 | 2013-08-16 06:33:51 +0000 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | return true; |
| 152 | } |
| 153 | |
weinig | 6d162e7 | 2007-07-17 17:46:39 +0000 | [diff] [blame] | 154 | } // namespace WebCore |