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