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#include "config.h" 22#include "HTMLFrameOwnerElement.h" 23 24#include "DOMWindow.h" 25#include "Frame.h" 26#include "FrameLoader.h" 27#include "RenderPart.h" 28 29#if ENABLE(SVG) 30#include "ExceptionCode.h" 31#include "SVGDocument.h" 32#endif 33 34namespace WebCore { 35 36HTMLFrameOwnerElement::HTMLFrameOwnerElement(const QualifiedName& tagName, Document* document) 37 : HTMLElement(tagName, document) 38 , m_contentFrame(0) 39 , m_sandboxFlags(SandboxNone) 40{ 41} 42 43RenderPart* HTMLFrameOwnerElement::renderPart() const 44{ 45 // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers 46 // when using fallback content. 47 if (!renderer() || !renderer()->isRenderPart()) 48 return 0; 49 return toRenderPart(renderer()); 50} 51 52void HTMLFrameOwnerElement::willRemove() 53{ 54 // FIXME: It is unclear why this can't be moved to removedFromDocument() 55 // this is the only implementation of willRemove in WebCore! 56 if (Frame* frame = contentFrame()) { 57 RefPtr<Frame> protect(frame); 58 frame->loader()->frameDetached(); 59 frame->disconnectOwnerElement(); 60 } 61 62 HTMLElement::willRemove(); 63} 64 65HTMLFrameOwnerElement::~HTMLFrameOwnerElement() 66{ 67 if (m_contentFrame) 68 m_contentFrame->disconnectOwnerElement(); 69} 70 71Document* HTMLFrameOwnerElement::contentDocument() const 72{ 73 return m_contentFrame ? m_contentFrame->document() : 0; 74} 75 76DOMWindow* HTMLFrameOwnerElement::contentWindow() const 77{ 78 return m_contentFrame ? m_contentFrame->domWindow() : 0; 79} 80 81void HTMLFrameOwnerElement::setSandboxFlags(SandboxFlags flags) 82{ 83 if (m_sandboxFlags == flags) 84 return; 85 86 m_sandboxFlags = flags; 87 88 if (Frame* frame = contentFrame()) 89 frame->loader()->ownerElementSandboxFlagsChanged(); 90} 91 92bool HTMLFrameOwnerElement::isKeyboardFocusable(KeyboardEvent* event) const 93{ 94 return m_contentFrame && HTMLElement::isKeyboardFocusable(event); 95} 96 97#if ENABLE(SVG) 98SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionCode& ec) const 99{ 100 Document* doc = contentDocument(); 101 if (doc && doc->isSVGDocument()) 102 return static_cast<SVGDocument*>(doc); 103 // Spec: http://www.w3.org/TR/SVG/struct.html#InterfaceGetSVGDocument 104 ec = NOT_SUPPORTED_ERR; 105 return 0; 106} 107#endif 108 109} // namespace WebCore 110