initial import
[vuplus_webkit] / Source / WebKit2 / WebProcess / Plugins / Plugin.h
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef Plugin_h
27 #define Plugin_h
28
29 #include <WebCore/GraphicsLayer.h>
30 #include <WebCore/KURL.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/Vector.h>
33
34 struct NPObject;
35
36 namespace CoreIPC {
37     class ArgumentEncoder;
38     class ArgumentDecoder;
39 }
40
41 namespace WebCore {
42     class GraphicsContext;
43     class IntRect;
44 }
45
46 namespace WebKit {
47
48 class ShareableBitmap;
49 class WebKeyboardEvent;
50 class WebMouseEvent;
51 class WebWheelEvent;
52     
53 class PluginController;
54
55 class Plugin : public ThreadSafeRefCounted<Plugin> {
56 public:
57     struct Parameters {
58         WebCore::KURL url;
59         Vector<String> names;
60         Vector<String> values;
61         String mimeType;
62         bool loadManually;
63
64         // The URL of the document that the plug-in is in.
65         String documentURL;
66
67         // The URL of the document in the main frame. Will be null if the document the plug-in
68         // doesn't have access to the main frame document.
69         String toplevelDocumentURL;
70
71         void encode(CoreIPC::ArgumentEncoder*) const;
72         static bool decode(CoreIPC::ArgumentDecoder*, Parameters&);
73     };
74
75     // Sets the active plug-in controller and initializes the plug-in.
76     bool initialize(PluginController*, const Parameters&);
77
78     // Destroys the plug-in.
79     void destroyPlugin();
80
81     // Returns the plug-in controller for this plug-in.
82     PluginController* controller() { return m_pluginController; }
83
84     virtual ~Plugin();
85
86 private:
87
88     // Initializes the plug-in. If the plug-in fails to initialize this should return false.
89     // This is only called by the other initialize overload so it can be made private.
90     virtual bool initialize(const Parameters&) = 0;
91
92     // Destroys the plug-in.
93     virtual void destroy() = 0;
94
95 public:
96
97     // Tells the plug-in to paint itself into the given graphics context. The passed-in context and
98     // dirty rect are in window coordinates. The context is saved/restored by the caller.
99     virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect) = 0;
100
101     // Tells the plug-in to draw itself into a bitmap, and return that.
102     virtual PassRefPtr<ShareableBitmap> snapshot() = 0;
103
104 #if PLATFORM(MAC)
105     // If a plug-in is using the Core Animation drawing model, this returns its plug-in layer.
106     virtual PlatformLayer* pluginLayer() = 0;
107 #endif
108     
109     // Returns whether the plug-in is transparent or not.
110     virtual bool isTransparent() = 0;
111
112     // Tells the plug-in that either the plug-ins frame rect or its clip rect has changed. Both rects are in window coordinates.
113     virtual void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect) = 0;
114
115     // 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.)
116     virtual void visibilityDidChange() = 0;
117
118     // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has finished.
119     virtual void frameDidFinishLoading(uint64_t requestID) = 0;
120
121     // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has failed.
122     virtual void frameDidFail(uint64_t requestID, bool wasCancelled) = 0;
123
124     // Tells the plug-in that a request to evaluate JavaScript (using PluginController::loadURL) has been fulfilled and passes
125     // back the result. If evaluating the script failed, result will be null.
126     virtual void didEvaluateJavaScript(uint64_t requestID, const String& result) = 0;
127
128     // Tells the plug-in that a stream has received its HTTP response.
129     virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, 
130                                           uint32_t lastModifiedTime, const String& mimeType, const String& headers) = 0;
131
132     // Tells the plug-in that a stream did receive data.
133     virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length) = 0;
134
135     // Tells the plug-in that a stream has finished loading.
136     virtual void streamDidFinishLoading(uint64_t streamID) = 0;
137
138     // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled.
139     virtual void streamDidFail(uint64_t streamID, bool wasCancelled) = 0;
140
141     // Tells the plug-in that the manual stream has received its HTTP response.
142     virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, 
143                                                 uint32_t lastModifiedTime, const String& mimeType, const String& headers) = 0;
144
145     // Tells the plug-in that the manual stream did receive data.
146     virtual void manualStreamDidReceiveData(const char* bytes, int length) = 0;
147
148     // Tells the plug-in that a stream has finished loading.
149     virtual void manualStreamDidFinishLoading() = 0;
150     
151     // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled.
152     virtual void manualStreamDidFail(bool wasCancelled) = 0;
153     
154     // Tells the plug-in to handle the passed in mouse event. The plug-in should return true if it processed the event.
155     virtual bool handleMouseEvent(const WebMouseEvent&) = 0;
156
157     // Tells the plug-in to handle the passed in wheel event. The plug-in should return true if it processed the event.
158     virtual bool handleWheelEvent(const WebWheelEvent&) = 0;
159
160     // Tells the plug-in to handle the passed in mouse over event. The plug-in should return true if it processed the event.
161     virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0;
162     
163     // Tells the plug-in to handle the passed in mouse leave event. The plug-in should return true if it processed the event.
164     virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0;
165
166     // Tells the plug-in to handle the passed in keyboard event. The plug-in should return true if it processed the event.
167     virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0;
168     
169     // Tells the plug-in about focus changes.
170     virtual void setFocus(bool) = 0;
171
172     // Get the NPObject that corresponds to the plug-in's scriptable object. Returns a retained object.
173     virtual NPObject* pluginScriptableNPObject() = 0;
174
175 #if PLATFORM(MAC)
176     // Tells the plug-in about window focus changes.
177     virtual void windowFocusChanged(bool) = 0;
178
179     // Tells the plug-in about window and plug-in frame changes.
180     virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates) = 0;
181
182     // Tells the plug-in about window visibility changes.
183     virtual void windowVisibilityChanged(bool) = 0;
184
185     // Get the per complex text input identifier.
186     virtual uint64_t pluginComplexTextInputIdentifier() const = 0;
187
188     // Send the complex text input to the plug-in.
189     virtual void sendComplexTextInput(const String& textInput) = 0;
190 #endif
191
192     // Called when the private browsing state for this plug-in changes.
193     virtual void privateBrowsingStateChanged(bool) = 0;
194
195     // Gets the form value representation for the plug-in, letting plug-ins participate in form submission.
196     virtual bool getFormValue(String& formValue) = 0;
197
198 protected:
199     Plugin();
200
201 private:
202     PluginController* m_pluginController;
203 };
204     
205 } // namespace WebKit
206
207 #endif // Plugin_h