1/*
2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
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
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#pragma once
22
23#include "HTMLElement.h"
24#include "ReferrerPolicy.h"
25#include <wtf/HashCountedSet.h>
26#include <wtf/NeverDestroyed.h>
27
28namespace WebCore {
29
30class DOMWindow;
31class Frame;
32class RenderWidget;
33class SVGDocument;
34
35class HTMLFrameOwnerElement : public HTMLElement {
36 WTF_MAKE_ISO_ALLOCATED(HTMLFrameOwnerElement);
37public:
38 virtual ~HTMLFrameOwnerElement();
39
40 Frame* contentFrame() const { return m_contentFrame; }
41 WEBCORE_EXPORT WindowProxy* contentWindow() const;
42 WEBCORE_EXPORT Document* contentDocument() const;
43
44 void setContentFrame(Frame*);
45 void clearContentFrame();
46
47 void disconnectContentFrame();
48
49 // Most subclasses use RenderWidget (either RenderEmbeddedObject or RenderIFrame)
50 // except for HTMLObjectElement and HTMLEmbedElement which may return any
51 // RenderElement when using fallback content.
52 RenderWidget* renderWidget() const;
53
54 ExceptionOr<Document&> getSVGDocument() const;
55
56 virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; }
57
58 SandboxFlags sandboxFlags() const { return m_sandboxFlags; }
59
60 void scheduleInvalidateStyleAndLayerComposition();
61
62 virtual bool isURLAllowed(const URL&) const { return true; }
63
64 virtual ReferrerPolicy referrerPolicy() const { return ReferrerPolicy::EmptyString; }
65
66protected:
67 HTMLFrameOwnerElement(const QualifiedName& tagName, Document&);
68 void setSandboxFlags(SandboxFlags);
69
70private:
71 bool isKeyboardFocusable(KeyboardEvent*) const override;
72 bool isFrameOwnerElement() const final { return true; }
73
74 Frame* m_contentFrame;
75 SandboxFlags m_sandboxFlags;
76};
77
78class SubframeLoadingDisabler {
79public:
80 explicit SubframeLoadingDisabler(ContainerNode* root)
81 : m_root(root)
82 {
83 if (m_root)
84 disabledSubtreeRoots().add(m_root);
85 }
86
87 ~SubframeLoadingDisabler()
88 {
89 if (m_root)
90 disabledSubtreeRoots().remove(m_root);
91 }
92
93 static bool canLoadFrame(HTMLFrameOwnerElement&);
94
95private:
96 static HashCountedSet<ContainerNode*>& disabledSubtreeRoots()
97 {
98 static NeverDestroyed<HashCountedSet<ContainerNode*>> nodes;
99 return nodes;
100 }
101
102 ContainerNode* m_root;
103};
104
105} // namespace WebCore
106
107SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLFrameOwnerElement)
108 static bool isType(const WebCore::Node& node) { return node.isFrameOwnerElement(); }
109SPECIALIZE_TYPE_TRAITS_END()
110