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