wintrust: Simplify error handling in SoftpubLoadSignature.
[wine] / dlls / mshtml / mshtml_private.h
1 /*
2  * Copyright 2005-2009 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 "wingdi.h"
20 #include "docobj.h"
21 #include "comcat.h"
22 #include "mshtml.h"
23 #include "mshtmhst.h"
24 #include "hlink.h"
25 #include "perhist.h"
26 #include "dispex.h"
27
28 #include "wine/list.h"
29 #include "wine/unicode.h"
30
31 #ifdef INIT_GUID
32 #include "initguid.h"
33 #endif
34
35 #include "nsiface.h"
36
37 #define NS_OK                     ((nsresult)0x00000000L)
38 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
39 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
40 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
41 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
42 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
43 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
44
45 #define NS_FAILED(res) ((res) & 0x80000000)
46 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
47
48 #define NSAPI WINAPI
49
50 #define MSHTML_E_NODOC    0x800a025c
51
52 typedef struct HTMLDOMNode HTMLDOMNode;
53 typedef struct ConnectionPoint ConnectionPoint;
54 typedef struct BSCallback BSCallback;
55 typedef struct event_target_t event_target_t;
56
57 /* NOTE: make sure to keep in sync with dispex.c */
58 typedef enum {
59     NULL_tid,
60     DispCEventObj_tid,
61     DispDOMChildrenCollection_tid,
62     DispHTMLAnchorElement_tid,
63     DispHTMLBody_tid,
64     DispHTMLCommentElement_tid,
65     DispHTMLCurrentStyle_tid,
66     DispHTMLDocument_tid,
67     DispHTMLDOMTextNode_tid,
68     DispHTMLElementCollection_tid,
69     DispHTMLFormElement_tid,
70     DispHTMLGenericElement_tid,
71     DispHTMLFrameElement_tid,
72     DispHTMLIFrame_tid,
73     DispHTMLImg_tid,
74     DispHTMLInputElement_tid,
75     DispHTMLLocation_tid,
76     DispHTMLNavigator_tid,
77     DispHTMLOptionElement_tid,
78     DispHTMLScreen_tid,
79     DispHTMLScriptElement_tid,
80     DispHTMLSelectElement_tid,
81     DispHTMLStyle_tid,
82     DispHTMLTable_tid,
83     DispHTMLTableRow_tid,
84     DispHTMLUnknownElement_tid,
85     DispHTMLWindow2_tid,
86     HTMLDocumentEvents_tid,
87     IHTMLAnchorElement_tid,
88     IHTMLBodyElement_tid,
89     IHTMLBodyElement2_tid,
90     IHTMLCommentElement_tid,
91     IHTMLCurrentStyle_tid,
92     IHTMLCurrentStyle2_tid,
93     IHTMLCurrentStyle3_tid,
94     IHTMLCurrentStyle4_tid,
95     IHTMLDocument2_tid,
96     IHTMLDocument3_tid,
97     IHTMLDocument4_tid,
98     IHTMLDocument5_tid,
99     IHTMLDOMChildrenCollection_tid,
100     IHTMLDOMNode_tid,
101     IHTMLDOMNode2_tid,
102     IHTMLDOMTextNode_tid,
103     IHTMLElement_tid,
104     IHTMLElement2_tid,
105     IHTMLElement3_tid,
106     IHTMLElement4_tid,
107     IHTMLElementCollection_tid,
108     IHTMLEventObj_tid,
109     IHTMLFiltersCollection_tid,
110     IHTMLFormElement_tid,
111     IHTMLFrameBase_tid,
112     IHTMLFrameBase2_tid,
113     IHTMLFrameElement3_tid,
114     IHTMLGenericElement_tid,
115     IHTMLIFrameElement_tid,
116     IHTMLImageElementFactory_tid,
117     IHTMLImgElement_tid,
118     IHTMLInputElement_tid,
119     IHTMLLocation_tid,
120     IHTMLOptionElement_tid,
121     IHTMLScreen_tid,
122     IHTMLScriptElement_tid,
123     IHTMLSelectElement_tid,
124     IHTMLStyle_tid,
125     IHTMLStyle2_tid,
126     IHTMLStyle3_tid,
127     IHTMLStyle4_tid,
128     IHTMLTable_tid,
129     IHTMLTableRow_tid,
130     IHTMLTextContainer_tid,
131     IHTMLUniqueName_tid,
132     IHTMLWindow2_tid,
133     IHTMLWindow3_tid,
134     IHTMLWindow4_tid,
135     IOmNavigator_tid,
136     LAST_tid
137 } tid_t;
138
139 typedef struct dispex_data_t dispex_data_t;
140 typedef struct dispex_dynamic_data_t dispex_dynamic_data_t;
141
142 #define MSHTML_DISPID_CUSTOM_MIN 0x60000000
143 #define MSHTML_DISPID_CUSTOM_MAX 0x6fffffff
144
145 typedef struct {
146     HRESULT (*value)(IUnknown*,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
147     HRESULT (*get_dispid)(IUnknown*,BSTR,DWORD,DISPID*);
148     HRESULT (*invoke)(IUnknown*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
149 } dispex_static_data_vtbl_t;
150
151 typedef struct {
152     const dispex_static_data_vtbl_t *vtbl;
153     const tid_t disp_tid;
154     dispex_data_t *data;
155     const tid_t* const iface_tids;
156 } dispex_static_data_t;
157
158 typedef struct {
159     const IDispatchExVtbl  *lpIDispatchExVtbl;
160
161     IUnknown *outer;
162
163     dispex_static_data_t *data;
164     dispex_dynamic_data_t *dynamic_data;
165 } DispatchEx;
166
167 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
168 void release_dispex(DispatchEx*);
169 BOOL dispex_query_interface(DispatchEx*,REFIID,void**);
170 HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**);
171 HRESULT get_dispids(tid_t,DWORD*,DISPID**);
172
173 typedef struct HTMLDocumentNode HTMLDocumentNode;
174 typedef struct HTMLDocumentObj HTMLDocumentObj;
175 typedef struct HTMLFrameBase HTMLFrameBase;
176
177 typedef enum {
178     SCRIPTMODE_GECKO,
179     SCRIPTMODE_ACTIVESCRIPT
180 } SCRIPTMODE;
181
182 typedef struct ScriptHost ScriptHost;
183
184 typedef enum {
185     GLOBAL_SCRIPTVAR,
186     GLOBAL_ELEMENTVAR
187 } global_prop_type_t;
188
189 typedef struct {
190     global_prop_type_t type;
191     WCHAR *name;
192     ScriptHost *script_host;
193     DISPID id;
194 } global_prop_t;
195
196 typedef struct {
197     const IHTMLOptionElementFactoryVtbl *lpHTMLOptionElementFactoryVtbl;
198
199     LONG ref;
200
201     HTMLWindow *window;
202 } HTMLOptionElementFactory;
203
204 typedef struct {
205     DispatchEx dispex;
206     const IHTMLImageElementFactoryVtbl *lpHTMLImageElementFactoryVtbl;
207
208     LONG ref;
209
210     HTMLWindow *window;
211 } HTMLImageElementFactory;
212
213 struct HTMLLocation {
214     DispatchEx dispex;
215     const IHTMLLocationVtbl *lpHTMLLocationVtbl;
216
217     LONG ref;
218
219     HTMLWindow *window;
220 };
221
222 typedef struct {
223     HTMLWindow *window;
224     LONG ref;
225 }  windowref_t;
226
227 struct HTMLWindow {
228     DispatchEx dispex;
229     const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
230     const IHTMLWindow3Vtbl *lpHTMLWindow3Vtbl;
231     const IHTMLWindow4Vtbl *lpHTMLWindow4Vtbl;
232     const IDispatchExVtbl  *lpIDispatchExVtbl;
233
234     LONG ref;
235
236     windowref_t *window_ref;
237     LONG task_magic;
238
239     HTMLDocumentNode *doc;
240     HTMLDocumentObj *doc_obj;
241     nsIDOMWindow *nswindow;
242     HTMLWindow *parent;
243     HTMLFrameBase *frame_element;
244     READYSTATE readystate;
245
246     nsChannelBSC *bscallback;
247     IMoniker *mon;
248     LPOLESTR url;
249
250     IHTMLEventObj *event;
251
252     SCRIPTMODE scriptmode;
253     struct list script_hosts;
254
255     HTMLOptionElementFactory *option_factory;
256     HTMLImageElementFactory *image_factory;
257     HTMLLocation *location;
258     IHTMLScreen *screen;
259
260     global_prop_t *global_props;
261     DWORD global_prop_cnt;
262     DWORD global_prop_size;
263
264     struct list children;
265     struct list sibling_entry;
266     struct list entry;
267 };
268
269 typedef enum {
270     UNKNOWN_USERMODE,
271     BROWSEMODE,
272     EDITMODE        
273 } USERMODE;
274
275 typedef struct _cp_static_data_t {
276     tid_t tid;
277     void (*on_advise)(IUnknown*,struct _cp_static_data_t*);
278     DWORD id_cnt;
279     DISPID *ids;
280 } cp_static_data_t;
281
282 typedef struct ConnectionPointContainer {
283     const IConnectionPointContainerVtbl  *lpConnectionPointContainerVtbl;
284
285     ConnectionPoint *cp_list;
286     IUnknown *outer;
287     struct ConnectionPointContainer *forward_container;
288 } ConnectionPointContainer;
289
290 struct ConnectionPoint {
291     const IConnectionPointVtbl *lpConnectionPointVtbl;
292
293     ConnectionPointContainer *container;
294
295     union {
296         IUnknown *unk;
297         IDispatch *disp;
298         IPropertyNotifySink *propnotif;
299     } *sinks;
300     DWORD sinks_size;
301
302     const IID *iid;
303     cp_static_data_t *data;
304
305     ConnectionPoint *next;
306 };
307
308 struct HTMLDocument {
309     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
310     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
311     const IHTMLDocument4Vtbl              *lpHTMLDocument4Vtbl;
312     const IHTMLDocument5Vtbl              *lpHTMLDocument5Vtbl;
313     const IHTMLDocument6Vtbl              *lpHTMLDocument6Vtbl;
314     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
315     const IPersistFileVtbl                *lpPersistFileVtbl;
316     const IPersistHistoryVtbl             *lpPersistHistoryVtbl;
317     const IMonikerPropVtbl                *lpMonikerPropVtbl;
318     const IOleObjectVtbl                  *lpOleObjectVtbl;
319     const IOleDocumentVtbl                *lpOleDocumentVtbl;
320     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
321     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
322     const IViewObjectExVtbl               *lpViewObjectExVtbl;
323     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
324     const IServiceProviderVtbl            *lpServiceProviderVtbl;
325     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
326     const IOleControlVtbl                 *lpOleControlVtbl;
327     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
328     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
329     const IDispatchExVtbl                 *lpIDispatchExVtbl;
330     const ISupportErrorInfoVtbl           *lpSupportErrorInfoVtbl;
331     const IObjectWithSiteVtbl             *lpObjectWithSiteVtbl;
332
333     IUnknown *unk_impl;
334     IDispatchEx *dispex;
335
336     HTMLDocumentObj *doc_obj;
337     HTMLDocumentNode *doc_node;
338
339     HTMLWindow *window;
340
341     LONG task_magic;
342
343     ConnectionPointContainer cp_container;
344     ConnectionPoint cp_htmldocevents;
345     ConnectionPoint cp_htmldocevents2;
346     ConnectionPoint cp_propnotif;
347     ConnectionPoint cp_dispatch;
348
349     IOleAdviseHolder *advise_holder;
350 };
351
352 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
353 {
354     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
355 }
356
357 static inline ULONG htmldoc_addref(HTMLDocument *This)
358 {
359     return IUnknown_AddRef(This->unk_impl);
360 }
361
362 static inline ULONG htmldoc_release(HTMLDocument *This)
363 {
364     return IUnknown_Release(This->unk_impl);
365 }
366
367 struct HTMLDocumentObj {
368     HTMLDocument basedoc;
369     DispatchEx dispex;
370     const ICustomDocVtbl  *lpCustomDocVtbl;
371
372     LONG ref;
373
374     NSContainer *nscontainer;
375
376     IOleClientSite *client;
377     IDocHostUIHandler *hostui;
378     IOleInPlaceSite *ipsite;
379     IOleInPlaceFrame *frame;
380     IOleInPlaceUIWindow *ip_window;
381
382     DOCHOSTUIINFO hostinfo;
383
384     IOleUndoManager *undomgr;
385
386     HWND hwnd;
387     HWND tooltips_hwnd;
388
389     BOOL request_uiactivate;
390     BOOL in_place_active;
391     BOOL ui_active;
392     BOOL window_active;
393     BOOL has_key_path;
394     BOOL container_locked;
395     BOOL focus;
396     INT download_state;
397
398     USERMODE usermode;
399     LPWSTR mime;
400
401     DWORD update;
402 };
403
404 struct NSContainer {
405     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
406     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
407     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
408     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
409     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
410     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
411     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
412     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
413
414     nsIWebBrowser *webbrowser;
415     nsIWebNavigation *navigation;
416     nsIBaseWindow *window;
417     nsIWebBrowserFocus *focus;
418
419     nsIEditor *editor;
420     nsIController *editor_controller;
421
422     LONG ref;
423
424     NSContainer *parent;
425     HTMLDocumentObj *doc;
426
427     nsIURIContentListener *content_listener;
428
429     HWND hwnd;
430
431     HWND reset_focus; /* hack */
432 };
433
434 typedef struct {
435     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
436     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
437     const nsIHttpChannelInternalVtbl *lpIHttpChannelInternalVtbl;
438
439     LONG ref;
440
441     nsIWineURI *uri;
442     nsIInputStream *post_data_stream;
443     nsILoadGroup *load_group;
444     nsIInterfaceRequestor *notif_callback;
445     nsISupports *owner;
446     nsLoadFlags load_flags;
447     nsIURI *original_uri;
448     char *content_type;
449     char *charset;
450     PRUint32 response_status;
451     UINT url_scheme;
452 } nsChannel;
453
454 typedef struct {
455     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
456     void (*destructor)(HTMLDOMNode*);
457     event_target_t **(*get_event_target)(HTMLDOMNode*);
458     HRESULT (*call_event)(HTMLDOMNode*,DWORD,BOOL*);
459     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
460     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
461     HRESULT (*get_document)(HTMLDOMNode*,IDispatch**);
462     HRESULT (*get_readystate)(HTMLDOMNode*,BSTR*);
463     HRESULT (*get_dispid)(HTMLDOMNode*,BSTR,DWORD,DISPID*);
464     HRESULT (*invoke)(HTMLDOMNode*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
465     HRESULT (*bind_to_tree)(HTMLDOMNode*);
466 } NodeImplVtbl;
467
468 struct HTMLDOMNode {
469     DispatchEx dispex;
470     const IHTMLDOMNodeVtbl   *lpHTMLDOMNodeVtbl;
471     const IHTMLDOMNode2Vtbl  *lpHTMLDOMNode2Vtbl;
472     const NodeImplVtbl *vtbl;
473
474     LONG ref;
475
476     nsIDOMNode *nsnode;
477     HTMLDocumentNode *doc;
478     event_target_t *event_target;
479     ConnectionPointContainer *cp_container;
480
481     HTMLDOMNode *next;
482 };
483
484 typedef struct {
485     HTMLDOMNode node;
486     ConnectionPointContainer cp_container;
487
488     const IHTMLElementVtbl   *lpHTMLElementVtbl;
489     const IHTMLElement2Vtbl  *lpHTMLElement2Vtbl;
490     const IHTMLElement3Vtbl  *lpHTMLElement3Vtbl;
491
492     nsIDOMHTMLElement *nselem;
493 } HTMLElement;
494
495 #define HTMLELEMENT_TIDS    \
496     IHTMLDOMNode_tid,       \
497     IHTMLDOMNode2_tid,      \
498     IHTMLElement_tid,       \
499     IHTMLElement2_tid,      \
500     IHTMLElement3_tid,      \
501     IHTMLElement4_tid
502
503 typedef struct {
504     HTMLElement element;
505
506     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
507
508     ConnectionPoint cp;
509 } HTMLTextContainer;
510
511 struct HTMLFrameBase {
512     HTMLElement element;
513
514     const IHTMLFrameBaseVtbl   *lpIHTMLFrameBaseVtbl;
515     const IHTMLFrameBase2Vtbl  *lpIHTMLFrameBase2Vtbl;
516
517     HTMLWindow *content_window;
518
519     nsIDOMHTMLFrameElement *nsframe;
520     nsIDOMHTMLIFrameElement *nsiframe;
521 };
522
523 typedef struct _mutation_queue_t {
524     DWORD type;
525     nsISupports *nsiface;
526
527     struct _mutation_queue_t *next;
528 } mutation_queue_t;
529
530 typedef struct nsDocumentEventListener nsDocumentEventListener;
531
532 struct HTMLDocumentNode {
533     HTMLDOMNode node;
534     HTMLDocument basedoc;
535
536     const IInternetHostSecurityManagerVtbl *lpIInternetHostSecurityManagerVtbl;
537
538     const nsIDocumentObserverVtbl  *lpIDocumentObserverVtbl;
539     const nsIRunnableVtbl  *lpIRunnableVtbl;
540
541     LONG ref;
542
543     nsIDOMHTMLDocument *nsdoc;
544     HTMLDOMNode *nodes;
545     BOOL content_ready;
546     event_target_t *body_event_target;
547
548     IInternetSecurityManager *secmgr;
549     ICatInformation *catmgr;
550     nsDocumentEventListener *nsevent_listener;
551     BOOL *event_vector;
552
553     mutation_queue_t *mutation_queue;
554     mutation_queue_t *mutation_queue_tail;
555
556     struct list bindings;
557     struct list selection_list;
558     struct list range_list;
559 };
560
561 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
562 #define HTMLWINDOW3(x)   ((IHTMLWindow3*)                 &(x)->lpHTMLWindow3Vtbl)
563 #define HTMLWINDOW4(x)   ((IHTMLWindow4*)                 &(x)->lpHTMLWindow4Vtbl)
564
565 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
566 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
567 #define HTMLDOC4(x)      ((IHTMLDocument4*)               &(x)->lpHTMLDocument4Vtbl)
568 #define HTMLDOC5(x)      ((IHTMLDocument5*)               &(x)->lpHTMLDocument5Vtbl)
569 #define HTMLDOC6(x)      ((IHTMLDocument6*)               &(x)->lpHTMLDocument6Vtbl)
570 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
571 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
572 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
573 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
574 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
575 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
576 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
577 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
578 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
579 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObjectExVtbl)
580 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObjectExVtbl)
581 #define VIEWOBJEX(x)      ((IViewObjectEx*)               &(x)->lpViewObjectExVtbl)
582 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
583 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
584 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
585 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
586 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
587 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
588 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
589 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
590 #define PERSISTHIST(x)   ((IPersistHistory*)              &(x)->lpPersistHistoryVtbl)
591 #define CUSTOMDOC(x)     ((ICustomDoc*)                   &(x)->lpCustomDocVtbl)
592 #define OBJSITE(x)       ((IObjectWithSite*)              &(x)->lpObjectWithSiteVtbl)
593
594 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
595 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
596 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
597 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
598 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
599 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
600 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
601 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
602 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
603
604 #define NSDOCOBS(x)      ((nsIDocumentObserver*)          &(x)->lpIDocumentObserverVtbl)
605
606 #define NSRUNNABLE(x)    ((nsIRunnable*)  &(x)->lpIRunnableVtbl)
607
608 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
609 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
610 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
611 #define NSHTTPINTERNAL(x) ((nsIHttpChannelInternal*)  &(x)->lpIHttpChannelInternalVtbl)
612
613 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
614 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
615 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
616
617 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
618 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
619 #define HTMLELEM3(x)     ((IHTMLElement3*)                &(x)->lpHTMLElement3Vtbl)
620 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
621 #define HTMLDOMNODE2(x)  ((IHTMLDOMNode2*)                &(x)->lpHTMLDOMNode2Vtbl)
622
623 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
624 #define HTMLFRAMEBASE(x) ((IHTMLFrameBase*)               &(x)->lpIHTMLFrameBaseVtbl)
625 #define HTMLFRAMEBASE2(x) ((IHTMLFrameBase2*)             &(x)->lpIHTMLFrameBase2Vtbl)
626
627 #define HTMLOPTFACTORY(x)  ((IHTMLOptionElementFactory*)  &(x)->lpHTMLOptionElementFactoryVtbl)
628 #define HTMLIMGFACTORY(x)  ((IHTMLImageElementFactory*)   &(x)->lpHTMLImageElementFactoryVtbl)
629 #define HTMLLOCATION(x)    ((IHTMLLocation*)              &(x)->lpHTMLLocationVtbl)
630
631 #define DISPATCHEX(x)    ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
632
633 #define SUPPERRINFO(x)   ((ISupportErrorInfo*) &(x)->lpSupportErrorInfoVtbl)
634
635 #define HOSTSECMGR(x)    ((IInternetHostSecurityManager*)  &(x)->lpIInternetHostSecurityManagerVtbl)
636
637 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
638 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
639
640 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
641 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
642 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**);
643
644 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**);
645 void update_window_doc(HTMLWindow*);
646 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
647 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument*);
648 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
649 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*);
650 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
651 IOmNavigator *OmNavigator_Create(void);
652 HRESULT HTMLScreen_Create(IHTMLScreen**);
653
654 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
655 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*);
656 void HTMLDocument_Persist_Init(HTMLDocument*);
657 void HTMLDocument_OleCmd_Init(HTMLDocument*);
658 void HTMLDocument_OleObj_Init(HTMLDocument*);
659 void HTMLDocument_View_Init(HTMLDocument*);
660 void HTMLDocument_Window_Init(HTMLDocument*);
661 void HTMLDocument_Service_Init(HTMLDocument*);
662 void HTMLDocument_Hlink_Init(HTMLDocument*);
663
664 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*);
665
666 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**);
667
668 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID,cp_static_data_t*);
669 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*);
670 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
671
672 NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*);
673 void NSContainer_Release(NSContainer*);
674
675 void init_mutation(HTMLDocumentNode*);
676 void release_mutation(HTMLDocumentNode*);
677
678 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL);
679 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*);
680 void notif_focus(HTMLDocumentObj*);
681
682 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR);
683 void hide_tooltip(HTMLDocumentObj*);
684 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
685
686 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
687
688 BOOL load_gecko(BOOL);
689 void close_gecko(void);
690 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
691 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
692 void release_nsio(void);
693 BOOL install_wine_gecko(BOOL);
694
695 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*);
696 HRESULT create_doc_uri(HTMLWindow*,WCHAR*,nsIWineURI**);
697
698 HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsIInputStream*,DWORD);
699 HRESULT navigate_url(HTMLWindow*,const WCHAR*,const WCHAR*);
700 HRESULT set_frame_doc(HTMLFrameBase*,nsIDOMDocument*);
701 HRESULT load_nsuri(HTMLWindow*,nsIWineURI*,DWORD);
702
703 void call_property_onchanged(ConnectionPoint*,DISPID);
704 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*);
705
706 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1);
707 void nsfree(void*);
708
709 void nsACString_SetData(nsACString*,const char*);
710 PRUint32 nsACString_GetData(const nsACString*,const char**);
711
712 void nsAString_Init(nsAString*,const PRUnichar*);
713 void nsAString_SetData(nsAString*,const PRUnichar*);
714 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**);
715 void nsAString_Finish(nsAString*);
716
717 nsICommandParams *create_nscommand_params(void);
718 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*);
719 void get_editor_controller(NSContainer*);
720 nsresult get_nsinterface(nsISupports*,REFIID,void**);
721
722 void init_nsevents(HTMLDocumentNode*);
723 void release_nsevents(HTMLDocumentNode*);
724 void add_nsevent_listener(HTMLDocumentNode*,LPCWSTR);
725
726 void set_window_bscallback(HTMLWindow*,nsChannelBSC*);
727 void set_current_mon(HTMLWindow*,IMoniker*);
728 HRESULT start_binding(HTMLWindow*,HTMLDocumentNode*,BSCallback*,IBindCtx*);
729 void abort_document_bindings(HTMLDocumentNode*);
730
731 HRESULT bind_mon_to_buffer(HTMLDocumentNode*,IMoniker*,void**,DWORD*);
732
733 nsChannelBSC *create_channelbsc(IMoniker*);
734 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*);
735 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*);
736 IMoniker *get_channelbsc_mon(nsChannelBSC*);
737
738 void set_ready_state(HTMLWindow*,READYSTATE);
739
740 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**);
741 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**);
742 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
743 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
744 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
745
746 void detach_selection(HTMLDocumentNode*);
747 void detach_ranges(HTMLDocumentNode*);
748 HRESULT get_node_text(HTMLDOMNode*,BSTR*);
749
750 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**);
751
752 HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*);
753
754 HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL);
755 HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*);
756 HTMLElement *HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
757 HTMLElement *HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
758 HTMLElement *HTMLFormElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
759 HTMLElement *HTMLFrameElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
760 HTMLElement *HTMLIFrame_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
761 HTMLElement *HTMLImgElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
762 HTMLElement *HTMLInputElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
763 HTMLElement *HTMLOptionElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
764 HTMLElement *HTMLScriptElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
765 HTMLElement *HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
766 HTMLElement *HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
767 HTMLElement *HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
768 HTMLElement *HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
769 HTMLElement *HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
770
771 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*);
772 void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
773 void HTMLElement2_Init(HTMLElement*);
774 void HTMLElement3_Init(HTMLElement*);
775 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
776 void HTMLFrameBase_Init(HTMLFrameBase*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
777
778 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
779 void HTMLDOMNode_destructor(HTMLDOMNode*);
780
781 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**);
782 void HTMLElement_destructor(HTMLDOMNode*);
783
784 HRESULT HTMLFrameBase_QI(HTMLFrameBase*,REFIID,void**);
785 void HTMLFrameBase_destructor(HTMLFrameBase*);
786
787 HTMLDOMNode *get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL);
788 void release_nodes(HTMLDocumentNode*);
789
790 void release_script_hosts(HTMLWindow*);
791 void connect_scripts(HTMLWindow*);
792 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*);
793 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR);
794 void set_script_mode(HTMLWindow*,SCRIPTMODE);
795 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*);
796 IDispatch *get_script_disp(ScriptHost*);
797 HRESULT search_window_props(HTMLWindow*,BSTR,DWORD,DISPID*);
798
799 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
800 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*);
801 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*);
802
803 /* commands */
804 typedef struct {
805     DWORD id;
806     HRESULT (*query)(HTMLDocument*,OLECMD*);
807     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
808 } cmdtable_t;
809
810 extern const cmdtable_t editmode_cmds[];
811
812 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*);
813
814 /* timer */
815 #define UPDATE_UI       0x0001
816 #define UPDATE_TITLE    0x0002
817
818 void update_doc(HTMLDocument*,DWORD);
819 void update_title(HTMLDocumentObj*);
820
821 /* editor */
822 void init_editor(HTMLDocument*);
823 void set_ns_editmode(NSContainer*);
824 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
825 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
826 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
827 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
828 void handle_edit_load(HTMLDocument*);
829 HRESULT editor_is_dirty(HTMLDocument*);
830 void set_dirty(HTMLDocument*,VARIANT_BOOL);
831
832 extern DWORD mshtml_tls;
833
834 typedef struct task_t task_t;
835 typedef void (*task_proc_t)(task_t*);
836
837 struct task_t {
838     LONG target_magic;
839     task_proc_t proc;
840     struct task_t *next;
841 };
842
843 typedef struct {
844     task_t header;
845     HTMLDocumentObj *doc;
846 } docobj_task_t;
847
848 typedef struct {
849     HWND thread_hwnd;
850     task_t *task_queue_head;
851     task_t *task_queue_tail;
852     struct list timer_list;
853 } thread_data_t;
854
855 thread_data_t *get_thread_data(BOOL);
856 HWND get_thread_hwnd(void);
857
858 LONG get_task_target_magic(void);
859 void push_task(task_t*,task_proc_t,LONG);
860 void remove_target_tasks(LONG);
861
862 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
863 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD);
864
865 void release_typelib(void);
866 HRESULT call_disp_func(IDispatch*,DISPPARAMS*);
867
868 const char *debugstr_variant(const VARIANT*);
869
870 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
871 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
872 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
873 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
874 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
875
876 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
877
878 /* memory allocation functions */
879
880 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
881 {
882     return HeapAlloc(GetProcessHeap(), 0, len);
883 }
884
885 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
886 {
887     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
888 }
889
890 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
891 {
892     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
893 }
894
895 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
896 {
897     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
898 }
899
900 static inline BOOL heap_free(void *mem)
901 {
902     return HeapFree(GetProcessHeap(), 0, mem);
903 }
904
905 static inline LPWSTR heap_strdupW(LPCWSTR str)
906 {
907     LPWSTR ret = NULL;
908
909     if(str) {
910         DWORD size;
911
912         size = (strlenW(str)+1)*sizeof(WCHAR);
913         ret = heap_alloc(size);
914         memcpy(ret, str, size);
915     }
916
917     return ret;
918 }
919
920 static inline char *heap_strdupA(const char *str)
921 {
922     char *ret = NULL;
923
924     if(str) {
925         DWORD size;
926
927         size = strlen(str)+1;
928         ret = heap_alloc(size);
929         memcpy(ret, str, size);
930     }
931
932     return ret;
933 }
934
935 static inline WCHAR *heap_strdupAtoW(const char *str)
936 {
937     LPWSTR ret = NULL;
938
939     if(str) {
940         DWORD len;
941
942         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
943         ret = heap_alloc(len*sizeof(WCHAR));
944         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
945     }
946
947     return ret;
948 }
949
950 static inline char *heap_strdupWtoA(LPCWSTR str)
951 {
952     char *ret = NULL;
953
954     if(str) {
955         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
956         ret = heap_alloc(size);
957         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
958     }
959
960     return ret;
961 }
962
963 static inline void windowref_addref(windowref_t *ref)
964 {
965     InterlockedIncrement(&ref->ref);
966 }
967
968 static inline void windowref_release(windowref_t *ref)
969 {
970     if(!InterlockedDecrement(&ref->ref))
971         heap_free(ref);
972 }
973
974 HDC get_display_dc(void);
975 HINSTANCE get_shdoclc(void);
976
977 extern HINSTANCE hInst;