1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004-2017 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#pragma once
24
25#include "HTMLFrameOwnerElement.h"
26#include "Image.h"
27#include "RenderEmbeddedObject.h"
28
29namespace JSC {
30namespace Bindings {
31class Instance;
32}
33}
34
35namespace WebCore {
36
37class PluginReplacement;
38class RenderWidget;
39class Widget;
40
41class HTMLPlugInElement : public HTMLFrameOwnerElement {
42 WTF_MAKE_ISO_ALLOCATED(HTMLPlugInElement);
43public:
44 virtual ~HTMLPlugInElement();
45
46 void resetInstance();
47
48 JSC::Bindings::Instance* bindingsInstance();
49
50 enum class PluginLoadingPolicy { DoNotLoad, Load };
51 WEBCORE_EXPORT Widget* pluginWidget(PluginLoadingPolicy = PluginLoadingPolicy::Load) const;
52
53 enum DisplayState {
54 WaitingForSnapshot,
55 DisplayingSnapshot,
56 Restarting,
57 RestartingWithPendingMouseClick,
58 Playing,
59 PreparingPluginReplacement,
60 DisplayingPluginReplacement,
61 };
62 DisplayState displayState() const { return m_displayState; }
63 virtual void setDisplayState(DisplayState);
64 virtual void updateSnapshot(Image*) { }
65 virtual void dispatchPendingMouseClick() { }
66 virtual bool isRestartedPlugin() const { return false; }
67
68 JSC::JSObject* scriptObjectForPluginReplacement();
69
70 bool isCapturingMouseEvents() const { return m_isCapturingMouseEvents; }
71 void setIsCapturingMouseEvents(bool capturing) { m_isCapturingMouseEvents = capturing; }
72
73 bool canContainRangeEndPoint() const override { return false; }
74
75 bool canProcessDrag() const;
76
77#if PLATFORM(IOS_FAMILY)
78 bool willRespondToMouseMoveEvents() override { return false; }
79#endif
80 bool willRespondToMouseClickEvents() override;
81
82 virtual bool isPlugInImageElement() const { return false; }
83
84 bool isUserObservable() const;
85
86 WEBCORE_EXPORT bool isBelowSizeThreshold() const;
87
88 // Return whether or not the replacement content for blocked plugins is accessible to the user.
89 WEBCORE_EXPORT bool setReplacement(RenderEmbeddedObject::PluginUnavailabilityReason, const String& unavailabilityDescription);
90
91 WEBCORE_EXPORT bool isReplacementObscured();
92
93protected:
94 HTMLPlugInElement(const QualifiedName& tagName, Document&);
95
96 void willDetachRenderers() override;
97 bool isPresentationAttribute(const QualifiedName&) const override;
98 void collectStyleForPresentationAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) override;
99
100 virtual bool useFallbackContent() const { return false; }
101
102 void defaultEventHandler(Event&) override;
103
104 virtual bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues);
105 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
106 void didAddUserAgentShadowRoot(ShadowRoot&) override;
107
108 // Subclasses should use guardedDispatchBeforeLoadEvent instead of calling dispatchBeforeLoadEvent directly.
109 bool guardedDispatchBeforeLoadEvent(const String& sourceURL);
110
111 bool m_inBeforeLoadEventHandler;
112
113private:
114 void swapRendererTimerFired();
115 bool shouldOverridePlugin(const String& url, const String& mimeType);
116
117 bool dispatchBeforeLoadEvent(const String& sourceURL) = delete; // Generate a compile error if someone calls this by mistake.
118
119 // This will load the plugin if necessary.
120 virtual RenderWidget* renderWidgetLoadingPlugin() const = 0;
121
122 bool supportsFocus() const override;
123
124 bool isKeyboardFocusable(KeyboardEvent*) const override;
125 bool isPluginElement() const final;
126
127 RefPtr<JSC::Bindings::Instance> m_instance;
128 Timer m_swapRendererTimer;
129 RefPtr<PluginReplacement> m_pluginReplacement;
130 bool m_isCapturingMouseEvents;
131
132 DisplayState m_displayState;
133};
134
135} // namespace WebCore
136
137SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLPlugInElement)
138 static bool isType(const WebCore::Node& node) { return node.isPluginElement(); }
139SPECIALIZE_TYPE_TRAITS_END()
140