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.
26 #ifndef NetscapePlugin_h
27 #define NetscapePlugin_h
29 #include "NetscapePluginModule.h"
32 #include <WebCore/GraphicsLayer.h>
33 #include <WebCore/IntRect.h>
34 #include <wtf/HashMap.h>
35 #include <wtf/text/CString.h>
36 #include <wtf/text/StringHash.h>
40 class ProtectionSpace;
45 class NetscapePluginStream;
47 class NetscapePlugin : public Plugin {
49 static PassRefPtr<NetscapePlugin> create(PassRefPtr<NetscapePluginModule> pluginModule);
50 virtual ~NetscapePlugin();
52 static PassRefPtr<NetscapePlugin> fromNPP(NPP);
55 NPError setDrawingModel(NPDrawingModel);
56 NPError setEventModel(NPEventModel);
57 NPBool convertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double& destX, double& destY, NPCoordinateSpace destSpace);
58 NPError popUpContextMenu(NPMenu*);
60 void setPluginReturnsNonretainedLayer(bool pluginReturnsNonretainedLayer) { m_pluginReturnsNonretainedLayer = pluginReturnsNonretainedLayer; }
61 void setPluginWantsLegacyCocoaTextInput(bool pluginWantsLegacyCocoaTextInput) { m_pluginWantsLegacyCocoaTextInput = pluginWantsLegacyCocoaTextInput; }
63 bool hasHandledAKeyDownEvent() const { return m_hasHandledAKeyDownEvent; }
65 mach_port_t compositingRenderServerPort();
68 WindowRef windowRef() const;
69 bool isWindowActive() const { return m_windowHasFocus; }
71 static NetscapePlugin* netscapePluginFromWindow(WindowRef);
72 static unsigned buttonState();
76 HWND containingWindow();
79 PluginQuirks quirks() const { return m_pluginModule->pluginQuirks(); }
81 void invalidate(const NPRect*);
82 static const char* userAgent(NPP);
83 void loadURL(const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields,
84 const Vector<uint8_t>& httpBody, bool sendNotification, void* notificationData);
85 NPError destroyStream(NPStream*, NPReason);
86 void setIsWindowed(bool);
87 void setIsTransparent(bool);
88 void setStatusbarText(const String&);
89 static void setException(const String&);
90 bool evaluate(NPObject*, const String&scriptString, NPVariant* result);
91 bool isPrivateBrowsingEnabled();
93 static void setSetExceptionFunction(void (*)(const String&));
95 // These return retained objects.
96 NPObject* windowScriptNPObject();
97 NPObject* pluginElementNPObject();
99 bool tryToShortCircuitInvoke(NPObject*, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, bool& returnValue, NPVariant& result);
101 void cancelStreamLoad(NetscapePluginStream*);
102 void removePluginStream(NetscapePluginStream*);
104 bool isAcceleratedCompositingEnabled();
106 void pushPopupsEnabledState(bool enabled);
107 void popPopupsEnabledState();
109 void pluginThreadAsyncCall(void (*function)(void*), void* userData);
111 // Called on the plug-in run loop (which is currently the main thread run loop).
112 void handlePluginThreadAsyncCall(void (*function)(void*), void* userData);
114 unsigned scheduleTimer(unsigned interval, bool repeat, void (*timerFunc)(NPP, unsigned timerID));
115 void unscheduleTimer(unsigned timerID);
117 String proxiesForURL(const String& urlString);
118 String cookiesForURL(const String& urlString);
119 void setCookiesForURL(const String& urlString, const String& cookieString);
120 bool getAuthenticationInfo(const WebCore::ProtectionSpace&, String& username, String& password);
122 // Member functions for calling into the plug-in.
123 NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData*);
124 NPError NPP_Destroy(NPSavedData**);
125 NPError NPP_SetWindow(NPWindow*);
126 NPError NPP_NewStream(NPMIMEType, NPStream*, NPBool seekable, uint16_t* stype);
127 NPError NPP_DestroyStream(NPStream*, NPReason);
128 void NPP_StreamAsFile(NPStream*, const char* filename);
129 int32_t NPP_WriteReady(NPStream*);
130 int32_t NPP_Write(NPStream*, int32_t offset, int32_t len, void* buffer);
131 int16_t NPP_HandleEvent(void* event);
132 void NPP_URLNotify(const char* url, NPReason, void* notifyData);
133 NPError NPP_GetValue(NPPVariable, void *value);
134 NPError NPP_SetValue(NPNVariable, void *value);
137 NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule);
139 void callSetWindow();
140 bool shouldLoadSrcURL();
141 NetscapePluginStream* streamFromID(uint64_t streamID);
142 void stopAllStreams();
143 bool allowPopups() const;
145 const char* userAgent();
147 bool platformPostInitialize();
148 void platformDestroy();
149 bool platformInvalidate(const WebCore::IntRect&);
150 void platformGeometryDidChange();
151 void platformVisibilityDidChange();
152 void platformPaint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect, bool isSnapshot = false);
154 bool platformHandleMouseEvent(const WebMouseEvent&);
155 bool platformHandleWheelEvent(const WebWheelEvent&);
156 bool platformHandleMouseEnterEvent(const WebMouseEvent&);
157 bool platformHandleMouseLeaveEvent(const WebMouseEvent&);
158 bool platformHandleKeyboardEvent(const WebKeyboardEvent&);
159 void platformSetFocus(bool);
162 virtual bool initialize(const Parameters&);
163 virtual void destroy();
164 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect);
165 virtual PassRefPtr<ShareableBitmap> snapshot();
167 virtual PlatformLayer* pluginLayer();
169 virtual bool isTransparent();
170 virtual void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect);
171 virtual void visibilityDidChange();
172 virtual void frameDidFinishLoading(uint64_t requestID);
173 virtual void frameDidFail(uint64_t requestID, bool wasCancelled);
174 virtual void didEvaluateJavaScript(uint64_t requestID, const String& result);
175 virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength,
176 uint32_t lastModifiedTime, const String& mimeType, const String& headers);
177 virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length);
178 virtual void streamDidFinishLoading(uint64_t streamID);
179 virtual void streamDidFail(uint64_t streamID, bool wasCancelled);
180 virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength,
181 uint32_t lastModifiedTime, const String& mimeType, const String& headers);
182 virtual void manualStreamDidReceiveData(const char* bytes, int length);
183 virtual void manualStreamDidFinishLoading();
184 virtual void manualStreamDidFail(bool wasCancelled);
186 virtual bool handleMouseEvent(const WebMouseEvent&);
187 virtual bool handleWheelEvent(const WebWheelEvent&);
188 virtual bool handleMouseEnterEvent(const WebMouseEvent&);
189 virtual bool handleMouseLeaveEvent(const WebMouseEvent&);
190 virtual bool handleKeyboardEvent(const WebKeyboardEvent&);
191 virtual void setFocus(bool);
192 virtual NPObject* pluginScriptableNPObject();
195 virtual void windowFocusChanged(bool);
196 virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
197 virtual void windowVisibilityChanged(bool);
199 virtual uint64_t pluginComplexTextInputIdentifier() const;
200 virtual void sendComplexTextInput(const String& textInput);
202 void pluginFocusOrWindowFocusChanged();
203 void setComplexTextInputEnabled(bool);
206 virtual void privateBrowsingStateChanged(bool);
207 virtual bool getFormValue(String& formValue);
209 bool supportsSnapshotting() const;
211 #if PLUGIN_ARCHITECTURE(WIN)
212 static BOOL WINAPI hookedTrackPopupMenu(HMENU, UINT uFlags, int x, int y, int nReserved, HWND, const RECT*);
213 void scheduleWindowedGeometryUpdate();
216 uint64_t m_nextRequestID;
218 typedef HashMap<uint64_t, std::pair<String, void*> > PendingURLNotifyMap;
219 PendingURLNotifyMap m_pendingURLNotifications;
221 typedef HashMap<uint64_t, RefPtr<NetscapePluginStream> > StreamsMap;
222 StreamsMap m_streams;
224 RefPtr<NetscapePluginModule> m_pluginModule;
228 WebCore::IntRect m_frameRect;
229 WebCore::IntRect m_clipRect;
235 bool m_isTransparent;
238 RefPtr<NetscapePluginStream> m_manualStream;
239 Vector<bool, 8> m_popupEnabledStates;
242 WTF_MAKE_NONCOPYABLE(Timer);
245 typedef void (*TimerFunc)(NPP, uint32_t timerID);
247 static PassOwnPtr<Timer> create(NetscapePlugin*, unsigned timerID, unsigned interval, bool repeat, TimerFunc);
254 Timer(NetscapePlugin*, unsigned timerID, unsigned interval, bool repeat, TimerFunc);
258 // This is a weak pointer since Timer objects are destroyed before the NetscapePlugin object itself is destroyed.
259 NetscapePlugin* m_netscapePlugin;
264 TimerFunc m_timerFunc;
266 RunLoop::Timer<Timer> m_timer;
268 typedef HashMap<unsigned, Timer*> TimerMap;
270 unsigned m_nextTimerID;
272 #if PLUGIN_ARCHITECTURE(MAC)
273 NPDrawingModel m_drawingModel;
274 NPEventModel m_eventModel;
276 RetainPtr<PlatformLayer> m_pluginLayer;
277 bool m_pluginReturnsNonretainedLayer;
279 NPCocoaEvent* m_currentMouseEvent;
281 bool m_pluginHasFocus;
282 bool m_windowHasFocus;
284 // Whether the plug-in wants to use the legacy Cocoa text input handling that
285 // existed in WebKit1, or the updated Cocoa text input handling specified on
286 // https://wiki.mozilla.org/NPAPI:CocoaEventModel#Text_Input
287 bool m_pluginWantsLegacyCocoaTextInput;
289 // Whether complex text input is enabled.
290 bool m_isComplexTextInputEnabled;
292 // Whether the plug-in has handled a keydown event. This is used to determine
293 // if we can tell the plug-in that we support the updated Cocoa text input specification.
294 bool m_hasHandledAKeyDownEvent;
296 // The number of NPCocoaEventKeyUp events that should be ignored.
297 unsigned m_ignoreNextKeyUpEventCounter;
299 WebCore::IntRect m_windowFrameInScreenCoordinates;
300 WebCore::IntRect m_viewFrameInWindowCoordinates;
303 void nullEventTimerFired();
305 // FIXME: It's a bit wasteful to have one null event timer per plug-in.
306 // We should investigate having one per window.
307 RunLoop::Timer<NetscapePlugin> m_nullEventTimer;
308 NP_CGContext m_npCGContext;
310 #elif PLUGIN_ARCHITECTURE(WIN)
312 HWND m_contextMenuOwnerWindow;
313 #elif PLUGIN_ARCHITECTURE(X11)
315 Display* m_pluginDisplay;
319 } // namespace WebKit
321 #endif // NetscapePlugin_h