• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/html/HTMLElement.h"
25 #include "wtf/HashCountedSet.h"
26 
27 namespace WebCore {
28 
29 class DOMWindow;
30 class ExceptionState;
31 class Frame;
32 class RenderPart;
33 class SVGDocument;
34 
35 class HTMLFrameOwnerElement : public HTMLElement {
36 public:
37     virtual ~HTMLFrameOwnerElement();
38 
contentFrame()39     Frame* contentFrame() const { return m_contentFrame; }
40     DOMWindow* contentWindow() const;
41     Document* contentDocument() const;
42 
43     void setContentFrame(Frame&);
44     void clearContentFrame();
45 
46     void disconnectContentFrame();
47 
48     // Most subclasses use RenderPart (either RenderEmbeddedObject or RenderIFrame)
49     // except for HTMLObjectElement and HTMLEmbedElement which may return any
50     // RenderObject when using fallback content.
51     RenderPart* renderPart() const;
52 
53     SVGDocument* getSVGDocument(ExceptionState&) const;
54 
scrollingMode()55     virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; }
56 
sandboxFlags()57     SandboxFlags sandboxFlags() const { return m_sandboxFlags; }
58 
loadedNonEmptyDocument()59     virtual bool loadedNonEmptyDocument() const { return false; }
didLoadNonEmptyDocument()60     virtual void didLoadNonEmptyDocument() { }
61 
renderFallbackContent()62     virtual void renderFallbackContent() { }
63 
isObjectElement()64     virtual bool isObjectElement() const { return false; }
65 
66 protected:
67     HTMLFrameOwnerElement(const QualifiedName& tagName, Document&);
68     void setSandboxFlags(SandboxFlags);
69 
70     bool loadOrRedirectSubframe(const KURL&, const AtomicString& frameName, bool lockBackForwardList);
71 
72 private:
73     virtual bool isKeyboardFocusable() const OVERRIDE;
isFrameOwnerElement()74     virtual bool isFrameOwnerElement() const OVERRIDE { return true; }
75 
76     Frame* m_contentFrame;
77     SandboxFlags m_sandboxFlags;
78 };
79 
80 DEFINE_NODE_TYPE_CASTS(HTMLFrameOwnerElement, isFrameOwnerElement());
81 
82 class SubframeLoadingDisabler {
83 public:
SubframeLoadingDisabler(Node & root)84     explicit SubframeLoadingDisabler(Node& root)
85         : m_root(root)
86     {
87         disabledSubtreeRoots().add(&m_root);
88     }
89 
~SubframeLoadingDisabler()90     ~SubframeLoadingDisabler()
91     {
92         disabledSubtreeRoots().remove(&m_root);
93     }
94 
canLoadFrame(HTMLFrameOwnerElement & owner)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 
104 private:
disabledSubtreeRoots()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