summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/WebProcess/Plugins/Plugin.h
blob: b91174f9eb7c27ef3b2fee8b2440af9e41817cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * Copyright (C) 2010 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef Plugin_h
#define Plugin_h

#include <WebCore/GraphicsLayer.h>
#include <WebCore/KURL.h>
#include <WebCore/ScrollTypes.h>
#include <wtf/RefCounted.h>
#include <wtf/RetainPtr.h>
#include <wtf/Vector.h>

#if PLATFORM(MAC)
#include "LayerHostingContext.h"

OBJC_CLASS PDFDocument;
#endif

struct NPObject;

namespace CoreIPC {
    class ArgumentEncoder;
    class ArgumentDecoder;
}

namespace WebCore {
    class AffineTransform;
    class GraphicsContext;
    class IntRect;
    class IntSize;
    class Scrollbar;
}

namespace WebKit {

class ShareableBitmap;
class WebKeyboardEvent;
class WebMouseEvent;
class WebWheelEvent;
    
class PluginController;

class Plugin : public ThreadSafeRefCounted<Plugin> {
public:
    struct Parameters {
        WebCore::KURL url;
        Vector<String> names;
        Vector<String> values;
        String mimeType;
        bool isFullFramePlugin;
        bool shouldUseManualLoader;
#if PLATFORM(MAC)
        LayerHostingMode layerHostingMode;
#endif

        void encode(CoreIPC::ArgumentEncoder*) const;
        static bool decode(CoreIPC::ArgumentDecoder*, Parameters&);
    };

    // Sets the active plug-in controller and initializes the plug-in.
    bool initialize(PluginController*, const Parameters&);

    // Forces synchronous initialization of a plugin previously initialized asynchronously.
    virtual void waitForAsynchronousInitialization() = 0;
    virtual bool isBeingAsynchronouslyInitialized() const = 0;

    // Destroys the plug-in.
    void destroyPlugin();

    // Returns the plug-in controller for this plug-in.
    PluginController* controller() { return m_pluginController; }
    const PluginController* controller() const { return m_pluginController; }

    virtual ~Plugin();

private:

    // Initializes the plug-in. If the plug-in fails to initialize this should return false.
    // This is only called by the other initialize overload so it can be made private.
    virtual bool initialize(const Parameters&) = 0;

    // Destroys the plug-in.
    virtual void destroy() = 0;

public:

    // Tells the plug-in to paint itself into the given graphics context. The passed-in context and
    // dirty rect are in window coordinates. The context is saved/restored by the caller.
    virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect) = 0;

    // Invalidate native tintable controls. The passed-in context is in window coordinates.
    virtual void updateControlTints(WebCore::GraphicsContext*);

    // Tells the plug-in to draw itself into a bitmap, and return that.
    virtual PassRefPtr<ShareableBitmap> snapshot() = 0;

#if PLATFORM(MAC)
    // If a plug-in is using the Core Animation drawing model, this returns its plug-in layer.
    virtual PlatformLayer* pluginLayer() = 0;
#endif
    
    // Returns whether the plug-in is transparent or not.
    virtual bool isTransparent() = 0;

    // Returns whether we should send wheel events to this plug-in.
    virtual bool wantsWheelEvents() = 0;

    // Tells the plug-in that its geometry has changed. The clip rect is in plug-in coordinates, and the affine transform can be used
    // to convert from root view coordinates to plug-in coordinates.
    virtual void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform) = 0;

    // Tells the plug-in that it has been explicitly hidden or shown. (Note that this is not called when the plug-in becomes obscured from view on screen.)
    virtual void visibilityDidChange() = 0;

    // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has finished.
    virtual void frameDidFinishLoading(uint64_t requestID) = 0;

    // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has failed.
    virtual void frameDidFail(uint64_t requestID, bool wasCancelled) = 0;

    // Tells the plug-in that a request to evaluate JavaScript (using PluginController::loadURL) has been fulfilled and passes
    // back the result. If evaluating the script failed, result will be null.
    virtual void didEvaluateJavaScript(uint64_t requestID, const String& result) = 0;

    // Tells the plug-in that a stream has received its HTTP response.
    virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, 
                                          uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFileName) = 0;

    // Tells the plug-in that a stream did receive data.
    virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length) = 0;

    // Tells the plug-in that a stream has finished loading.
    virtual void streamDidFinishLoading(uint64_t streamID) = 0;

    // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled.
    virtual void streamDidFail(uint64_t streamID, bool wasCancelled) = 0;

    // Tells the plug-in that the manual stream has received its HTTP response.
    virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, 
                                                uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFileName) = 0;

    // Tells the plug-in that the manual stream did receive data.
    virtual void manualStreamDidReceiveData(const char* bytes, int length) = 0;

    // Tells the plug-in that a stream has finished loading.
    virtual void manualStreamDidFinishLoading() = 0;
    
    // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled.
    virtual void manualStreamDidFail(bool wasCancelled) = 0;
    
    // Tells the plug-in to handle the passed in mouse event. The plug-in should return true if it processed the event.
    virtual bool handleMouseEvent(const WebMouseEvent&) = 0;

    // Tells the plug-in to handle the passed in wheel event. The plug-in should return true if it processed the event.
    virtual bool handleWheelEvent(const WebWheelEvent&) = 0;

    // Tells the plug-in to handle the passed in mouse over event. The plug-in should return true if it processed the event.
    virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0;
    
    // Tells the plug-in to handle the passed in mouse leave event. The plug-in should return true if it processed the event.
    virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0;

    // Tells the plug-in to handle the passed in context menu event. The plug-in should return true if it processed the event.
    virtual bool handleContextMenuEvent(const WebMouseEvent&) = 0;

    // Tells the plug-in to handle the passed in keyboard event. The plug-in should return true if it processed the event.
    virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0;
    
    // Tells the plug-in about focus changes.
    virtual void setFocus(bool) = 0;

    // Get the NPObject that corresponds to the plug-in's scriptable object. Returns a retained object.
    virtual NPObject* pluginScriptableNPObject() = 0;

#if PLATFORM(MAC)
    // Tells the plug-in about window focus changes.
    virtual void windowFocusChanged(bool) = 0;

    // Tells the plug-in about window and plug-in frame changes.
    virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates) = 0;

    // Tells the plug-in about window visibility changes.
    virtual void windowVisibilityChanged(bool) = 0;

    // Get the per complex text input identifier.
    virtual uint64_t pluginComplexTextInputIdentifier() const = 0;

    // Send the complex text input to the plug-in.
    virtual void sendComplexTextInput(const String& textInput) = 0;

    // Tells the plug-in about changes to the layer hosting mode.
    virtual void setLayerHostingMode(LayerHostingMode) = 0;
#endif

    // Tells the plug-in about scale factor changes.
    virtual void contentsScaleFactorChanged(float) = 0;

    // Called when the private browsing state for this plug-in changes.
    virtual void privateBrowsingStateChanged(bool) = 0;

    // Gets the form value representation for the plug-in, letting plug-ins participate in form submission.
    virtual bool getFormValue(String& formValue) = 0;

    // Tells the plug-in that it should scroll. The plug-in should return true if it did scroll.
    virtual bool handleScroll(WebCore::ScrollDirection, WebCore::ScrollGranularity) = 0;

    // A plug-in can use WebCore scroll bars. Make them known, so that hit testing can find them.
    // FIXME: This code should be in PluginView or its base class, not in individual plug-ins.
    virtual WebCore::Scrollbar* horizontalScrollbar() = 0;
    virtual WebCore::Scrollbar* verticalScrollbar() = 0;

#if PLATFORM(MAC)
    virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; }
#endif

protected:
    Plugin();

private:
    PluginController* m_pluginController;
};
    
} // namespace WebKit

#endif // Plugin_h