WebCore/html/HTMLAppletElement.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 Stefan Schimanski (1Stein@gmx.de)
       
     5  * Copyright (C) 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
       
     6  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
       
     7  *
       
     8  * This library is free software; you can redistribute it and/or
       
     9  * modify it under the terms of the GNU Library General Public
       
    10  * License as published by the Free Software Foundation; either
       
    11  * version 2 of the License, or (at your option) any later version.
       
    12  *
       
    13  * This library is distributed in the hope that it will be useful,
       
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    16  * Library General Public License for more details.
       
    17  *
       
    18  * You should have received a copy of the GNU Library General Public License
       
    19  * along with this library; see the file COPYING.LIB.  If not, write to
       
    20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    21  * Boston, MA 02110-1301, USA.
       
    22  */
       
    23 
       
    24 #include "config.h"
       
    25 #include "HTMLAppletElement.h"
       
    26 
       
    27 #include "Attribute.h"
       
    28 #include "HTMLDocument.h"
       
    29 #include "HTMLNames.h"
       
    30 #include "RenderApplet.h"
       
    31 #include "SecurityOrigin.h"
       
    32 #include "Settings.h"
       
    33 
       
    34 namespace WebCore {
       
    35 
       
    36 using namespace HTMLNames;
       
    37 
       
    38 inline HTMLAppletElement::HTMLAppletElement(const QualifiedName& tagName, Document* document)
       
    39     : HTMLPlugInElement(tagName, document)
       
    40 {
       
    41     ASSERT(hasTagName(appletTag));
       
    42 }
       
    43 
       
    44 PassRefPtr<HTMLAppletElement> HTMLAppletElement::create(const QualifiedName& tagName, Document* document)
       
    45 {
       
    46     return adoptRef(new HTMLAppletElement(tagName, document));
       
    47 }
       
    48 
       
    49 void HTMLAppletElement::parseMappedAttribute(Attribute* attr)
       
    50 {
       
    51     if (attr->name() == altAttr ||
       
    52         attr->name() == archiveAttr ||
       
    53         attr->name() == codeAttr ||
       
    54         attr->name() == codebaseAttr ||
       
    55         attr->name() == mayscriptAttr ||
       
    56         attr->name() == objectAttr) {
       
    57         // Do nothing.
       
    58     } else if (attr->name() == nameAttr) {
       
    59         const AtomicString& newName = attr->value();
       
    60         if (inDocument() && document()->isHTMLDocument()) {
       
    61             HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
       
    62             document->removeNamedItem(m_name);
       
    63             document->addNamedItem(newName);
       
    64         }
       
    65         m_name = newName;
       
    66     } else if (isIdAttributeName(attr->name())) {
       
    67         const AtomicString& newId = attr->value();
       
    68         if (inDocument() && document()->isHTMLDocument()) {
       
    69             HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
       
    70             document->removeExtraNamedItem(m_id);
       
    71             document->addExtraNamedItem(newId);
       
    72         }
       
    73         m_id = newId;
       
    74         // also call superclass
       
    75         HTMLPlugInElement::parseMappedAttribute(attr);
       
    76     } else
       
    77         HTMLPlugInElement::parseMappedAttribute(attr);
       
    78 }
       
    79 
       
    80 void HTMLAppletElement::insertedIntoDocument()
       
    81 {
       
    82     if (document()->isHTMLDocument()) {
       
    83         HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
       
    84         document->addNamedItem(m_name);
       
    85         document->addExtraNamedItem(m_id);
       
    86     }
       
    87 
       
    88     HTMLPlugInElement::insertedIntoDocument();
       
    89 }
       
    90 
       
    91 void HTMLAppletElement::removedFromDocument()
       
    92 {
       
    93     if (document()->isHTMLDocument()) {
       
    94         HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
       
    95         document->removeNamedItem(m_name);
       
    96         document->removeExtraNamedItem(m_id);
       
    97     }
       
    98 
       
    99     HTMLPlugInElement::removedFromDocument();
       
   100 }
       
   101 
       
   102 bool HTMLAppletElement::rendererIsNeeded(RenderStyle* style)
       
   103 {
       
   104     if (getAttribute(codeAttr).isNull())
       
   105         return false;
       
   106 
       
   107     return HTMLPlugInElement::rendererIsNeeded(style);
       
   108 }
       
   109 
       
   110 RenderObject* HTMLAppletElement::createRenderer(RenderArena*, RenderStyle* style)
       
   111 {
       
   112     if (canEmbedJava()) {
       
   113         HashMap<String, String> args;
       
   114 
       
   115         args.set("code", getAttribute(codeAttr));
       
   116 
       
   117         const AtomicString& codeBase = getAttribute(codebaseAttr);
       
   118         if (!codeBase.isNull())
       
   119             args.set("codeBase", codeBase);
       
   120 
       
   121         const AtomicString& name = document()->isHTMLDocument() ? getAttribute(nameAttr) : getIdAttribute();
       
   122         if (!name.isNull())
       
   123             args.set("name", name);
       
   124         const AtomicString& archive = getAttribute(archiveAttr);
       
   125         if (!archive.isNull())
       
   126             args.set("archive", archive);
       
   127 
       
   128         args.set("baseURL", document()->baseURL().string());
       
   129 
       
   130         const AtomicString& mayScript = getAttribute(mayscriptAttr);
       
   131         if (!mayScript.isNull())
       
   132             args.set("mayScript", mayScript);
       
   133 
       
   134         // Other arguments (from <PARAM> tags) are added later.
       
   135         
       
   136         return new (document()->renderArena()) RenderApplet(this, args);
       
   137     }
       
   138 
       
   139     return RenderObject::createObject(this, style);
       
   140 }
       
   141 
       
   142 RenderWidget* HTMLAppletElement::renderWidgetForJSBindings() const
       
   143 {
       
   144     if (!canEmbedJava())
       
   145         return 0;
       
   146 
       
   147     RenderApplet* applet = toRenderApplet(renderer());
       
   148     if (applet)
       
   149         applet->createWidgetIfNecessary();
       
   150 
       
   151     return applet;
       
   152 }
       
   153 
       
   154 bool HTMLAppletElement::canEmbedJava() const
       
   155 {
       
   156     if (document()->securityOrigin()->isSandboxed(SandboxPlugins))
       
   157         return false;
       
   158 
       
   159     Settings* settings = document()->settings();
       
   160     return settings && settings->isJavaEnabled();
       
   161 }
       
   162 
       
   163 void HTMLAppletElement::finishParsingChildren()
       
   164 {
       
   165     // The parser just reached </applet>, so all the params are available now.
       
   166     HTMLPlugInElement::finishParsingChildren();
       
   167     if (renderer())
       
   168         renderer()->setNeedsLayout(true); // This will cause it to create its widget & the Java applet
       
   169 }
       
   170 
       
   171 }