• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
6  *           (C) 2000 Stefan Schimanski (1Stein@gmx.de)
7  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
8  *
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.
13  *
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.
18  *
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., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 
25 #include "config.h"
26 #include "HTMLPlugInElement.h"
27 
28 #include "CSSPropertyNames.h"
29 #include "Document.h"
30 #include "Frame.h"
31 #include "FrameLoader.h"
32 #include "FrameTree.h"
33 #include "HTMLNames.h"
34 #include "MappedAttribute.h"
35 #include "Page.h"
36 #include "RenderWidget.h"
37 #include "ScriptController.h"
38 #include "Settings.h"
39 #include "Widget.h"
40 
41 #if ENABLE(NETSCAPE_PLUGIN_API)
42 #include "npruntime_impl.h"
43 #endif
44 
45 namespace WebCore {
46 
47 using namespace HTMLNames;
48 
HTMLPlugInElement(const QualifiedName & tagName,Document * doc)49 HTMLPlugInElement::HTMLPlugInElement(const QualifiedName& tagName, Document* doc)
50     // FIXME: Always passing false as createdByParser is odd (see bug22851).
51     : HTMLFrameOwnerElement(tagName, doc)
52 #if ENABLE(NETSCAPE_PLUGIN_API)
53     , m_NPObject(0)
54 #endif
55 {
56 }
57 
~HTMLPlugInElement()58 HTMLPlugInElement::~HTMLPlugInElement()
59 {
60     ASSERT(!m_instance); // cleared in detach()
61 
62 #if ENABLE(NETSCAPE_PLUGIN_API)
63     if (m_NPObject) {
64         _NPN_ReleaseObject(m_NPObject);
65         m_NPObject = 0;
66     }
67 #endif
68 }
69 
detach()70 void HTMLPlugInElement::detach()
71 {
72     m_instance.clear();
73     HTMLFrameOwnerElement::detach();
74 }
75 
getInstance() const76 PassScriptInstance HTMLPlugInElement::getInstance() const
77 {
78     Frame* frame = document()->frame();
79     if (!frame)
80         return 0;
81 
82     // If the host dynamically turns off JavaScript (or Java) we will still return
83     // the cached allocated Bindings::Instance.  Not supporting this edge-case is OK.
84     if (m_instance)
85         return m_instance;
86 
87     RenderWidget* renderWidget = renderWidgetForJSBindings();
88     if (renderWidget && renderWidget->widget())
89         m_instance = frame->script()->createScriptInstanceForWidget(renderWidget->widget());
90 
91     return m_instance;
92 }
93 
align() const94 String HTMLPlugInElement::align() const
95 {
96     return getAttribute(alignAttr);
97 }
98 
setAlign(const String & value)99 void HTMLPlugInElement::setAlign(const String& value)
100 {
101     setAttribute(alignAttr, value);
102 }
103 
height() const104 String HTMLPlugInElement::height() const
105 {
106     return getAttribute(heightAttr);
107 }
108 
setHeight(const String & value)109 void HTMLPlugInElement::setHeight(const String& value)
110 {
111     setAttribute(heightAttr, value);
112 }
113 
name() const114 String HTMLPlugInElement::name() const
115 {
116     return getAttribute(nameAttr);
117 }
118 
setName(const String & value)119 void HTMLPlugInElement::setName(const String& value)
120 {
121     setAttribute(nameAttr, value);
122 }
123 
width() const124 String HTMLPlugInElement::width() const
125 {
126     return getAttribute(widthAttr);
127 }
128 
setWidth(const String & value)129 void HTMLPlugInElement::setWidth(const String& value)
130 {
131     setAttribute(widthAttr, value);
132 }
133 
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const134 bool HTMLPlugInElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
135 {
136     if (attrName == widthAttr ||
137         attrName == heightAttr ||
138         attrName == vspaceAttr ||
139         attrName == hspaceAttr) {
140             result = eUniversal;
141             return false;
142     }
143 
144     if (attrName == alignAttr) {
145         result = eReplaced; // Share with <img> since the alignment behavior is the same.
146         return false;
147     }
148 
149     return HTMLFrameOwnerElement::mapToEntry(attrName, result);
150 }
151 
parseMappedAttribute(MappedAttribute * attr)152 void HTMLPlugInElement::parseMappedAttribute(MappedAttribute* attr)
153 {
154     if (attr->name() == widthAttr)
155         addCSSLength(attr, CSSPropertyWidth, attr->value());
156     else if (attr->name() == heightAttr)
157         addCSSLength(attr, CSSPropertyHeight, attr->value());
158     else if (attr->name() == vspaceAttr) {
159         addCSSLength(attr, CSSPropertyMarginTop, attr->value());
160         addCSSLength(attr, CSSPropertyMarginBottom, attr->value());
161     } else if (attr->name() == hspaceAttr) {
162         addCSSLength(attr, CSSPropertyMarginLeft, attr->value());
163         addCSSLength(attr, CSSPropertyMarginRight, attr->value());
164     } else if (attr->name() == alignAttr)
165         addHTMLAlignment(attr);
166     else
167         HTMLFrameOwnerElement::parseMappedAttribute(attr);
168 }
169 
checkDTD(const Node * newChild)170 bool HTMLPlugInElement::checkDTD(const Node* newChild)
171 {
172     return newChild->hasTagName(paramTag) || HTMLFrameOwnerElement::checkDTD(newChild);
173 }
174 
defaultEventHandler(Event * event)175 void HTMLPlugInElement::defaultEventHandler(Event* event)
176 {
177     RenderObject* r = renderer();
178     if (!r || !r->isWidget())
179         return;
180     Widget* widget = toRenderWidget(r)->widget();
181     if (!widget)
182         return;
183     widget->handleEvent(event);
184 }
185 
186 #if ENABLE(NETSCAPE_PLUGIN_API)
187 
getNPObject()188 NPObject* HTMLPlugInElement::getNPObject()
189 {
190     ASSERT(document()->frame());
191     if (!m_NPObject)
192         m_NPObject = document()->frame()->script()->createScriptObjectForPluginElement(this);
193     return m_NPObject;
194 }
195 
196 #endif /* ENABLE(NETSCAPE_PLUGIN_API) */
197 
updateWidgetCallback(Node * n)198 void HTMLPlugInElement::updateWidgetCallback(Node* n)
199 {
200     static_cast<HTMLPlugInElement*>(n)->updateWidget();
201 }
202 
203 }
204