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 PluginReplacement;
42class RenderEmbeddedObject;
43class RenderWidget;
44class Widget;
45
46class HTMLPlugInElement : public HTMLFrameOwnerElement {
47public:
48    virtual ~HTMLPlugInElement();
49
50    void resetInstance();
51
52    PassRefPtr<JSC::Bindings::Instance> getInstance();
53
54    Widget* pluginWidget() const;
55
56    enum DisplayState {
57        WaitingForSnapshot,
58        DisplayingSnapshot,
59        Restarting,
60        RestartingWithPendingMouseClick,
61        Playing,
62        PreparingPluginReplacement,
63        DisplayingPluginReplacement,
64    };
65    DisplayState displayState() const { return m_displayState; }
66    virtual void setDisplayState(DisplayState);
67    virtual void updateSnapshot(PassRefPtr<Image>) { }
68    virtual void dispatchPendingMouseClick() { }
69    virtual bool isRestartedPlugin() const { return false; }
70
71    JSC::JSObject* scriptObjectForPluginReplacement();
72
73#if ENABLE(NETSCAPE_PLUGIN_API)
74    NPObject* getNPObject();
75#endif
76
77    bool isCapturingMouseEvents() const { return m_isCapturingMouseEvents; }
78    void setIsCapturingMouseEvents(bool capturing) { m_isCapturingMouseEvents = capturing; }
79
80    virtual bool canContainRangeEndPoint() const override { return false; }
81
82    bool canProcessDrag() const;
83
84#if PLATFORM(IOS)
85    virtual bool willRespondToMouseMoveEvents() override { return false; }
86#endif
87    virtual bool willRespondToMouseClickEvents() override;
88
89    virtual bool isPlugInImageElement() const { return false; }
90
91protected:
92    HTMLPlugInElement(const QualifiedName& tagName, Document&);
93
94    virtual void willDetachRenderers() override;
95    virtual bool isPresentationAttribute(const QualifiedName&) const override;
96    virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
97
98    virtual bool useFallbackContent() const { return false; }
99
100    virtual void defaultEventHandler(Event*) override;
101
102    virtual bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues);
103    virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override;
104    virtual void didAddUserAgentShadowRoot(ShadowRoot*) override;
105
106    // Subclasses should use guardedDispatchBeforeLoadEvent instead of calling dispatchBeforeLoadEvent directly.
107    bool guardedDispatchBeforeLoadEvent(const String& sourceURL);
108
109    bool m_inBeforeLoadEventHandler;
110
111private:
112    void swapRendererTimerFired(Timer<HTMLPlugInElement>&);
113    bool shouldOverridePlugin(const String& url, const String& mimeType);
114
115    bool dispatchBeforeLoadEvent(const String& sourceURL); // Not implemented, generates a compile error if subclasses call this by mistake.
116
117    virtual RenderWidget* renderWidgetForJSBindings() const = 0;
118
119    virtual bool supportsFocus() const override;
120
121    virtual bool isKeyboardFocusable(KeyboardEvent*) const override;
122    virtual bool isPluginElement() const override final;
123
124    RefPtr<JSC::Bindings::Instance> m_instance;
125    Timer<HTMLPlugInElement> m_swapRendererTimer;
126    RefPtr<PluginReplacement> m_pluginReplacement;
127#if ENABLE(NETSCAPE_PLUGIN_API)
128    NPObject* m_NPObject;
129#endif
130    bool m_isCapturingMouseEvents;
131
132    DisplayState m_displayState;
133};
134
135void isHTMLPlugInElement(const HTMLPlugInElement&); // Catch unnecessary runtime check of type known at compile time.
136inline bool isHTMLPlugInElement(const Node& node) { return node.isPluginElement(); }
137NODE_TYPE_CASTS(HTMLPlugInElement)
138
139} // namespace WebCore
140
141#endif // HTMLPlugInElement_h
142