2
* This file is part of the KDE project.
4
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5
* (C) 2000 Simon Hausmann <hausmann@kde.org>
6
* (C) 2000 Stefan Schimanski (1Stein@gmx.de)
7
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
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.
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.
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., 59 Temple Place - Suite 330,
22
* Boston, MA 02111-1307, USA.
26
#include "RenderPartObject.h"
29
#include "EventHandler.h"
31
#include "FrameLoader.h"
32
#include "FrameLoaderClient.h"
33
#include "FrameTree.h"
34
#include "FrameView.h"
35
#include "HTMLEmbedElement.h"
36
#include "HTMLIFrameElement.h"
37
#include "HTMLNames.h"
38
#include "HTMLObjectElement.h"
39
#include "HTMLParamElement.h"
41
#include "MIMETypeRegistry.h"
47
using namespace HTMLNames;
49
RenderPartObject::RenderPartObject(HTMLFrameOwnerElement* element)
52
// init RenderObject attributes
54
m_hasFallbackContent = false;
57
static bool isURLAllowed(Document *doc, const String &url)
59
KURL newURL(doc->completeURL(url.deprecatedString()));
60
newURL.setRef(DeprecatedString::null);
62
if (doc->frame()->page()->frameCount() >= 200)
65
// We allow one level of self-reference because some sites depend on that.
66
// But we don't allow more than one.
67
bool foundSelfReference = false;
68
for (Frame *frame = doc->frame(); frame; frame = frame->tree()->parent()) {
69
KURL frameURL = frame->loader()->url();
70
frameURL.setRef(DeprecatedString::null);
71
if (frameURL == newURL) {
72
if (foundSelfReference)
74
foundSelfReference = true;
80
static inline void mapClassIdToServiceType(const String& classId, String& serviceType)
82
// It is ActiveX, but the nsplugin system handling
83
// should also work, that's why we don't override the
84
// serviceType with application/x-activex-handler
85
// but let the KTrader in khtmlpart::createPart() detect
86
// the user's preference: launch with activex viewer or
87
// with nspluginviewer (Niko)
88
if (classId.contains("D27CDB6E-AE6D-11cf-96B8-444553540000"))
89
serviceType = "application/x-shockwave-flash";
90
else if (classId.contains("CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"))
91
serviceType = "audio/x-pn-realaudio-plugin";
92
else if (classId.contains("02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"))
93
serviceType = "video/quicktime";
94
else if (classId.contains("166B1BCA-3F9C-11CF-8075-444553540000"))
95
serviceType = "application/x-director";
96
else if (classId.contains("6BF52A52-394A-11d3-B153-00C04F79FAA6"))
97
serviceType = "application/x-mplayer2";
98
else if (!classId.isEmpty())
99
// We have a clsid, means this is activex (Niko)
100
serviceType = "application/x-activex-handler";
101
// TODO: add more plugins here
104
void RenderPartObject::updateWidget(bool onlyCreateNonPlugins)
108
Vector<String> paramNames;
109
Vector<String> paramValues;
110
Frame* frame = m_view->frame();
112
if (element()->hasTagName(objectTag)) {
114
HTMLObjectElement* o = static_cast<HTMLObjectElement*>(element());
116
if (!o->isComplete())
118
// Check for a child EMBED tag.
119
HTMLEmbedElement* embed = 0;
120
for (Node* child = o->firstChild(); child;) {
121
if (child->hasTagName(embedTag)) {
122
embed = static_cast<HTMLEmbedElement*>(child);
124
} else if (child->hasTagName(objectTag))
125
child = child->nextSibling(); // Don't descend into nested OBJECT tags
127
child = child->traverseNextNode(o); // Otherwise descend (EMBEDs may be inside COMMENT tags)
130
// Use the attributes from the EMBED tag instead of the OBJECT tag including WIDTH and HEIGHT.
131
HTMLElement *embedOrObject;
133
embedOrObject = (HTMLElement *)embed;
134
String attribute = embedOrObject->getAttribute(widthAttr);
135
if (!attribute.isEmpty())
136
o->setAttribute(widthAttr, attribute);
137
attribute = embedOrObject->getAttribute(heightAttr);
138
if (!attribute.isEmpty())
139
o->setAttribute(heightAttr, attribute);
141
serviceType = embed->m_serviceType;
143
embedOrObject = (HTMLElement *)o;
145
// If there was no URL or type defined in EMBED, try the OBJECT tag.
148
if (serviceType.isEmpty())
149
serviceType = o->m_serviceType;
151
HashSet<StringImpl*, CaseInsensitiveHash<StringImpl*> > uniqueParamNames;
153
// Scan the PARAM children.
154
// Get the URL and type from the params if we don't already have them.
155
// Get the attributes from the params if there is no EMBED tag.
156
Node *child = o->firstChild();
157
while (child && (url.isEmpty() || serviceType.isEmpty() || !embed)) {
158
if (child->hasTagName(paramTag)) {
159
HTMLParamElement* p = static_cast<HTMLParamElement*>(child);
160
String name = p->name().lower();
161
if (url.isEmpty() && (name == "src" || name == "movie" || name == "code" || name == "url"))
163
if (serviceType.isEmpty() && name == "type") {
164
serviceType = p->value();
165
int pos = serviceType.find(";");
167
serviceType = serviceType.left(pos);
169
if (!embed && !name.isEmpty()) {
170
uniqueParamNames.add(p->name().impl());
171
paramNames.append(p->name());
172
paramValues.append(p->value());
175
child = child->nextSibling();
178
// When OBJECT is used for an applet via Sun's Java plugin, the CODEBASE attribute in the tag
179
// points to the Java plugin itself (an ActiveX component) while the actual applet CODEBASE is
180
// in a PARAM tag. See <http://java.sun.com/products/plugin/1.2/docs/tags.html>. This means
181
// we have to explicitly suppress the tag's CODEBASE attribute if there is none in a PARAM,
182
// else our Java plugin will misinterpret it. [4004531]
184
if (!embed && MIMETypeRegistry::isJavaAppletMIMEType(serviceType)) {
185
codebase = "codebase";
186
uniqueParamNames.add(codebase.impl()); // pretend we found it in a PARAM already
189
// Turn the attributes of either the EMBED tag or OBJECT tag into arrays, but don't override PARAM values.
190
NamedAttrMap* attributes = embedOrObject->attributes();
192
for (unsigned i = 0; i < attributes->length(); ++i) {
193
Attribute* it = attributes->attributeItem(i);
194
const AtomicString& name = it->name().localName();
195
if (embed || !uniqueParamNames.contains(name.impl())) {
196
paramNames.append(name.domString());
197
paramValues.append(it->value().domString());
202
// If we still don't have a type, try to map from a specific CLASSID to a type.
203
if (serviceType.isEmpty() && !o->m_classId.isEmpty())
204
mapClassIdToServiceType(o->m_classId, serviceType);
206
// If no URL and type, abort.
207
if (url.isEmpty() && serviceType.isEmpty())
209
if (!isURLAllowed(document(), url))
212
// Find out if we support fallback content.
213
m_hasFallbackContent = false;
214
for (Node *child = o->firstChild(); child && !m_hasFallbackContent; child = child->nextSibling()) {
215
if ((!child->isTextNode() && !child->hasTagName(embedTag) && !child->hasTagName(paramTag)) || // Discount <embed> and <param>
216
(child->isTextNode() && !static_cast<Text*>(child)->containsOnlyWhitespace()))
217
m_hasFallbackContent = true;
220
if (onlyCreateNonPlugins) {
223
completedURL = frame->loader()->completeURL(url);
225
if (frame->loader()->client()->objectContentType(completedURL, serviceType) == ObjectContentPlugin)
229
bool success = frame->loader()->requestObject(this, url, AtomicString(o->name()), serviceType, paramNames, paramValues);
230
if (!success && m_hasFallbackContent)
231
o->renderFallbackContent();
232
} else if (element()->hasTagName(embedTag)) {
233
HTMLEmbedElement *o = static_cast<HTMLEmbedElement*>(element());
235
serviceType = o->m_serviceType;
237
if (url.isEmpty() && serviceType.isEmpty())
239
if (!isURLAllowed(document(), url))
242
// add all attributes set on the embed object
243
NamedAttrMap* a = o->attributes();
245
for (unsigned i = 0; i < a->length(); ++i) {
246
Attribute* it = a->attributeItem(i);
247
paramNames.append(it->name().localName().domString());
248
paramValues.append(it->value().domString());
252
if (onlyCreateNonPlugins) {
255
completedURL = frame->loader()->completeURL(url);
257
if (frame->loader()->client()->objectContentType(completedURL, serviceType) == ObjectContentPlugin)
261
frame->loader()->requestObject(this, url, o->getAttribute(nameAttr), serviceType, paramNames, paramValues);
265
void RenderPartObject::layout()
267
ASSERT(needsLayout());
271
adjustOverflowForBoxShadow();
273
RenderPart::layout();
278
setNeedsLayout(false);
281
void RenderPartObject::viewCleared()
283
if (element() && m_widget && m_widget->isFrameView()) {
284
FrameView* view = static_cast<FrameView*>(m_widget);
287
if (element()->hasTagName(iframeTag)) {
288
HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(element());
289
marginw = frame->getMarginWidth();
290
marginh = frame->getMarginHeight();
293
view->setMarginWidth(marginw);
295
view->setMarginHeight(marginh);