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