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#ifndef HTMLFrameOwnerElement_h
22#define HTMLFrameOwnerElement_h
23
24#include "FrameLoaderTypes.h"
25#include "HTMLElement.h"
26#include <wtf/HashCountedSet.h>
27
28namespace WebCore {
29
30class DOMWindow;
31class Frame;
32class RenderPart;
33
34#if ENABLE(SVG)
35class SVGDocument;
36#endif
37
38class HTMLFrameOwnerElement : public HTMLElement {
39public:
40    virtual ~HTMLFrameOwnerElement();
41
42    Frame* contentFrame() const { return m_contentFrame; }
43    DOMWindow* contentWindow() const;
44    Document* contentDocument() const;
45
46    void setContentFrame(Frame*);
47    void clearContentFrame();
48
49    void disconnectContentFrame();
50
51    // Most subclasses use RenderPart (either RenderEmbeddedObject or RenderIFrame)
52    // except for HTMLObjectElement and HTMLEmbedElement which may return any
53    // RenderObject when using fallback content.
54    RenderPart* renderPart() const;
55
56#if ENABLE(SVG)
57    SVGDocument* getSVGDocument(ExceptionCode&) const;
58#endif
59
60    virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; }
61
62    SandboxFlags sandboxFlags() const { return m_sandboxFlags; }
63
64protected:
65    HTMLFrameOwnerElement(const QualifiedName& tagName, Document*);
66    void setSandboxFlags(SandboxFlags);
67
68private:
69    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
70    virtual bool isFrameOwnerElement() const OVERRIDE { return true; }
71
72    Frame* m_contentFrame;
73    SandboxFlags m_sandboxFlags;
74};
75
76inline HTMLFrameOwnerElement* toFrameOwnerElement(Node* node)
77{
78    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isFrameOwnerElement());
79    return static_cast<HTMLFrameOwnerElement*>(node);
80}
81
82class SubframeLoadingDisabler {
83public:
84    explicit SubframeLoadingDisabler(Node* root)
85        : m_root(root)
86    {
87        disabledSubtreeRoots().add(m_root);
88    }
89
90    ~SubframeLoadingDisabler()
91    {
92        disabledSubtreeRoots().remove(m_root);
93    }
94
95    static bool canLoadFrame(HTMLFrameOwnerElement* owner)
96    {
97        for (Node* node = owner; node; node = node->parentOrShadowHostNode()) {
98            if (disabledSubtreeRoots().contains(node))
99                return false;
100        }
101        return true;
102    }
103
104private:
105    static HashCountedSet<Node*>& disabledSubtreeRoots()
106    {
107        DEFINE_STATIC_LOCAL(HashCountedSet<Node*>, nodes, ());
108        return nodes;
109    }
110
111    Node* m_root;
112};
113
114} // namespace WebCore
115
116#endif // HTMLFrameOwnerElement_h
117