mshtml: Use lazy allocation for connection points.
[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 "docobjectservice.h"
22 #include "comcat.h"
23 #include "mshtml.h"
24 #include "mshtmhst.h"
25 #include "hlink.h"
26 #include "perhist.h"
27 #include "dispex.h"
28 #include "objsafe.h"
29 #include "htiframe.h"
30 #include "tlogstg.h"
31
32 #include "wine/list.h"
33 #include "wine/unicode.h"
34
35 #ifdef INIT_GUID
36 #include "initguid.h"
37 #endif
38
39 #include "nsiface.h"
40
41 #define NS_ERROR_GENERATE_FAILURE(module,code) \
42     ((nsresult) (((UINT32)(1<<31)) | ((UINT32)(module+0x45)<<16) | ((UINT32)(code))))
43
44 #define NS_OK                     ((nsresult)0x00000000L)
45 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
46 #define NS_ERROR_OUT_OF_MEMORY    ((nsresult)0x8007000EL)
47 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
48 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
49 #define NS_ERROR_INVALID_POINTER  ((nsresult)0x80004003L)
50 #define NS_ERROR_NULL_POINTER     NS_ERROR_INVALID_POINTER
51 #define NS_ERROR_NOT_AVAILABLE    ((nsresult)0x80040111L)
52 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
53 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
54
55 #define NS_ERROR_MODULE_NETWORK    6
56
57 #define NS_BINDING_ABORTED         NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 2)
58 #define NS_ERROR_UNKNOWN_PROTOCOL  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 18)
59
60 #define NS_FAILED(res) ((res) & 0x80000000)
61 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
62
63 #define NSAPI WINAPI
64
65 #define MSHTML_E_NODOC    0x800a025c
66
67 typedef struct HTMLDOMNode HTMLDOMNode;
68 typedef struct ConnectionPoint ConnectionPoint;
69 typedef struct BSCallback BSCallback;
70 typedef struct event_target_t event_target_t;
71
72 #define TID_LIST \
73     XIID(NULL) \
74     XDIID(DispCEventObj) \
75     XDIID(DispCPlugins) \
76     XDIID(DispDOMChildrenCollection) \
77     XDIID(DispHTMLAnchorElement) \
78     XDIID(DispHTMLAttributeCollection) \
79     XDIID(DispHTMLBody) \
80     XDIID(DispHTMLButtonElement) \
81     XDIID(DispHTMLCommentElement) \
82     XDIID(DispHTMLCurrentStyle) \
83     XDIID(DispHTMLDocument) \
84     XDIID(DispHTMLDOMAttribute) \
85     XDIID(DispHTMLDOMTextNode) \
86     XDIID(DispHTMLElementCollection) \
87     XDIID(DispHTMLEmbed) \
88     XDIID(DispHTMLFormElement) \
89     XDIID(DispHTMLGenericElement) \
90     XDIID(DispHTMLFrameElement) \
91     XDIID(DispHTMLHeadElement) \
92     XDIID(DispHTMLHistory) \
93     XDIID(DispHTMLIFrame) \
94     XDIID(DispHTMLImg) \
95     XDIID(DispHTMLInputElement) \
96     XDIID(DispHTMLLabelElement) \
97     XDIID(DispHTMLLinkElement) \
98     XDIID(DispHTMLLocation) \
99     XDIID(DispHTMLMetaElement) \
100     XDIID(DispHTMLNavigator) \
101     XDIID(DispHTMLObjectElement) \
102     XDIID(DispHTMLOptionElement) \
103     XDIID(DispHTMLScreen) \
104     XDIID(DispHTMLScriptElement) \
105     XDIID(DispHTMLSelectElement) \
106     XDIID(DispHTMLStyle) \
107     XDIID(DispHTMLStyleElement) \
108     XDIID(DispHTMLStyleSheetsCollection) \
109     XDIID(DispHTMLTable) \
110     XDIID(DispHTMLTableCell) \
111     XDIID(DispHTMLTableRow) \
112     XDIID(DispHTMLTextAreaElement) \
113     XDIID(DispHTMLTitleElement) \
114     XDIID(DispHTMLUnknownElement) \
115     XDIID(DispHTMLWindow2) \
116     XDIID(HTMLDocumentEvents) \
117     XIID(IHTMLAnchorElement) \
118     XIID(IHTMLAttributeCollection) \
119     XIID(IHTMLAttributeCollection2) \
120     XIID(IHTMLAttributeCollection3) \
121     XIID(IHTMLBodyElement) \
122     XIID(IHTMLBodyElement2) \
123     XIID(IHTMLButtonElement) \
124     XIID(IHTMLCommentElement) \
125     XIID(IHTMLCurrentStyle) \
126     XIID(IHTMLCurrentStyle2) \
127     XIID(IHTMLCurrentStyle3) \
128     XIID(IHTMLCurrentStyle4) \
129     XIID(IHTMLDocument2) \
130     XIID(IHTMLDocument3) \
131     XIID(IHTMLDocument4) \
132     XIID(IHTMLDocument5) \
133     XIID(IHTMLDOMAttribute) \
134     XIID(IHTMLDOMChildrenCollection) \
135     XIID(IHTMLDOMNode) \
136     XIID(IHTMLDOMNode2) \
137     XIID(IHTMLDOMTextNode) \
138     XIID(IHTMLElement) \
139     XIID(IHTMLElement2) \
140     XIID(IHTMLElement3) \
141     XIID(IHTMLElement4) \
142     XIID(IHTMLElementCollection) \
143     XIID(IHTMLEmbedElement) \
144     XIID(IHTMLEventObj) \
145     XIID(IHTMLFiltersCollection) \
146     XIID(IHTMLFormElement) \
147     XIID(IHTMLFrameBase) \
148     XIID(IHTMLFrameBase2) \
149     XIID(IHTMLFrameElement3) \
150     XIID(IHTMLGenericElement) \
151     XIID(IHTMLHeadElement) \
152     XIID(IHTMLIFrameElement) \
153     XIID(IHTMLIFrameElement2) \
154     XIID(IHTMLIFrameElement3) \
155     XIID(IHTMLImageElementFactory) \
156     XIID(IHTMLImgElement) \
157     XIID(IHTMLInputElement) \
158     XIID(IHTMLLabelElement) \
159     XIID(IHTMLLinkElement) \
160     XIID(IHTMLLocation) \
161     XIID(IHTMLMetaElement) \
162     XIID(IHTMLMimeTypesCollection) \
163     XIID(IHTMLObjectElement) \
164     XIID(IHTMLObjectElement2) \
165     XIID(IHTMLOptionElement) \
166     XIID(IHTMLPluginsCollection) \
167     XIID(IHTMLRect) \
168     XIID(IHTMLScreen) \
169     XIID(IHTMLScriptElement) \
170     XIID(IHTMLSelectElement) \
171     XIID(IHTMLStorage) \
172     XIID(IHTMLStyle) \
173     XIID(IHTMLStyle2) \
174     XIID(IHTMLStyle3) \
175     XIID(IHTMLStyle4) \
176     XIID(IHTMLStyle5) \
177     XIID(IHTMLStyle6) \
178     XIID(IHTMLStyleElement) \
179     XIID(IHTMLStyleSheetsCollection) \
180     XIID(IHTMLTable) \
181     XIID(IHTMLTable2) \
182     XIID(IHTMLTable3) \
183     XIID(IHTMLTableCell) \
184     XIID(IHTMLTableRow) \
185     XIID(IHTMLTextAreaElement) \
186     XIID(IHTMLTextContainer) \
187     XIID(IHTMLTitleElement) \
188     XIID(IHTMLUniqueName) \
189     XIID(IHTMLWindow2) \
190     XIID(IHTMLWindow3) \
191     XIID(IHTMLWindow4) \
192     XIID(IHTMLWindow5) \
193     XIID(IHTMLWindow6) \
194     XIID(IOmHistory) \
195     XIID(IOmNavigator)
196
197 typedef enum {
198 #define XIID(iface) iface ## _tid,
199 #define XDIID(iface) iface ## _tid,
200 TID_LIST
201 #undef XIID
202 #undef XDIID
203     LAST_tid
204 } tid_t;
205
206 typedef struct dispex_data_t dispex_data_t;
207 typedef struct dispex_dynamic_data_t dispex_dynamic_data_t;
208
209 #define MSHTML_DISPID_CUSTOM_MIN 0x60000000
210 #define MSHTML_DISPID_CUSTOM_MAX 0x6fffffff
211 #define MSHTML_CUSTOM_DISPID_CNT (MSHTML_DISPID_CUSTOM_MAX-MSHTML_DISPID_CUSTOM_MIN)
212
213 typedef struct DispatchEx DispatchEx;
214
215 typedef struct {
216     HRESULT (*value)(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
217     HRESULT (*get_dispid)(DispatchEx*,BSTR,DWORD,DISPID*);
218     HRESULT (*invoke)(DispatchEx*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
219     HRESULT (*populate_props)(DispatchEx*);
220 } dispex_static_data_vtbl_t;
221
222 typedef struct {
223     const dispex_static_data_vtbl_t *vtbl;
224     const tid_t disp_tid;
225     dispex_data_t *data;
226     const tid_t* const iface_tids;
227 } dispex_static_data_t;
228
229 struct DispatchEx {
230     IDispatchEx IDispatchEx_iface;
231
232     IUnknown *outer;
233
234     dispex_static_data_t *data;
235     dispex_dynamic_data_t *dynamic_data;
236 };
237
238 typedef struct {
239     void *x;
240 } nsCycleCollectingAutoRefCnt;
241
242 typedef struct {
243     void *x[9];
244 } nsXPCOMCycleCollectionParticipant;
245
246 typedef struct nsCycleCollectionTraversalCallback nsCycleCollectionTraversalCallback;
247
248 typedef struct {
249     void (NSAPI *unmark_if_purple)(void*);
250     nsresult (NSAPI *traverse)(void*,void*,nsCycleCollectionTraversalCallback*);
251     nsresult (NSAPI *unlink)(void*);
252 } CCObjCallback;
253
254 DEFINE_GUID(IID_nsXPCOMCycleCollectionParticipant, 0x9674489b,0x1f6f,0x4550,0xa7,0x30, 0xcc,0xae,0xdd,0x10,0x4c,0xf9);
255
256 nsrefcnt (__cdecl *ccref_incr)(nsCycleCollectingAutoRefCnt*,nsISupports*);
257 nsrefcnt (__cdecl *ccref_decr)(nsCycleCollectingAutoRefCnt*,nsISupports*);
258 void (__cdecl *ccref_init)(nsCycleCollectingAutoRefCnt*,nsrefcnt);
259 void (__cdecl *ccref_unmark_if_purple)(nsCycleCollectingAutoRefCnt*);
260 void (__cdecl *ccp_init)(nsXPCOMCycleCollectionParticipant*,const CCObjCallback*);
261 void (__cdecl *describe_cc_node)(nsCycleCollectingAutoRefCnt*,const char*,nsCycleCollectionTraversalCallback*);
262 void (__cdecl *note_cc_edge)(nsISupports*,const char*,nsCycleCollectionTraversalCallback*);
263
264 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*) DECLSPEC_HIDDEN;
265 void release_dispex(DispatchEx*) DECLSPEC_HIDDEN;
266 BOOL dispex_query_interface(DispatchEx*,REFIID,void**) DECLSPEC_HIDDEN;
267 HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**) DECLSPEC_HIDDEN;
268 HRESULT get_dispids(tid_t,DWORD*,DISPID**) DECLSPEC_HIDDEN;
269 HRESULT remove_prop(DispatchEx*,BSTR,VARIANT_BOOL*) DECLSPEC_HIDDEN;
270 HRESULT dispex_get_dynid(DispatchEx*,const WCHAR*,DISPID*) DECLSPEC_HIDDEN;
271 void dispex_traverse(DispatchEx*,nsCycleCollectionTraversalCallback*) DECLSPEC_HIDDEN;
272 void dispex_unlink(DispatchEx*) DECLSPEC_HIDDEN;
273 void release_typelib(void) DECLSPEC_HIDDEN;
274 HRESULT get_htmldoc_classinfo(ITypeInfo **typeinfo) DECLSPEC_HIDDEN;
275
276 typedef enum {
277     DISPEXPROP_CUSTOM,
278     DISPEXPROP_DYNAMIC,
279     DISPEXPROP_BUILTIN
280 } dispex_prop_type_t;
281
282 dispex_prop_type_t get_dispid_type(DISPID) DECLSPEC_HIDDEN;
283
284 typedef struct HTMLWindow HTMLWindow;
285 typedef struct HTMLInnerWindow HTMLInnerWindow;
286 typedef struct HTMLOuterWindow HTMLOuterWindow;
287 typedef struct HTMLDocumentNode HTMLDocumentNode;
288 typedef struct HTMLDocumentObj HTMLDocumentObj;
289 typedef struct HTMLFrameBase HTMLFrameBase;
290 typedef struct NSContainer NSContainer;
291 typedef struct HTMLAttributeCollection HTMLAttributeCollection;
292
293 typedef enum {
294     SCRIPTMODE_GECKO,
295     SCRIPTMODE_ACTIVESCRIPT
296 } SCRIPTMODE;
297
298 typedef struct ScriptHost ScriptHost;
299
300 typedef enum {
301     GLOBAL_SCRIPTVAR,
302     GLOBAL_ELEMENTVAR,
303     GLOBAL_DISPEXVAR,
304     GLOBAL_FRAMEVAR
305 } global_prop_type_t;
306
307 typedef struct {
308     global_prop_type_t type;
309     WCHAR *name;
310     ScriptHost *script_host;
311     DISPID id;
312 } global_prop_t;
313
314 typedef struct {
315     IHTMLOptionElementFactory IHTMLOptionElementFactory_iface;
316
317     LONG ref;
318
319     HTMLInnerWindow *window;
320 } HTMLOptionElementFactory;
321
322 typedef struct {
323     DispatchEx dispex;
324     IHTMLImageElementFactory IHTMLImageElementFactory_iface;
325
326     LONG ref;
327
328     HTMLInnerWindow *window;
329 } HTMLImageElementFactory;
330
331 struct HTMLLocation {
332     DispatchEx dispex;
333     IHTMLLocation IHTMLLocation_iface;
334
335     LONG ref;
336
337     HTMLInnerWindow *window;
338 };
339
340 typedef struct {
341     HTMLOuterWindow *window;
342     LONG ref;
343 }  windowref_t;
344
345 typedef struct nsChannelBSC nsChannelBSC;
346
347 struct HTMLWindow {
348     IHTMLWindow2       IHTMLWindow2_iface;
349     IHTMLWindow3       IHTMLWindow3_iface;
350     IHTMLWindow4       IHTMLWindow4_iface;
351     IHTMLWindow5       IHTMLWindow5_iface;
352     IHTMLWindow6       IHTMLWindow6_iface;
353     IHTMLPrivateWindow IHTMLPrivateWindow_iface;
354     IDispatchEx        IDispatchEx_iface;
355     IServiceProvider   IServiceProvider_iface;
356     ITravelLogClient   ITravelLogClient_iface;
357
358     LONG ref;
359
360     HTMLInnerWindow *inner_window;
361     HTMLOuterWindow *outer_window;
362 };
363
364 struct HTMLOuterWindow {
365     HTMLWindow base;
366
367     windowref_t *window_ref;
368     LONG task_magic;
369
370     HTMLDocumentObj *doc_obj;
371     nsIDOMWindow *nswindow;
372     HTMLOuterWindow *parent;
373     HTMLFrameBase *frame_element;
374     READYSTATE readystate;
375
376     HTMLInnerWindow *pending_window;
377     IMoniker *mon;
378     IUri *uri;
379     IUri *uri_nofrag;
380     BSTR url;
381     DWORD load_flags;
382
383     SCRIPTMODE scriptmode;
384
385     IInternetSecurityManager *secmgr;
386
387     struct list children;
388     struct list sibling_entry;
389     struct list entry;
390 };
391
392 struct HTMLInnerWindow {
393     HTMLWindow base;
394     DispatchEx dispex;
395
396     HTMLDocumentNode *doc;
397
398     struct list script_hosts;
399
400     IHTMLEventObj *event;
401
402     HTMLImageElementFactory *image_factory;
403     HTMLOptionElementFactory *option_factory;
404     IHTMLScreen *screen;
405     IOmHistory *history;
406     IHTMLStorage *session_storage;
407
408     unsigned parser_callback_cnt;
409     struct list script_queue;
410
411     global_prop_t *global_props;
412     DWORD global_prop_cnt;
413     DWORD global_prop_size;
414
415     LONG task_magic;
416
417     HTMLLocation *location;
418
419     IMoniker *mon;
420     nsChannelBSC *bscallback;
421     struct list bindings;
422 };
423
424 typedef enum {
425     UNKNOWN_USERMODE,
426     BROWSEMODE,
427     EDITMODE        
428 } USERMODE;
429
430 typedef struct _cp_static_data_t {
431     tid_t tid;
432     void (*on_advise)(IUnknown*,struct _cp_static_data_t*);
433     DWORD id_cnt;
434     DISPID *ids;
435 } cp_static_data_t;
436
437 typedef struct {
438     const IID *riid;
439     cp_static_data_t *desc;
440 } cpc_entry_t;
441
442 typedef struct ConnectionPointContainer {
443     IConnectionPointContainer IConnectionPointContainer_iface;
444
445     ConnectionPoint *cps;
446     const cpc_entry_t *cp_entries;
447     IUnknown *outer;
448     struct ConnectionPointContainer *forward_container;
449 } ConnectionPointContainer;
450
451 struct  ConnectionPoint {
452     IConnectionPoint IConnectionPoint_iface;
453
454     ConnectionPointContainer *container;
455
456     union {
457         IUnknown *unk;
458         IDispatch *disp;
459         IPropertyNotifySink *propnotif;
460     } *sinks;
461     DWORD sinks_size;
462
463     const IID *iid;
464     cp_static_data_t *data;
465 };
466
467 struct HTMLDocument {
468     IHTMLDocument2              IHTMLDocument2_iface;
469     IHTMLDocument3              IHTMLDocument3_iface;
470     IHTMLDocument4              IHTMLDocument4_iface;
471     IHTMLDocument5              IHTMLDocument5_iface;
472     IHTMLDocument6              IHTMLDocument6_iface;
473     IPersistMoniker             IPersistMoniker_iface;
474     IPersistFile                IPersistFile_iface;
475     IPersistHistory             IPersistHistory_iface;
476     IMonikerProp                IMonikerProp_iface;
477     IOleObject                  IOleObject_iface;
478     IOleDocument                IOleDocument_iface;
479     IOleDocumentView            IOleDocumentView_iface;
480     IOleInPlaceActiveObject     IOleInPlaceActiveObject_iface;
481     IViewObjectEx               IViewObjectEx_iface;
482     IOleInPlaceObjectWindowless IOleInPlaceObjectWindowless_iface;
483     IServiceProvider            IServiceProvider_iface;
484     IOleCommandTarget           IOleCommandTarget_iface;
485     IOleControl                 IOleControl_iface;
486     IHlinkTarget                IHlinkTarget_iface;
487     IPersistStreamInit          IPersistStreamInit_iface;
488     IDispatchEx                 IDispatchEx_iface;
489     ISupportErrorInfo           ISupportErrorInfo_iface;
490     IObjectWithSite             IObjectWithSite_iface;
491     IOleContainer               IOleContainer_iface;
492     IObjectSafety               IObjectSafety_iface;
493     IProvideClassInfo           IProvideClassInfo_iface;
494
495     IUnknown *unk_impl;
496     IDispatchEx *dispex;
497
498     HTMLDocumentObj *doc_obj;
499     HTMLDocumentNode *doc_node;
500
501     HTMLOuterWindow *window;
502
503     LONG task_magic;
504
505     ConnectionPointContainer cp_container;
506     IOleAdviseHolder *advise_holder;
507 };
508
509 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
510 {
511     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
512 }
513
514 static inline ULONG htmldoc_addref(HTMLDocument *This)
515 {
516     return IUnknown_AddRef(This->unk_impl);
517 }
518
519 static inline ULONG htmldoc_release(HTMLDocument *This)
520 {
521     return IUnknown_Release(This->unk_impl);
522 }
523
524 struct HTMLDocumentObj {
525     HTMLDocument basedoc;
526     DispatchEx dispex;
527     ICustomDoc ICustomDoc_iface;
528     ITargetContainer ITargetContainer_iface;
529
530     IWindowForBindingUI IWindowForBindingUI_iface;
531
532     LONG ref;
533
534     NSContainer *nscontainer;
535
536     IOleClientSite *client;
537     IDocHostUIHandler *hostui;
538     IOleCommandTarget *client_cmdtrg;
539     BOOL custom_hostui;
540     IOleInPlaceSite *ipsite;
541     IOleInPlaceFrame *frame;
542     IOleInPlaceUIWindow *ip_window;
543     IAdviseSink *view_sink;
544     IDocObjectService *doc_object_service;
545
546     DOCHOSTUIINFO hostinfo;
547
548     IOleUndoManager *undomgr;
549
550     HWND hwnd;
551     HWND tooltips_hwnd;
552
553     BOOL request_uiactivate;
554     BOOL in_place_active;
555     BOOL ui_active;
556     BOOL window_active;
557     BOOL hostui_setup;
558     BOOL is_webbrowser;
559     BOOL container_locked;
560     BOOL focus;
561     BOOL has_popup;
562     INT download_state;
563
564     USERMODE usermode;
565     LPWSTR mime;
566
567     DWORD update;
568 };
569
570 typedef struct nsWeakReference nsWeakReference;
571
572 struct NSContainer {
573     nsIWebBrowserChrome      nsIWebBrowserChrome_iface;
574     nsIContextMenuListener   nsIContextMenuListener_iface;
575     nsIURIContentListener    nsIURIContentListener_iface;
576     nsIEmbeddingSiteWindow   nsIEmbeddingSiteWindow_iface;
577     nsITooltipListener       nsITooltipListener_iface;
578     nsIInterfaceRequestor    nsIInterfaceRequestor_iface;
579     nsISupportsWeakReference nsISupportsWeakReference_iface;
580
581     nsIWebBrowser *webbrowser;
582     nsIWebNavigation *navigation;
583     nsIBaseWindow *window;
584     nsIWebBrowserFocus *focus;
585
586     nsIEditor *editor;
587     nsIController *editor_controller;
588
589     LONG ref;
590
591     nsWeakReference *weak_reference;
592
593     NSContainer *parent;
594     HTMLDocumentObj *doc;
595
596     nsIURIContentListener *content_listener;
597
598     HWND hwnd;
599 };
600
601 typedef struct {
602     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
603     void (*destructor)(HTMLDOMNode*);
604     const cpc_entry_t *cpc_entries;
605     HRESULT (*clone)(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**);
606     HRESULT (*handle_event)(HTMLDOMNode*,DWORD,nsIDOMEvent*,BOOL*);
607     HRESULT (*get_attr_col)(HTMLDOMNode*,HTMLAttributeCollection**);
608     event_target_t **(*get_event_target)(HTMLDOMNode*);
609     HRESULT (*fire_event)(HTMLDOMNode*,DWORD,BOOL*);
610     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
611     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
612     HRESULT (*get_document)(HTMLDOMNode*,IDispatch**);
613     HRESULT (*get_readystate)(HTMLDOMNode*,BSTR*);
614     HRESULT (*get_dispid)(HTMLDOMNode*,BSTR,DWORD,DISPID*);
615     HRESULT (*invoke)(HTMLDOMNode*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
616     HRESULT (*bind_to_tree)(HTMLDOMNode*);
617     void (*traverse)(HTMLDOMNode*,nsCycleCollectionTraversalCallback*);
618     void (*unlink)(HTMLDOMNode*);
619 } NodeImplVtbl;
620
621 struct HTMLDOMNode {
622     DispatchEx dispex;
623     IHTMLDOMNode  IHTMLDOMNode_iface;
624     IHTMLDOMNode2 IHTMLDOMNode2_iface;
625     const NodeImplVtbl *vtbl;
626
627     nsCycleCollectingAutoRefCnt ccref;
628
629     nsIDOMNode *nsnode;
630     HTMLDocumentNode *doc;
631     event_target_t *event_target;
632     ConnectionPointContainer *cp_container;
633 };
634
635 static inline void node_addref(HTMLDOMNode *node)
636 {
637     IHTMLDOMNode_AddRef(&node->IHTMLDOMNode_iface);
638 }
639
640 static inline void node_release(HTMLDOMNode *node)
641 {
642     IHTMLDOMNode_Release(&node->IHTMLDOMNode_iface);
643 }
644
645 typedef struct {
646     HTMLDOMNode node;
647     ConnectionPointContainer cp_container;
648
649     IHTMLElement  IHTMLElement_iface;
650     IHTMLElement2 IHTMLElement2_iface;
651     IHTMLElement3 IHTMLElement3_iface;
652     IHTMLElement4 IHTMLElement4_iface;
653
654     nsIDOMHTMLElement *nselem;
655     HTMLStyle *style;
656     HTMLStyle *runtime_style;
657     HTMLAttributeCollection *attrs;
658     WCHAR *filter;
659 } HTMLElement;
660
661 #define HTMLELEMENT_TIDS    \
662     IHTMLDOMNode_tid,       \
663     IHTMLDOMNode2_tid,      \
664     IHTMLElement_tid,       \
665     IHTMLElement2_tid,      \
666     IHTMLElement3_tid,      \
667     IHTMLElement4_tid
668
669 #define HTMLELEMENT_CPC {NULL}
670 extern const cpc_entry_t HTMLElement_cpc[];
671
672 typedef struct {
673     HTMLElement element;
674
675     IHTMLTextContainer IHTMLTextContainer_iface;
676 } HTMLTextContainer;
677
678 struct HTMLFrameBase {
679     HTMLElement element;
680
681     IHTMLFrameBase  IHTMLFrameBase_iface;
682     IHTMLFrameBase2 IHTMLFrameBase2_iface;
683
684     HTMLOuterWindow *content_window;
685
686     nsIDOMHTMLFrameElement *nsframe;
687     nsIDOMHTMLIFrameElement *nsiframe;
688 };
689
690 typedef struct nsDocumentEventListener nsDocumentEventListener;
691
692 struct HTMLDocumentNode {
693     HTMLDOMNode node;
694     HTMLDocument basedoc;
695
696     IInternetHostSecurityManager IInternetHostSecurityManager_iface;
697
698     nsIDocumentObserver          nsIDocumentObserver_iface;
699
700     LONG ref;
701
702     HTMLInnerWindow *window;
703
704     nsIDOMHTMLDocument *nsdoc;
705     nsIDOMNodeSelector *nsnode_selector;
706     BOOL content_ready;
707     event_target_t *body_event_target;
708
709     ICatInformation *catmgr;
710     nsDocumentEventListener *nsevent_listener;
711     BOOL *event_vector;
712
713     WCHAR **elem_vars;
714     unsigned elem_vars_size;
715     unsigned elem_vars_cnt;
716
717     BOOL skip_mutation_notif;
718
719     struct list selection_list;
720     struct list range_list;
721     struct list plugin_hosts;
722 };
723
724 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
725 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
726 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLInnerWindow*,HTMLDocumentNode**) DECLSPEC_HIDDEN;
727 HRESULT create_document_fragment(nsIDOMNode*,HTMLDocumentNode*,HTMLDocumentNode**) DECLSPEC_HIDDEN;
728
729 HRESULT HTMLOuterWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLOuterWindow*,HTMLOuterWindow**) DECLSPEC_HIDDEN;
730 HRESULT update_window_doc(HTMLInnerWindow*) DECLSPEC_HIDDEN;
731 HTMLOuterWindow *nswindow_to_window(const nsIDOMWindow*) DECLSPEC_HIDDEN;
732 void get_top_window(HTMLOuterWindow*,HTMLOuterWindow**) DECLSPEC_HIDDEN;
733 HRESULT HTMLOptionElementFactory_Create(HTMLInnerWindow*,HTMLOptionElementFactory**) DECLSPEC_HIDDEN;
734 HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow*,HTMLImageElementFactory**) DECLSPEC_HIDDEN;
735 HRESULT HTMLLocation_Create(HTMLInnerWindow*,HTMLLocation**) DECLSPEC_HIDDEN;
736 IOmNavigator *OmNavigator_Create(void) DECLSPEC_HIDDEN;
737 HRESULT HTMLScreen_Create(IHTMLScreen**) DECLSPEC_HIDDEN;
738 HRESULT create_history(IOmHistory**) DECLSPEC_HIDDEN;
739
740 HRESULT create_storage(IHTMLStorage**) DECLSPEC_HIDDEN;
741
742 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*) DECLSPEC_HIDDEN;
743 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*) DECLSPEC_HIDDEN;
744 void HTMLDocument_Persist_Init(HTMLDocument*) DECLSPEC_HIDDEN;
745 void HTMLDocument_OleCmd_Init(HTMLDocument*) DECLSPEC_HIDDEN;
746 void HTMLDocument_OleObj_Init(HTMLDocument*) DECLSPEC_HIDDEN;
747 void HTMLDocument_View_Init(HTMLDocument*) DECLSPEC_HIDDEN;
748 void HTMLDocument_Window_Init(HTMLDocument*) DECLSPEC_HIDDEN;
749 void HTMLDocument_Service_Init(HTMLDocument*) DECLSPEC_HIDDEN;
750 void HTMLDocument_Hlink_Init(HTMLDocument*) DECLSPEC_HIDDEN;
751
752 void TargetContainer_Init(HTMLDocumentObj*) DECLSPEC_HIDDEN;
753 void init_binding_ui(HTMLDocumentObj*) DECLSPEC_HIDDEN;
754
755 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*) DECLSPEC_HIDDEN;
756
757 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**) DECLSPEC_HIDDEN;
758
759 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*,const cpc_entry_t*) DECLSPEC_HIDDEN;
760 void ConnectionPointContainer_Destroy(ConnectionPointContainer*) DECLSPEC_HIDDEN;
761
762 HRESULT create_nscontainer(HTMLDocumentObj*,NSContainer**) DECLSPEC_HIDDEN;
763 void NSContainer_Release(NSContainer*) DECLSPEC_HIDDEN;
764
765 void init_mutation(nsIComponentManager*) DECLSPEC_HIDDEN;
766 void init_document_mutation(HTMLDocumentNode*) DECLSPEC_HIDDEN;
767 void release_document_mutation(HTMLDocumentNode*) DECLSPEC_HIDDEN;
768
769 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL) DECLSPEC_HIDDEN;
770 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*) DECLSPEC_HIDDEN;
771 void notif_focus(HTMLDocumentObj*) DECLSPEC_HIDDEN;
772
773 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR) DECLSPEC_HIDDEN;
774 void hide_tooltip(HTMLDocumentObj*) DECLSPEC_HIDDEN;
775 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*) DECLSPEC_HIDDEN;
776
777 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**) DECLSPEC_HIDDEN;
778
779 BOOL load_gecko(void) DECLSPEC_HIDDEN;
780 void close_gecko(void) DECLSPEC_HIDDEN;
781 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*) DECLSPEC_HIDDEN;
782 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*) DECLSPEC_HIDDEN;
783 void release_nsio(void) DECLSPEC_HIDDEN;
784 BOOL is_gecko_path(const char*) DECLSPEC_HIDDEN;
785
786 void init_node_cc(void);
787
788 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*) DECLSPEC_HIDDEN;
789
790 HRESULT set_frame_doc(HTMLFrameBase*,nsIDOMDocument*) DECLSPEC_HIDDEN;
791
792 void call_property_onchanged(ConnectionPointContainer*,DISPID) DECLSPEC_HIDDEN;
793 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*) DECLSPEC_HIDDEN;
794
795 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1) DECLSPEC_HIDDEN;
796 void nsfree(void*) DECLSPEC_HIDDEN;
797
798 void nsACString_InitDepend(nsACString*,const char*) DECLSPEC_HIDDEN;
799 void nsACString_SetData(nsACString*,const char*) DECLSPEC_HIDDEN;
800 UINT32 nsACString_GetData(const nsACString*,const char**) DECLSPEC_HIDDEN;
801 void nsACString_Finish(nsACString*) DECLSPEC_HIDDEN;
802
803 BOOL nsAString_Init(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
804 void nsAString_InitDepend(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
805 void nsAString_SetData(nsAString*,const PRUnichar*) DECLSPEC_HIDDEN;
806 UINT32 nsAString_GetData(const nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;
807 void nsAString_Finish(nsAString*) DECLSPEC_HIDDEN;
808 HRESULT return_nsstr(nsresult,nsAString*,BSTR*) DECLSPEC_HIDDEN;
809
810 nsICommandParams *create_nscommand_params(void) DECLSPEC_HIDDEN;
811 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*) DECLSPEC_HIDDEN;
812 void get_editor_controller(NSContainer*) DECLSPEC_HIDDEN;
813 nsresult get_nsinterface(nsISupports*,REFIID,void**) DECLSPEC_HIDDEN;
814 nsIWritableVariant *create_nsvariant(void) DECLSPEC_HIDDEN;
815 nsresult create_nsfile(const PRUnichar*,nsIFile**) DECLSPEC_HIDDEN;
816
817 HRESULT create_pending_window(HTMLOuterWindow*,nsChannelBSC*) DECLSPEC_HIDDEN;
818 HRESULT start_binding(HTMLInnerWindow*,BSCallback*,IBindCtx*) DECLSPEC_HIDDEN;
819 HRESULT async_start_doc_binding(HTMLOuterWindow*,HTMLInnerWindow*) DECLSPEC_HIDDEN;
820 void abort_window_bindings(HTMLInnerWindow*) DECLSPEC_HIDDEN;
821 void set_download_state(HTMLDocumentObj*,int) DECLSPEC_HIDDEN;
822 void call_docview_84(HTMLDocumentObj*) DECLSPEC_HIDDEN;
823
824 void set_ready_state(HTMLOuterWindow*,READYSTATE) DECLSPEC_HIDDEN;
825
826 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**) DECLSPEC_HIDDEN;
827 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**) DECLSPEC_HIDDEN;
828 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*) DECLSPEC_HIDDEN;
829 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*) DECLSPEC_HIDDEN;
830
831 void detach_selection(HTMLDocumentNode*) DECLSPEC_HIDDEN;
832 void detach_ranges(HTMLDocumentNode*) DECLSPEC_HIDDEN;
833 HRESULT get_node_text(HTMLDOMNode*,BSTR*) DECLSPEC_HIDDEN;
834 HRESULT replace_node_by_html(nsIDOMHTMLDocument*,nsIDOMNode*,const WCHAR*) DECLSPEC_HIDDEN;
835
836 HRESULT insert_adjacent_node(HTMLElement*,const WCHAR*,nsIDOMNode*,HTMLDOMNode**) DECLSPEC_HIDDEN;
837
838 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**) DECLSPEC_HIDDEN;
839 HRESULT create_element(HTMLDocumentNode*,const WCHAR*,HTMLElement**) DECLSPEC_HIDDEN;
840
841 HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**) DECLSPEC_HIDDEN;
842
843 struct HTMLAttributeCollection {
844     DispatchEx dispex;
845     IHTMLAttributeCollection IHTMLAttributeCollection_iface;
846     IHTMLAttributeCollection2 IHTMLAttributeCollection2_iface;
847     IHTMLAttributeCollection3 IHTMLAttributeCollection3_iface;
848
849     LONG ref;
850
851     HTMLElement *elem;
852     struct list attrs;
853 };
854
855 typedef struct {
856     DispatchEx dispex;
857     IHTMLDOMAttribute IHTMLDOMAttribute_iface;
858
859     LONG ref;
860
861     WCHAR *name;
862
863     HTMLElement *elem;
864     DISPID dispid;
865     struct list entry;
866 } HTMLDOMAttribute;
867
868 HRESULT HTMLDOMAttribute_Create(const WCHAR*,HTMLElement*,DISPID,HTMLDOMAttribute**) DECLSPEC_HIDDEN;
869
870 HRESULT HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLElement**) DECLSPEC_HIDDEN;
871 HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**) DECLSPEC_HIDDEN;
872 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
873 HRESULT HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
874 HRESULT HTMLButtonElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
875 HRESULT HTMLEmbedElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
876 HRESULT HTMLFormElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
877 HRESULT HTMLFrameElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
878 HRESULT HTMLHeadElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
879 HRESULT HTMLIFrame_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
880 HRESULT HTMLStyleElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
881 HRESULT HTMLImgElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
882 HRESULT HTMLInputElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
883 HRESULT HTMLLabelElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
884 HRESULT HTMLLinkElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
885 HRESULT HTMLMetaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
886 HRESULT HTMLObjectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
887 HRESULT HTMLOptionElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
888 HRESULT HTMLScriptElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
889 HRESULT HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
890 HRESULT HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
891 HRESULT HTMLTableCell_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
892 HRESULT HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
893 HRESULT HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
894 HRESULT HTMLTitleElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
895 HRESULT HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**) DECLSPEC_HIDDEN;
896
897 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*) DECLSPEC_HIDDEN;
898 void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
899 void HTMLElement2_Init(HTMLElement*) DECLSPEC_HIDDEN;
900 void HTMLElement3_Init(HTMLElement*) DECLSPEC_HIDDEN;
901 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
902 void HTMLFrameBase_Init(HTMLFrameBase*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*) DECLSPEC_HIDDEN;
903
904 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**) DECLSPEC_HIDDEN;
905 void HTMLDOMNode_destructor(HTMLDOMNode*) DECLSPEC_HIDDEN;
906
907 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**) DECLSPEC_HIDDEN;
908 void HTMLElement_destructor(HTMLDOMNode*) DECLSPEC_HIDDEN;
909 HRESULT HTMLElement_clone(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**) DECLSPEC_HIDDEN;
910 HRESULT HTMLElement_get_attr_col(HTMLDOMNode*,HTMLAttributeCollection**) DECLSPEC_HIDDEN;
911 HRESULT HTMLElement_handle_event(HTMLDOMNode*,DWORD,nsIDOMEvent*,BOOL*) DECLSPEC_HIDDEN;
912
913 HRESULT HTMLFrameBase_QI(HTMLFrameBase*,REFIID,void**) DECLSPEC_HIDDEN;
914 void HTMLFrameBase_destructor(HTMLFrameBase*) DECLSPEC_HIDDEN;
915
916 HRESULT get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLDOMNode**) DECLSPEC_HIDDEN;
917 HRESULT get_elem(HTMLDocumentNode*,nsIDOMElement*,HTMLElement**) DECLSPEC_HIDDEN;
918
919 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement*) DECLSPEC_HIDDEN;
920
921 HRESULT search_window_props(HTMLInnerWindow*,BSTR,DWORD,DISPID*) DECLSPEC_HIDDEN;
922 HRESULT get_frame_by_name(HTMLOuterWindow*,const WCHAR*,BOOL,HTMLOuterWindow**) DECLSPEC_HIDDEN;
923 HRESULT get_doc_elem_by_id(HTMLDocumentNode*,const WCHAR*,HTMLElement**) DECLSPEC_HIDDEN;
924
925 HRESULT wrap_iface(IUnknown*,IUnknown*,IUnknown**) DECLSPEC_HIDDEN;
926
927 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL) DECLSPEC_HIDDEN;
928 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,nsIDOMNodeList*) DECLSPEC_HIDDEN;
929 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,nsIDOMHTMLCollection*) DECLSPEC_HIDDEN;
930
931 /* commands */
932 typedef struct {
933     DWORD id;
934     HRESULT (*query)(HTMLDocument*,OLECMD*);
935     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
936 } cmdtable_t;
937
938 extern const cmdtable_t editmode_cmds[] DECLSPEC_HIDDEN;
939
940 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*) DECLSPEC_HIDDEN;
941
942 /* timer */
943 #define UPDATE_UI       0x0001
944 #define UPDATE_TITLE    0x0002
945
946 void update_doc(HTMLDocument*,DWORD) DECLSPEC_HIDDEN;
947 void update_title(HTMLDocumentObj*) DECLSPEC_HIDDEN;
948
949 HRESULT do_query_service(IUnknown*,REFGUID,REFIID,void**) DECLSPEC_HIDDEN;
950
951 /* editor */
952 void init_editor(HTMLDocument*) DECLSPEC_HIDDEN;
953 void handle_edit_event(HTMLDocument*,nsIDOMEvent*) DECLSPEC_HIDDEN;
954 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
955 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
956 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*) DECLSPEC_HIDDEN;
957 void handle_edit_load(HTMLDocument*) DECLSPEC_HIDDEN;
958 HRESULT editor_is_dirty(HTMLDocument*) DECLSPEC_HIDDEN;
959 void set_dirty(HTMLDocument*,VARIANT_BOOL) DECLSPEC_HIDDEN;
960
961 extern DWORD mshtml_tls DECLSPEC_HIDDEN;
962
963 typedef struct task_t task_t;
964 typedef void (*task_proc_t)(task_t*);
965
966 struct task_t {
967     LONG target_magic;
968     task_proc_t proc;
969     task_proc_t destr;
970     struct task_t *next;
971 };
972
973 typedef struct {
974     task_t header;
975     HTMLDocumentObj *doc;
976 } docobj_task_t;
977
978 typedef struct {
979     HWND thread_hwnd;
980     task_t *task_queue_head;
981     task_t *task_queue_tail;
982     struct list timer_list;
983 } thread_data_t;
984
985 thread_data_t *get_thread_data(BOOL) DECLSPEC_HIDDEN;
986 HWND get_thread_hwnd(void) DECLSPEC_HIDDEN;
987
988 LONG get_task_target_magic(void) DECLSPEC_HIDDEN;
989 HRESULT push_task(task_t*,task_proc_t,task_proc_t,LONG) DECLSPEC_HIDDEN;
990 void remove_target_tasks(LONG) DECLSPEC_HIDDEN;
991
992 HRESULT set_task_timer(HTMLInnerWindow*,DWORD,BOOL,IDispatch*,LONG*) DECLSPEC_HIDDEN;
993 HRESULT clear_task_timer(HTMLInnerWindow*,BOOL,DWORD) DECLSPEC_HIDDEN;
994
995 const char *debugstr_variant(const VARIANT*) DECLSPEC_HIDDEN;
996
997 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
998 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
999 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
1000 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
1001 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
1002
1003 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
1004
1005 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
1006
1007 DEFINE_GUID(CLSID_JScript, 0xf414c260,0x6ac0,0x11cf, 0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58);
1008 DEFINE_GUID(CLSID_VBScript, 0xb54f3741,0x5b07,0x11cf, 0xa4,0xb0,0x00,0xaa,0x00,0x4a,0x55,0xe8);
1009
1010 /* memory allocation functions */
1011
1012 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
1013 {
1014     return HeapAlloc(GetProcessHeap(), 0, len);
1015 }
1016
1017 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
1018 {
1019     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
1020 }
1021
1022 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
1023 {
1024     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
1025 }
1026
1027 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
1028 {
1029     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
1030 }
1031
1032 static inline BOOL heap_free(void *mem)
1033 {
1034     return HeapFree(GetProcessHeap(), 0, mem);
1035 }
1036
1037 static inline LPWSTR heap_strdupW(LPCWSTR str)
1038 {
1039     LPWSTR ret = NULL;
1040
1041     if(str) {
1042         DWORD size;
1043
1044         size = (strlenW(str)+1)*sizeof(WCHAR);
1045         ret = heap_alloc(size);
1046         if(ret)
1047             memcpy(ret, str, size);
1048     }
1049
1050     return ret;
1051 }
1052
1053 static inline LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
1054 {
1055     LPWSTR ret = NULL;
1056
1057     if(str) {
1058         ret = heap_alloc((len+1)*sizeof(WCHAR));
1059         if(ret)
1060         {
1061             memcpy(ret, str, len*sizeof(WCHAR));
1062             ret[len] = 0;
1063         }
1064     }
1065
1066     return ret;
1067 }
1068
1069 static inline char *heap_strdupA(const char *str)
1070 {
1071     char *ret = NULL;
1072
1073     if(str) {
1074         DWORD size;
1075
1076         size = strlen(str)+1;
1077         ret = heap_alloc(size);
1078         if(ret)
1079             memcpy(ret, str, size);
1080     }
1081
1082     return ret;
1083 }
1084
1085 static inline WCHAR *heap_strdupAtoW(const char *str)
1086 {
1087     LPWSTR ret = NULL;
1088
1089     if(str) {
1090         DWORD len;
1091
1092         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
1093         ret = heap_alloc(len*sizeof(WCHAR));
1094         if(ret)
1095             MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
1096     }
1097
1098     return ret;
1099 }
1100
1101 static inline char *heap_strdupWtoA(LPCWSTR str)
1102 {
1103     char *ret = NULL;
1104
1105     if(str) {
1106         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
1107         ret = heap_alloc(size);
1108         if(ret)
1109             WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
1110     }
1111
1112     return ret;
1113 }
1114
1115 static inline WCHAR *heap_strdupUtoW(const char *str)
1116 {
1117     WCHAR *ret = NULL;
1118
1119     if(str) {
1120         size_t len;
1121
1122         len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
1123         ret = heap_alloc(len*sizeof(WCHAR));
1124         if(ret)
1125             MultiByteToWideChar(CP_UTF8, 0, str, -1, ret, len);
1126     }
1127
1128     return ret;
1129 }
1130
1131 static inline char *heap_strdupWtoU(const WCHAR *str)
1132 {
1133     char *ret = NULL;
1134
1135     if(str) {
1136         size_t size = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL);
1137         ret = heap_alloc(size);
1138         if(ret)
1139             WideCharToMultiByte(CP_UTF8, 0, str, -1, ret, size, NULL, NULL);
1140     }
1141
1142     return ret;
1143 }
1144
1145 static inline void windowref_addref(windowref_t *ref)
1146 {
1147     InterlockedIncrement(&ref->ref);
1148 }
1149
1150 static inline void windowref_release(windowref_t *ref)
1151 {
1152     if(!InterlockedDecrement(&ref->ref))
1153         heap_free(ref);
1154 }
1155
1156 HDC get_display_dc(void) DECLSPEC_HIDDEN;
1157 HINSTANCE get_shdoclc(void) DECLSPEC_HIDDEN;
1158 void set_statustext(HTMLDocumentObj*,INT,LPCWSTR) DECLSPEC_HIDDEN;
1159
1160 extern HINSTANCE hInst DECLSPEC_HIDDEN;