2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #include <WebCore/GraphicsLayer.h>
30 #include <WebCore/KURL.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/Vector.h>
37 class ArgumentEncoder;
38 class ArgumentDecoder;
42 class GraphicsContext;
48 class ShareableBitmap;
49 class WebKeyboardEvent;
53 class PluginController;
55 class Plugin : public ThreadSafeRefCounted<Plugin> {
60 Vector<String> values;
64 // The URL of the document that the plug-in is in.
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;
71 void encode(CoreIPC::ArgumentEncoder*) const;
72 static bool decode(CoreIPC::ArgumentDecoder*, Parameters&);
75 // Sets the active plug-in controller and initializes the plug-in.
76 bool initialize(PluginController*, const Parameters&);
78 // Destroys the plug-in.
81 // Returns the plug-in controller for this plug-in.
82 PluginController* controller() { return m_pluginController; }
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;
92 // Destroys the plug-in.
93 virtual void destroy() = 0;
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;
101 // Tells the plug-in to draw itself into a bitmap, and return that.
102 virtual PassRefPtr<ShareableBitmap> snapshot() = 0;
105 // If a plug-in is using the Core Animation drawing model, this returns its plug-in layer.
106 virtual PlatformLayer* pluginLayer() = 0;
109 // Returns whether the plug-in is transparent or not.
110 virtual bool isTransparent() = 0;
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;
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;
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;
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;
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;
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;
132 // Tells the plug-in that a stream did receive data.
133 virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length) = 0;
135 // Tells the plug-in that a stream has finished loading.
136 virtual void streamDidFinishLoading(uint64_t streamID) = 0;
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;
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;
145 // Tells the plug-in that the manual stream did receive data.
146 virtual void manualStreamDidReceiveData(const char* bytes, int length) = 0;
148 // Tells the plug-in that a stream has finished loading.
149 virtual void manualStreamDidFinishLoading() = 0;
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;
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;
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;
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;
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;
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;
169 // Tells the plug-in about focus changes.
170 virtual void setFocus(bool) = 0;
172 // Get the NPObject that corresponds to the plug-in's scriptable object. Returns a retained object.
173 virtual NPObject* pluginScriptableNPObject() = 0;
176 // Tells the plug-in about window focus changes.
177 virtual void windowFocusChanged(bool) = 0;
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;
182 // Tells the plug-in about window visibility changes.
183 virtual void windowVisibilityChanged(bool) = 0;
185 // Get the per complex text input identifier.
186 virtual uint64_t pluginComplexTextInputIdentifier() const = 0;
188 // Send the complex text input to the plug-in.
189 virtual void sendComplexTextInput(const String& textInput) = 0;
192 // Called when the private browsing state for this plug-in changes.
193 virtual void privateBrowsingStateChanged(bool) = 0;
195 // Gets the form value representation for the plug-in, letting plug-ins participate in form submission.
196 virtual bool getFormValue(String& formValue) = 0;
202 PluginController* m_pluginController;
205 } // namespace WebKit