| OLD | NEW |
| (Empty) |
| 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, 2012 Apple Inc. All rights reserv
ed. | |
| 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 "core/HTMLNames.h" | |
| 28 #include "core/dom/ElementTraversal.h" | |
| 29 #include "core/dom/shadow/ShadowRoot.h" | |
| 30 #include "core/frame/LocalFrame.h" | |
| 31 #include "core/frame/Settings.h" | |
| 32 #include "core/frame/csp/ContentSecurityPolicy.h" | |
| 33 #include "core/html/HTMLParamElement.h" | |
| 34 #include "core/layout/LayoutApplet.h" | |
| 35 #include "core/layout/LayoutBlockFlow.h" | |
| 36 #include "core/loader/FrameLoader.h" | |
| 37 #include "core/loader/FrameLoaderClient.h" | |
| 38 #include "platform/Widget.h" | |
| 39 #include "platform/weborigin/KURL.h" | |
| 40 #include "platform/weborigin/SecurityOrigin.h" | |
| 41 | |
| 42 namespace blink { | |
| 43 | |
| 44 using namespace HTMLNames; | |
| 45 | |
| 46 HTMLAppletElement::HTMLAppletElement(Document& document, bool createdByParser) | |
| 47 : HTMLPlugInElement(appletTag, document, createdByParser, ShouldNotPreferPlu
gInsForImages) | |
| 48 { | |
| 49 m_serviceType = "application/x-java-applet"; | |
| 50 } | |
| 51 | |
| 52 PassRefPtrWillBeRawPtr<HTMLAppletElement> HTMLAppletElement::create(Document& do
cument, bool createdByParser) | |
| 53 { | |
| 54 RefPtrWillBeRawPtr<HTMLAppletElement> element = adoptRefWillBeNoop(new HTMLA
ppletElement(document, createdByParser)); | |
| 55 element->ensureUserAgentShadowRoot(); | |
| 56 return element.release(); | |
| 57 } | |
| 58 | |
| 59 void HTMLAppletElement::parseAttribute(const QualifiedName& name, const AtomicSt
ring& value) | |
| 60 { | |
| 61 if (name == altAttr | |
| 62 || name == archiveAttr | |
| 63 || name == codeAttr | |
| 64 || name == codebaseAttr | |
| 65 || name == mayscriptAttr | |
| 66 || name == objectAttr) { | |
| 67 // Do nothing. | |
| 68 return; | |
| 69 } | |
| 70 | |
| 71 HTMLPlugInElement::parseAttribute(name, value); | |
| 72 } | |
| 73 | |
| 74 bool HTMLAppletElement::isURLAttribute(const Attribute& attribute) const | |
| 75 { | |
| 76 return attribute.name() == codebaseAttr || attribute.name() == objectAttr | |
| 77 || HTMLPlugInElement::isURLAttribute(attribute); | |
| 78 } | |
| 79 | |
| 80 bool HTMLAppletElement::hasLegalLinkAttribute(const QualifiedName& name) const | |
| 81 { | |
| 82 return name == codebaseAttr || HTMLPlugInElement::hasLegalLinkAttribute(name
); | |
| 83 } | |
| 84 | |
| 85 bool HTMLAppletElement::layoutObjectIsNeeded(const ComputedStyle& style) | |
| 86 { | |
| 87 if (!fastHasAttribute(codeAttr) && !openShadowRoot()) | |
| 88 return false; | |
| 89 return HTMLPlugInElement::layoutObjectIsNeeded(style); | |
| 90 } | |
| 91 | |
| 92 LayoutObject* HTMLAppletElement::createLayoutObject(const ComputedStyle& style) | |
| 93 { | |
| 94 return LayoutObject::createObject(this, style); | |
| 95 } | |
| 96 | |
| 97 LayoutPart* HTMLAppletElement::layoutPartForJSBindings() const | |
| 98 { | |
| 99 return nullptr; | |
| 100 } | |
| 101 | |
| 102 LayoutPart* HTMLAppletElement::existingLayoutPart() const | |
| 103 { | |
| 104 return layoutPart(); | |
| 105 } | |
| 106 | |
| 107 void HTMLAppletElement::updateWidgetInternal() | |
| 108 { | |
| 109 setNeedsWidgetUpdate(false); | |
| 110 // FIXME: This should ASSERT isFinishedParsingChildren() instead. | |
| 111 if (!isFinishedParsingChildren()) | |
| 112 return; | |
| 113 | |
| 114 LayoutEmbeddedObject* layoutObject = layoutEmbeddedObject(); | |
| 115 | |
| 116 LocalFrame* frame = document().frame(); | |
| 117 ASSERT(frame); | |
| 118 | |
| 119 Vector<String> paramNames; | |
| 120 Vector<String> paramValues; | |
| 121 | |
| 122 const AtomicString& codeBase = getAttribute(codebaseAttr); | |
| 123 if (!codeBase.isNull()) { | |
| 124 KURL codeBaseURL = document().completeURL(codeBase); | |
| 125 paramNames.append("codeBase"); | |
| 126 paramValues.append(codeBase.string()); | |
| 127 } | |
| 128 | |
| 129 const AtomicString& archive = getAttribute(archiveAttr); | |
| 130 if (!archive.isNull()) { | |
| 131 paramNames.append("archive"); | |
| 132 paramValues.append(archive.string()); | |
| 133 } | |
| 134 | |
| 135 const AtomicString& code = getAttribute(codeAttr); | |
| 136 paramNames.append("code"); | |
| 137 paramValues.append(code.string()); | |
| 138 | |
| 139 // If the 'codebase' attribute is set, it serves as a relative root for the
file that the Java | |
| 140 // plugin will load. If the 'code' attribute is set, and the 'archive' is no
t set, then we need | |
| 141 // to check the url generated by resolving 'code' against 'codebase'. If the
'archive' | |
| 142 // attribute is set, then 'code' points to a class inside the archive, so we
need to check the | |
| 143 // url generated by resolving 'archive' against 'codebase'. | |
| 144 KURL urlToCheck; | |
| 145 KURL rootURL; | |
| 146 if (!codeBase.isNull()) | |
| 147 rootURL = document().completeURL(codeBase); | |
| 148 if (rootURL.isNull() || !rootURL.isValid()) | |
| 149 rootURL = document().url(); | |
| 150 | |
| 151 if (!archive.isNull()) | |
| 152 urlToCheck = KURL(rootURL, archive); | |
| 153 else if (!code.isNull()) | |
| 154 urlToCheck = KURL(rootURL, code); | |
| 155 if (!canEmbedURL(urlToCheck)) | |
| 156 return; | |
| 157 | |
| 158 const AtomicString& name = document().isHTMLDocument() ? getNameAttribute()
: getIdAttribute(); | |
| 159 if (!name.isNull()) { | |
| 160 paramNames.append("name"); | |
| 161 paramValues.append(name.string()); | |
| 162 } | |
| 163 | |
| 164 paramNames.append("baseURL"); | |
| 165 KURL baseURL = document().baseURL(); | |
| 166 paramValues.append(baseURL.string()); | |
| 167 | |
| 168 const AtomicString& mayScript = getAttribute(mayscriptAttr); | |
| 169 if (!mayScript.isNull()) { | |
| 170 paramNames.append("mayScript"); | |
| 171 paramValues.append(mayScript.string()); | |
| 172 } | |
| 173 | |
| 174 for (HTMLParamElement* param = Traversal<HTMLParamElement>::firstChild(*this
); param; param = Traversal<HTMLParamElement>::nextSibling(*param)) { | |
| 175 if (param->name().isEmpty()) | |
| 176 continue; | |
| 177 | |
| 178 paramNames.append(param->name()); | |
| 179 paramValues.append(param->value()); | |
| 180 } | |
| 181 | |
| 182 RefPtrWillBeRawPtr<Widget> widget = nullptr; | |
| 183 if (frame->loader().allowPlugins(AboutToInstantiatePlugin)) | |
| 184 widget = frame->loader().client()->createJavaAppletWidget(this, baseURL,
paramNames, paramValues); | |
| 185 | |
| 186 if (!widget) { | |
| 187 if (!layoutObject->showsUnavailablePluginIndicator()) | |
| 188 layoutObject->setPluginUnavailabilityReason(LayoutEmbeddedObject::Pl
uginMissing); | |
| 189 return; | |
| 190 } | |
| 191 document().setContainsPlugins(); | |
| 192 setWidget(widget); | |
| 193 } | |
| 194 | |
| 195 bool HTMLAppletElement::canEmbedURL(const KURL& url) const | |
| 196 { | |
| 197 if (!document().securityOrigin()->canDisplay(url)) { | |
| 198 FrameLoader::reportLocalLoadFailed(document().frame(), url.string()); | |
| 199 return false; | |
| 200 } | |
| 201 | |
| 202 if (!document().contentSecurityPolicy()->allowObjectFromSource(url) | |
| 203 || !document().contentSecurityPolicy()->allowPluginTypeForDocument(docum
ent(), m_serviceType, m_serviceType, url)) { | |
| 204 layoutEmbeddedObject()->setPluginUnavailabilityReason(LayoutEmbeddedObje
ct::PluginBlockedByContentSecurityPolicy); | |
| 205 return false; | |
| 206 } | |
| 207 return true; | |
| 208 } | |
| 209 | |
| 210 } | |
| OLD | NEW |