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, 2012 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 HTMLPlugInElement_h
24#define HTMLPlugInElement_h
25
26#include "HTMLFrameOwnerElement.h"
27#include "Image.h"
28
29#if ENABLE(NETSCAPE_PLUGIN_API)
30struct NPObject;
31#endif
32
33namespace JSC {
34namespace Bindings {
35class Instance;
36}
37}
38
39namespace WebCore {
40
41class RenderEmbeddedObject;
42class RenderWidget;
43class Widget;
44
45class HTMLPlugInElement : public HTMLFrameOwnerElement {
46public:
47    virtual ~HTMLPlugInElement();
48
49    void resetInstance();
50
51    PassRefPtr<JSC::Bindings::Instance> getInstance();
52
53    Widget* pluginWidget() const;
54
55    enum DisplayState {
56        WaitingForSnapshot,
57        DisplayingSnapshot,
58        Restarting,
59        RestartingWithPendingMouseClick,
60        Playing
61    };
62    DisplayState displayState() const { return m_displayState; }
63    virtual void setDisplayState(DisplayState state) { m_displayState = state; }
64    virtual void updateSnapshot(PassRefPtr<Image>) { }
65    virtual void dispatchPendingMouseClick() { }
66    virtual bool isRestartedPlugin() const { return false; }
67
68#if ENABLE(NETSCAPE_PLUGIN_API)
69    NPObject* getNPObject();
70#endif
71
72    bool isCapturingMouseEvents() const { return m_isCapturingMouseEvents; }
73    void setIsCapturingMouseEvents(bool capturing) { m_isCapturingMouseEvents = capturing; }
74
75    bool canContainRangeEndPoint() const { return false; }
76
77    bool canProcessDrag() const;
78
79    virtual bool willRespondToMouseClickEvents() OVERRIDE;
80
81    virtual bool isPlugInImageElement() const { return false; }
82
83protected:
84    HTMLPlugInElement(const QualifiedName& tagName, Document*);
85
86    virtual void detach(const AttachContext& = AttachContext()) OVERRIDE;
87    virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
88    virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
89
90    virtual bool useFallbackContent() const { return false; }
91
92    virtual void defaultEventHandler(Event*) OVERRIDE;
93
94    // Subclasses should use guardedDispatchBeforeLoadEvent instead of calling dispatchBeforeLoadEvent directly.
95    bool guardedDispatchBeforeLoadEvent(const String& sourceURL);
96
97    bool m_inBeforeLoadEventHandler;
98
99private:
100    bool dispatchBeforeLoadEvent(const String& sourceURL); // Not implemented, generates a compile error if subclasses call this by mistake.
101
102    virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
103
104    virtual RenderWidget* renderWidgetForJSBindings() const = 0;
105
106    virtual bool supportsFocus() const OVERRIDE;
107
108    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
109    virtual bool isPluginElement() const OVERRIDE;
110
111    RefPtr<JSC::Bindings::Instance> m_instance;
112#if ENABLE(NETSCAPE_PLUGIN_API)
113    NPObject* m_NPObject;
114#endif
115    bool m_isCapturingMouseEvents;
116
117    DisplayState m_displayState;
118};
119
120inline HTMLPlugInElement* toHTMLPlugInElement(Node* node)
121{
122    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isPluginElement());
123    return static_cast<HTMLPlugInElement*>(node);
124}
125
126inline const HTMLPlugInElement* toHTMLPlugInElement(const Node* node)
127{
128    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isPluginElement());
129    return static_cast<const HTMLPlugInElement*>(node);
130}
131
132// This will catch anyone doing an unnecessary cast.
133void toHTMLPlugInElement(const HTMLPlugInElement*);
134
135} // namespace WebCore
136
137#endif // HTMLPlugInElement_h
138