mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / mshtml / npplugin.c
blobdc34727cdb504356146460a1c274386bffd65d21
1 /*
2 * Copyright 2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27 #include "shlobj.h"
29 #include "mshtml_private.h"
30 #include "pluginhost.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36 /* Parts of npapi.h */
38 #define NP_VERSION_MAJOR 0
39 #define NP_VERSION_MINOR 25
41 typedef unsigned char NPBool;
42 typedef INT16 NPError;
43 typedef INT16 NPReason;
44 typedef char *NPMIMEType;
46 typedef struct _NPP {
47 void *pdata;
48 void *ndata;
49 } NPP_t, *NPP;
51 typedef struct _NPStream {
52 void *pdata;
53 void *ndata;
54 const char *url;
55 UINT32 end;
56 UINT32 lastmodified;
57 void *notifyData;
58 const char *headers;
59 } NPStream;
61 typedef struct _NPSavedData {
62 INT32 len;
63 void *buf;
64 } NPSavedData;
66 typedef struct _NPRect {
67 UINT16 top;
68 UINT16 left;
69 UINT16 bottom;
70 UINT16 right;
71 } NPRect;
73 typedef enum {
74 NPFocusNext = 0,
75 NPFocusPrevious = 1
76 } NPFocusDirection;
78 #define NP_ABI_MASK 0
80 typedef enum {
81 NPPVpluginNameString = 1,
82 NPPVpluginDescriptionString,
83 NPPVpluginWindowBool,
84 NPPVpluginTransparentBool,
85 NPPVjavaClass,
86 NPPVpluginWindowSize,
87 NPPVpluginTimerInterval,
88 NPPVpluginScriptableInstance = (10 | NP_ABI_MASK),
89 NPPVpluginScriptableIID = 11,
90 NPPVjavascriptPushCallerBool = 12,
91 NPPVpluginKeepLibraryInMemory = 13,
92 NPPVpluginNeedsXEmbed = 14,
93 NPPVpluginScriptableNPObject = 15,
94 NPPVformValue = 16,
95 NPPVpluginUrlRequestsDisplayedBool = 17,
96 NPPVpluginWantsAllNetworkStreams = 18,
97 NPPVpluginNativeAccessibleAtkPlugId = 19,
98 NPPVpluginCancelSrcStream = 20,
99 NPPVSupportsAdvancedKeyHandling = 21
100 } NPPVariable;
102 typedef enum {
103 NPNVxDisplay = 1,
104 NPNVxtAppContext,
105 NPNVnetscapeWindow,
106 NPNVjavascriptEnabledBool,
107 NPNVasdEnabledBool,
108 NPNVisOfflineBool,
109 NPNVserviceManager = (10 | NP_ABI_MASK),
110 NPNVDOMElement = (11 | NP_ABI_MASK),
111 NPNVDOMWindow = (12 | NP_ABI_MASK),
112 NPNVToolkit = (13 | NP_ABI_MASK),
113 NPNVSupportsXEmbedBool = 14,
114 NPNVWindowNPObject = 15,
115 NPNVPluginElementNPObject = 16,
116 NPNVSupportsWindowless = 17,
117 NPNVprivateModeBool = 18,
118 NPNVsupportsAdvancedKeyHandling = 21
119 } NPNVariable;
121 typedef enum {
122 NPWindowTypeWindow = 1,
123 NPWindowTypeDrawable
124 } NPWindowType;
126 typedef struct _NPWindow {
127 void *window;
128 INT32 x;
129 INT32 y;
130 UINT32 width;
131 UINT32 height;
132 NPRect clipRect;
133 NPWindowType type;
134 } NPWindow;
136 typedef struct _NPFullPrint {
137 NPBool pluginPrinted;
138 NPBool printOne;
139 void *platformPrint;
140 } NPFullPrint;
142 typedef struct _NPEmbedPrint {
143 NPWindow window;
144 void *platformPrint;
145 } NPEmbedPrint;
147 typedef struct _NPPrint {
148 UINT16 mode;
149 union {
150 NPFullPrint fullPrint;
151 NPEmbedPrint embedPrint;
152 } print;
153 } NPPrint;
155 typedef HRGN NPRegion;
157 #define NPERR_BASE 0
158 #define NPERR_NO_ERROR (NPERR_BASE + 0)
159 #define NPERR_GENERIC_ERROR (NPERR_BASE + 1)
160 #define NPERR_INVALID_INSTANCE_ERROR (NPERR_BASE + 2)
161 #define NPERR_INVALID_FUNCTABLE_ERROR (NPERR_BASE + 3)
162 #define NPERR_MODULE_LOAD_FAILED_ERROR (NPERR_BASE + 4)
163 #define NPERR_OUT_OF_MEMORY_ERROR (NPERR_BASE + 5)
164 #define NPERR_INVALID_PLUGIN_ERROR (NPERR_BASE + 6)
165 #define NPERR_INVALID_PLUGIN_DIR_ERROR (NPERR_BASE + 7)
166 #define NPERR_INCOMPATIBLE_VERSION_ERROR (NPERR_BASE + 8)
167 #define NPERR_INVALID_PARAM (NPERR_BASE + 9)
168 #define NPERR_INVALID_URL (NPERR_BASE + 10)
169 #define NPERR_FILE_NOT_FOUND (NPERR_BASE + 11)
170 #define NPERR_NO_DATA (NPERR_BASE + 12)
171 #define NPERR_STREAM_NOT_SEEKABLE (NPERR_BASE + 13)
173 /* Parts of npfunctions.h */
175 typedef NPError (CDECL *NPP_NewProcPtr)(NPMIMEType,NPP,UINT16,INT16,char**,char**,NPSavedData*);
176 typedef NPError (CDECL *NPP_DestroyProcPtr)(NPP,NPSavedData**);
177 typedef NPError (CDECL *NPP_SetWindowProcPtr)(NPP,NPWindow*);
178 typedef NPError (CDECL *NPP_NewStreamProcPtr)(NPP,NPMIMEType,NPStream*,NPBool,UINT16*);
179 typedef NPError (CDECL *NPP_DestroyStreamProcPtr)(NPP,NPStream*,NPReason);
180 typedef INT32 (CDECL *NPP_WriteReadyProcPtr)(NPP,NPStream*);
181 typedef INT32 (CDECL *NPP_WriteProcPtr)(NPP,NPStream*,INT32,INT32,void*);
182 typedef void (CDECL *NPP_StreamAsFileProcPtr)(NPP,NPStream*,const char*);
183 typedef void (CDECL *NPP_PrintProcPtr)(NPP,NPPrint*);
184 typedef INT16 (CDECL *NPP_HandleEventProcPtr)(NPP,void*);
185 typedef void (CDECL *NPP_URLNotifyProcPtr)(NPP,const char*,NPReason,void*);
186 typedef NPError (CDECL *NPP_GetValueProcPtr)(NPP,NPPVariable,void*);
187 typedef NPError (CDECL *NPP_SetValueProcPtr)(NPP,NPNVariable,void*);
188 typedef NPBool (CDECL *NPP_GotFocusPtr)(NPP,NPFocusDirection);
189 typedef void (CDECL *NPP_LostFocusPtr)(NPP);
191 typedef struct _NPPluginFuncs {
192 UINT16 size;
193 UINT16 version;
194 NPP_NewProcPtr newp;
195 NPP_DestroyProcPtr destroy;
196 NPP_SetWindowProcPtr setwindow;
197 NPP_NewStreamProcPtr newstream;
198 NPP_DestroyStreamProcPtr destroystream;
199 NPP_StreamAsFileProcPtr asfile;
200 NPP_WriteReadyProcPtr writeready;
201 NPP_WriteProcPtr write;
202 NPP_PrintProcPtr print;
203 NPP_HandleEventProcPtr event;
204 NPP_URLNotifyProcPtr urlnotify;
205 void *javaClass;
206 NPP_GetValueProcPtr getvalue;
207 NPP_SetValueProcPtr setvalue;
208 NPP_GotFocusPtr gotfocus;
209 NPP_LostFocusPtr lostfocus;
210 } NPPluginFuncs;
212 static nsIDOMElement *get_dom_element(NPP instance)
214 nsISupports *instance_unk = (nsISupports*)instance->ndata;
215 nsIPluginInstance *plugin_instance;
216 nsIDOMElement *elem;
217 nsresult nsres;
219 nsres = nsISupports_QueryInterface(instance_unk, &IID_nsIPluginInstance, (void**)&plugin_instance);
220 if(NS_FAILED(nsres)) {
221 ERR("Could not get nsIPluginInstance interface: %08x\n", nsres);
222 return NULL;
225 nsres = nsIPluginInstance_GetDOMElement(plugin_instance, &elem);
226 nsIPluginInstance_Release(plugin_instance);
227 if(NS_FAILED(nsres)) {
228 ERR("GetDOMElement failed: %08x\n", nsres);
229 return NULL;
232 return elem;
235 static HTMLInnerWindow *get_elem_window(nsIDOMElement *elem)
237 mozIDOMWindowProxy *mozwindow;
238 nsIDOMDocument *nsdoc;
239 HTMLOuterWindow *window;
240 nsresult nsres;
242 nsres = nsIDOMElement_GetOwnerDocument(elem, &nsdoc);
243 if(NS_FAILED(nsres))
244 return NULL;
246 nsres = nsIDOMDocument_GetDefaultView(nsdoc, &mozwindow);
247 nsIDOMDocument_Release(nsdoc);
248 if(NS_FAILED(nsres) || !mozwindow)
249 return NULL;
251 window = mozwindow_to_window(mozwindow);
252 mozIDOMWindowProxy_Release(mozwindow);
254 return window->base.inner_window;
257 static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, INT16 argc, char **argn,
258 char **argv, NPSavedData *saved)
260 HTMLPluginContainer *container;
261 nsIDOMElement *nselem;
262 HTMLInnerWindow *window;
263 HTMLDOMNode *node;
264 NPError err = NPERR_NO_ERROR;
265 HRESULT hres;
267 TRACE("(%s %p %x %d %p %p %p)\n", debugstr_a(pluginType), instance, mode, argc, argn, argv, saved);
269 nselem = get_dom_element(instance);
270 if(!nselem) {
271 ERR("Could not get DOM element\n");
272 return NPERR_GENERIC_ERROR;
275 window = get_elem_window(nselem);
276 if(!window) {
277 ERR("Could not get element's window object\n");
278 nsIDOMElement_Release(nselem);
279 return NPERR_GENERIC_ERROR;
282 hres = get_node((nsIDOMNode*)nselem, TRUE, &node);
283 nsIDOMElement_Release(nselem);
284 if(FAILED(hres))
285 return NPERR_GENERIC_ERROR;
287 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
288 (void**)&container);
289 node_release(node);
290 if(FAILED(hres)) {
291 ERR("Not an object element\n");
292 return NPERR_GENERIC_ERROR;
295 if(!container->plugin_host) {
296 hres = create_plugin_host(window->doc, container);
297 if(FAILED(hres))
298 err = NPERR_GENERIC_ERROR;
299 }else {
300 TRACE("plugin host already associated.\n");
303 instance->pdata = container->plugin_host;
305 node_release(&container->element.node);
306 return err;
309 static NPError CDECL NPP_Destroy(NPP instance, NPSavedData **save)
311 PluginHost *host = instance->pdata;
313 TRACE("(%p %p)\n", instance, save);
315 if(!host)
316 return NPERR_GENERIC_ERROR;
318 detach_plugin_host(host);
319 IOleClientSite_Release(&host->IOleClientSite_iface);
320 instance->pdata = NULL;
321 return NPERR_NO_ERROR;
324 static NPError CDECL NPP_SetWindow(NPP instance, NPWindow *window)
326 PluginHost *host = instance->pdata;
327 RECT pos_rect = {0, 0, window->width, window->height};
329 TRACE("(%p %p)\n", instance, window);
331 if(!host)
332 return NPERR_GENERIC_ERROR;
334 update_plugin_window(host, window->window, &pos_rect);
335 return NPERR_NO_ERROR;
338 static NPError CDECL NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, UINT16 *stype)
340 TRACE("\n");
341 return NPERR_GENERIC_ERROR;
344 static NPError CDECL NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
346 TRACE("\n");
347 return NPERR_GENERIC_ERROR;
350 static INT32 CDECL NPP_WriteReady(NPP instance, NPStream *stream)
352 TRACE("\n");
353 return NPERR_GENERIC_ERROR;
356 static INT32 CDECL NPP_Write(NPP instance, NPStream *stream, INT32 offset, INT32 len, void *buffer)
358 TRACE("\n");
359 return NPERR_GENERIC_ERROR;
362 static void CDECL NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
364 TRACE("\n");
367 static void CDECL NPP_Print(NPP instance, NPPrint *platformPrint)
369 FIXME("\n");
372 static INT16 CDECL NPP_HandleEvent(NPP instance, void *event)
374 TRACE("\n");
375 return NPERR_GENERIC_ERROR;
378 static void CDECL NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
380 TRACE("\n");
383 static NPError CDECL NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value)
385 TRACE("\n");
386 return NPERR_GENERIC_ERROR;
389 static NPError CDECL NPP_SetValue(NPP instance, NPNVariable variable, void *value)
391 TRACE("\n");
392 return NPERR_GENERIC_ERROR;
395 static NPBool CDECL NPP_GotFocus(NPP instance, NPFocusDirection direction)
397 FIXME("\n");
398 return NPERR_GENERIC_ERROR;
401 static void CDECL NPP_LostFocus(NPP instance)
403 FIXME("\n");
406 /***********************************************************************
407 * NP_GetEntryPoints (mshtml.@)
409 NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* funcs)
411 TRACE("(%p)\n", funcs);
413 funcs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
414 funcs->newp = NPP_New;
415 funcs->destroy = NPP_Destroy;
416 funcs->setwindow = NPP_SetWindow;
417 funcs->newstream = NPP_NewStream;
418 funcs->destroystream = NPP_DestroyStream;
419 funcs->asfile = NPP_StreamAsFile;
420 funcs->writeready = NPP_WriteReady;
421 funcs->write = NPP_Write;
422 funcs->print = NPP_Print;
423 funcs->event = NPP_HandleEvent;
424 funcs->urlnotify = NPP_URLNotify;
425 funcs->javaClass = NULL;
426 funcs->getvalue = NPP_GetValue;
427 funcs->setvalue = NPP_SetValue;
428 funcs->gotfocus = NPP_GotFocus;
429 funcs->lostfocus = NPP_LostFocus;
431 return NPERR_NO_ERROR;