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
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 */
41 #define NPERR_NO_ERROR (NPERR_BASE + 0)
42 #define NPERR_GENERIC_ERROR (NPERR_BASE + 1)
43 #define NPERR_INVALID_INSTANCE_ERROR (NPERR_BASE + 2)
44 #define NPERR_INVALID_FUNCTABLE_ERROR (NPERR_BASE + 3)
45 #define NPERR_MODULE_LOAD_FAILED_ERROR (NPERR_BASE + 4)
46 #define NPERR_OUT_OF_MEMORY_ERROR (NPERR_BASE + 5)
47 #define NPERR_INVALID_PLUGIN_ERROR (NPERR_BASE + 6)
48 #define NPERR_INVALID_PLUGIN_DIR_ERROR (NPERR_BASE + 7)
49 #define NPERR_INCOMPATIBLE_VERSION_ERROR (NPERR_BASE + 8)
50 #define NPERR_INVALID_PARAM (NPERR_BASE + 9)
51 #define NPERR_INVALID_URL (NPERR_BASE + 10)
52 #define NPERR_FILE_NOT_FOUND (NPERR_BASE + 11)
53 #define NPERR_NO_DATA (NPERR_BASE + 12)
54 #define NPERR_STREAM_NOT_SEEKABLE (NPERR_BASE + 13)
56 /* Parts of npfunctions.h */
58 typedef NPError (CDECL
*NPP_NewProcPtr
)(NPMIMEType
,NPP
,UINT16
,INT16
,char**,char**,NPSavedData
*);
59 typedef NPError (CDECL
*NPP_DestroyProcPtr
)(NPP
,NPSavedData
**);
60 typedef NPError (CDECL
*NPP_SetWindowProcPtr
)(NPP
,NPWindow
*);
61 typedef NPError (CDECL
*NPP_NewStreamProcPtr
)(NPP
,NPMIMEType
,NPStream
*,NPBool
,UINT16
*);
62 typedef NPError (CDECL
*NPP_DestroyStreamProcPtr
)(NPP
,NPStream
*,NPReason
);
63 typedef INT32 (CDECL
*NPP_WriteReadyProcPtr
)(NPP
,NPStream
*);
64 typedef INT32 (CDECL
*NPP_WriteProcPtr
)(NPP
,NPStream
*,INT32
,INT32
,void*);
65 typedef void (CDECL
*NPP_StreamAsFileProcPtr
)(NPP
,NPStream
*,const char*);
66 typedef void (CDECL
*NPP_PrintProcPtr
)(NPP
,NPPrint
*);
67 typedef INT16 (CDECL
*NPP_HandleEventProcPtr
)(NPP
,void*);
68 typedef void (CDECL
*NPP_URLNotifyProcPtr
)(NPP
,const char*,NPReason
,void*);
69 typedef NPError (CDECL
*NPP_GetValueProcPtr
)(NPP
,NPPVariable
,void*);
70 typedef NPError (CDECL
*NPP_SetValueProcPtr
)(NPP
,NPNVariable
,void*);
71 typedef NPBool (CDECL
*NPP_GotFocusPtr
)(NPP
,NPFocusDirection
);
72 typedef void (CDECL
*NPP_LostFocusPtr
)(NPP
);
74 typedef struct _NPPluginFuncs
{
78 NPP_DestroyProcPtr destroy
;
79 NPP_SetWindowProcPtr setwindow
;
80 NPP_NewStreamProcPtr newstream
;
81 NPP_DestroyStreamProcPtr destroystream
;
82 NPP_StreamAsFileProcPtr asfile
;
83 NPP_WriteReadyProcPtr writeready
;
84 NPP_WriteProcPtr write
;
85 NPP_PrintProcPtr print
;
86 NPP_HandleEventProcPtr event
;
87 NPP_URLNotifyProcPtr urlnotify
;
89 NPP_GetValueProcPtr getvalue
;
90 NPP_SetValueProcPtr setvalue
;
91 NPP_GotFocusPtr gotfocus
;
92 NPP_LostFocusPtr lostfocus
;
95 static nsIDOMElement
*get_dom_element(NPP instance
)
97 nsISupports
*instance_unk
= (nsISupports
*)instance
->ndata
;
98 nsIPluginInstance
*plugin_instance
;
102 nsres
= nsISupports_QueryInterface(instance_unk
, &IID_nsIPluginInstance
, (void**)&plugin_instance
);
103 if(NS_FAILED(nsres
)) {
104 ERR("Could not get nsIPluginInstance interface: %08x\n", nsres
);
108 nsres
= nsIPluginInstance_GetDOMElement(plugin_instance
, &elem
);
109 nsIPluginInstance_Release(plugin_instance
);
110 if(NS_FAILED(nsres
)) {
111 ERR("GetDOMElement failed: %08x\n", nsres
);
118 static HTMLWindow
*get_elem_window(nsIDOMElement
*elem
)
120 nsIDOMWindow
*nswindow
;
121 nsIDOMDocument
*nsdoc
;
125 nsres
= nsIDOMElement_GetOwnerDocument(elem
, &nsdoc
);
129 nsres
= nsIDOMDocument_GetDefaultView(nsdoc
, &nswindow
);
130 nsIDOMDocument_Release(nsdoc
);
131 if(NS_FAILED(nsres
) || !nswindow
)
134 window
= nswindow_to_window(nswindow
);
135 nsIDOMWindow_Release(nswindow
);
140 static BOOL
parse_classid(const PRUnichar
*classid
, CLSID
*clsid
)
146 static const PRUnichar clsidW
[] = {'c','l','s','i','d',':'};
148 if(strncmpiW(classid
, clsidW
, sizeof(clsidW
)/sizeof(WCHAR
)))
151 ptr
= classid
+ sizeof(clsidW
)/sizeof(WCHAR
);
155 hres
= CLSIDFromString(ptr
, clsid
);
156 }else if(len
== 36) {
160 memcpy(buf
+1, ptr
, len
*sizeof(WCHAR
));
163 hres
= CLSIDFromString(buf
, clsid
);
168 return SUCCEEDED(hres
);
171 static BOOL
get_elem_clsid(nsIDOMElement
*elem
, CLSID
*clsid
)
173 nsAString attr_str
, val_str
;
177 static const PRUnichar classidW
[] = {'c','l','a','s','s','i','d',0};
179 nsAString_InitDepend(&attr_str
, classidW
);
180 nsAString_Init(&val_str
, NULL
);
181 nsres
= nsIDOMElement_GetAttribute(elem
, &attr_str
, &val_str
);
182 nsAString_Finish(&attr_str
);
183 if(NS_SUCCEEDED(nsres
)) {
184 const PRUnichar
*val
;
186 nsAString_GetData(&val_str
, &val
);
188 ret
= parse_classid(val
, clsid
);
190 ERR("GetAttribute failed: %08x\n", nsres
);
193 nsAString_Finish(&attr_str
);
197 static IUnknown
*create_activex_object(HTMLWindow
*window
, nsIDOMElement
*nselem
, CLSID
*clsid
)
199 IClassFactoryEx
*cfex
;
205 if(!get_elem_clsid(nselem
, clsid
)) {
206 WARN("Could not determine element CLSID\n");
210 TRACE("clsid %s\n", debugstr_guid(clsid
));
213 hres
= IInternetHostSecurityManager_ProcessUrlAction(&window
->doc
->IInternetHostSecurityManager_iface
,
214 URLACTION_ACTIVEX_RUN
, (BYTE
*)&policy
, sizeof(policy
), (BYTE
*)clsid
, sizeof(GUID
), 0, 0);
215 if(FAILED(hres
) || policy
!= URLPOLICY_ALLOW
) {
216 WARN("ProcessUrlAction returned %08x %x\n", hres
, policy
);
220 hres
= CoGetClassObject(clsid
, CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, NULL
, &IID_IClassFactory
, (void**)&cf
);
224 hres
= IClassFactory_QueryInterface(cf
, &IID_IClassFactoryEx
, (void**)&cfex
);
225 if(SUCCEEDED(hres
)) {
226 FIXME("Use IClassFactoryEx\n");
227 IClassFactoryEx_Release(cfex
);
230 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IUnknown
, (void**)&obj
);
237 static NPError CDECL
NPP_New(NPMIMEType pluginType
, NPP instance
, UINT16 mode
, INT16 argc
, char **argn
,
238 char **argv
, NPSavedData
*saved
)
240 nsIDOMElement
*nselem
;
244 NPError err
= NPERR_NO_ERROR
;
246 TRACE("(%s %p %x %d %p %p %p)\n", debugstr_a(pluginType
), instance
, mode
, argc
, argn
, argv
, saved
);
248 nselem
= get_dom_element(instance
);
250 ERR("Could not get DOM element\n");
251 return NPERR_GENERIC_ERROR
;
254 window
= get_elem_window(nselem
);
256 ERR("Could not get element's window object\n");
257 nsIDOMElement_Release(nselem
);
258 return NPERR_GENERIC_ERROR
;
261 obj
= create_activex_object(window
, nselem
, &clsid
);
266 hres
= create_plugin_host(window
->doc
, nselem
, obj
, &clsid
, &host
);
267 nsIDOMElement_Release(nselem
);
268 IUnknown_Release(obj
);
270 instance
->pdata
= host
;
272 err
= NPERR_GENERIC_ERROR
;
274 err
= NPERR_GENERIC_ERROR
;
277 nsIDOMElement_Release(nselem
);
281 static NPError CDECL
NPP_Destroy(NPP instance
, NPSavedData
**save
)
283 PluginHost
*host
= instance
->pdata
;
285 TRACE("(%p %p)\n", instance
, save
);
288 return NPERR_GENERIC_ERROR
;
290 detach_plugin_host(host
);
291 IOleClientSite_Release(&host
->IOleClientSite_iface
);
292 instance
->pdata
= NULL
;
293 return NPERR_NO_ERROR
;
296 static NPError CDECL
NPP_SetWindow(NPP instance
, NPWindow
*window
)
298 PluginHost
*host
= instance
->pdata
;
299 RECT pos_rect
= {0, 0, window
->width
, window
->height
};
301 TRACE("(%p %p)\n", instance
, window
);
304 return NPERR_GENERIC_ERROR
;
306 update_plugin_window(host
, window
->window
, &pos_rect
);
307 return NPERR_NO_ERROR
;
310 static NPError CDECL
NPP_NewStream(NPP instance
, NPMIMEType type
, NPStream
*stream
, NPBool seekable
, UINT16
*stype
)
313 return NPERR_GENERIC_ERROR
;
316 static NPError CDECL
NPP_DestroyStream(NPP instance
, NPStream
*stream
, NPReason reason
)
319 return NPERR_GENERIC_ERROR
;
322 static INT32 CDECL
NPP_WriteReady(NPP instance
, NPStream
*stream
)
325 return NPERR_GENERIC_ERROR
;
328 static INT32 CDECL
NPP_Write(NPP instance
, NPStream
*stream
, INT32 offset
, INT32 len
, void *buffer
)
331 return NPERR_GENERIC_ERROR
;
334 static void CDECL
NPP_StreamAsFile(NPP instance
, NPStream
*stream
, const char *fname
)
339 static void CDECL
NPP_Print(NPP instance
, NPPrint
*platformPrint
)
344 static INT16 CDECL
NPP_HandleEvent(NPP instance
, void *event
)
347 return NPERR_GENERIC_ERROR
;
350 static void CDECL
NPP_URLNotify(NPP instance
, const char *url
, NPReason reason
, void *notifyData
)
355 static NPError CDECL
NPP_GetValue(NPP instance
, NPPVariable variable
, void *ret_value
)
358 return NPERR_GENERIC_ERROR
;
361 static NPError CDECL
NPP_SetValue(NPP instance
, NPNVariable variable
, void *value
)
364 return NPERR_GENERIC_ERROR
;
367 static NPBool CDECL
NPP_GotFocus(NPP instance
, NPFocusDirection direction
)
370 return NPERR_GENERIC_ERROR
;
373 static void CDECL
NPP_LostFocus(NPP instance
)
378 /***********************************************************************
379 * NP_GetEntryPoints (mshtml.@)
381 NPError WINAPI
NP_GetEntryPoints(NPPluginFuncs
* funcs
)
383 TRACE("(%p)\n", funcs
);
385 funcs
->version
= (NP_VERSION_MAJOR
<< 8) | NP_VERSION_MINOR
;
386 funcs
->newp
= NPP_New
;
387 funcs
->destroy
= NPP_Destroy
;
388 funcs
->setwindow
= NPP_SetWindow
;
389 funcs
->newstream
= NPP_NewStream
;
390 funcs
->destroystream
= NPP_DestroyStream
;
391 funcs
->asfile
= NPP_StreamAsFile
;
392 funcs
->writeready
= NPP_WriteReady
;
393 funcs
->write
= NPP_Write
;
394 funcs
->print
= NPP_Print
;
395 funcs
->event
= NPP_HandleEvent
;
396 funcs
->urlnotify
= NPP_URLNotify
;
397 funcs
->javaClass
= NULL
;
398 funcs
->getvalue
= NPP_GetValue
;
399 funcs
->setvalue
= NPP_SetValue
;
400 funcs
->gotfocus
= NPP_GotFocus
;
401 funcs
->lostfocus
= NPP_LostFocus
;
403 return NPERR_NO_ERROR
;