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