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