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