1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Stefan Schimanski (1Stein (at) gmx.de) 5 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2012 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 "core/html/HTMLAppletElement.h" 26 27 #include "HTMLNames.h" 28 #include "core/html/HTMLParamElement.h" 29 #include "core/loader/FrameLoader.h" 30 #include "core/loader/FrameLoaderClient.h" 31 #include "core/page/ContentSecurityPolicy.h" 32 #include "core/page/Frame.h" 33 #include "core/page/Settings.h" 34 #include "core/platform/Widget.h" 35 #include "core/rendering/RenderApplet.h" 36 #include "weborigin/SecurityOrigin.h" 37 38 namespace WebCore { 39 40 using namespace HTMLNames; 41 42 HTMLAppletElement::HTMLAppletElement(const QualifiedName& tagName, Document* document, bool createdByParser) 43 : HTMLPlugInImageElement(tagName, document, createdByParser, ShouldNotPreferPlugInsForImages) 44 { 45 ASSERT(hasTagName(appletTag)); 46 ScriptWrappable::init(this); 47 48 m_serviceType = "application/x-java-applet"; 49 } 50 51 PassRefPtr<HTMLAppletElement> HTMLAppletElement::create(const QualifiedName& tagName, Document* document, bool createdByParser) 52 { 53 return adoptRef(new HTMLAppletElement(tagName, document, createdByParser)); 54 } 55 56 void HTMLAppletElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 57 { 58 if (name == altAttr 59 || name == archiveAttr 60 || name == codeAttr 61 || name == codebaseAttr 62 || name == mayscriptAttr 63 || name == objectAttr) { 64 // Do nothing. 65 return; 66 } 67 68 HTMLPlugInImageElement::parseAttribute(name, value); 69 } 70 71 bool HTMLAppletElement::rendererIsNeeded(const NodeRenderingContext& context) 72 { 73 if (!fastHasAttribute(codeAttr)) 74 return false; 75 return HTMLPlugInImageElement::rendererIsNeeded(context); 76 } 77 78 RenderObject* HTMLAppletElement::createRenderer(RenderStyle* style) 79 { 80 if (!canEmbedJava()) 81 return RenderObject::createObject(this, style); 82 83 return new RenderApplet(this); 84 } 85 86 RenderWidget* HTMLAppletElement::renderWidgetForJSBindings() const 87 { 88 if (!canEmbedJava()) 89 return 0; 90 91 document()->updateLayoutIgnorePendingStylesheets(); 92 return renderPart(); 93 } 94 95 void HTMLAppletElement::updateWidget(PluginCreationOption) 96 { 97 setNeedsWidgetUpdate(false); 98 // FIXME: This should ASSERT isFinishedParsingChildren() instead. 99 if (!isFinishedParsingChildren()) 100 return; 101 102 RenderEmbeddedObject* renderer = renderEmbeddedObject(); 103 104 Frame* frame = document()->frame(); 105 ASSERT(frame); 106 107 LayoutUnit contentWidth = renderer->style()->width().isFixed() ? LayoutUnit(renderer->style()->width().value()) : 108 renderer->width() - renderer->borderAndPaddingWidth(); 109 LayoutUnit contentHeight = renderer->style()->height().isFixed() ? LayoutUnit(renderer->style()->height().value()) : 110 renderer->height() - renderer->borderAndPaddingHeight(); 111 112 Vector<String> paramNames; 113 Vector<String> paramValues; 114 115 paramNames.append("code"); 116 paramValues.append(getAttribute(codeAttr).string()); 117 118 const AtomicString& codeBase = getAttribute(codebaseAttr); 119 if (!codeBase.isNull()) { 120 KURL codeBaseURL = document()->completeURL(codeBase); 121 if (!document()->securityOrigin()->canDisplay(codeBaseURL)) { 122 FrameLoader::reportLocalLoadFailed(frame, codeBaseURL.string()); 123 return; 124 } 125 const char javaAppletMimeType[] = "application/x-java-applet"; 126 if (!document()->contentSecurityPolicy()->allowObjectFromSource(codeBaseURL) 127 || !document()->contentSecurityPolicy()->allowPluginType(javaAppletMimeType, javaAppletMimeType, codeBaseURL)) 128 return; 129 paramNames.append("codeBase"); 130 paramValues.append(codeBase.string()); 131 } 132 133 const AtomicString& name = document()->isHTMLDocument() ? getNameAttribute() : getIdAttribute(); 134 if (!name.isNull()) { 135 paramNames.append("name"); 136 paramValues.append(name.string()); 137 } 138 139 const AtomicString& archive = getAttribute(archiveAttr); 140 if (!archive.isNull()) { 141 paramNames.append("archive"); 142 paramValues.append(archive.string()); 143 } 144 145 paramNames.append("baseURL"); 146 KURL baseURL = document()->baseURL(); 147 paramValues.append(baseURL.string()); 148 149 const AtomicString& mayScript = getAttribute(mayscriptAttr); 150 if (!mayScript.isNull()) { 151 paramNames.append("mayScript"); 152 paramValues.append(mayScript.string()); 153 } 154 155 for (Node* child = firstChild(); child; child = child->nextSibling()) { 156 if (!child->hasTagName(paramTag)) 157 continue; 158 159 HTMLParamElement* param = static_cast<HTMLParamElement*>(child); 160 if (param->name().isEmpty()) 161 continue; 162 163 paramNames.append(param->name()); 164 paramValues.append(param->value()); 165 } 166 167 RefPtr<Widget> widget; 168 if (frame->loader()->allowPlugins(AboutToInstantiatePlugin)) 169 widget = frame->loader()->client()->createJavaAppletWidget(roundedIntSize(LayoutSize(contentWidth, contentHeight)), this, baseURL, paramNames, paramValues); 170 171 if (!widget) { 172 if (!renderer->showsUnavailablePluginIndicator()) 173 renderer->setPluginUnavailabilityReason(RenderEmbeddedObject::PluginMissing); 174 return; 175 } 176 frame->loader()->setContainsPlugins(); 177 renderer->setWidget(widget); 178 } 179 180 bool HTMLAppletElement::canEmbedJava() const 181 { 182 if (document()->isSandboxed(SandboxPlugins)) 183 return false; 184 185 Settings* settings = document()->settings(); 186 if (!settings) 187 return false; 188 189 if (!settings->isJavaEnabled()) 190 return false; 191 192 return true; 193 } 194 195 } 196