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