wmvcore: Print the debug string and not the pointer to it.
[wine.git] / dlls / mshtml / npplugin.c
blob302ff42a2b7b693a009bc1ccf402c3d3d390020f
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 "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "shlobj.h"
31 #include "mshtml_private.h"
32 #include "pluginhost.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 /* Parts of npapi.h */
40 #define NP_VERSION_MAJOR 0
41 #define NP_VERSION_MINOR 25
43 typedef unsigned char NPBool;
44 typedef INT16 NPError;
45 typedef INT16 NPReason;
46 typedef char *NPMIMEType;
48 typedef struct _NPP {
49 void *pdata;
50 void *ndata;
51 } NPP_t, *NPP;
53 typedef struct _NPStream {
54 void *pdata;
55 void *ndata;
56 const char *url;
57 UINT32 end;
58 UINT32 lastmodified;
59 void *notifyData;
60 const char *headers;
61 } NPStream;
63 typedef struct _NPSavedData {
64 INT32 len;
65 void *buf;
66 } NPSavedData;
68 typedef struct _NPRect {
69 UINT16 top;
70 UINT16 left;
71 UINT16 bottom;
72 UINT16 right;
73 } NPRect;
75 typedef enum {
76 NPFocusNext = 0,
77 NPFocusPrevious = 1
78 } NPFocusDirection;
80 #define NP_ABI_MASK 0
82 typedef enum {
83 NPPVpluginNameString = 1,
84 NPPVpluginDescriptionString,
85 NPPVpluginWindowBool,
86 NPPVpluginTransparentBool,
87 NPPVjavaClass,
88 NPPVpluginWindowSize,
89 NPPVpluginTimerInterval,
90 NPPVpluginScriptableInstance = (10 | NP_ABI_MASK),
91 NPPVpluginScriptableIID = 11,
92 NPPVjavascriptPushCallerBool = 12,
93 NPPVpluginKeepLibraryInMemory = 13,
94 NPPVpluginNeedsXEmbed = 14,
95 NPPVpluginScriptableNPObject = 15,
96 NPPVformValue = 16,
97 NPPVpluginUrlRequestsDisplayedBool = 17,
98 NPPVpluginWantsAllNetworkStreams = 18,
99 NPPVpluginNativeAccessibleAtkPlugId = 19,
100 NPPVpluginCancelSrcStream = 20,
101 NPPVSupportsAdvancedKeyHandling = 21
102 } NPPVariable;
104 typedef enum {
105 NPNVxDisplay = 1,
106 NPNVxtAppContext,
107 NPNVnetscapeWindow,
108 NPNVjavascriptEnabledBool,
109 NPNVasdEnabledBool,
110 NPNVisOfflineBool,
111 NPNVserviceManager = (10 | NP_ABI_MASK),
112 NPNVDOMElement = (11 | NP_ABI_MASK),
113 NPNVDOMWindow = (12 | NP_ABI_MASK),
114 NPNVToolkit = (13 | NP_ABI_MASK),
115 NPNVSupportsXEmbedBool = 14,
116 NPNVWindowNPObject = 15,
117 NPNVPluginElementNPObject = 16,
118 NPNVSupportsWindowless = 17,
119 NPNVprivateModeBool = 18,
120 NPNVsupportsAdvancedKeyHandling = 21
121 } NPNVariable;
123 typedef enum {
124 NPWindowTypeWindow = 1,
125 NPWindowTypeDrawable
126 } NPWindowType;
128 typedef struct _NPWindow {
129 void *window;
130 INT32 x;
131 INT32 y;
132 UINT32 width;
133 UINT32 height;
134 NPRect clipRect;
135 NPWindowType type;
136 } NPWindow;
138 typedef struct _NPFullPrint {
139 NPBool pluginPrinted;
140 NPBool printOne;
141 void *platformPrint;
142 } NPFullPrint;
144 typedef struct _NPEmbedPrint {
145 NPWindow window;
146 void *platformPrint;
147 } NPEmbedPrint;
149 typedef struct _NPPrint {
150 UINT16 mode;
151 union {
152 NPFullPrint fullPrint;
153 NPEmbedPrint embedPrint;
154 } print;
155 } NPPrint;
157 typedef HRGN NPRegion;
159 #define NPERR_BASE 0
160 #define NPERR_NO_ERROR (NPERR_BASE + 0)
161 #define NPERR_GENERIC_ERROR (NPERR_BASE + 1)
162 #define NPERR_INVALID_INSTANCE_ERROR (NPERR_BASE + 2)
163 #define NPERR_INVALID_FUNCTABLE_ERROR (NPERR_BASE + 3)
164 #define NPERR_MODULE_LOAD_FAILED_ERROR (NPERR_BASE + 4)
165 #define NPERR_OUT_OF_MEMORY_ERROR (NPERR_BASE + 5)
166 #define NPERR_INVALID_PLUGIN_ERROR (NPERR_BASE + 6)
167 #define NPERR_INVALID_PLUGIN_DIR_ERROR (NPERR_BASE + 7)
168 #define NPERR_INCOMPATIBLE_VERSION_ERROR (NPERR_BASE + 8)
169 #define NPERR_INVALID_PARAM (NPERR_BASE + 9)
170 #define NPERR_INVALID_URL (NPERR_BASE + 10)
171 #define NPERR_FILE_NOT_FOUND (NPERR_BASE + 11)
172 #define NPERR_NO_DATA (NPERR_BASE + 12)
173 #define NPERR_STREAM_NOT_SEEKABLE (NPERR_BASE + 13)
175 /* Parts of npfunctions.h */
177 typedef NPError (CDECL *NPP_NewProcPtr)(NPMIMEType,NPP,UINT16,INT16,char**,char**,NPSavedData*);
178 typedef NPError (CDECL *NPP_DestroyProcPtr)(NPP,NPSavedData**);
179 typedef NPError (CDECL *NPP_SetWindowProcPtr)(NPP,NPWindow*);
180 typedef NPError (CDECL *NPP_NewStreamProcPtr)(NPP,NPMIMEType,NPStream*,NPBool,UINT16*);
181 typedef NPError (CDECL *NPP_DestroyStreamProcPtr)(NPP,NPStream*,NPReason);
182 typedef INT32 (CDECL *NPP_WriteReadyProcPtr)(NPP,NPStream*);
183 typedef INT32 (CDECL *NPP_WriteProcPtr)(NPP,NPStream*,INT32,INT32,void*);
184 typedef void (CDECL *NPP_StreamAsFileProcPtr)(NPP,NPStream*,const char*);
185 typedef void (CDECL *NPP_PrintProcPtr)(NPP,NPPrint*);
186 typedef INT16 (CDECL *NPP_HandleEventProcPtr)(NPP,void*);
187 typedef void (CDECL *NPP_URLNotifyProcPtr)(NPP,const char*,NPReason,void*);
188 typedef NPError (CDECL *NPP_GetValueProcPtr)(NPP,NPPVariable,void*);
189 typedef NPError (CDECL *NPP_SetValueProcPtr)(NPP,NPNVariable,void*);
190 typedef NPBool (CDECL *NPP_GotFocusPtr)(NPP,NPFocusDirection);
191 typedef void (CDECL *NPP_LostFocusPtr)(NPP);
193 typedef struct _NPPluginFuncs {
194 UINT16 size;
195 UINT16 version;
196 NPP_NewProcPtr newp;
197 NPP_DestroyProcPtr destroy;
198 NPP_SetWindowProcPtr setwindow;
199 NPP_NewStreamProcPtr newstream;
200 NPP_DestroyStreamProcPtr destroystream;
201 NPP_StreamAsFileProcPtr asfile;
202 NPP_WriteReadyProcPtr writeready;
203 NPP_WriteProcPtr write;
204 NPP_PrintProcPtr print;
205 NPP_HandleEventProcPtr event;
206 NPP_URLNotifyProcPtr urlnotify;
207 void *javaClass;
208 NPP_GetValueProcPtr getvalue;
209 NPP_SetValueProcPtr setvalue;
210 NPP_GotFocusPtr gotfocus;
211 NPP_LostFocusPtr lostfocus;
212 } NPPluginFuncs;
214 static nsIDOMHTMLElement *get_dom_element(NPP instance)
216 nsISupports *instance_unk = (nsISupports*)instance->ndata;
217 nsIPluginInstance *plugin_instance;
218 nsIDOMHTMLElement *html_elem;
219 nsIDOMElement *elem;
220 nsresult nsres;
222 nsres = nsISupports_QueryInterface(instance_unk, &IID_nsIPluginInstance, (void**)&plugin_instance);
223 if(NS_FAILED(nsres)) {
224 ERR("Could not get nsIPluginInstance interface: %08x\n", nsres);
225 return NULL;
228 nsres = nsIPluginInstance_GetDOMElement(plugin_instance, &elem);
229 nsIPluginInstance_Release(plugin_instance);
230 if(NS_FAILED(nsres)) {
231 ERR("GetDOMElement failed: %08x\n", nsres);
232 return NULL;
235 nsres = nsIDOMElement_QueryInterface(elem, &IID_nsIDOMHTMLElement, (void**)&html_elem);
236 nsIDOMElement_Release(elem);
237 if(NS_FAILED(nsres)) {
238 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
239 return NULL;
242 return html_elem;
245 static HTMLInnerWindow *get_elem_window(nsIDOMHTMLElement *elem)
247 mozIDOMWindowProxy *mozwindow;
248 nsIDOMDocument *nsdoc;
249 HTMLOuterWindow *window;
250 nsresult nsres;
252 nsres = nsIDOMHTMLElement_GetOwnerDocument(elem, &nsdoc);
253 if(NS_FAILED(nsres))
254 return NULL;
256 nsres = nsIDOMDocument_GetDefaultView(nsdoc, &mozwindow);
257 nsIDOMDocument_Release(nsdoc);
258 if(NS_FAILED(nsres) || !mozwindow)
259 return NULL;
261 window = mozwindow_to_window(mozwindow);
262 mozIDOMWindowProxy_Release(mozwindow);
264 return window->base.inner_window;
267 static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, INT16 argc, char **argn,
268 char **argv, NPSavedData *saved)
270 HTMLPluginContainer *container;
271 nsIDOMHTMLElement *nselem;
272 HTMLInnerWindow *window;
273 HTMLDOMNode *node;
274 NPError err = NPERR_NO_ERROR;
275 HRESULT hres;
277 TRACE("(%s %p %x %d %p %p %p)\n", debugstr_a(pluginType), instance, mode, argc, argn, argv, saved);
279 nselem = get_dom_element(instance);
280 if(!nselem) {
281 ERR("Could not get DOM element\n");
282 return NPERR_GENERIC_ERROR;
285 window = get_elem_window(nselem);
286 if(!window) {
287 ERR("Could not get element's window object\n");
288 nsIDOMHTMLElement_Release(nselem);
289 return NPERR_GENERIC_ERROR;
292 hres = get_node(window->doc, (nsIDOMNode*)nselem, TRUE, &node);
293 nsIDOMHTMLElement_Release(nselem);
294 if(FAILED(hres))
295 return NPERR_GENERIC_ERROR;
297 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
298 (void**)&container);
299 node_release(node);
300 if(FAILED(hres)) {
301 ERR("Not an object element\n");
302 return NPERR_GENERIC_ERROR;
305 if(!container->plugin_host) {
306 hres = create_plugin_host(window->doc, container);
307 if(FAILED(hres))
308 err = NPERR_GENERIC_ERROR;
309 }else {
310 TRACE("plugin host already associated.\n");
313 instance->pdata = container->plugin_host;
315 node_release(&container->element.node);
316 return err;
319 static NPError CDECL NPP_Destroy(NPP instance, NPSavedData **save)
321 PluginHost *host = instance->pdata;
323 TRACE("(%p %p)\n", instance, save);
325 if(!host)
326 return NPERR_GENERIC_ERROR;
328 detach_plugin_host(host);
329 IOleClientSite_Release(&host->IOleClientSite_iface);
330 instance->pdata = NULL;
331 return NPERR_NO_ERROR;
334 static NPError CDECL NPP_SetWindow(NPP instance, NPWindow *window)
336 PluginHost *host = instance->pdata;
337 RECT pos_rect = {0, 0, window->width, window->height};
339 TRACE("(%p %p)\n", instance, window);
341 if(!host)
342 return NPERR_GENERIC_ERROR;
344 update_plugin_window(host, window->window, &pos_rect);
345 return NPERR_NO_ERROR;
348 static NPError CDECL NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, UINT16 *stype)
350 TRACE("\n");
351 return NPERR_GENERIC_ERROR;
354 static NPError CDECL NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
356 TRACE("\n");
357 return NPERR_GENERIC_ERROR;
360 static INT32 CDECL NPP_WriteReady(NPP instance, NPStream *stream)
362 TRACE("\n");
363 return NPERR_GENERIC_ERROR;
366 static INT32 CDECL NPP_Write(NPP instance, NPStream *stream, INT32 offset, INT32 len, void *buffer)
368 TRACE("\n");
369 return NPERR_GENERIC_ERROR;
372 static void CDECL NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
374 TRACE("\n");
377 static void CDECL NPP_Print(NPP instance, NPPrint *platformPrint)
379 FIXME("\n");
382 static INT16 CDECL NPP_HandleEvent(NPP instance, void *event)
384 TRACE("\n");
385 return NPERR_GENERIC_ERROR;
388 static void CDECL NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
390 TRACE("\n");
393 static NPError CDECL NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value)
395 TRACE("\n");
396 return NPERR_GENERIC_ERROR;
399 static NPError CDECL NPP_SetValue(NPP instance, NPNVariable variable, void *value)
401 TRACE("\n");
402 return NPERR_GENERIC_ERROR;
405 static NPBool CDECL NPP_GotFocus(NPP instance, NPFocusDirection direction)
407 FIXME("\n");
408 return NPERR_GENERIC_ERROR;
411 static void CDECL NPP_LostFocus(NPP instance)
413 FIXME("\n");
416 /***********************************************************************
417 * NP_GetEntryPoints (mshtml.@)
419 NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* funcs)
421 TRACE("(%p)\n", funcs);
423 funcs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
424 funcs->newp = NPP_New;
425 funcs->destroy = NPP_Destroy;
426 funcs->setwindow = NPP_SetWindow;
427 funcs->newstream = NPP_NewStream;
428 funcs->destroystream = NPP_DestroyStream;
429 funcs->asfile = NPP_StreamAsFile;
430 funcs->writeready = NPP_WriteReady;
431 funcs->write = NPP_Write;
432 funcs->print = NPP_Print;
433 funcs->event = NPP_HandleEvent;
434 funcs->urlnotify = NPP_URLNotify;
435 funcs->javaClass = NULL;
436 funcs->getvalue = NPP_GetValue;
437 funcs->setvalue = NPP_SetValue;
438 funcs->gotfocus = NPP_GotFocus;
439 funcs->lostfocus = NPP_LostFocus;
441 return NPERR_NO_ERROR;