rpcrt4: Try a lot harder to resuse existing connections by comparing inside the RpcQu...
[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     IMoniker *mon;
105     BSTR url;
106
107     HWND hwnd;
108     HWND tooltips_hwnd;
109
110     DOCHOSTUIINFO hostinfo;
111
112     USERMODE usermode;
113     READYSTATE readystate;
114     BOOL in_place_active;
115     BOOL ui_active;
116     BOOL window_active;
117     BOOL has_key_path;
118     BOOL container_locked;
119     BOOL focus;
120
121     DWORD update;
122
123     ConnectionPoint *cp_htmldocevents;
124     ConnectionPoint *cp_htmldocevents2;
125     ConnectionPoint *cp_propnotif;
126
127     HTMLDOMNode *nodes;
128 };
129
130 typedef struct {
131     const nsIDOMEventListenerVtbl      *lpDOMEventListenerVtbl;
132     NSContainer *This;
133 } nsEventListener;
134
135 struct NSContainer {
136     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
137     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
138     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
139     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
140     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
141     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
142     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
143     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
144
145     nsEventListener blur_listener;
146     nsEventListener focus_listener;
147     nsEventListener keypress_listener;
148     nsEventListener load_listener;
149
150     nsIWebBrowser *webbrowser;
151     nsIWebNavigation *navigation;
152     nsIBaseWindow *window;
153     nsIWebBrowserFocus *focus;
154
155     nsIController *editor_controller;
156
157     LONG ref;
158
159     NSContainer *parent;
160     HTMLDocument *doc;
161
162     nsIURIContentListener *content_listener;
163
164     HWND hwnd;
165
166     BSCallback *bscallback; /* hack */
167 };
168
169 typedef struct {
170     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
171     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
172
173     LONG ref;
174
175     nsIChannel *channel;
176     nsIHttpChannel *http_channel;
177     nsIWineURI *uri;
178     nsIInputStream *post_data_stream;
179     nsILoadGroup *load_group;
180     nsIInterfaceRequestor *notif_callback;
181     nsLoadFlags load_flags;
182     nsIURI *original_uri;
183     char *content;
184     char *charset;
185 } nsChannel;
186
187 typedef struct {
188     const nsIInputStreamVtbl *lpInputStreamVtbl;
189
190     LONG ref;
191
192     char buf[1024];
193     DWORD buf_size;
194 } nsProtocolStream;
195
196 struct BSCallback {
197     const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
198     const IServiceProviderVtbl    *lpServiceProviderVtbl;
199     const IHttpNegotiate2Vtbl     *lpHttpNegotiate2Vtbl;
200     const IInternetBindInfoVtbl   *lpInternetBindInfoVtbl;
201
202     LONG ref;
203
204     LPWSTR headers;
205     HGLOBAL post_data;
206     ULONG post_data_len;
207     ULONG readed;
208
209     nsChannel *nschannel;
210     nsIStreamListener *nslistener;
211     nsISupports *nscontext;
212
213     IMoniker *mon;
214     IBinding *binding;
215
216     HTMLDocument *doc;
217
218     nsProtocolStream *nsstream;
219 };
220
221 struct HTMLDOMNode {
222     const IHTMLDOMNodeVtbl *lpHTMLDOMNodeVtbl;
223
224     void (*destructor)(IUnknown*);
225
226     enum {
227         NT_UNKNOWN,
228         NT_HTMLELEM
229     } node_type;
230
231     union {
232         IUnknown *unk;
233         IHTMLElement *elem;
234     } impl;
235
236     nsIDOMNode *nsnode;
237     HTMLDocument *doc;
238
239     HTMLDOMNode *next;
240 };
241
242 typedef struct {
243     const IHTMLElementVtbl *lpHTMLElementVtbl;
244     const IHTMLElement2Vtbl *lpHTMLElement2Vtbl;
245
246     void (*destructor)(IUnknown*);
247
248     nsIDOMHTMLElement *nselem;
249     HTMLDOMNode *node;
250
251     IUnknown *impl;
252 } HTMLElement;
253
254 typedef struct {
255     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
256
257     HTMLElement *element;
258 } HTMLTextContainer;
259
260 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
261
262 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
263 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
264 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
265 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
266 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
267 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
268 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
269 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
270 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
271 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
272 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
273 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
274 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
275 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
276 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
277 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
278 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
279 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
280 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
281 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
282 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
283
284 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
285 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
286 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
287 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
288 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
289 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
290 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
291 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
292 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
293
294 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
295 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
296 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
297
298 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
299 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
300 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
301
302 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
303 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
304 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
305
306 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
307
308 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
309
310 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
311 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
312
313 HTMLWindow *HTMLWindow_Create(HTMLDocument*);
314 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
315
316 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
317 void HTMLDocument_Persist_Init(HTMLDocument*);
318 void HTMLDocument_OleCmd_Init(HTMLDocument*);
319 void HTMLDocument_OleObj_Init(HTMLDocument*);
320 void HTMLDocument_View_Init(HTMLDocument*);
321 void HTMLDocument_Window_Init(HTMLDocument*);
322 void HTMLDocument_Service_Init(HTMLDocument*);
323 void HTMLDocument_Hlink_Init(HTMLDocument*);
324 void HTMLDocument_ConnectionPoints_Init(HTMLDocument*);
325
326 void HTMLDocument_ConnectionPoints_Destroy(HTMLDocument*);
327
328 NSContainer *NSContainer_Create(HTMLDocument*,NSContainer*);
329 void NSContainer_Release(NSContainer*);
330
331 void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
332 void show_context_menu(HTMLDocument*,DWORD,POINT*);
333 void notif_focus(HTMLDocument*);
334
335 void show_tooltip(HTMLDocument*,DWORD,DWORD,LPCWSTR);
336 void hide_tooltip(HTMLDocument*);
337 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
338
339 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
340
341 void close_gecko(void);
342 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
343 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
344
345 void hlink_frame_navigate(HTMLDocument*,IHlinkFrame*,LPCWSTR,nsIInputStream*,DWORD);
346
347 void call_property_onchanged(ConnectionPoint*,DISPID);
348
349 void *nsalloc(size_t);
350 void nsfree(void*);
351
352 void nsACString_Init(nsACString*,const char*);
353 void nsACString_SetData(nsACString*,const char*);
354 PRUint32 nsACString_GetData(const nsACString*,const char**,PRBool*);
355 void nsACString_Finish(nsACString*);
356
357 void nsAString_Init(nsAString*,const PRUnichar*);
358 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**,PRBool*);
359 void nsAString_Finish(nsAString*);
360
361 nsIInputStream *create_nsstream(const char*,PRInt32);
362 nsICommandParams *create_nscommand_params(void);
363 void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
364 nsIController *get_editor_controller(NSContainer*);
365 void init_nsevents(NSContainer*);
366
367 BSCallback *create_bscallback(IMoniker*);
368 HRESULT start_binding(BSCallback*);
369 HRESULT load_stream(BSCallback*,IStream*);
370 void set_document_bscallback(HTMLDocument*,BSCallback*);
371 void set_current_mon(HTMLDocument*,IMoniker*);
372
373 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
374 IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange*);
375 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
376 IHTMLStyleSheet *HTMLStyleSheet_Create(void);
377
378 void HTMLElement_Create(HTMLDOMNode*);
379 void HTMLBodyElement_Create(HTMLElement*);
380 void HTMLInputElement_Create(HTMLElement*);
381 void HTMLSelectElement_Create(HTMLElement*);
382 void HTMLTextAreaElement_Create(HTMLElement*);
383
384 void HTMLElement2_Init(HTMLElement*);
385
386 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLElement*);
387
388 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
389 HRESULT HTMLElement_QI(HTMLElement*,REFIID,void**);
390
391 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
392 void release_nodes(HTMLDocument*);
393
394 BOOL install_wine_gecko(void);
395
396 /* commands */
397 typedef struct {
398     DWORD id;
399     HRESULT (*query)(HTMLDocument*,OLECMD*);
400     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
401 } cmdtable_t;
402
403 extern const cmdtable_t editmode_cmds[];
404
405 /* timer */
406 #define UPDATE_UI       0x0001
407 #define UPDATE_TITLE    0x0002
408
409 void update_doc(HTMLDocument *This, DWORD flags);
410 void update_title(HTMLDocument*);
411
412 /* editor */
413 void init_editor(HTMLDocument*);
414 void set_ns_editmode(NSContainer*);
415 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
416 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
417 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
418 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
419
420 extern DWORD mshtml_tls;
421
422 typedef struct task_t {
423     HTMLDocument *doc;
424
425     enum {
426         TASK_SETDOWNLOADSTATE,
427         TASK_PARSECOMPLETE,
428         TASK_SETPROGRESS,
429         TASK_START_BINDING
430     } task_id;
431
432     BSCallback *bscallback;
433
434     struct task_t *next;
435 } task_t;
436
437 typedef struct {
438     HWND thread_hwnd;
439     task_t *task_queue_head;
440     task_t *task_queue_tail;
441 } thread_data_t;
442
443 thread_data_t *get_thread_data(BOOL);
444 HWND get_thread_hwnd(void);
445 void push_task(task_t*);
446 void remove_doc_tasks(const HTMLDocument*);
447
448 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
449 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
450 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
451 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
452 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
453
454 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
455
456 extern LONG module_ref;
457 #define LOCK_MODULE()   InterlockedIncrement(&module_ref)
458 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
459
460 /* memory allocation functions */
461
462 static inline void *mshtml_alloc(size_t len)
463 {
464     return HeapAlloc(GetProcessHeap(), 0, len);
465 }
466
467 static inline void *mshtml_alloc_zero(size_t len)
468 {
469     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
470 }
471
472 static inline void *mshtml_realloc(void *mem, size_t len)
473 {
474     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
475 }
476
477 static inline BOOL mshtml_free(void *mem)
478 {
479     return HeapFree(GetProcessHeap(), 0, mem);
480 }
481
482 HINSTANCE get_shdoclc(void);
483
484 extern HINSTANCE hInst;