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
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
;
51 typedef struct _NPStream
{
61 typedef struct _NPSavedData
{
66 typedef struct _NPRect
{
81 NPPVpluginNameString
= 1,
82 NPPVpluginDescriptionString
,
84 NPPVpluginTransparentBool
,
87 NPPVpluginTimerInterval
,
88 NPPVpluginScriptableInstance
= (10 | NP_ABI_MASK
),
89 NPPVpluginScriptableIID
= 11,
90 NPPVjavascriptPushCallerBool
= 12,
91 NPPVpluginKeepLibraryInMemory
= 13,
92 NPPVpluginNeedsXEmbed
= 14,
93 NPPVpluginScriptableNPObject
= 15,
95 NPPVpluginUrlRequestsDisplayedBool
= 17,
96 NPPVpluginWantsAllNetworkStreams
= 18,
97 NPPVpluginNativeAccessibleAtkPlugId
= 19,
98 NPPVpluginCancelSrcStream
= 20,
99 NPPVSupportsAdvancedKeyHandling
= 21
106 NPNVjavascriptEnabledBool
,
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
122 NPWindowTypeWindow
= 1,
126 typedef struct _NPWindow
{
136 typedef struct _NPFullPrint
{
137 NPBool pluginPrinted
;
142 typedef struct _NPEmbedPrint
{
147 typedef struct _NPPrint
{
150 NPFullPrint fullPrint
;
151 NPEmbedPrint embedPrint
;
155 typedef HRGN NPRegion
;
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
{
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
;
206 NPP_GetValueProcPtr getvalue
;
207 NPP_SetValueProcPtr setvalue
;
208 NPP_GotFocusPtr gotfocus
;
209 NPP_LostFocusPtr lostfocus
;
212 static nsIDOMElement
*get_dom_element(NPP instance
)
214 nsISupports
*instance_unk
= (nsISupports
*)instance
->ndata
;
215 nsIPluginInstance
*plugin_instance
;
219 nsres
= nsISupports_QueryInterface(instance_unk
, &IID_nsIPluginInstance
, (void**)&plugin_instance
);
220 if(NS_FAILED(nsres
)) {
221 ERR("Could not get nsIPluginInstance interface: %08lx\n", nsres
);
225 nsres
= nsIPluginInstance_GetDOMElement(plugin_instance
, &elem
);
226 nsIPluginInstance_Release(plugin_instance
);
227 if(NS_FAILED(nsres
)) {
228 ERR("GetDOMElement failed: %08lx\n", nsres
);
235 static HTMLInnerWindow
*get_elem_window(nsIDOMElement
*elem
)
237 mozIDOMWindowProxy
*mozwindow
;
238 nsIDOMDocument
*nsdoc
;
239 HTMLOuterWindow
*window
;
242 nsres
= nsIDOMElement_GetOwnerDocument(elem
, &nsdoc
);
246 nsres
= nsIDOMDocument_GetDefaultView(nsdoc
, &mozwindow
);
247 nsIDOMDocument_Release(nsdoc
);
248 if(NS_FAILED(nsres
) || !mozwindow
)
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
;
264 NPError err
= NPERR_NO_ERROR
;
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
);
271 ERR("Could not get DOM element\n");
272 return NPERR_GENERIC_ERROR
;
275 window
= get_elem_window(nselem
);
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
);
285 return NPERR_GENERIC_ERROR
;
287 hres
= IHTMLDOMNode_QueryInterface(&node
->IHTMLDOMNode_iface
, &IID_HTMLPluginContainer
,
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
);
298 err
= NPERR_GENERIC_ERROR
;
300 TRACE("plugin host already associated.\n");
303 instance
->pdata
= container
->plugin_host
;
305 node_release(&container
->element
.node
);
309 static NPError CDECL
NPP_Destroy(NPP instance
, NPSavedData
**save
)
311 PluginHost
*host
= instance
->pdata
;
313 TRACE("(%p %p)\n", instance
, save
);
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
);
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
)
341 return NPERR_GENERIC_ERROR
;
344 static NPError CDECL
NPP_DestroyStream(NPP instance
, NPStream
*stream
, NPReason reason
)
347 return NPERR_GENERIC_ERROR
;
350 static INT32 CDECL
NPP_WriteReady(NPP instance
, NPStream
*stream
)
353 return NPERR_GENERIC_ERROR
;
356 static INT32 CDECL
NPP_Write(NPP instance
, NPStream
*stream
, INT32 offset
, INT32 len
, void *buffer
)
359 return NPERR_GENERIC_ERROR
;
362 static void CDECL
NPP_StreamAsFile(NPP instance
, NPStream
*stream
, const char *fname
)
367 static void CDECL
NPP_Print(NPP instance
, NPPrint
*platformPrint
)
372 static INT16 CDECL
NPP_HandleEvent(NPP instance
, void *event
)
375 return NPERR_GENERIC_ERROR
;
378 static void CDECL
NPP_URLNotify(NPP instance
, const char *url
, NPReason reason
, void *notifyData
)
383 static NPError CDECL
NPP_GetValue(NPP instance
, NPPVariable variable
, void *ret_value
)
386 return NPERR_GENERIC_ERROR
;
389 static NPError CDECL
NPP_SetValue(NPP instance
, NPNVariable variable
, void *value
)
392 return NPERR_GENERIC_ERROR
;
395 static NPBool CDECL
NPP_GotFocus(NPP instance
, NPFocusDirection direction
)
398 return NPERR_GENERIC_ERROR
;
401 static void CDECL
NPP_LostFocus(NPP instance
)
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
;