Home | History | Annotate | Download | only in html
      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 
     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 
     55     virtual ScrollbarMode scrollingMode() const { return ScrollbarAuto; }
     56 
     57     SandboxFlags sandboxFlags() const { return m_sandboxFlags; }
     58 
     59     virtual bool loadedNonEmptyDocument() const { return false; }
     60     virtual void didLoadNonEmptyDocument() { }
     61 
     62 protected:
     63     HTMLFrameOwnerElement(const QualifiedName& tagName, Document*);
     64     void setSandboxFlags(SandboxFlags);
     65 
     66     bool loadOrRedirectSubframe(const KURL&, const AtomicString& frameName, bool lockBackForwardList);
     67 
     68     virtual bool allowScrollingInContentFrame() { return true; }
     69     virtual int marginWidth() const { return -1; }
     70     virtual int marginHeight() const { return -1; }
     71 
     72 private:
     73     virtual bool isKeyboardFocusable() const OVERRIDE;
     74     virtual bool isFrameOwnerElement() const OVERRIDE { return true; }
     75 
     76     Frame* m_contentFrame;
     77     SandboxFlags m_sandboxFlags;
     78 };
     79 
     80 inline HTMLFrameOwnerElement* toFrameOwnerElement(Node* node)
     81 {
     82     ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isFrameOwnerElement());
     83     return static_cast<HTMLFrameOwnerElement*>(node);
     84 }
     85 
     86 class SubframeLoadingDisabler {
     87 public:
     88     explicit SubframeLoadingDisabler(Node* root)
     89         : m_root(root)
     90     {
     91         disabledSubtreeRoots().add(m_root);
     92     }
     93 
     94     ~SubframeLoadingDisabler()
     95     {
     96         disabledSubtreeRoots().remove(m_root);
     97     }
     98 
     99     static bool canLoadFrame(HTMLFrameOwnerElement* owner)
    100     {
    101         for (Node* node = owner; node; node = node->parentOrShadowHostNode()) {
    102             if (disabledSubtreeRoots().contains(node))
    103                 return false;
    104         }
    105         return true;
    106     }
    107 
    108 private:
    109     static HashCountedSet<Node*>& disabledSubtreeRoots()
    110     {
    111         DEFINE_STATIC_LOCAL(HashCountedSet<Node*>, nodes, ());
    112         return nodes;
    113     }
    114 
    115     Node* m_root;
    116 };
    117 
    118 } // namespace WebCore
    119 
    120 #endif // HTMLFrameOwnerElement_h
    121