WebCore/html/HTMLIFrameElement.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
       
     3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
       
     4  *           (C) 2000 Simon Hausmann (hausmann@kde.org)
       
     5  *           (C) 2001 Dirk Mueller (mueller@kde.org)
       
     6  * Copyright (C) 2004, 2006, 2008, 2009 Apple Inc. All rights reserved.
       
     7  * Copyright (C) 2009 Ericsson AB. All rights reserved.
       
     8  *
       
     9  * This library is free software; you can redistribute it and/or
       
    10  * modify it under the terms of the GNU Library General Public
       
    11  * License as published by the Free Software Foundation; either
       
    12  * version 2 of the License, or (at your option) any later version.
       
    13  *
       
    14  * This library is distributed in the hope that it will be useful,
       
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    17  * Library General Public License for more details.
       
    18  *
       
    19  * You should have received a copy of the GNU Library General Public License
       
    20  * along with this library; see the file COPYING.LIB.  If not, write to
       
    21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    22  * Boston, MA 02110-1301, USA.
       
    23  */
       
    24 
       
    25 #include "config.h"
       
    26 #include "HTMLIFrameElement.h"
       
    27 
       
    28 #include "Attribute.h"
       
    29 #include "CSSPropertyNames.h"
       
    30 #include "Frame.h"
       
    31 #include "HTMLDocument.h"
       
    32 #include "HTMLNames.h"
       
    33 #include "RenderIFrame.h"
       
    34 
       
    35 namespace WebCore {
       
    36 
       
    37 using namespace HTMLNames;
       
    38 
       
    39 inline HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
       
    40     : HTMLFrameElementBase(tagName, document)
       
    41 {
       
    42     ASSERT(hasTagName(iframeTag));
       
    43 }
       
    44 
       
    45 PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(const QualifiedName& tagName, Document* document)
       
    46 {
       
    47     return adoptRef(new HTMLIFrameElement(tagName, document));
       
    48 }
       
    49 
       
    50 bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
       
    51 {
       
    52     if (attrName == widthAttr || attrName == heightAttr) {
       
    53         result = eUniversal;
       
    54         return false;
       
    55     }
       
    56     
       
    57     if (attrName == alignAttr) {
       
    58         result = eReplaced; // Share with <img> since the alignment behavior is the same.
       
    59         return false;
       
    60     }
       
    61     
       
    62     if (attrName == frameborderAttr) {
       
    63         result = eReplaced;
       
    64         return false;
       
    65     }
       
    66 
       
    67     return HTMLFrameElementBase::mapToEntry(attrName, result);
       
    68 }
       
    69 
       
    70 #if ENABLE(SANDBOX)
       
    71 static SandboxFlags parseSandboxAttribute(Attribute* attribute)
       
    72 {
       
    73     if (attribute->isNull())
       
    74         return SandboxNone;
       
    75 
       
    76     // Parse the unordered set of unique space-separated tokens.
       
    77     SandboxFlags flags = SandboxAll;
       
    78     const UChar* characters = attribute->value().characters();
       
    79     unsigned length = attribute->value().length();
       
    80     unsigned start = 0;
       
    81     while (true) {
       
    82         while (start < length && isASCIISpace(characters[start]))
       
    83             ++start;
       
    84         if (start >= length)
       
    85             break;
       
    86         unsigned end = start + 1;
       
    87         while (end < length && !isASCIISpace(characters[end]))
       
    88             ++end;
       
    89 
       
    90         // Turn off the corresponding sandbox flag if it's set as "allowed".
       
    91         String sandboxToken = String(characters + start, end - start);
       
    92         if (equalIgnoringCase(sandboxToken, "allow-same-origin"))
       
    93             flags &= ~SandboxOrigin;
       
    94         else if (equalIgnoringCase(sandboxToken, "allow-forms"))
       
    95             flags &= ~SandboxForms;
       
    96         else if (equalIgnoringCase(sandboxToken, "allow-scripts"))
       
    97             flags &= ~SandboxScripts;
       
    98         else if (equalIgnoringCase(sandboxToken, "allow-top-navigation"))
       
    99             flags &= ~SandboxTopNavigation;
       
   100 
       
   101         start = end + 1;
       
   102     }
       
   103 
       
   104     return flags;
       
   105 }
       
   106 #endif
       
   107 
       
   108 void HTMLIFrameElement::parseMappedAttribute(Attribute* attr)
       
   109 {
       
   110     if (attr->name() == widthAttr)
       
   111         addCSSLength(attr, CSSPropertyWidth, attr->value());
       
   112     else if (attr->name() == heightAttr)
       
   113         addCSSLength(attr, CSSPropertyHeight, attr->value());
       
   114     else if (attr->name() == alignAttr)
       
   115         addHTMLAlignment(attr);
       
   116     else if (attr->name() == nameAttr) {
       
   117         const AtomicString& newName = attr->value();
       
   118         if (inDocument() && document()->isHTMLDocument()) {
       
   119             HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
       
   120             document->removeExtraNamedItem(m_name);
       
   121             document->addExtraNamedItem(newName);
       
   122         }
       
   123         m_name = newName;
       
   124     } else if (attr->name() == frameborderAttr) {
       
   125         // Frame border doesn't really match the HTML4 spec definition for iframes.  It simply adds
       
   126         // a presentational hint that the border should be off if set to zero.
       
   127         if (!attr->isNull() && !attr->value().toInt())
       
   128             // Add a rule that nulls out our border width.
       
   129             addCSSLength(attr, CSSPropertyBorderWidth, "0");
       
   130     }
       
   131 #if ENABLE(SANDBOX)
       
   132     else if (attr->name() == sandboxAttr)
       
   133         setSandboxFlags(parseSandboxAttribute(attr));
       
   134 #endif
       
   135     else
       
   136         HTMLFrameElementBase::parseMappedAttribute(attr);
       
   137 }
       
   138 
       
   139 bool HTMLIFrameElement::rendererIsNeeded(RenderStyle* style)
       
   140 {
       
   141     return isURLAllowed() && style->display() != NONE;
       
   142 }
       
   143 
       
   144 RenderObject* HTMLIFrameElement::createRenderer(RenderArena* arena, RenderStyle*)
       
   145 {
       
   146     return new (arena) RenderIFrame(this);
       
   147 }
       
   148 
       
   149 void HTMLIFrameElement::insertedIntoDocument()
       
   150 {
       
   151     if (document()->isHTMLDocument())
       
   152         static_cast<HTMLDocument*>(document())->addExtraNamedItem(m_name);
       
   153 
       
   154     HTMLFrameElementBase::insertedIntoDocument();
       
   155 }
       
   156 
       
   157 void HTMLIFrameElement::removedFromDocument()
       
   158 {
       
   159     if (document()->isHTMLDocument())
       
   160         static_cast<HTMLDocument*>(document())->removeExtraNamedItem(m_name);
       
   161 
       
   162     HTMLFrameElementBase::removedFromDocument();
       
   163 }
       
   164 
       
   165 bool HTMLIFrameElement::isURLAttribute(Attribute* attr) const
       
   166 {
       
   167     return attr->name() == srcAttr;
       
   168 }
       
   169 
       
   170 }