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