d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / mshtml / npplugin.c
blobca0d9fd4896e101fbad4421aac8bb0e67153db67
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 nsIDOMWindow *nswindow;
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, &nswindow);
257 nsIDOMDocument_Release(nsdoc);
258 if(NS_FAILED(nsres) || !nswindow)
259 return NULL;
261 window = nswindow_to_window(nswindow);
262 nsIDOMWindow_Release(nswindow);
264 return window->base.inner_window;
267 static BOOL parse_classid(const PRUnichar *classid, CLSID *clsid)
269 const WCHAR *ptr;
270 unsigned len;
271 HRESULT hres;
273 static const PRUnichar clsidW[] = {'c','l','s','i','d',':'};
275 if(strncmpiW(classid, clsidW, sizeof(clsidW)/sizeof(WCHAR)))
276 return FALSE;
278 ptr = classid + sizeof(clsidW)/sizeof(WCHAR);
279 len = strlenW(ptr);
281 if(len == 38) {
282 hres = CLSIDFromString(ptr, clsid);
283 }else if(len == 36) {
284 WCHAR buf[39];
286 buf[0] = '{';
287 memcpy(buf+1, ptr, len*sizeof(WCHAR));
288 buf[37] = '}';
289 buf[38] = 0;
290 hres = CLSIDFromString(buf, clsid);
291 }else {
292 return FALSE;
295 return SUCCEEDED(hres);
298 static BOOL get_elem_clsid(nsIDOMHTMLElement *elem, CLSID *clsid)
300 const PRUnichar *val;
301 nsAString val_str;
302 nsresult nsres;
303 BOOL ret = FALSE;
305 static const PRUnichar classidW[] = {'c','l','a','s','s','i','d',0};
307 nsres = get_elem_attr_value(elem, classidW, &val_str, &val);
308 if(NS_SUCCEEDED(nsres)) {
309 if(*val)
310 ret = parse_classid(val, clsid);
311 nsAString_Finish(&val_str);
314 return ret;
317 typedef struct {
318 IBindStatusCallback IBindStatusCallback_iface;
319 IWindowForBindingUI IWindowForBindingUI_iface;
320 LONG ref;
321 } InstallCallback;
323 static inline InstallCallback *impl_from_IBindStatusCallback(IBindStatusCallback *iface)
325 return CONTAINING_RECORD(iface, InstallCallback, IBindStatusCallback_iface);
328 static HRESULT WINAPI InstallCallback_QueryInterface(IBindStatusCallback *iface,
329 REFIID riid, void **ppv)
331 InstallCallback *This = impl_from_IBindStatusCallback(iface);
333 if(IsEqualGUID(&IID_IUnknown, riid)) {
334 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
335 *ppv = &This->IBindStatusCallback_iface;
336 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
337 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
338 *ppv = &This->IBindStatusCallback_iface;
339 }else if(IsEqualGUID(&IID_IWindowForBindingUI, riid)) {
340 TRACE("(%p)->(IID_IWindowForBindingUI %p)\n", This, ppv);
341 *ppv = &This->IWindowForBindingUI_iface;
342 }else {
343 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
344 *ppv = NULL;
345 return E_NOINTERFACE;
348 IUnknown_AddRef((IUnknown*)*ppv);
349 return S_OK;
352 static ULONG WINAPI InstallCallback_AddRef(IBindStatusCallback *iface)
354 InstallCallback *This = impl_from_IBindStatusCallback(iface);
355 LONG ref = InterlockedIncrement(&This->ref);
357 TRACE("(%p) ref=%d\n", This, ref);
359 return ref;
362 static ULONG WINAPI InstallCallback_Release(IBindStatusCallback *iface)
364 InstallCallback *This = impl_from_IBindStatusCallback(iface);
365 LONG ref = InterlockedIncrement(&This->ref);
367 TRACE("(%p) ref=%d\n", This, ref);
369 if(!ref)
370 heap_free(This);
372 return ref;
375 static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
376 DWORD dwReserved, IBinding *pib)
378 InstallCallback *This = impl_from_IBindStatusCallback(iface);
379 TRACE("(%p)->(%x %p)\n", This, dwReserved, pib);
380 return S_OK;
383 static HRESULT WINAPI InstallCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
385 InstallCallback *This = impl_from_IBindStatusCallback(iface);
386 TRACE("(%p)->(%p)\n", This, pnPriority);
387 return E_NOTIMPL;
390 static HRESULT WINAPI InstallCallback_OnLowResource(IBindStatusCallback *iface, DWORD dwReserved)
392 InstallCallback *This = impl_from_IBindStatusCallback(iface);
393 TRACE("(%p)->(%x)\n", This, dwReserved);
394 return S_OK;
397 static HRESULT WINAPI InstallCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
398 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
400 InstallCallback *This = impl_from_IBindStatusCallback(iface);
401 TRACE("(%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode, debugstr_w(szStatusText));
402 return S_OK;
405 static HRESULT WINAPI InstallCallback_OnStopBinding(IBindStatusCallback *iface,
406 HRESULT hresult, LPCWSTR szError)
408 InstallCallback *This = impl_from_IBindStatusCallback(iface);
409 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
410 return S_OK;
413 static HRESULT WINAPI InstallCallback_GetBindInfo(IBindStatusCallback *iface,
414 DWORD* grfBINDF, BINDINFO* pbindinfo)
416 InstallCallback *This = impl_from_IBindStatusCallback(iface);
418 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
420 *grfBINDF = BINDF_ASYNCHRONOUS;
421 return S_OK;
424 static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
425 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
427 InstallCallback *This = impl_from_IBindStatusCallback(iface);
428 ERR("(%p)\n", This);
429 return E_NOTIMPL;
432 static HRESULT WINAPI InstallCallback_OnObjectAvailable(IBindStatusCallback *iface,
433 REFIID riid, IUnknown* punk)
435 InstallCallback *This = impl_from_IBindStatusCallback(iface);
436 ERR("(%p)\n", This);
437 return E_NOTIMPL;
440 static IBindStatusCallbackVtbl InstallCallbackVtbl = {
441 InstallCallback_QueryInterface,
442 InstallCallback_AddRef,
443 InstallCallback_Release,
444 InstallCallback_OnStartBinding,
445 InstallCallback_GetPriority,
446 InstallCallback_OnLowResource,
447 InstallCallback_OnProgress,
448 InstallCallback_OnStopBinding,
449 InstallCallback_GetBindInfo,
450 InstallCallback_OnDataAvailable,
451 InstallCallback_OnObjectAvailable
454 static inline InstallCallback *impl_from_IWindowForBindingUI(IWindowForBindingUI *iface)
456 return CONTAINING_RECORD(iface, InstallCallback, IWindowForBindingUI_iface);
459 static HRESULT WINAPI WindowForBindingUI_QueryInterface(IWindowForBindingUI *iface, REFIID riid, void **ppv)
461 InstallCallback *This = impl_from_IWindowForBindingUI(iface);
462 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
465 static ULONG WINAPI WindowForBindingUI_AddRef(IWindowForBindingUI *iface)
467 InstallCallback *This = impl_from_IWindowForBindingUI(iface);
468 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
471 static ULONG WINAPI WindowForBindingUI_Release(IWindowForBindingUI *iface)
473 InstallCallback *This = impl_from_IWindowForBindingUI(iface);
474 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
477 static HRESULT WINAPI WindowForBindingUI_GetWindow(IWindowForBindingUI *iface, REFGUID rguidReason, HWND *phwnd)
479 InstallCallback *This = impl_from_IWindowForBindingUI(iface);
480 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(rguidReason), phwnd);
481 *phwnd = NULL;
482 return S_OK;
485 static const IWindowForBindingUIVtbl WindowForBindingUIVtbl = {
486 WindowForBindingUI_QueryInterface,
487 WindowForBindingUI_AddRef,
488 WindowForBindingUI_Release,
489 WindowForBindingUI_GetWindow
492 typedef struct {
493 struct list entry;
494 IUri *uri;
495 } install_entry_t;
497 static struct list install_list = LIST_INIT(install_list);
499 static CRITICAL_SECTION cs_install_list;
500 static CRITICAL_SECTION_DEBUG cs_install_list_dbg =
502 0, 0, &cs_install_list,
503 { &cs_install_list_dbg.ProcessLocksList, &cs_install_list_dbg.ProcessLocksList },
504 0, 0, { (DWORD_PTR)(__FILE__ ": install_list") }
506 static CRITICAL_SECTION cs_install_list = { &cs_install_list_dbg, -1, 0, 0, 0, 0 };
508 static void install_codebase(const WCHAR *url)
510 InstallCallback *callback;
511 IBindCtx *bctx;
512 HRESULT hres;
514 callback = heap_alloc(sizeof(*callback));
515 if(!callback)
516 return;
518 callback->IBindStatusCallback_iface.lpVtbl = &InstallCallbackVtbl;
519 callback->IWindowForBindingUI_iface.lpVtbl = &WindowForBindingUIVtbl;
520 callback->ref = 1;
522 hres = CreateAsyncBindCtx(0, &callback->IBindStatusCallback_iface, NULL, &bctx);
523 IBindStatusCallback_Release(&callback->IBindStatusCallback_iface);
524 if(FAILED(hres))
525 return;
527 hres = AsyncInstallDistributionUnit(NULL, NULL, NULL, 0, 0, url, bctx, NULL, 0);
528 IBindCtx_Release(bctx);
529 if(FAILED(hres))
530 WARN("FAILED: %08x\n", hres);
533 static void check_codebase(HTMLInnerWindow *window, nsIDOMHTMLElement *nselem)
535 BOOL is_on_list = FALSE;
536 install_entry_t *iter;
537 const PRUnichar *val;
538 nsAString val_str;
539 IUri *uri = NULL;
540 nsresult nsres;
541 HRESULT hres;
543 static const PRUnichar codebaseW[] = {'c','o','d','e','b','a','s','e',0};
545 nsres = get_elem_attr_value(nselem, codebaseW, &val_str, &val);
546 if(NS_SUCCEEDED(nsres)) {
547 if(*val) {
548 hres = CoInternetCombineUrlEx(window->base.outer_window->uri, val, 0, &uri, 0);
549 if(FAILED(hres))
550 uri = NULL;
552 nsAString_Finish(&val_str);
555 if(!uri)
556 return;
558 EnterCriticalSection(&cs_install_list);
560 LIST_FOR_EACH_ENTRY(iter, &install_list, install_entry_t, entry) {
561 BOOL eq;
563 hres = IUri_IsEqual(uri, iter->uri, &eq);
564 if(SUCCEEDED(hres) && eq) {
565 TRACE("already proceeded\n");
566 is_on_list = TRUE;
567 break;
571 if(!is_on_list) {
572 iter = heap_alloc(sizeof(*iter));
573 if(iter) {
574 IUri_AddRef(uri);
575 iter->uri = uri;
577 list_add_tail(&install_list, &iter->entry);
581 LeaveCriticalSection(&cs_install_list);
583 if(!is_on_list) {
584 BSTR display_uri;
586 hres = IUri_GetDisplayUri(uri, &display_uri);
587 if(SUCCEEDED(hres)) {
588 install_codebase(display_uri);
589 SysFreeString(display_uri);
593 IUri_Release(uri);
596 static IUnknown *create_activex_object(HTMLInnerWindow *window, nsIDOMHTMLElement *nselem, CLSID *clsid)
598 IClassFactoryEx *cfex;
599 IClassFactory *cf;
600 IUnknown *obj;
601 DWORD policy;
602 HRESULT hres;
604 if(!get_elem_clsid(nselem, clsid)) {
605 WARN("Could not determine element CLSID\n");
606 return NULL;
609 TRACE("clsid %s\n", debugstr_guid(clsid));
611 policy = 0;
612 hres = IInternetHostSecurityManager_ProcessUrlAction(&window->doc->IInternetHostSecurityManager_iface,
613 URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy), (BYTE*)clsid, sizeof(GUID), 0, 0);
614 if(FAILED(hres) || policy != URLPOLICY_ALLOW) {
615 WARN("ProcessUrlAction returned %08x %x\n", hres, policy);
616 return NULL;
619 hres = CoGetClassObject(clsid, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, NULL, &IID_IClassFactory, (void**)&cf);
620 if(hres == REGDB_E_CLASSNOTREG)
621 check_codebase(window, nselem);
622 if(FAILED(hres))
623 return NULL;
625 hres = IClassFactory_QueryInterface(cf, &IID_IClassFactoryEx, (void**)&cfex);
626 if(SUCCEEDED(hres)) {
627 FIXME("Use IClassFactoryEx\n");
628 IClassFactoryEx_Release(cfex);
631 hres = IClassFactory_CreateInstance(cf, NULL, &IID_IUnknown, (void**)&obj);
632 IClassFactory_Release(cf);
633 if(FAILED(hres))
634 return NULL;
636 return obj;
639 static NPError CDECL NPP_New(NPMIMEType pluginType, NPP instance, UINT16 mode, INT16 argc, char **argn,
640 char **argv, NPSavedData *saved)
642 nsIDOMHTMLElement *nselem;
643 HTMLInnerWindow *window;
644 IUnknown *obj;
645 CLSID clsid;
646 NPError err = NPERR_NO_ERROR;
648 TRACE("(%s %p %x %d %p %p %p)\n", debugstr_a(pluginType), instance, mode, argc, argn, argv, saved);
650 nselem = get_dom_element(instance);
651 if(!nselem) {
652 ERR("Could not get DOM element\n");
653 return NPERR_GENERIC_ERROR;
656 window = get_elem_window(nselem);
657 if(!window) {
658 ERR("Could not get element's window object\n");
659 nsIDOMHTMLElement_Release(nselem);
660 return NPERR_GENERIC_ERROR;
663 obj = create_activex_object(window, nselem, &clsid);
664 if(obj) {
665 PluginHost *host;
666 HRESULT hres;
668 hres = create_plugin_host(window->doc, (nsIDOMElement*)nselem, obj, &clsid, &host);
669 IUnknown_Release(obj);
670 if(SUCCEEDED(hres))
671 instance->pdata = host;
672 else
673 err = NPERR_GENERIC_ERROR;
674 }else {
675 err = NPERR_GENERIC_ERROR;
678 nsIDOMHTMLElement_Release(nselem);
679 return err;
682 static NPError CDECL NPP_Destroy(NPP instance, NPSavedData **save)
684 PluginHost *host = instance->pdata;
686 TRACE("(%p %p)\n", instance, save);
688 if(!host)
689 return NPERR_GENERIC_ERROR;
691 detach_plugin_host(host);
692 IOleClientSite_Release(&host->IOleClientSite_iface);
693 instance->pdata = NULL;
694 return NPERR_NO_ERROR;
697 static NPError CDECL NPP_SetWindow(NPP instance, NPWindow *window)
699 PluginHost *host = instance->pdata;
700 RECT pos_rect = {0, 0, window->width, window->height};
702 TRACE("(%p %p)\n", instance, window);
704 if(!host)
705 return NPERR_GENERIC_ERROR;
707 update_plugin_window(host, window->window, &pos_rect);
708 return NPERR_NO_ERROR;
711 static NPError CDECL NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, UINT16 *stype)
713 TRACE("\n");
714 return NPERR_GENERIC_ERROR;
717 static NPError CDECL NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
719 TRACE("\n");
720 return NPERR_GENERIC_ERROR;
723 static INT32 CDECL NPP_WriteReady(NPP instance, NPStream *stream)
725 TRACE("\n");
726 return NPERR_GENERIC_ERROR;
729 static INT32 CDECL NPP_Write(NPP instance, NPStream *stream, INT32 offset, INT32 len, void *buffer)
731 TRACE("\n");
732 return NPERR_GENERIC_ERROR;
735 static void CDECL NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
737 TRACE("\n");
740 static void CDECL NPP_Print(NPP instance, NPPrint *platformPrint)
742 FIXME("\n");
745 static INT16 CDECL NPP_HandleEvent(NPP instance, void *event)
747 TRACE("\n");
748 return NPERR_GENERIC_ERROR;
751 static void CDECL NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
753 TRACE("\n");
756 static NPError CDECL NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value)
758 TRACE("\n");
759 return NPERR_GENERIC_ERROR;
762 static NPError CDECL NPP_SetValue(NPP instance, NPNVariable variable, void *value)
764 TRACE("\n");
765 return NPERR_GENERIC_ERROR;
768 static NPBool CDECL NPP_GotFocus(NPP instance, NPFocusDirection direction)
770 FIXME("\n");
771 return NPERR_GENERIC_ERROR;
774 static void CDECL NPP_LostFocus(NPP instance)
776 FIXME("\n");
779 /***********************************************************************
780 * NP_GetEntryPoints (mshtml.@)
782 NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* funcs)
784 TRACE("(%p)\n", funcs);
786 funcs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
787 funcs->newp = NPP_New;
788 funcs->destroy = NPP_Destroy;
789 funcs->setwindow = NPP_SetWindow;
790 funcs->newstream = NPP_NewStream;
791 funcs->destroystream = NPP_DestroyStream;
792 funcs->asfile = NPP_StreamAsFile;
793 funcs->writeready = NPP_WriteReady;
794 funcs->write = NPP_Write;
795 funcs->print = NPP_Print;
796 funcs->event = NPP_HandleEvent;
797 funcs->urlnotify = NPP_URLNotify;
798 funcs->javaClass = NULL;
799 funcs->getvalue = NPP_GetValue;
800 funcs->setvalue = NPP_SetValue;
801 funcs->gotfocus = NPP_GotFocus;
802 funcs->lostfocus = NPP_LostFocus;
804 return NPERR_NO_ERROR;