ReactOS  0.4.14-dev-50-g13bb5e2
npplugin.c
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include "mshtml_private.h"
20 
21 /* Parts of npapi.h */
22 
23 #define NP_VERSION_MAJOR 0
24 #define NP_VERSION_MINOR 25
25 
26 typedef unsigned char NPBool;
27 typedef INT16 NPError;
28 typedef INT16 NPReason;
29 typedef char *NPMIMEType;
30 
31 typedef struct _NPP {
32  void *pdata;
33  void *ndata;
34 } NPP_t, *NPP;
35 
36 typedef struct _NPStream {
37  void *pdata;
38  void *ndata;
39  const char *url;
42  void *notifyData;
43  const char *headers;
44 } NPStream;
45 
46 typedef struct _NPSavedData {
48  void *buf;
49 } NPSavedData;
50 
51 typedef struct _NPRect {
56 } NPRect;
57 
58 typedef enum {
62 
63 #define NP_ABI_MASK 0
64 
65 typedef enum {
85 } NPPVariable;
86 
87 typedef enum {
104 } NPNVariable;
105 
106 typedef enum {
109 } NPWindowType;
110 
111 typedef struct _NPWindow {
112  void *window;
119 } NPWindow;
120 
121 typedef struct _NPFullPrint {
125 } NPFullPrint;
126 
127 typedef struct _NPEmbedPrint {
130 } NPEmbedPrint;
131 
132 typedef struct _NPPrint {
134  union {
137  } print;
138 } NPPrint;
139 
140 typedef HRGN NPRegion;
141 
142 #define NPERR_BASE 0
143 #define NPERR_NO_ERROR (NPERR_BASE + 0)
144 #define NPERR_GENERIC_ERROR (NPERR_BASE + 1)
145 #define NPERR_INVALID_INSTANCE_ERROR (NPERR_BASE + 2)
146 #define NPERR_INVALID_FUNCTABLE_ERROR (NPERR_BASE + 3)
147 #define NPERR_MODULE_LOAD_FAILED_ERROR (NPERR_BASE + 4)
148 #define NPERR_OUT_OF_MEMORY_ERROR (NPERR_BASE + 5)
149 #define NPERR_INVALID_PLUGIN_ERROR (NPERR_BASE + 6)
150 #define NPERR_INVALID_PLUGIN_DIR_ERROR (NPERR_BASE + 7)
151 #define NPERR_INCOMPATIBLE_VERSION_ERROR (NPERR_BASE + 8)
152 #define NPERR_INVALID_PARAM (NPERR_BASE + 9)
153 #define NPERR_INVALID_URL (NPERR_BASE + 10)
154 #define NPERR_FILE_NOT_FOUND (NPERR_BASE + 11)
155 #define NPERR_NO_DATA (NPERR_BASE + 12)
156 #define NPERR_STREAM_NOT_SEEKABLE (NPERR_BASE + 13)
157 
158 /* Parts of npfunctions.h */
159 
167 typedef void (CDECL *NPP_StreamAsFileProcPtr)(NPP,NPStream*,const char*);
170 typedef void (CDECL *NPP_URLNotifyProcPtr)(NPP,const char*,NPReason,void*);
175 
176 typedef struct _NPPluginFuncs {
190  void *javaClass;
195 } NPPluginFuncs;
196 
198 {
199  nsISupports *instance_unk = (nsISupports*)instance->ndata;
200  nsIPluginInstance *plugin_instance;
201  nsIDOMHTMLElement *html_elem;
203  nsresult nsres;
204 
205  nsres = nsISupports_QueryInterface(instance_unk, &IID_nsIPluginInstance, (void**)&plugin_instance);
206  if(NS_FAILED(nsres)) {
207  ERR("Could not get nsIPluginInstance interface: %08x\n", nsres);
208  return NULL;
209  }
210 
211  nsres = nsIPluginInstance_GetDOMElement(plugin_instance, &elem);
212  nsIPluginInstance_Release(plugin_instance);
213  if(NS_FAILED(nsres)) {
214  ERR("GetDOMElement failed: %08x\n", nsres);
215  return NULL;
216  }
217 
218  nsres = nsIDOMElement_QueryInterface(elem, &IID_nsIDOMHTMLElement, (void**)&html_elem);
219  nsIDOMElement_Release(elem);
220  if(NS_FAILED(nsres)) {
221  ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
222  return NULL;
223  }
224 
225  return html_elem;
226 }
227 
229 {
230  nsIDOMWindow *nswindow;
231  nsIDOMDocument *nsdoc;
233  nsresult nsres;
234 
235  nsres = nsIDOMHTMLElement_GetOwnerDocument(elem, &nsdoc);
236  if(NS_FAILED(nsres))
237  return NULL;
238 
239  nsres = nsIDOMDocument_GetDefaultView(nsdoc, &nswindow);
240  nsIDOMDocument_Release(nsdoc);
241  if(NS_FAILED(nsres) || !nswindow)
242  return NULL;
243 
244  window = nswindow_to_window(nswindow);
245  nsIDOMWindow_Release(nswindow);
246 
247  return window->base.inner_window;
248 }
249 
250 static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, INT16 argc, char **argn,
251  char **argv, NPSavedData *saved)
252 {
254  nsIDOMHTMLElement *nselem;
256  HTMLDOMNode *node;
258  HRESULT hres;
259 
260  TRACE("(%s %p %x %d %p %p %p)\n", debugstr_a(pluginType), instance, mode, argc, argn, argv, saved);
261 
262  nselem = get_dom_element(instance);
263  if(!nselem) {
264  ERR("Could not get DOM element\n");
265  return NPERR_GENERIC_ERROR;
266  }
267 
268  window = get_elem_window(nselem);
269  if(!window) {
270  ERR("Could not get element's window object\n");
271  nsIDOMHTMLElement_Release(nselem);
272  return NPERR_GENERIC_ERROR;
273  }
274 
275  hres = get_node(window->doc, (nsIDOMNode*)nselem, TRUE, &node);
276  nsIDOMHTMLElement_Release(nselem);
277  if(FAILED(hres))
278  return NPERR_GENERIC_ERROR;
279 
280  hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer,
281  (void**)&container);
283  if(FAILED(hres)) {
284  ERR("Not an object element\n");
285  return NPERR_GENERIC_ERROR;
286  }
287 
288  if(!container->plugin_host) {
290  if(FAILED(hres))
292  }else {
293  TRACE("plugin host already associated.\n");
294  }
295 
296  instance->pdata = container->plugin_host;
297 
298  node_release(&container->element.node);
299  return err;
300 }
301 
303 {
304  PluginHost *host = instance->pdata;
305 
306  TRACE("(%p %p)\n", instance, save);
307 
308  if(!host)
309  return NPERR_GENERIC_ERROR;
310 
312  IOleClientSite_Release(&host->IOleClientSite_iface);
313  instance->pdata = NULL;
314  return NPERR_NO_ERROR;
315 }
316 
318 {
319  PluginHost *host = instance->pdata;
320  RECT pos_rect = {0, 0, window->width, window->height};
321 
322  TRACE("(%p %p)\n", instance, window);
323 
324  if(!host)
325  return NPERR_GENERIC_ERROR;
326 
327  update_plugin_window(host, window->window, &pos_rect);
328  return NPERR_NO_ERROR;
329 }
330 
332 {
333  TRACE("\n");
334  return NPERR_GENERIC_ERROR;
335 }
336 
338 {
339  TRACE("\n");
340  return NPERR_GENERIC_ERROR;
341 }
342 
344 {
345  TRACE("\n");
346  return NPERR_GENERIC_ERROR;
347 }
348 
350 {
351  TRACE("\n");
352  return NPERR_GENERIC_ERROR;
353 }
354 
355 static void CDECL NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
356 {
357  TRACE("\n");
358 }
359 
360 static void CDECL NPP_Print(NPP instance, NPPrint *platformPrint)
361 {
362  FIXME("\n");
363 }
364 
366 {
367  TRACE("\n");
368  return NPERR_GENERIC_ERROR;
369 }
370 
371 static void CDECL NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
372 {
373  TRACE("\n");
374 }
375 
377 {
378  TRACE("\n");
379  return NPERR_GENERIC_ERROR;
380 }
381 
383 {
384  TRACE("\n");
385  return NPERR_GENERIC_ERROR;
386 }
387 
389 {
390  FIXME("\n");
391  return NPERR_GENERIC_ERROR;
392 }
393 
395 {
396  FIXME("\n");
397 }
398 
399 /***********************************************************************
400  * NP_GetEntryPoints (mshtml.@)
401  */
403 {
404  TRACE("(%p)\n", funcs);
405 
406  funcs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
407  funcs->newp = NPP_New;
408  funcs->destroy = NPP_Destroy;
409  funcs->setwindow = NPP_SetWindow;
410  funcs->newstream = NPP_NewStream;
411  funcs->destroystream = NPP_DestroyStream;
412  funcs->asfile = NPP_StreamAsFile;
413  funcs->writeready = NPP_WriteReady;
414  funcs->write = NPP_Write;
415  funcs->print = NPP_Print;
416  funcs->event = NPP_HandleEvent;
417  funcs->urlnotify = NPP_URLNotify;
418  funcs->javaClass = NULL;
419  funcs->getvalue = NPP_GetValue;
420  funcs->setvalue = NPP_SetValue;
421  funcs->gotfocus = NPP_GotFocus;
422  funcs->lostfocus = NPP_LostFocus;
423 
424  return NPERR_NO_ERROR;
425 }
NPFocusDirection
Definition: npplugin.c:58
INT16 NPError
Definition: npplugin.c:27
NPWindow window
Definition: npplugin.c:128
static int argc
Definition: ServiceArgs.c:12
struct _NPP * NPP
#define TRUE
Definition: types.h:120
#define NPERR_GENERIC_ERROR
Definition: npplugin.c:144
void * window
Definition: npplugin.c:112
#define NPERR_NO_ERROR
Definition: npplugin.c:143
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
NPFullPrint fullPrint
Definition: npplugin.c:135
static void CDECL NPP_LostFocus(NPP instance)
Definition: npplugin.c:394
struct _NPPluginFuncs NPPluginFuncs
static NPBool CDECL NPP_GotFocus(NPP instance, NPFocusDirection direction)
Definition: npplugin.c:388
static NPError CDECL NPP_SetValue(NPP instance, NPNVariable variable, void *value)
Definition: npplugin.c:382
static NPError CDECL NPP_Destroy(NPP instance, NPSavedData **save)
Definition: npplugin.c:302
void update_plugin_window(PluginHost *host, HWND hwnd, const RECT *rect)
Definition: pluginhost.c:287
static INT16 CDECL NPP_HandleEvent(NPP instance, void *event)
Definition: npplugin.c:365
UINT16 right
Definition: npplugin.c:55
void(CDECL * NPP_PrintProcPtr)(NPP, NPPrint *)
Definition: npplugin.c:168
static void CDECL NPP_Print(NPP instance, NPPrint *platformPrint)
Definition: npplugin.c:360
void * platformPrint
Definition: npplugin.c:129
void(CDECL * NPP_URLNotifyProcPtr)(NPP, const char *, NPReason, void *)
Definition: npplugin.c:170
NPP_StreamAsFileProcPtr asfile
Definition: npplugin.c:184
char * host
Definition: whois.c:55
GLintptr offset
Definition: glext.h:5920
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
void * platformPrint
Definition: npplugin.c:124
static INT32 CDECL NPP_Write(NPP instance, NPStream *stream, INT32 offset, INT32 len, void *buffer)
Definition: npplugin.c:349
NPError(CDECL * NPP_NewStreamProcPtr)(NPP, NPMIMEType, NPStream *, NPBool, UINT16 *)
Definition: npplugin.c:163
const char * url
Definition: npplugin.c:39
#define argv
Definition: mplay32.c:18
UINT32 end
Definition: npplugin.c:40
INT16 NPReason
Definition: npplugin.c:28
void * pdata
Definition: npplugin.c:32
NPP_GetValueProcPtr getvalue
Definition: npplugin.c:191
union _NPPrint::@469 print
struct _NPSavedData NPSavedData
NPP_WriteReadyProcPtr writeready
Definition: npplugin.c:185
static NPError CDECL NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, UINT16 *stype)
Definition: npplugin.c:331
NPError(CDECL * NPP_DestroyProcPtr)(NPP, NPSavedData **)
Definition: npplugin.c:161
struct container container
struct node node
UINT32 height
Definition: npplugin.c:116
static void node_release(HTMLDOMNode *node)
static NPError CDECL NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
Definition: npplugin.c:337
unsigned int UINT32
INT32 len
Definition: npplugin.c:47
INT32 x
Definition: npplugin.c:113
static size_t elem
Definition: string.c:68
UINT16 version
Definition: npplugin.c:178
#define FIXME(fmt,...)
Definition: debug.h:110
NPError WINAPI NP_GetEntryPoints(NPPluginFuncs *funcs)
Definition: npplugin.c:402
void * notifyData
Definition: npplugin.c:42
INT32(CDECL * NPP_WriteReadyProcPtr)(NPP, NPStream *)
Definition: npplugin.c:165
smooth NULL
Definition: ftsmooth.c:416
void * ndata
Definition: npplugin.c:33
HTMLOuterWindow * nswindow_to_window(const nsIDOMWindow *nswindow)
Definition: htmlwindow.c:3099
static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, INT16 argc, char **argn, char **argv, NPSavedData *saved)
Definition: npplugin.c:250
static INT32 CDECL NPP_WriteReady(NPP instance, NPStream *stream)
Definition: npplugin.c:343
NPP_GotFocusPtr gotfocus
Definition: npplugin.c:193
NPP_WriteProcPtr write
Definition: npplugin.c:186
UINT32 width
Definition: npplugin.c:115
void * javaClass
Definition: npplugin.c:190
#define NS_FAILED(res)
void(CDECL * NPP_LostFocusPtr)(NPP)
Definition: npplugin.c:174
UINT16 bottom
Definition: npplugin.c:54
NPBool pluginPrinted
Definition: npplugin.c:122
GLenum GLenum variable
Definition: glext.h:9031
const char * stype[]
Definition: cmds.c:192
NPP_PrintProcPtr print
Definition: npplugin.c:187
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT hres
Definition: protocol.c:465
static HTMLInnerWindow * get_elem_window(nsIDOMHTMLElement *elem)
Definition: npplugin.c:228
struct _NPP NPP_t
NPError(CDECL * NPP_GetValueProcPtr)(NPP, NPPVariable, void *)
Definition: npplugin.c:171
NPError(CDECL * NPP_SetWindowProcPtr)(NPP, NPWindow *)
Definition: npplugin.c:162
#define debugstr_a
Definition: kernel32.h:31
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR url[]
Definition: encode.c:1432
UINT16 left
Definition: npplugin.c:53
NPBool printOne
Definition: npplugin.c:123
#define WINAPI
Definition: msvc.h:8
HRGN NPRegion
Definition: npplugin.c:140
static struct __wine_debug_functions funcs
Definition: debug.c:59
static void CDECL NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
Definition: npplugin.c:355
INT32 y
Definition: npplugin.c:114
UINT16 size
Definition: npplugin.c:177
NPP_NewStreamProcPtr newstream
Definition: npplugin.c:182
NPP_URLNotifyProcPtr urlnotify
Definition: npplugin.c:189
struct _NPWindow NPWindow
void * pdata
Definition: npplugin.c:37
void * ndata
Definition: npplugin.c:38
NPP_DestroyProcPtr destroy
Definition: npplugin.c:180
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
char * NPMIMEType
Definition: npplugin.c:29
void * buf
Definition: npplugin.c:48
Definition: parse.h:22
struct _NPFullPrint NPFullPrint
struct _NPEmbedPrint NPEmbedPrint
GLenum GLsizei len
Definition: glext.h:6722
#define NP_ABI_MASK
Definition: npplugin.c:63
static NPError CDECL NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value)
Definition: npplugin.c:376
NPWindowType
Definition: npplugin.c:106
#define err(...)
HRESULT create_plugin_host(HTMLDocumentNode *doc, HTMLPluginContainer *container)
Definition: pluginhost.c:2048
static IHTMLWindow2 * window
Definition: events.c:77
struct _cl_event * event
Definition: glext.h:7739
GLenum mode
Definition: glext.h:6217
static nsIDOMHTMLElement * get_dom_element(NPP instance)
Definition: npplugin.c:197
NPWindowType type
Definition: npplugin.c:118
NPError(CDECL * NPP_NewProcPtr)(NPMIMEType, NPP, UINT16, INT16, char **, char **, NPSavedData *)
Definition: npplugin.c:160
#define ERR(fmt,...)
Definition: debug.h:109
NPRect clipRect
Definition: npplugin.c:117
NPPVariable
Definition: npplugin.c:65
NPError(CDECL * NPP_SetValueProcPtr)(NPP, NPNVariable, void *)
Definition: npplugin.c:172
#define NP_VERSION_MAJOR
Definition: npplugin.c:23
struct _NPRect NPRect
#define CDECL
Definition: compat.h:21
HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
Definition: htmlnode.c:1339
static HINSTANCE instance
Definition: main.c:40
struct _NPPrint NPPrint
UINT16 top
Definition: npplugin.c:52
unsigned short UINT16
NPP_NewProcPtr newp
Definition: npplugin.c:179
const char * headers
Definition: npplugin.c:43
NPError(CDECL * NPP_DestroyStreamProcPtr)(NPP, NPStream *, NPReason)
Definition: npplugin.c:164
NPP_DestroyStreamProcPtr destroystream
Definition: npplugin.c:183
static void CDECL NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
Definition: npplugin.c:371
Definition: npplugin.c:31
UINT32 lastmodified
Definition: npplugin.c:41
static NPError CDECL NPP_SetWindow(NPP instance, NPWindow *window)
Definition: npplugin.c:317
HRESULT nsresult
Definition: nsiface.idl:39
NPNVariable
Definition: npplugin.c:87
signed int INT32
#define NP_VERSION_MINOR
Definition: npplugin.c:24
NPP_SetWindowProcPtr setwindow
Definition: npplugin.c:181
NPP_HandleEventProcPtr event
Definition: npplugin.c:188
NPP_LostFocusPtr lostfocus
Definition: npplugin.c:194
NPP_SetValueProcPtr setvalue
Definition: npplugin.c:192
void detach_plugin_host(PluginHost *host)
Definition: pluginhost.c:1988
unsigned char NPBool
Definition: npplugin.c:26
INT32(CDECL * NPP_WriteProcPtr)(NPP, NPStream *, INT32, INT32, void *)
Definition: npplugin.c:166
INT16(CDECL * NPP_HandleEventProcPtr)(NPP, void *)
Definition: npplugin.c:169
struct _NPStream NPStream
NPBool(CDECL * NPP_GotFocusPtr)(NPP, NPFocusDirection)
Definition: npplugin.c:173
NPEmbedPrint embedPrint
Definition: npplugin.c:136
UINT16 mode
Definition: npplugin.c:133
void(CDECL * NPP_StreamAsFileProcPtr)(NPP, NPStream *, const char *)
Definition: npplugin.c:167
Definition: dlist.c:348
signed short INT16