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