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