1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB.  If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef HTMLObjectElement_h
24#define HTMLObjectElement_h
25
26#include "core/html/FormAssociatedElement.h"
27#include "core/html/HTMLPlugInElement.h"
28
29namespace blink {
30
31class HTMLFormElement;
32
33class HTMLObjectElement FINAL : public HTMLPlugInElement, public FormAssociatedElement {
34    DEFINE_WRAPPERTYPEINFO();
35    WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLObjectElement);
36public:
37    static PassRefPtrWillBeRawPtr<HTMLObjectElement> create(Document&, HTMLFormElement*, bool createdByParser);
38    virtual ~HTMLObjectElement();
39    virtual void trace(Visitor*) OVERRIDE;
40
41    const String& classId() const { return m_classId; }
42
43    virtual HTMLFormElement* formOwner() const OVERRIDE;
44
45    bool containsJavaApplet() const;
46
47    virtual bool hasFallbackContent() const OVERRIDE;
48    virtual bool useFallbackContent() const OVERRIDE;
49    virtual void renderFallbackContent() OVERRIDE;
50
51    virtual bool isFormControlElement() const OVERRIDE { return false; }
52
53    virtual bool isEnumeratable() const OVERRIDE { return true; }
54    virtual bool isInteractiveContent() const OVERRIDE;
55    virtual bool appendFormData(FormDataList&, bool) OVERRIDE;
56
57    virtual bool isObjectElement() const OVERRIDE { return true; }
58
59    // Implementations of constraint validation API.
60    // Note that the object elements are always barred from constraint validation.
61    virtual String validationMessage() const OVERRIDE { return String(); }
62    bool checkValidity() { return true; }
63    virtual void setCustomValidity(const String&) OVERRIDE { }
64
65#if !ENABLE(OILPAN)
66    using Node::ref;
67    using Node::deref;
68#endif
69
70    virtual bool canContainRangeEndPoint() const OVERRIDE { return useFallbackContent(); }
71
72    bool isExposed() const;
73
74private:
75    HTMLObjectElement(Document&, HTMLFormElement*, bool createdByParser);
76
77    virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
78    virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
79    virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
80
81    virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
82    virtual void removedFrom(ContainerNode*) OVERRIDE;
83
84    virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
85    virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
86
87    virtual void childrenChanged(const ChildrenChange&) OVERRIDE;
88
89    virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
90    virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
91    virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
92    virtual const AtomicString imageSourceURL() const OVERRIDE;
93
94    virtual RenderWidget* existingRenderWidget() const OVERRIDE;
95
96    virtual void updateWidgetInternal() OVERRIDE;
97    void updateDocNamedItem();
98
99    void reattachFallbackContent();
100
101    // FIXME: This function should not deal with url or serviceType
102    // so that we can better share code between <object> and <embed>.
103    void parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues, String& url, String& serviceType);
104
105    bool hasValidClassId();
106
107    void reloadPluginOnAttributeChange(const QualifiedName&);
108
109#if !ENABLE(OILPAN)
110    virtual void refFormAssociatedElement() OVERRIDE { ref(); }
111    virtual void derefFormAssociatedElement() OVERRIDE { deref(); }
112#endif
113
114    virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
115    virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return true; }
116
117    String m_classId;
118    bool m_useFallbackContent : 1;
119};
120
121// Intentionally left unimplemented, template specialization needs to be provided for specific
122// return types.
123template<typename T> inline const T& toElement(const FormAssociatedElement&);
124template<typename T> inline const T* toElement(const FormAssociatedElement*);
125
126// Make toHTMLObjectElement() accept a FormAssociatedElement as input instead of a Node.
127template<> inline const HTMLObjectElement* toElement<HTMLObjectElement>(const FormAssociatedElement* element)
128{
129    ASSERT_WITH_SECURITY_IMPLICATION(!element || !element->isFormControlElement());
130    ASSERT_WITH_SECURITY_IMPLICATION(!element || !element->isLabelElement());
131    const HTMLObjectElement* objectElement = static_cast<const HTMLObjectElement*>(element);
132    // We need to assert after the cast because FormAssociatedElement doesn't
133    // have hasTagName.
134    ASSERT_WITH_SECURITY_IMPLICATION(!objectElement || objectElement->hasTagName(HTMLNames::objectTag));
135    return objectElement;
136}
137
138template<> inline const HTMLObjectElement& toElement<HTMLObjectElement>(const FormAssociatedElement& element)
139{
140    ASSERT_WITH_SECURITY_IMPLICATION(!element.isFormControlElement());
141    ASSERT_WITH_SECURITY_IMPLICATION(!element.isLabelElement());
142    const HTMLObjectElement& objectElement = static_cast<const HTMLObjectElement&>(element);
143    // We need to assert after the cast because FormAssociatedElement doesn't
144    // have hasTagName.
145    ASSERT_WITH_SECURITY_IMPLICATION(objectElement.hasTagName(HTMLNames::objectTag));
146    return objectElement;
147}
148
149} // namespace blink
150
151#endif // HTMLObjectElement_h
152