ReactOS 0.4.15-dev-5667-ged97270
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
26typedef unsigned char NPBool;
27typedef INT16 NPError;
29typedef char *NPMIMEType;
30
31typedef struct _NPP {
32 void *pdata;
33 void *ndata;
35
36typedef struct _NPStream {
37 void *pdata;
38 void *ndata;
39 const char *url;
43 const char *headers;
45
46typedef struct _NPSavedData {
48 void *buf;
50
51typedef struct _NPRect {
57
58typedef enum {
62
63#define NP_ABI_MASK 0
64
65typedef enum {
86
87typedef enum {
105
106typedef enum {
110
111typedef struct _NPWindow {
112 void *window;
120
121typedef struct _NPFullPrint {
126
127typedef struct _NPEmbedPrint {
131
132typedef struct _NPPrint {
134 union {
139
140typedef 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
170typedef void (CDECL *NPP_URLNotifyProcPtr)(NPP,const char*,NPReason,void*);
175
176typedef struct _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
250static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, INT16 argc, char **argn,
251 char **argv, NPSavedData *saved)
252{
254 nsIDOMHTMLElement *nselem;
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
355static void CDECL NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
356{
357 TRACE("\n");
358}
359
360static 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
371static 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}
unsigned short UINT16
signed int INT32
signed short INT16
unsigned int UINT32
static int argc
Definition: ServiceArgs.c:12
const char * stype[]
Definition: cmds.c:192
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static HINSTANCE instance
Definition: main.c:40
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
#define CDECL
Definition: compat.h:29
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
struct _cl_event * event
Definition: glext.h:7739
GLuint buffer
Definition: glext.h:5915
GLenum mode
Definition: glext.h:6217
GLenum GLenum variable
Definition: glext.h:9031
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
Definition: htmlnode.c:1339
HTMLOuterWindow * nswindow_to_window(const nsIDOMWindow *nswindow)
Definition: htmlwindow.c:3099
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_a
Definition: kernel32.h:31
static const WCHAR url[]
Definition: encode.c:1432
HRESULT hres
Definition: protocol.c:465
static IHTMLWindow2 * window
Definition: events.c:77
static size_t elem
Definition: string.c:68
#define argv
Definition: mplay32.c:18
static void node_release(HTMLDOMNode *node)
#define NS_FAILED(res)
static NPError CDECL NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, UINT16 *stype)
Definition: npplugin.c:331
NPError(CDECL * NPP_GetValueProcPtr)(NPP, NPPVariable, void *)
Definition: npplugin.c:171
static NPError CDECL NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
Definition: npplugin.c:337
NPError(CDECL * NPP_NewProcPtr)(NPMIMEType, NPP, UINT16, INT16, char **, char **, NPSavedData *)
Definition: npplugin.c:160
NPError(CDECL * NPP_SetWindowProcPtr)(NPP, NPWindow *)
Definition: npplugin.c:162
INT16 NPReason
Definition: npplugin.c:28
static NPError CDECL NPP_SetValue(NPP instance, NPNVariable variable, void *value)
Definition: npplugin.c:382
static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, INT16 argc, char **argn, char **argv, NPSavedData *saved)
Definition: npplugin.c:250
static NPError CDECL NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value)
Definition: npplugin.c:376
NPPVariable
Definition: npplugin.c:65
@ NPPVpluginNeedsXEmbed
Definition: npplugin.c:77
@ NPPVpluginTimerInterval
Definition: npplugin.c:72
@ NPPVjavascriptPushCallerBool
Definition: npplugin.c:75
@ NPPVpluginScriptableNPObject
Definition: npplugin.c:78
@ NPPVformValue
Definition: npplugin.c:79
@ NPPVpluginWindowSize
Definition: npplugin.c:71
@ NPPVpluginDescriptionString
Definition: npplugin.c:67
@ NPPVpluginScriptableInstance
Definition: npplugin.c:73
@ NPPVSupportsAdvancedKeyHandling
Definition: npplugin.c:84
@ NPPVpluginNativeAccessibleAtkPlugId
Definition: npplugin.c:82
@ NPPVpluginKeepLibraryInMemory
Definition: npplugin.c:76
@ NPPVpluginWantsAllNetworkStreams
Definition: npplugin.c:81
@ NPPVpluginUrlRequestsDisplayedBool
Definition: npplugin.c:80
@ NPPVpluginCancelSrcStream
Definition: npplugin.c:83
@ NPPVpluginScriptableIID
Definition: npplugin.c:74
@ NPPVpluginWindowBool
Definition: npplugin.c:68
@ NPPVpluginTransparentBool
Definition: npplugin.c:69
@ NPPVpluginNameString
Definition: npplugin.c:66
@ NPPVjavaClass
Definition: npplugin.c:70
NPBool(CDECL * NPP_GotFocusPtr)(NPP, NPFocusDirection)
Definition: npplugin.c:173
INT32(CDECL * NPP_WriteReadyProcPtr)(NPP, NPStream *)
Definition: npplugin.c:165
NPError(CDECL * NPP_DestroyProcPtr)(NPP, NPSavedData **)
Definition: npplugin.c:161
static void CDECL NPP_Print(NPP instance, NPPrint *platformPrint)
Definition: npplugin.c:360
NPFocusDirection
Definition: npplugin.c:58
@ NPFocusPrevious
Definition: npplugin.c:60
@ NPFocusNext
Definition: npplugin.c:59
INT16(CDECL * NPP_HandleEventProcPtr)(NPP, void *)
Definition: npplugin.c:169
void(CDECL * NPP_LostFocusPtr)(NPP)
Definition: npplugin.c:174
void(CDECL * NPP_PrintProcPtr)(NPP, NPPrint *)
Definition: npplugin.c:168
static NPError CDECL NPP_Destroy(NPP instance, NPSavedData **save)
Definition: npplugin.c:302
NPError(CDECL * NPP_NewStreamProcPtr)(NPP, NPMIMEType, NPStream *, NPBool, UINT16 *)
Definition: npplugin.c:163
static HTMLInnerWindow * get_elem_window(nsIDOMHTMLElement *elem)
Definition: npplugin.c:228
#define NP_ABI_MASK
Definition: npplugin.c:63
char * NPMIMEType
Definition: npplugin.c:29
#define NPERR_NO_ERROR
Definition: npplugin.c:143
struct _NPP * NPP
#define NP_VERSION_MINOR
Definition: npplugin.c:24
static INT32 CDECL NPP_WriteReady(NPP instance, NPStream *stream)
Definition: npplugin.c:343
static INT32 CDECL NPP_Write(NPP instance, NPStream *stream, INT32 offset, INT32 len, void *buffer)
Definition: npplugin.c:349
INT16 NPError
Definition: npplugin.c:27
struct _NPP NPP_t
static void CDECL NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
Definition: npplugin.c:371
static INT16 CDECL NPP_HandleEvent(NPP instance, void *event)
Definition: npplugin.c:365
struct _NPSavedData NPSavedData
static nsIDOMHTMLElement * get_dom_element(NPP instance)
Definition: npplugin.c:197
struct _NPRect NPRect
static NPBool CDECL NPP_GotFocus(NPP instance, NPFocusDirection direction)
Definition: npplugin.c:388
void(CDECL * NPP_StreamAsFileProcPtr)(NPP, NPStream *, const char *)
Definition: npplugin.c:167
NPWindowType
Definition: npplugin.c:106
@ NPWindowTypeWindow
Definition: npplugin.c:107
@ NPWindowTypeDrawable
Definition: npplugin.c:108
static NPError CDECL NPP_SetWindow(NPP instance, NPWindow *window)
Definition: npplugin.c:317
void(CDECL * NPP_URLNotifyProcPtr)(NPP, const char *, NPReason, void *)
Definition: npplugin.c:170
INT32(CDECL * NPP_WriteProcPtr)(NPP, NPStream *, INT32, INT32, void *)
Definition: npplugin.c:166
NPError(CDECL * NPP_DestroyStreamProcPtr)(NPP, NPStream *, NPReason)
Definition: npplugin.c:164
#define NP_VERSION_MAJOR
Definition: npplugin.c:23
struct _NPWindow NPWindow
NPError(CDECL * NPP_SetValueProcPtr)(NPP, NPNVariable, void *)
Definition: npplugin.c:172
NPNVariable
Definition: npplugin.c:87
@ NPNVWindowNPObject
Definition: npplugin.c:99
@ NPNVsupportsAdvancedKeyHandling
Definition: npplugin.c:103
@ NPNVSupportsWindowless
Definition: npplugin.c:101
@ NPNVxtAppContext
Definition: npplugin.c:89
@ NPNVDOMElement
Definition: npplugin.c:95
@ NPNVToolkit
Definition: npplugin.c:97
@ NPNVnetscapeWindow
Definition: npplugin.c:90
@ NPNVPluginElementNPObject
Definition: npplugin.c:100
@ NPNVjavascriptEnabledBool
Definition: npplugin.c:91
@ NPNVisOfflineBool
Definition: npplugin.c:93
@ NPNVprivateModeBool
Definition: npplugin.c:102
@ NPNVasdEnabledBool
Definition: npplugin.c:92
@ NPNVSupportsXEmbedBool
Definition: npplugin.c:98
@ NPNVDOMWindow
Definition: npplugin.c:96
@ NPNVserviceManager
Definition: npplugin.c:94
@ NPNVxDisplay
Definition: npplugin.c:88
unsigned char NPBool
Definition: npplugin.c:26
NPError WINAPI NP_GetEntryPoints(NPPluginFuncs *funcs)
Definition: npplugin.c:402
struct _NPStream NPStream
struct _NPFullPrint NPFullPrint
struct _NPPluginFuncs NPPluginFuncs
struct _NPPrint NPPrint
HRGN NPRegion
Definition: npplugin.c:140
struct _NPEmbedPrint NPEmbedPrint
static void CDECL NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
Definition: npplugin.c:355
static void CDECL NPP_LostFocus(NPP instance)
Definition: npplugin.c:394
#define NPERR_GENERIC_ERROR
Definition: npplugin.c:144
void update_plugin_window(PluginHost *host, HWND hwnd, const RECT *rect)
Definition: pluginhost.c:287
void detach_plugin_host(PluginHost *host)
Definition: pluginhost.c:1988
HRESULT create_plugin_host(HTMLDocumentNode *doc, HTMLPluginContainer *container)
Definition: pluginhost.c:2048
#define err(...)
static struct __wine_debug_functions funcs
Definition: debug.c:59
#define TRACE(s)
Definition: solgame.cpp:4
void * platformPrint
Definition: npplugin.c:129
NPWindow window
Definition: npplugin.c:128
NPBool pluginPrinted
Definition: npplugin.c:122
void * platformPrint
Definition: npplugin.c:124
NPBool printOne
Definition: npplugin.c:123
Definition: npplugin.c:31
void * ndata
Definition: npplugin.c:33
void * pdata
Definition: npplugin.c:32
UINT16 version
Definition: npplugin.c:178
NPP_GotFocusPtr gotfocus
Definition: npplugin.c:193
NPP_GetValueProcPtr getvalue
Definition: npplugin.c:191
NPP_LostFocusPtr lostfocus
Definition: npplugin.c:194
NPP_StreamAsFileProcPtr asfile
Definition: npplugin.c:184
NPP_DestroyStreamProcPtr destroystream
Definition: npplugin.c:183
NPP_WriteProcPtr write
Definition: npplugin.c:186
NPP_DestroyProcPtr destroy
Definition: npplugin.c:180
NPP_SetWindowProcPtr setwindow
Definition: npplugin.c:181
NPP_HandleEventProcPtr event
Definition: npplugin.c:188
NPP_NewStreamProcPtr newstream
Definition: npplugin.c:182
NPP_URLNotifyProcPtr urlnotify
Definition: npplugin.c:189
NPP_NewProcPtr newp
Definition: npplugin.c:179
NPP_WriteReadyProcPtr writeready
Definition: npplugin.c:185
NPP_SetValueProcPtr setvalue
Definition: npplugin.c:192
NPP_PrintProcPtr print
Definition: npplugin.c:187
void * javaClass
Definition: npplugin.c:190
UINT16 size
Definition: npplugin.c:177
NPFullPrint fullPrint
Definition: npplugin.c:135
UINT16 mode
Definition: npplugin.c:133
union _NPPrint::@480 print
NPEmbedPrint embedPrint
Definition: npplugin.c:136
UINT16 top
Definition: npplugin.c:52
UINT16 left
Definition: npplugin.c:53
UINT16 bottom
Definition: npplugin.c:54
UINT16 right
Definition: npplugin.c:55
INT32 len
Definition: npplugin.c:47
void * buf
Definition: npplugin.c:48
void * pdata
Definition: npplugin.c:37
UINT32 lastmodified
Definition: npplugin.c:41
UINT32 end
Definition: npplugin.c:40
void * ndata
Definition: npplugin.c:38
const char * headers
Definition: npplugin.c:43
const char * url
Definition: npplugin.c:39
void * notifyData
Definition: npplugin.c:42
UINT32 height
Definition: npplugin.c:116
NPWindowType type
Definition: npplugin.c:118
INT32 y
Definition: npplugin.c:114
UINT32 width
Definition: npplugin.c:115
NPRect clipRect
Definition: npplugin.c:117
void * window
Definition: npplugin.c:112
INT32 x
Definition: npplugin.c:113
Definition: parse.h:23
Definition: dlist.c:348
Definition: pdh_main.c:94
char * host
Definition: whois.c:55
#define WINAPI
Definition: msvc.h:6