mshtml: Make load_gecko thread safe.
[wine] / dlls / mshtml / mshtml_private.h
1 /*
2  * Copyright 2005-2006 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 "docobj.h"
20 #include "mshtml.h"
21 #include "mshtmhst.h"
22 #include "hlink.h"
23
24 #include "wine/list.h"
25
26 #ifdef INIT_GUID
27 #include "initguid.h"
28 #endif
29
30 #include "nsiface.h"
31
32 #define GENERATE_MSHTML_NS_FAILURE(code) \
33     ((nsresult) ((PRUint32)(1<<31) | ((PRUint32)(0x45+6)<<16) | (PRUint32)(code)))
34
35 #define NS_OK                     ((nsresult)0x00000000L)
36 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
37 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
38 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
39 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
40 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
41 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
42
43 #define WINE_NS_LOAD_FROM_MONIKER GENERATE_MSHTML_NS_FAILURE(0)
44
45 #define NS_FAILED(res) ((res) & 0x80000000)
46 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
47
48 #define NSAPI WINAPI
49
50 #define NS_ELEMENT_NODE   1
51 #define NS_DOCUMENT_NODE  9
52
53 typedef struct HTMLDOMNode HTMLDOMNode;
54 typedef struct ConnectionPoint ConnectionPoint;
55 typedef struct BSCallback BSCallback;
56
57 typedef struct {
58     const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
59
60     LONG ref;
61
62     HTMLDocument *doc;
63     nsIDOMWindow *nswindow;
64
65     struct list entry;
66 } HTMLWindow;
67
68 typedef enum {
69     UNKNOWN_USERMODE,
70     BROWSEMODE,
71     EDITMODE        
72 } USERMODE;
73
74 struct HTMLDocument {
75     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
76     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
77     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
78     const IPersistFileVtbl                *lpPersistFileVtbl;
79     const IMonikerPropVtbl                *lpMonikerPropVtbl;
80     const IOleObjectVtbl                  *lpOleObjectVtbl;
81     const IOleDocumentVtbl                *lpOleDocumentVtbl;
82     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
83     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
84     const IViewObject2Vtbl                *lpViewObject2Vtbl;
85     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
86     const IServiceProviderVtbl            *lpServiceProviderVtbl;
87     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
88     const IOleControlVtbl                 *lpOleControlVtbl;
89     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
90     const IConnectionPointContainerVtbl   *lpConnectionPointContainerVtbl;
91     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
92
93     LONG ref;
94
95     NSContainer *nscontainer;
96     HTMLWindow *window;
97
98     IOleClientSite *client;
99     IDocHostUIHandler *hostui;
100     IOleInPlaceSite *ipsite;
101     IOleInPlaceFrame *frame;
102
103     BSCallback *bscallback;
104
105     HWND hwnd;
106     HWND tooltips_hwnd;
107
108     DOCHOSTUIINFO hostinfo;
109
110     USERMODE usermode;
111     READYSTATE readystate;
112     BOOL in_place_active;
113     BOOL ui_active;
114     BOOL window_active;
115     BOOL has_key_path;
116     BOOL container_locked;
117
118     ConnectionPoint *cp_htmldocevents;
119     ConnectionPoint *cp_htmldocevents2;
120     ConnectionPoint *cp_propnotif;
121
122     HTMLDOMNode *nodes;
123 };
124
125 struct NSContainer {
126     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
127     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
128     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
129     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
130     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
131     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
132     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
133     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
134     const nsIDOMEventListenerVtbl       *lpDOMEventListenerVtbl;
135
136     nsIWebBrowser *webbrowser;
137     nsIWebNavigation *navigation;
138     nsIBaseWindow *window;
139     nsIWebBrowserFocus *focus;
140
141     LONG ref;
142
143     NSContainer *parent;
144     HTMLDocument *doc;
145
146     nsIURIContentListener *content_listener;
147
148     HWND hwnd;
149
150     BSCallback *bscallback; /* hack */
151 };
152
153 typedef struct {
154     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
155     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
156
157     LONG ref;
158
159     nsIChannel *channel;
160     nsIHttpChannel *http_channel;
161     nsIWineURI *uri;
162     nsIInputStream *post_data_stream;
163     nsILoadGroup *load_group;
164     nsIInterfaceRequestor *notif_callback;
165     nsLoadFlags load_flags;
166     nsIURI *original_uri;
167     char *content;
168 } nsChannel;
169
170 typedef struct {
171     const nsIInputStreamVtbl *lpInputStreamVtbl;
172
173     LONG ref;
174
175     char buf[1024];
176     DWORD buf_size;
177 } nsProtocolStream;
178
179 struct BSCallback {
180     const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
181     const IServiceProviderVtbl    *lpServiceProviderVtbl;
182     const IHttpNegotiate2Vtbl     *lpHttpNegotiate2Vtbl;
183     const IInternetBindInfoVtbl   *lpInternetBindInfoVtbl;
184
185     LONG ref;
186
187     LPWSTR headers;
188     HGLOBAL post_data;
189     ULONG post_data_len;
190     ULONG readed;
191
192     nsChannel *nschannel;
193     nsIStreamListener *nslistener;
194     nsISupports *nscontext;
195
196     IMoniker *mon;
197     IBinding *binding;
198
199     HTMLDocument *doc;
200
201     nsProtocolStream *nsstream;
202 };
203
204 struct HTMLDOMNode {
205     const IHTMLDOMNodeVtbl *lpHTMLDOMNodeVtbl;
206
207     void (*destructor)(IUnknown*);
208
209     enum {
210         NT_UNKNOWN,
211         NT_HTMLELEM
212     } node_type;
213
214     union {
215         IUnknown *unk;
216         IHTMLElement *elem;
217     } impl;
218
219     nsIDOMNode *nsnode;
220     HTMLDocument *doc;
221
222     HTMLDOMNode *next;
223 };
224
225 typedef struct {
226     const IHTMLElementVtbl *lpHTMLElementVtbl;
227     const IHTMLElement2Vtbl *lpHTMLElement2Vtbl;
228
229     void (*destructor)(IUnknown*);
230
231     nsIDOMHTMLElement *nselem;
232     HTMLDOMNode *node;
233
234     IUnknown *impl;
235 } HTMLElement;
236
237 typedef struct {
238     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
239
240     HTMLElement *element;
241 } HTMLTextContainer;
242
243 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
244
245 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
246 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
247 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
248 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
249 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
250 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
251 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
252 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
253 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
254 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
255 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
256 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
257 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
258 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
259 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
260 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
261 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
262 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
263 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
264 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
265 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
266
267 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
268 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
269 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
270 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
271 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
272 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
273 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
274 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
275 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
276
277 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
278 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
279 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
280
281 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
282 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
283 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
284
285 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
286 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
287 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
288
289 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
290
291 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
292
293 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
294 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
295
296 HTMLWindow *HTMLWindow_Create(HTMLDocument*);
297 HTMLWindow *nswindow_to_window(nsIDOMWindow*);
298
299 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
300 void HTMLDocument_Persist_Init(HTMLDocument*);
301 void HTMLDocument_OleCmd_Init(HTMLDocument*);
302 void HTMLDocument_OleObj_Init(HTMLDocument*);
303 void HTMLDocument_View_Init(HTMLDocument*);
304 void HTMLDocument_Window_Init(HTMLDocument*);
305 void HTMLDocument_Service_Init(HTMLDocument*);
306 void HTMLDocument_Hlink_Init(HTMLDocument*);
307 void HTMLDocument_ConnectionPoints_Init(HTMLDocument*);
308
309 void HTMLDocument_ConnectionPoints_Destroy(HTMLDocument*);
310
311 NSContainer *NSContainer_Create(HTMLDocument*,NSContainer*);
312 void NSContainer_Release(NSContainer*);
313
314 void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
315 void HTMLDocument_ShowContextMenu(HTMLDocument*,DWORD,POINT*);
316
317 void show_tooltip(HTMLDocument*,DWORD,DWORD,LPCWSTR);
318 void hide_tooltip(HTMLDocument*);
319 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
320
321 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
322
323 void close_gecko(void);
324 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
325 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
326
327 void hlink_frame_navigate(HTMLDocument*,IHlinkFrame*,LPCWSTR,nsIInputStream*,DWORD);
328
329 void call_property_onchanged(ConnectionPoint*,DISPID);
330
331 void *nsalloc(size_t);
332 void nsfree(void*);
333
334 void nsACString_Init(nsACString*,const char*);
335 void nsACString_SetData(nsACString*,const char*);
336 PRUint32 nsACString_GetData(const nsACString*,const char**,PRBool*);
337 void nsACString_Finish(nsACString*);
338
339 void nsAString_Init(nsAString*,const PRUnichar*);
340 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**,PRBool*);
341 void nsAString_Finish(nsAString*);
342
343 nsIInputStream *create_nsstream(const char*,PRInt32);
344 nsICommandParams *create_nscommand_params(void);
345 void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
346
347 BSCallback *create_bscallback(IMoniker*);
348 HRESULT start_binding(BSCallback*);
349 void set_document_bscallback(HTMLDocument*,BSCallback*);
350
351 IHlink *Hlink_Create(void);
352 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
353 IHTMLTxtRange *HTMLTxtRange_Create(nsISelection*);
354 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
355 IHTMLStyleSheet *HTMLStyleSheet_Create(void);
356
357 void HTMLElement_Create(HTMLDOMNode*);
358 void HTMLBodyElement_Create(HTMLElement*);
359 void HTMLInputElement_Create(HTMLElement*);
360 void HTMLSelectElement_Create(HTMLElement*);
361 void HTMLTextAreaElement_Create(HTMLElement*);
362
363 void HTMLElement2_Init(HTMLElement*);
364
365 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLElement*);
366
367 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
368 HRESULT HTMLElement_QI(HTMLElement*,REFIID,void**);
369
370 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
371 void release_nodes(HTMLDocument*);
372
373 BOOL install_wine_gecko(void);
374
375 /* editor */
376 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
377
378 void get_font_size(HTMLDocument*,WCHAR*);
379 void set_font_size(HTMLDocument*,LPCWSTR);
380
381 extern DWORD mshtml_tls;
382
383 typedef struct task_t {
384     HTMLDocument *doc;
385
386     enum {
387         TASK_SETDOWNLOADSTATE,
388         TASK_PARSECOMPLETE,
389         TASK_SETPROGRESS,
390         TASK_START_BINDING
391     } task_id;
392
393     BSCallback *bscallback;
394
395     struct task_t *next;
396 } task_t;
397
398 typedef struct {
399     HWND thread_hwnd;
400     task_t *task_queue_head;
401     task_t *task_queue_tail;
402 } thread_data_t;
403
404 thread_data_t *get_thread_data(BOOL);
405 HWND get_thread_hwnd(void);
406 void push_task(task_t*);
407 void remove_doc_tasks(HTMLDocument*);
408
409 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
410 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
411 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
412 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
413 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
414
415 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
416
417 extern LONG module_ref;
418 #define LOCK_MODULE()   InterlockedIncrement(&module_ref)
419 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
420
421 /* memory allocation functions */
422
423 static inline void *mshtml_alloc(size_t len)
424 {
425     return HeapAlloc(GetProcessHeap(), 0, len);
426 }
427
428 static inline void *mshtml_alloc_zero(size_t len)
429 {
430     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
431 }
432
433 static inline void *mshtml_realloc(void *mem, size_t len)
434 {
435     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
436 }
437
438 static inline BOOL mshtml_free(void *mem)
439 {
440     return HeapFree(GetProcessHeap(), 0, mem);
441 }
442
443 HINSTANCE get_shdoclc(void);
444
445 extern HINSTANCE hInst;