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/dom/Document.h" 25 #include "core/frame/FrameOwner.h" 26 #include "core/html/HTMLElement.h" 27 #include "wtf/HashCountedSet.h" 28 29 namespace WebCore { 30 31 class LocalDOMWindow; 32 class ExceptionState; 33 class Frame; 34 class RenderPart; 35 class Widget; 36 37 class HTMLFrameOwnerElement : public HTMLElement, public FrameOwner { 38 public: 39 virtual ~HTMLFrameOwnerElement(); 40 41 Frame* contentFrame() const { return m_contentFrame; } 42 LocalDOMWindow* contentWindow() const; 43 Document* contentDocument() const; 44 45 void setContentFrame(Frame&); 46 void clearContentFrame(); 47 48 void disconnectContentFrame(); 49 50 // Most subclasses use RenderPart (either RenderEmbeddedObject or RenderIFrame) 51 // except for HTMLObjectElement and HTMLEmbedElement which may return any 52 // RenderObject when using fallback content. 53 RenderPart* renderPart() const; 54 55 Document* getSVGDocument(ExceptionState&) const; 56 57 virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; } 58 59 virtual bool loadedNonEmptyDocument() const { return false; } 60 virtual void didLoadNonEmptyDocument() { } 61 62 virtual void renderFallbackContent() { } 63 64 virtual bool isObjectElement() const { return false; } 65 void setWidget(PassRefPtr<Widget>); 66 Widget* ownedWidget() const; 67 68 class UpdateSuspendScope { 69 public: 70 UpdateSuspendScope(); 71 ~UpdateSuspendScope(); 72 73 private: 74 void performDeferredWidgetTreeOperations(); 75 }; 76 77 protected: 78 HTMLFrameOwnerElement(const QualifiedName& tagName, Document&); 79 void setSandboxFlags(SandboxFlags); 80 81 bool loadOrRedirectSubframe(const KURL&, const AtomicString& frameName, bool lockBackForwardList); 82 83 private: 84 virtual bool isKeyboardFocusable() const OVERRIDE; 85 virtual bool isFrameOwnerElement() const OVERRIDE FINAL { return true; } 86 87 // FrameOwner overrides: 88 virtual bool isLocal() const { return true; } 89 virtual SandboxFlags sandboxFlags() const OVERRIDE { return m_sandboxFlags; } 90 virtual void dispatchLoad() OVERRIDE; 91 92 Frame* m_contentFrame; 93 RefPtr<Widget> m_widget; 94 SandboxFlags m_sandboxFlags; 95 }; 96 97 DEFINE_ELEMENT_TYPE_CASTS(HTMLFrameOwnerElement, isFrameOwnerElement()); 98 99 class SubframeLoadingDisabler { 100 public: 101 explicit SubframeLoadingDisabler(Node& root) 102 : m_root(root) 103 { 104 disabledSubtreeRoots().add(&m_root); 105 } 106 107 ~SubframeLoadingDisabler() 108 { 109 disabledSubtreeRoots().remove(&m_root); 110 } 111 112 static bool canLoadFrame(HTMLFrameOwnerElement& owner) 113 { 114 if (owner.document().unloadStarted()) 115 return false; 116 for (Node* node = &owner; node; node = node->parentOrShadowHostNode()) { 117 if (disabledSubtreeRoots().contains(node)) 118 return false; 119 } 120 return true; 121 } 122 123 private: 124 static HashCountedSet<Node*>& disabledSubtreeRoots() 125 { 126 DEFINE_STATIC_LOCAL(HashCountedSet<Node*>, nodes, ()); 127 return nodes; 128 } 129 130 Node& m_root; 131 }; 132 133 DEFINE_TYPE_CASTS(HTMLFrameOwnerElement, FrameOwner, owner, owner->isLocal(), owner.isLocal()); 134 135 } // namespace WebCore 136 137 #endif // HTMLFrameOwnerElement_h 138