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