1 | /* |
2 | * Copyright (C) 2010, 2015 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 | #pragma once |
27 | |
28 | #include <WebCore/FindOptions.h> |
29 | #include <WebCore/GraphicsLayer.h> |
30 | #include <WebCore/ScrollTypes.h> |
31 | #include <WebCore/SecurityOrigin.h> |
32 | #include <wtf/RefCounted.h> |
33 | #include <wtf/RetainPtr.h> |
34 | #include <wtf/URL.h> |
35 | #include <wtf/Vector.h> |
36 | |
37 | #if PLATFORM(COCOA) |
38 | #include "LayerHostingContext.h" |
39 | typedef struct objc_object* id; |
40 | |
41 | OBJC_CLASS NSDictionary; |
42 | OBJC_CLASS NSObject; |
43 | OBJC_CLASS PDFDocument; |
44 | OBJC_CLASS PDFSelection; |
45 | #endif |
46 | |
47 | struct NPObject; |
48 | |
49 | namespace IPC { |
50 | class Encoder; |
51 | class Decoder; |
52 | } |
53 | |
54 | namespace WebCore { |
55 | class AffineTransform; |
56 | class FloatPoint; |
57 | class GraphicsContext; |
58 | class IntPoint; |
59 | class IntRect; |
60 | class IntSize; |
61 | class FloatPoint; |
62 | class Scrollbar; |
63 | class SharedBuffer; |
64 | } |
65 | |
66 | namespace WebKit { |
67 | |
68 | class ShareableBitmap; |
69 | class WebKeyboardEvent; |
70 | class WebMouseEvent; |
71 | class WebWheelEvent; |
72 | |
73 | class PluginController; |
74 | |
75 | enum PluginType { |
76 | PluginProxyType, |
77 | NetscapePluginType, |
78 | PDFPluginType, |
79 | }; |
80 | |
81 | class Plugin : public ThreadSafeRefCounted<Plugin> { |
82 | public: |
83 | struct Parameters { |
84 | URL url; |
85 | Vector<String> names; |
86 | Vector<String> values; |
87 | String mimeType; |
88 | bool isFullFramePlugin; |
89 | bool shouldUseManualLoader; |
90 | #if PLATFORM(COCOA) |
91 | LayerHostingMode layerHostingMode; |
92 | #endif |
93 | |
94 | void encode(IPC::Encoder&) const; |
95 | static bool decode(IPC::Decoder&, Parameters&); |
96 | }; |
97 | |
98 | // Sets the active plug-in controller and initializes the plug-in. |
99 | bool initialize(PluginController*, const Parameters&); |
100 | |
101 | virtual bool isBeingAsynchronouslyInitialized() const = 0; |
102 | |
103 | // Destroys the plug-in. |
104 | void destroyPlugin(); |
105 | |
106 | bool isBeingDestroyed() const { return m_isBeingDestroyed; } |
107 | |
108 | // Returns the plug-in controller for this plug-in. |
109 | PluginController* controller() { return m_pluginController; } |
110 | const PluginController* controller() const { return m_pluginController; } |
111 | |
112 | virtual ~Plugin(); |
113 | |
114 | PluginType type() const { return m_type; } |
115 | |
116 | private: |
117 | |
118 | // Initializes the plug-in. If the plug-in fails to initialize this should return false. |
119 | // This is only called by the other initialize overload so it can be made private. |
120 | virtual bool initialize(const Parameters&) = 0; |
121 | |
122 | // Destroys the plug-in. |
123 | virtual void destroy() = 0; |
124 | |
125 | public: |
126 | |
127 | // Tells the plug-in to paint itself into the given graphics context. The passed-in context and |
128 | // dirty rect are in window coordinates. The context is saved/restored by the caller. |
129 | virtual void paint(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) = 0; |
130 | |
131 | // Invalidate native tintable controls. The passed-in context is in window coordinates. |
132 | virtual void updateControlTints(WebCore::GraphicsContext&); |
133 | |
134 | // Returns whether the plug-in supports snapshotting or not. |
135 | virtual bool supportsSnapshotting() const = 0; |
136 | |
137 | // Tells the plug-in to draw itself into a bitmap, and return that. |
138 | virtual RefPtr<ShareableBitmap> snapshot() = 0; |
139 | |
140 | #if PLATFORM(COCOA) |
141 | // If a plug-in is using the Core Animation drawing model, this returns its plug-in layer. |
142 | virtual PlatformLayer* pluginLayer() = 0; |
143 | #endif |
144 | |
145 | // Returns whether the plug-in is transparent or not. |
146 | virtual bool isTransparent() = 0; |
147 | |
148 | // Returns whether we should send wheel events to this plug-in. |
149 | virtual bool wantsWheelEvents() = 0; |
150 | |
151 | // Tells the plug-in that its geometry has changed. The clip rect is in plug-in coordinates, and the affine transform can be used |
152 | // to convert from root view coordinates to plug-in coordinates. |
153 | virtual void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform) = 0; |
154 | |
155 | // 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.) |
156 | virtual void visibilityDidChange(bool isVisible) = 0; |
157 | |
158 | // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has finished. |
159 | virtual void frameDidFinishLoading(uint64_t requestID) = 0; |
160 | |
161 | // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has failed. |
162 | virtual void frameDidFail(uint64_t requestID, bool wasCancelled) = 0; |
163 | |
164 | // Tells the plug-in that a request to evaluate JavaScript (using PluginController::loadURL) has been fulfilled and passes |
165 | // back the result. If evaluating the script failed, result will be null. |
166 | virtual void didEvaluateJavaScript(uint64_t requestID, const String& result) = 0; |
167 | |
168 | // Tells the plug-in that a stream may send an HTTP request. |
169 | virtual void streamWillSendRequest(uint64_t streamID, const URL& requestURL, const URL& responseURL, int responseStatusCode) = 0; |
170 | |
171 | // Tells the plug-in that a stream has received its HTTP response. |
172 | virtual void streamDidReceiveResponse(uint64_t streamID, const URL& responseURL, uint32_t streamLength, |
173 | uint32_t lastModifiedTime, const String& mimeType, const String& , const String& suggestedFileName) = 0; |
174 | |
175 | // Tells the plug-in that a stream did receive data. |
176 | virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length) = 0; |
177 | |
178 | // Tells the plug-in that a stream has finished loading. |
179 | virtual void streamDidFinishLoading(uint64_t streamID) = 0; |
180 | |
181 | // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled. |
182 | virtual void streamDidFail(uint64_t streamID, bool wasCancelled) = 0; |
183 | |
184 | // Tells the plug-in that the manual stream has received its HTTP response. |
185 | virtual void manualStreamDidReceiveResponse(const URL& responseURL, uint32_t streamLength, |
186 | uint32_t lastModifiedTime, const String& mimeType, const String& , const String& suggestedFileName) = 0; |
187 | |
188 | // Tells the plug-in that the manual stream did receive data. |
189 | virtual void manualStreamDidReceiveData(const char* bytes, int length) = 0; |
190 | |
191 | // Tells the plug-in that a stream has finished loading. |
192 | virtual void manualStreamDidFinishLoading() = 0; |
193 | |
194 | // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled. |
195 | virtual void manualStreamDidFail(bool wasCancelled) = 0; |
196 | |
197 | // Tells the plug-in to handle the passed in mouse event. The plug-in should return true if it processed the event. |
198 | virtual bool handleMouseEvent(const WebMouseEvent&) = 0; |
199 | |
200 | // Tells the plug-in to handle the passed in wheel event. The plug-in should return true if it processed the event. |
201 | virtual bool handleWheelEvent(const WebWheelEvent&) = 0; |
202 | |
203 | // Tells the plug-in to handle the passed in mouse over event. The plug-in should return true if it processed the event. |
204 | virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0; |
205 | |
206 | // Tells the plug-in to handle the passed in mouse leave event. The plug-in should return true if it processed the event. |
207 | virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0; |
208 | |
209 | // Tells the plug-in to handle the passed in context menu event. The plug-in should return true if it processed the event. |
210 | virtual bool handleContextMenuEvent(const WebMouseEvent&) = 0; |
211 | |
212 | // Tells the plug-in to handle the passed in keyboard event. The plug-in should return true if it processed the event. |
213 | virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0; |
214 | |
215 | // Tells the plug-in to handle the passed in editing command. The plug-in should return true if it executed the command. |
216 | virtual bool handleEditingCommand(const String& commandName, const String& argument) = 0; |
217 | |
218 | // Ask the plug-in whether it will be able to handle the given editing command. |
219 | virtual bool isEditingCommandEnabled(const String&) = 0; |
220 | |
221 | // Ask the plug-in whether it should be allowed to execute JavaScript or navigate to JavaScript URLs. |
222 | virtual bool shouldAllowScripting() = 0; |
223 | |
224 | // Ask the plug-in whether it wants URLs and files dragged onto it to cause navigation. |
225 | virtual bool shouldAllowNavigationFromDrags() = 0; |
226 | |
227 | // Ask the plug-in whether it wants to override full-page zoom. |
228 | virtual bool handlesPageScaleFactor() const = 0; |
229 | |
230 | // Tells the plug-in about focus changes. |
231 | virtual void setFocus(bool) = 0; |
232 | |
233 | // Get the NPObject that corresponds to the plug-in's scriptable object. Returns a retained object. |
234 | virtual NPObject* pluginScriptableNPObject() = 0; |
235 | |
236 | // Tells the plug-in about window focus changes. |
237 | virtual void windowFocusChanged(bool) = 0; |
238 | |
239 | // Tells the plug-in about window visibility changes. |
240 | virtual void windowVisibilityChanged(bool) = 0; |
241 | |
242 | #if PLATFORM(COCOA) |
243 | // Tells the plug-in about window and plug-in frame changes. |
244 | virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates) = 0; |
245 | |
246 | // Get the per complex text input identifier. |
247 | virtual uint64_t pluginComplexTextInputIdentifier() const = 0; |
248 | |
249 | // Send the complex text input to the plug-in. |
250 | virtual void sendComplexTextInput(const String& textInput) = 0; |
251 | |
252 | // Tells the plug-in about changes to the layer hosting mode. |
253 | virtual void setLayerHostingMode(LayerHostingMode) = 0; |
254 | #endif |
255 | |
256 | // Tells the plug-in about scale factor changes. |
257 | virtual void contentsScaleFactorChanged(float) = 0; |
258 | |
259 | // Called when the storage blocking policy for this plug-in changes. |
260 | virtual void storageBlockingStateChanged(bool) = 0; |
261 | |
262 | // Called when the private browsing state for this plug-in changes. |
263 | virtual void privateBrowsingStateChanged(bool) = 0; |
264 | |
265 | // Gets the form value representation for the plug-in, letting plug-ins participate in form submission. |
266 | virtual bool getFormValue(String& formValue) = 0; |
267 | |
268 | // Tells the plug-in that it should scroll. The plug-in should return true if it did scroll. |
269 | virtual bool handleScroll(WebCore::ScrollDirection, WebCore::ScrollGranularity) = 0; |
270 | |
271 | // A plug-in can use WebCore scroll bars. Make them known, so that hit testing can find them. |
272 | // FIXME: This code should be in PluginView or its base class, not in individual plug-ins. |
273 | virtual WebCore::Scrollbar* horizontalScrollbar() = 0; |
274 | virtual WebCore::Scrollbar* verticalScrollbar() = 0; |
275 | |
276 | #if PLATFORM(COCOA) |
277 | virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; } |
278 | virtual NSObject *accessibilityObject() const { return 0; } |
279 | virtual id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const { return nullptr; } |
280 | #endif |
281 | |
282 | virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0; |
283 | |
284 | virtual bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0; |
285 | |
286 | virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint& pointInLocalCoordinates) const; |
287 | |
288 | virtual bool shouldAlwaysAutoStart() const { return false; } |
289 | |
290 | virtual RefPtr<WebCore::SharedBuffer> liveResourceData() const = 0; |
291 | |
292 | virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) = 0; |
293 | |
294 | virtual String getSelectionString() const = 0; |
295 | virtual String getSelectionForWordAtPoint(const WebCore::FloatPoint&) const = 0; |
296 | virtual bool existingSelectionContainsPoint(const WebCore::FloatPoint&) const = 0; |
297 | |
298 | virtual void mutedStateChanged(bool) { } |
299 | |
300 | virtual bool canCreateTransientPaintingSnapshot() const { return true; } |
301 | |
302 | virtual bool requiresUnifiedScaleFactor() const { return false; } |
303 | |
304 | virtual void willDetachRenderer() { } |
305 | |
306 | virtual bool pluginHandlesContentOffsetForAccessibilityHitTest() const { return false; } |
307 | |
308 | protected: |
309 | Plugin(PluginType); |
310 | |
311 | PluginType m_type; |
312 | |
313 | bool m_isBeingDestroyed { false }; |
314 | |
315 | private: |
316 | PluginController* m_pluginController; |
317 | }; |
318 | |
319 | } // namespace WebKit |
320 | |
321 | #define SPECIALIZE_TYPE_TRAITS_PLUGIN(ToValueTypeName, SpecificPluginType) \ |
322 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::ToValueTypeName) \ |
323 | static bool isType(const WebKit::Plugin& plugin) { return plugin.type() == WebKit::SpecificPluginType; } \ |
324 | SPECIALIZE_TYPE_TRAITS_END() |
325 | |