mshtml: Implement HTTPChannel::GetResponseHeader.
[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     HWND reset_focus; /* hack */
442 };
443
444 typedef struct nsWineURI nsWineURI;
445
446 HRESULT set_wine_url(nsWineURI*,LPCWSTR);
447 nsresult on_start_uri_open(NSContainer*,nsIURI*,PRBool*);
448
449 typedef struct {
450     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
451     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
452     const nsIHttpChannelInternalVtbl *lpIHttpChannelInternalVtbl;
453
454     LONG ref;
455
456     nsWineURI *uri;
457     nsIInputStream *post_data_stream;
458     nsILoadGroup *load_group;
459     nsIInterfaceRequestor *notif_callback;
460     nsISupports *owner;
461     nsLoadFlags load_flags;
462     nsIURI *original_uri;
463     char *content_type;
464     char *charset;
465     PRUint32 response_status;
466     struct list response_headers;
467     UINT url_scheme;
468 } nsChannel;
469
470 struct ResponseHeader {
471     struct list entry;
472     WCHAR *header;
473     WCHAR *data;
474 };
475
476 typedef struct {
477     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
478     void (*destructor)(HTMLDOMNode*);
479     event_target_t **(*get_event_target)(HTMLDOMNode*);
480     HRESULT (*call_event)(HTMLDOMNode*,DWORD,BOOL*);
481     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
482     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
483     HRESULT (*get_document)(HTMLDOMNode*,IDispatch**);
484     HRESULT (*get_readystate)(HTMLDOMNode*,BSTR*);
485     HRESULT (*get_dispid)(HTMLDOMNode*,BSTR,DWORD,DISPID*);
486     HRESULT (*invoke)(HTMLDOMNode*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
487     HRESULT (*bind_to_tree)(HTMLDOMNode*);
488 } NodeImplVtbl;
489
490 struct HTMLDOMNode {
491     DispatchEx dispex;
492     const IHTMLDOMNodeVtbl   *lpHTMLDOMNodeVtbl;
493     const IHTMLDOMNode2Vtbl  *lpHTMLDOMNode2Vtbl;
494     const NodeImplVtbl *vtbl;
495
496     LONG ref;
497
498     nsIDOMNode *nsnode;
499     HTMLDocumentNode *doc;
500     event_target_t *event_target;
501     ConnectionPointContainer *cp_container;
502
503     HTMLDOMNode *next;
504 };
505
506 typedef struct {
507     HTMLDOMNode node;
508     ConnectionPointContainer cp_container;
509
510     const IHTMLElementVtbl   *lpHTMLElementVtbl;
511     const IHTMLElement2Vtbl  *lpHTMLElement2Vtbl;
512     const IHTMLElement3Vtbl  *lpHTMLElement3Vtbl;
513
514     nsIDOMHTMLElement *nselem;
515 } HTMLElement;
516
517 #define HTMLELEMENT_TIDS    \
518     IHTMLDOMNode_tid,       \
519     IHTMLDOMNode2_tid,      \
520     IHTMLElement_tid,       \
521     IHTMLElement2_tid,      \
522     IHTMLElement3_tid,      \
523     IHTMLElement4_tid
524
525 typedef struct {
526     HTMLElement element;
527
528     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
529
530     ConnectionPoint cp;
531 } HTMLTextContainer;
532
533 struct HTMLFrameBase {
534     HTMLElement element;
535
536     const IHTMLFrameBaseVtbl   *lpIHTMLFrameBaseVtbl;
537     const IHTMLFrameBase2Vtbl  *lpIHTMLFrameBase2Vtbl;
538
539     HTMLWindow *content_window;
540
541     nsIDOMHTMLFrameElement *nsframe;
542     nsIDOMHTMLIFrameElement *nsiframe;
543 };
544
545 typedef struct _mutation_queue_t {
546     DWORD type;
547     nsISupports *nsiface;
548
549     struct _mutation_queue_t *next;
550 } mutation_queue_t;
551
552 typedef struct nsDocumentEventListener nsDocumentEventListener;
553
554 struct HTMLDocumentNode {
555     HTMLDOMNode node;
556     HTMLDocument basedoc;
557
558     const IInternetHostSecurityManagerVtbl *lpIInternetHostSecurityManagerVtbl;
559
560     const nsIDocumentObserverVtbl  *lpIDocumentObserverVtbl;
561     const nsIRunnableVtbl  *lpIRunnableVtbl;
562
563     LONG ref;
564
565     nsIDOMHTMLDocument *nsdoc;
566     HTMLDOMNode *nodes;
567     BOOL content_ready;
568     event_target_t *body_event_target;
569
570     IInternetSecurityManager *secmgr;
571     ICatInformation *catmgr;
572     nsDocumentEventListener *nsevent_listener;
573     BOOL *event_vector;
574
575     mutation_queue_t *mutation_queue;
576     mutation_queue_t *mutation_queue_tail;
577
578     struct list bindings;
579     struct list selection_list;
580     struct list range_list;
581 };
582
583 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
584 #define HTMLWINDOW3(x)   ((IHTMLWindow3*)                 &(x)->lpHTMLWindow3Vtbl)
585 #define HTMLWINDOW4(x)   ((IHTMLWindow4*)                 &(x)->lpHTMLWindow4Vtbl)
586
587 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
588 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
589 #define HTMLDOC4(x)      ((IHTMLDocument4*)               &(x)->lpHTMLDocument4Vtbl)
590 #define HTMLDOC5(x)      ((IHTMLDocument5*)               &(x)->lpHTMLDocument5Vtbl)
591 #define HTMLDOC6(x)      ((IHTMLDocument6*)               &(x)->lpHTMLDocument6Vtbl)
592 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
593 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
594 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
595 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
596 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
597 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
598 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
599 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
600 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
601 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObjectExVtbl)
602 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObjectExVtbl)
603 #define VIEWOBJEX(x)      ((IViewObjectEx*)               &(x)->lpViewObjectExVtbl)
604 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
605 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
606 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
607 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
608 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
609 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
610 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
611 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
612 #define PERSISTHIST(x)   ((IPersistHistory*)              &(x)->lpPersistHistoryVtbl)
613 #define CUSTOMDOC(x)     ((ICustomDoc*)                   &(x)->lpCustomDocVtbl)
614 #define OBJSITE(x)       ((IObjectWithSite*)              &(x)->lpObjectWithSiteVtbl)
615
616 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
617 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
618 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
619 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
620 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
621 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
622 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
623 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
624 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
625
626 #define NSDOCOBS(x)      ((nsIDocumentObserver*)          &(x)->lpIDocumentObserverVtbl)
627
628 #define NSRUNNABLE(x)    ((nsIRunnable*)  &(x)->lpIRunnableVtbl)
629
630 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
631 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
632 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
633 #define NSHTTPINTERNAL(x) ((nsIHttpChannelInternal*)  &(x)->lpIHttpChannelInternalVtbl)
634
635 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
636 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
637 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
638
639 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
640 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
641 #define HTMLELEM3(x)     ((IHTMLElement3*)                &(x)->lpHTMLElement3Vtbl)
642 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
643 #define HTMLDOMNODE2(x)  ((IHTMLDOMNode2*)                &(x)->lpHTMLDOMNode2Vtbl)
644
645 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
646 #define HTMLFRAMEBASE(x) ((IHTMLFrameBase*)               &(x)->lpIHTMLFrameBaseVtbl)
647 #define HTMLFRAMEBASE2(x) ((IHTMLFrameBase2*)             &(x)->lpIHTMLFrameBase2Vtbl)
648
649 #define HTMLOPTFACTORY(x)  ((IHTMLOptionElementFactory*)  &(x)->lpHTMLOptionElementFactoryVtbl)
650 #define HTMLIMGFACTORY(x)  ((IHTMLImageElementFactory*)   &(x)->lpHTMLImageElementFactoryVtbl)
651 #define HTMLLOCATION(x)    ((IHTMLLocation*)              &(x)->lpHTMLLocationVtbl)
652
653 #define DISPATCHEX(x)    ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
654
655 #define SUPPERRINFO(x)   ((ISupportErrorInfo*) &(x)->lpSupportErrorInfoVtbl)
656
657 #define HOSTSECMGR(x)    ((IInternetHostSecurityManager*)  &(x)->lpIInternetHostSecurityManagerVtbl)
658
659 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
660 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
661
662 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
663 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
664 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**);
665
666 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**);
667 void update_window_doc(HTMLWindow*);
668 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
669 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument*);
670 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
671 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*);
672 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
673 IOmNavigator *OmNavigator_Create(void);
674 HRESULT HTMLScreen_Create(IHTMLScreen**);
675
676 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
677 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*);
678 void HTMLDocument_Persist_Init(HTMLDocument*);
679 void HTMLDocument_OleCmd_Init(HTMLDocument*);
680 void HTMLDocument_OleObj_Init(HTMLDocument*);
681 void HTMLDocument_View_Init(HTMLDocument*);
682 void HTMLDocument_Window_Init(HTMLDocument*);
683 void HTMLDocument_Service_Init(HTMLDocument*);
684 void HTMLDocument_Hlink_Init(HTMLDocument*);
685
686 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*);
687
688 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**);
689
690 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID,cp_static_data_t*);
691 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*);
692 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
693
694 NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*);
695 void NSContainer_Release(NSContainer*);
696
697 void init_mutation(HTMLDocumentNode*);
698 void release_mutation(HTMLDocumentNode*);
699
700 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL);
701 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*);
702 void notif_focus(HTMLDocumentObj*);
703
704 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR);
705 void hide_tooltip(HTMLDocumentObj*);
706 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
707
708 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
709
710 BOOL load_gecko(BOOL);
711 void close_gecko(void);
712 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
713 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
714 void release_nsio(void);
715 BOOL install_wine_gecko(BOOL);
716
717 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*);
718 HRESULT create_doc_uri(HTMLWindow*,WCHAR*,nsWineURI**);
719 HRESULT load_nsuri(HTMLWindow*,nsWineURI*,nsChannelBSC*,DWORD);
720
721 HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsIInputStream*,DWORD,BOOL*);
722 HRESULT navigate_url(HTMLWindow*,const WCHAR*,const WCHAR*);
723 HRESULT set_frame_doc(HTMLFrameBase*,nsIDOMDocument*);
724 HRESULT set_moniker(HTMLDocument*,IMoniker*,IBindCtx*,nsChannelBSC*,BOOL);
725
726 void call_property_onchanged(ConnectionPoint*,DISPID);
727 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*);
728
729 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1);
730 void nsfree(void*);
731
732 void nsACString_SetData(nsACString*,const char*);
733 PRUint32 nsACString_GetData(const nsACString*,const char**);
734
735 BOOL nsAString_Init(nsAString*,const PRUnichar*);
736 void nsAString_InitDepend(nsAString*,const PRUnichar*);
737 void nsAString_SetData(nsAString*,const PRUnichar*);
738 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**);
739 void nsAString_Finish(nsAString*);
740
741 nsICommandParams *create_nscommand_params(void);
742 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*);
743 void get_editor_controller(NSContainer*);
744 nsresult get_nsinterface(nsISupports*,REFIID,void**);
745
746 void init_nsevents(HTMLDocumentNode*);
747 void release_nsevents(HTMLDocumentNode*);
748 void add_nsevent_listener(HTMLDocumentNode*,nsIDOMNode*,LPCWSTR);
749
750 void set_window_bscallback(HTMLWindow*,nsChannelBSC*);
751 void set_current_mon(HTMLWindow*,IMoniker*);
752 HRESULT start_binding(HTMLWindow*,HTMLDocumentNode*,BSCallback*,IBindCtx*);
753 HRESULT async_start_doc_binding(HTMLWindow*,nsChannelBSC*);
754 void abort_document_bindings(HTMLDocumentNode*);
755
756 HRESULT bind_mon_to_buffer(HTMLDocumentNode*,IMoniker*,void**,DWORD*);
757
758 HRESULT create_channelbsc(IMoniker*,WCHAR*,BYTE*,DWORD,nsChannelBSC**);
759 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*);
760 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*);
761 IMoniker *get_channelbsc_mon(nsChannelBSC*);
762
763 void set_ready_state(HTMLWindow*,READYSTATE);
764
765 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**);
766 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**);
767 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
768 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
769 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
770
771 void detach_selection(HTMLDocumentNode*);
772 void detach_ranges(HTMLDocumentNode*);
773 HRESULT get_node_text(HTMLDOMNode*,BSTR*);
774
775 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**);
776
777 HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*);
778
779 HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL);
780 HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*);
781 HTMLElement *HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
782 HTMLElement *HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
783 HTMLElement *HTMLFormElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
784 HTMLElement *HTMLFrameElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
785 HTMLElement *HTMLIFrame_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
786 HTMLElement *HTMLImgElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
787 HTMLElement *HTMLInputElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
788 HTMLElement *HTMLOptionElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
789 HTMLElement *HTMLScriptElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
790 HTMLElement *HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
791 HTMLElement *HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
792 HTMLElement *HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
793 HTMLElement *HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
794 HTMLElement *HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
795
796 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*);
797 void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
798 void HTMLElement2_Init(HTMLElement*);
799 void HTMLElement3_Init(HTMLElement*);
800 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
801 void HTMLFrameBase_Init(HTMLFrameBase*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
802
803 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
804 void HTMLDOMNode_destructor(HTMLDOMNode*);
805
806 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**);
807 void HTMLElement_destructor(HTMLDOMNode*);
808
809 HRESULT HTMLFrameBase_QI(HTMLFrameBase*,REFIID,void**);
810 void HTMLFrameBase_destructor(HTMLFrameBase*);
811
812 HTMLDOMNode *get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL);
813 void release_nodes(HTMLDocumentNode*);
814
815 void release_script_hosts(HTMLWindow*);
816 void connect_scripts(HTMLWindow*);
817 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*);
818 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR);
819 void set_script_mode(HTMLWindow*,SCRIPTMODE);
820 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*);
821 IDispatch *get_script_disp(ScriptHost*);
822 HRESULT search_window_props(HTMLWindow*,BSTR,DWORD,DISPID*);
823
824 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
825 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*);
826 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*);
827
828 /* commands */
829 typedef struct {
830     DWORD id;
831     HRESULT (*query)(HTMLDocument*,OLECMD*);
832     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
833 } cmdtable_t;
834
835 extern const cmdtable_t editmode_cmds[];
836
837 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*);
838
839 /* timer */
840 #define UPDATE_UI       0x0001
841 #define UPDATE_TITLE    0x0002
842
843 void update_doc(HTMLDocument*,DWORD);
844 void update_title(HTMLDocumentObj*);
845
846 /* editor */
847 void init_editor(HTMLDocument*);
848 void set_ns_editmode(NSContainer*);
849 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
850 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
851 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
852 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
853 void handle_edit_load(HTMLDocument*);
854 HRESULT editor_is_dirty(HTMLDocument*);
855 void set_dirty(HTMLDocument*,VARIANT_BOOL);
856
857 extern DWORD mshtml_tls;
858
859 typedef struct task_t task_t;
860 typedef void (*task_proc_t)(task_t*);
861
862 struct task_t {
863     LONG target_magic;
864     task_proc_t proc;
865     struct task_t *next;
866 };
867
868 typedef struct {
869     task_t header;
870     HTMLDocumentObj *doc;
871 } docobj_task_t;
872
873 typedef struct {
874     HWND thread_hwnd;
875     task_t *task_queue_head;
876     task_t *task_queue_tail;
877     struct list timer_list;
878 } thread_data_t;
879
880 thread_data_t *get_thread_data(BOOL);
881 HWND get_thread_hwnd(void);
882
883 LONG get_task_target_magic(void);
884 void push_task(task_t*,task_proc_t,LONG);
885 void remove_target_tasks(LONG);
886
887 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
888 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD);
889
890 void release_typelib(void);
891 HRESULT call_disp_func(IDispatch*,DISPPARAMS*);
892
893 const char *debugstr_variant(const VARIANT*);
894
895 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
896 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
897 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
898 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
899 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
900
901 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
902
903 /* memory allocation functions */
904
905 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
906 {
907     return HeapAlloc(GetProcessHeap(), 0, len);
908 }
909
910 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
911 {
912     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
913 }
914
915 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
916 {
917     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
918 }
919
920 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
921 {
922     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
923 }
924
925 static inline BOOL heap_free(void *mem)
926 {
927     return HeapFree(GetProcessHeap(), 0, mem);
928 }
929
930 static inline LPWSTR heap_strdupW(LPCWSTR str)
931 {
932     LPWSTR ret = NULL;
933
934     if(str) {
935         DWORD size;
936
937         size = (strlenW(str)+1)*sizeof(WCHAR);
938         ret = heap_alloc(size);
939         memcpy(ret, str, size);
940     }
941
942     return ret;
943 }
944
945 static inline char *heap_strdupA(const char *str)
946 {
947     char *ret = NULL;
948
949     if(str) {
950         DWORD size;
951
952         size = strlen(str)+1;
953         ret = heap_alloc(size);
954         memcpy(ret, str, size);
955     }
956
957     return ret;
958 }
959
960 static inline WCHAR *heap_strdupAtoW(const char *str)
961 {
962     LPWSTR ret = NULL;
963
964     if(str) {
965         DWORD len;
966
967         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
968         ret = heap_alloc(len*sizeof(WCHAR));
969         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
970     }
971
972     return ret;
973 }
974
975 static inline char *heap_strdupWtoA(LPCWSTR str)
976 {
977     char *ret = NULL;
978
979     if(str) {
980         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
981         ret = heap_alloc(size);
982         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
983     }
984
985     return ret;
986 }
987
988 static inline void windowref_addref(windowref_t *ref)
989 {
990     InterlockedIncrement(&ref->ref);
991 }
992
993 static inline void windowref_release(windowref_t *ref)
994 {
995     if(!InterlockedDecrement(&ref->ref))
996         heap_free(ref);
997 }
998
999 HDC get_display_dc(void);
1000 HINSTANCE get_shdoclc(void);
1001
1002 extern HINSTANCE hInst;