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