2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
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.
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.
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
25 #include "wine/list.h"
26 #include "wine/unicode.h"
34 #define GENERATE_MSHTML_NS_FAILURE(code) \
35 ((nsresult) ((PRUint32)(1<<31) | ((PRUint32)(0x45+6)<<16) | (PRUint32)(code)))
37 #define NS_OK ((nsresult)0x00000000L)
38 #define NS_ERROR_FAILURE ((nsresult)0x80004005L)
39 #define NS_NOINTERFACE ((nsresult)0x80004002L)
40 #define NS_ERROR_NOT_IMPLEMENTED ((nsresult)0x80004001L)
41 #define NS_ERROR_INVALID_ARG ((nsresult)0x80070057L)
42 #define NS_ERROR_UNEXPECTED ((nsresult)0x8000ffffL)
43 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
45 #define WINE_NS_LOAD_FROM_MONIKER GENERATE_MSHTML_NS_FAILURE(0)
47 #define NS_FAILED(res) ((res) & 0x80000000)
48 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
52 #define MSHTML_E_NODOC 0x800a025c
54 typedef struct HTMLDOMNode HTMLDOMNode
;
55 typedef struct ConnectionPoint ConnectionPoint
;
56 typedef struct BSCallback BSCallback
;
59 const IHTMLWindow2Vtbl
*lpHTMLWindow2Vtbl
;
64 nsIDOMWindow
*nswindow
;
76 const IConnectionPointContainerVtbl
*lpConnectionPointContainerVtbl
;
78 ConnectionPoint
*cp_list
;
80 } ConnectionPointContainer
;
82 struct ConnectionPoint
{
83 const IConnectionPointVtbl
*lpConnectionPointVtbl
;
85 IConnectionPointContainer
*container
;
90 IPropertyNotifySink
*propnotif
;
96 ConnectionPoint
*next
;
100 const IHTMLOptionElementFactoryVtbl
*lpHTMLOptionElementFactoryVtbl
;
105 } HTMLOptionElementFactory
;
107 struct HTMLDocument
{
108 const IHTMLDocument2Vtbl
*lpHTMLDocument2Vtbl
;
109 const IHTMLDocument3Vtbl
*lpHTMLDocument3Vtbl
;
110 const IHTMLDocument4Vtbl
*lpHTMLDocument4Vtbl
;
111 const IHTMLDocument5Vtbl
*lpHTMLDocument5Vtbl
;
112 const IPersistMonikerVtbl
*lpPersistMonikerVtbl
;
113 const IPersistFileVtbl
*lpPersistFileVtbl
;
114 const IMonikerPropVtbl
*lpMonikerPropVtbl
;
115 const IOleObjectVtbl
*lpOleObjectVtbl
;
116 const IOleDocumentVtbl
*lpOleDocumentVtbl
;
117 const IOleDocumentViewVtbl
*lpOleDocumentViewVtbl
;
118 const IOleInPlaceActiveObjectVtbl
*lpOleInPlaceActiveObjectVtbl
;
119 const IViewObject2Vtbl
*lpViewObject2Vtbl
;
120 const IOleInPlaceObjectWindowlessVtbl
*lpOleInPlaceObjectWindowlessVtbl
;
121 const IServiceProviderVtbl
*lpServiceProviderVtbl
;
122 const IOleCommandTargetVtbl
*lpOleCommandTargetVtbl
;
123 const IOleControlVtbl
*lpOleControlVtbl
;
124 const IHlinkTargetVtbl
*lpHlinkTargetVtbl
;
125 const IPersistStreamInitVtbl
*lpPersistStreamInitVtbl
;
126 const ICustomDocVtbl
*lpCustomDocVtbl
;
130 NSContainer
*nscontainer
;
133 IOleClientSite
*client
;
134 IDocHostUIHandler
*hostui
;
135 IOleInPlaceSite
*ipsite
;
136 IOleInPlaceFrame
*frame
;
137 IOleInPlaceUIWindow
*ip_window
;
139 IOleUndoManager
*undomgr
;
141 BSCallback
*bscallback
;
144 struct list bindings
;
149 DOCHOSTUIINFO hostinfo
;
152 READYSTATE readystate
;
153 BOOL in_place_active
;
157 BOOL container_locked
;
163 ConnectionPointContainer cp_container
;
164 ConnectionPoint cp_htmldocevents
;
165 ConnectionPoint cp_htmldocevents2
;
166 ConnectionPoint cp_propnotif
;
168 HTMLOptionElementFactory
*option_factory
;
170 struct list selection_list
;
171 struct list range_list
;
177 const nsIDOMEventListenerVtbl
*lpDOMEventListenerVtbl
;
182 const nsIWebBrowserChromeVtbl
*lpWebBrowserChromeVtbl
;
183 const nsIContextMenuListenerVtbl
*lpContextMenuListenerVtbl
;
184 const nsIURIContentListenerVtbl
*lpURIContentListenerVtbl
;
185 const nsIEmbeddingSiteWindowVtbl
*lpEmbeddingSiteWindowVtbl
;
186 const nsITooltipListenerVtbl
*lpTooltipListenerVtbl
;
187 const nsIInterfaceRequestorVtbl
*lpInterfaceRequestorVtbl
;
188 const nsIWeakReferenceVtbl
*lpWeakReferenceVtbl
;
189 const nsISupportsWeakReferenceVtbl
*lpSupportsWeakReferenceVtbl
;
191 nsEventListener blur_listener
;
192 nsEventListener focus_listener
;
193 nsEventListener keypress_listener
;
194 nsEventListener load_listener
;
196 nsIWebBrowser
*webbrowser
;
197 nsIWebNavigation
*navigation
;
198 nsIBaseWindow
*window
;
199 nsIWebBrowserFocus
*focus
;
202 nsIController
*editor_controller
;
209 nsIURIContentListener
*content_listener
;
213 BSCallback
*bscallback
; /* hack */
214 HWND reset_focus
; /* hack */
218 const nsIHttpChannelVtbl
*lpHttpChannelVtbl
;
219 const nsIUploadChannelVtbl
*lpUploadChannelVtbl
;
224 nsIHttpChannel
*http_channel
;
226 nsIInputStream
*post_data_stream
;
227 nsILoadGroup
*load_group
;
228 nsIInterfaceRequestor
*notif_callback
;
229 nsLoadFlags load_flags
;
230 nsIURI
*original_uri
;
236 const nsIInputStreamVtbl
*lpInputStreamVtbl
;
245 const IBindStatusCallbackVtbl
*lpBindStatusCallbackVtbl
;
246 const IServiceProviderVtbl
*lpServiceProviderVtbl
;
247 const IHttpNegotiate2Vtbl
*lpHttpNegotiate2Vtbl
;
248 const IInternetBindInfoVtbl
*lpInternetBindInfoVtbl
;
257 nsChannel
*nschannel
;
258 nsIStreamListener
*nslistener
;
259 nsISupports
*nscontext
;
266 nsProtocolStream
*nsstream
;
272 HRESULT (*qi
)(HTMLDOMNode
*,REFIID
,void**);
273 void (*destructor
)(HTMLDOMNode
*);
277 const IHTMLDOMNodeVtbl
*lpHTMLDOMNodeVtbl
;
278 const NodeImplVtbl
*vtbl
;
290 ConnectionPointContainer cp_container
;
292 const IHTMLElementVtbl
*lpHTMLElementVtbl
;
293 const IHTMLElement2Vtbl
*lpHTMLElement2Vtbl
;
295 nsIDOMHTMLElement
*nselem
;
301 const IHTMLTextContainerVtbl
*lpHTMLTextContainerVtbl
;
306 #define HTMLWINDOW2(x) ((IHTMLWindow2*) &(x)->lpHTMLWindow2Vtbl)
308 #define HTMLDOC(x) ((IHTMLDocument2*) &(x)->lpHTMLDocument2Vtbl)
309 #define HTMLDOC3(x) ((IHTMLDocument3*) &(x)->lpHTMLDocument3Vtbl)
310 #define HTMLDOC4(x) ((IHTMLDocument4*) &(x)->lpHTMLDocument4Vtbl)
311 #define HTMLDOC5(x) ((IHTMLDocument5*) &(x)->lpHTMLDocument5Vtbl)
312 #define PERSIST(x) ((IPersist*) &(x)->lpPersistFileVtbl)
313 #define PERSISTMON(x) ((IPersistMoniker*) &(x)->lpPersistMonikerVtbl)
314 #define PERSISTFILE(x) ((IPersistFile*) &(x)->lpPersistFileVtbl)
315 #define MONPROP(x) ((IMonikerProp*) &(x)->lpMonikerPropVtbl)
316 #define OLEOBJ(x) ((IOleObject*) &(x)->lpOleObjectVtbl)
317 #define OLEDOC(x) ((IOleDocument*) &(x)->lpOleDocumentVtbl)
318 #define DOCVIEW(x) ((IOleDocumentView*) &(x)->lpOleDocumentViewVtbl)
319 #define OLEWIN(x) ((IOleWindow*) &(x)->lpOleInPlaceActiveObjectVtbl)
320 #define ACTOBJ(x) ((IOleInPlaceActiveObject*) &(x)->lpOleInPlaceActiveObjectVtbl)
321 #define VIEWOBJ(x) ((IViewObject*) &(x)->lpViewObject2Vtbl)
322 #define VIEWOBJ2(x) ((IViewObject2*) &(x)->lpViewObject2Vtbl)
323 #define INPLACEOBJ(x) ((IOleInPlaceObject*) &(x)->lpOleInPlaceObjectWindowlessVtbl)
324 #define INPLACEWIN(x) ((IOleInPlaceObjectWindowless*) &(x)->lpOleInPlaceObjectWindowlessVtbl)
325 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
326 #define CMDTARGET(x) ((IOleCommandTarget*) &(x)->lpOleCommandTargetVtbl)
327 #define CONTROL(x) ((IOleControl*) &(x)->lpOleControlVtbl)
328 #define HLNKTARGET(x) ((IHlinkTarget*) &(x)->lpHlinkTargetVtbl)
329 #define CONPTCONT(x) ((IConnectionPointContainer*) &(x)->lpConnectionPointContainerVtbl)
330 #define PERSTRINIT(x) ((IPersistStreamInit*) &(x)->lpPersistStreamInitVtbl)
331 #define CUSTOMDOC(x) ((ICustomDoc*) &(x)->lpCustomDocVtbl)
333 #define NSWBCHROME(x) ((nsIWebBrowserChrome*) &(x)->lpWebBrowserChromeVtbl)
334 #define NSCML(x) ((nsIContextMenuListener*) &(x)->lpContextMenuListenerVtbl)
335 #define NSURICL(x) ((nsIURIContentListener*) &(x)->lpURIContentListenerVtbl)
336 #define NSEMBWNDS(x) ((nsIEmbeddingSiteWindow*) &(x)->lpEmbeddingSiteWindowVtbl)
337 #define NSIFACEREQ(x) ((nsIInterfaceRequestor*) &(x)->lpInterfaceRequestorVtbl)
338 #define NSTOOLTIP(x) ((nsITooltipListener*) &(x)->lpTooltipListenerVtbl)
339 #define NSEVENTLIST(x) ((nsIDOMEventListener*) &(x)->lpDOMEventListenerVtbl)
340 #define NSWEAKREF(x) ((nsIWeakReference*) &(x)->lpWeakReferenceVtbl)
341 #define NSSUPWEAKREF(x) ((nsISupportsWeakReference*) &(x)->lpSupportsWeakReferenceVtbl)
343 #define NSCHANNEL(x) ((nsIChannel*) &(x)->lpHttpChannelVtbl)
344 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*) &(x)->lpHttpChannelVtbl)
345 #define NSUPCHANNEL(x) ((nsIUploadChannel*) &(x)->lpUploadChannelVtbl)
347 #define HTTPNEG(x) ((IHttpNegotiate2*) &(x)->lpHttpNegotiate2Vtbl)
348 #define STATUSCLB(x) ((IBindStatusCallback*) &(x)->lpBindStatusCallbackVtbl)
349 #define BINDINFO(x) ((IInternetBindInfo*) &(x)->lpInternetBindInfoVtbl);
351 #define HTMLELEM(x) ((IHTMLElement*) &(x)->lpHTMLElementVtbl)
352 #define HTMLELEM2(x) ((IHTMLElement2*) &(x)->lpHTMLElement2Vtbl)
353 #define HTMLDOMNODE(x) ((IHTMLDOMNode*) &(x)->lpHTMLDOMNodeVtbl)
355 #define HTMLTEXTCONT(x) ((IHTMLTextContainer*) &(x)->lpHTMLTextContainerVtbl)
357 #define HTMLOPTFACTORY(x) ((IHTMLOptionElementFactory*) &(x)->lpHTMLOptionElementFactoryVtbl)
359 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
360 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
362 HRESULT
HTMLDocument_Create(IUnknown
*,REFIID
,void**);
363 HRESULT
HTMLLoadOptions_Create(IUnknown
*,REFIID
,void**);
365 HTMLWindow
*HTMLWindow_Create(HTMLDocument
*);
366 HTMLWindow
*nswindow_to_window(const nsIDOMWindow
*);
367 HTMLOptionElementFactory
*HTMLOptionElementFactory_Create(HTMLDocument
*);
368 void setup_nswindow(HTMLWindow
*);
370 void HTMLDocument_HTMLDocument3_Init(HTMLDocument
*);
371 void HTMLDocument_HTMLDocument5_Init(HTMLDocument
*);
372 void HTMLDocument_Persist_Init(HTMLDocument
*);
373 void HTMLDocument_OleCmd_Init(HTMLDocument
*);
374 void HTMLDocument_OleObj_Init(HTMLDocument
*);
375 void HTMLDocument_View_Init(HTMLDocument
*);
376 void HTMLDocument_Window_Init(HTMLDocument
*);
377 void HTMLDocument_Service_Init(HTMLDocument
*);
378 void HTMLDocument_Hlink_Init(HTMLDocument
*);
380 void ConnectionPoint_Init(ConnectionPoint
*,ConnectionPointContainer
*,REFIID
);
381 void ConnectionPointContainer_Init(ConnectionPointContainer
*,IUnknown
*);
382 void ConnectionPointContainer_Destroy(ConnectionPointContainer
*);
384 NSContainer
*NSContainer_Create(HTMLDocument
*,NSContainer
*);
385 void NSContainer_Release(NSContainer
*);
387 void HTMLDocument_LockContainer(HTMLDocument
*,BOOL
);
388 void show_context_menu(HTMLDocument
*,DWORD
,POINT
*,IDispatch
*);
389 void notif_focus(HTMLDocument
*);
391 void show_tooltip(HTMLDocument
*,DWORD
,DWORD
,LPCWSTR
);
392 void hide_tooltip(HTMLDocument
*);
393 HRESULT
get_client_disp_property(IOleClientSite
*,DISPID
,VARIANT
*);
395 HRESULT
ProtocolFactory_Create(REFCLSID
,REFIID
,void**);
397 BOOL
load_gecko(BOOL
);
398 void close_gecko(void);
399 void register_nsservice(nsIComponentRegistrar
*,nsIServiceManager
*);
400 void init_nsio(nsIComponentManager
*,nsIComponentRegistrar
*);
401 BOOL
install_wine_gecko(BOOL
);
403 void hlink_frame_navigate(HTMLDocument
*,IHlinkFrame
*,LPCWSTR
,nsIInputStream
*,DWORD
);
405 void call_property_onchanged(ConnectionPoint
*,DISPID
);
406 HRESULT
call_set_active_object(IOleInPlaceUIWindow
*,IOleInPlaceActiveObject
*);
408 void *nsalloc(size_t);
411 void nsACString_Init(nsACString
*,const char*);
412 void nsACString_SetData(nsACString
*,const char*);
413 PRUint32
nsACString_GetData(const nsACString
*,const char**);
414 void nsACString_Finish(nsACString
*);
416 void nsAString_Init(nsAString
*,const PRUnichar
*);
417 PRUint32
nsAString_GetData(const nsAString
*,const PRUnichar
**);
418 void nsAString_Finish(nsAString
*);
420 nsIInputStream
*create_nsstream(const char*,PRInt32
);
421 nsICommandParams
*create_nscommand_params(void);
422 nsIMutableArray
*create_nsarray(void);
423 nsIWritableVariant
*create_nsvariant(void);
424 void nsnode_to_nsstring(nsIDOMNode
*,nsAString
*);
425 void get_editor_controller(NSContainer
*);
426 void init_nsevents(NSContainer
*);
427 nsresult
get_nsinterface(nsISupports
*,REFIID
,void**);
429 BSCallback
*create_bscallback(IMoniker
*);
430 HRESULT
start_binding(HTMLDocument
*,BSCallback
*,IBindCtx
*);
431 HRESULT
load_stream(BSCallback
*,IStream
*);
432 void set_document_bscallback(HTMLDocument
*,BSCallback
*);
433 void set_current_mon(HTMLDocument
*,IMoniker
*);
435 IHTMLSelectionObject
*HTMLSelectionObject_Create(HTMLDocument
*,nsISelection
*);
436 IHTMLTxtRange
*HTMLTxtRange_Create(HTMLDocument
*,nsIDOMRange
*);
437 IHTMLStyle
*HTMLStyle_Create(nsIDOMCSSStyleDeclaration
*);
438 IHTMLStyleSheet
*HTMLStyleSheet_Create(nsIDOMStyleSheet
*);
439 IHTMLStyleSheetsCollection
*HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList
*);
441 void detach_selection(HTMLDocument
*);
442 void detach_ranges(HTMLDocument
*);
444 HTMLElement
*HTMLElement_Create(nsIDOMNode
*);
445 HTMLElement
*HTMLAnchorElement_Create(nsIDOMHTMLElement
*);
446 HTMLElement
*HTMLBodyElement_Create(nsIDOMHTMLElement
*);
447 HTMLElement
*HTMLInputElement_Create(nsIDOMHTMLElement
*);
448 HTMLElement
*HTMLOptionElement_Create(nsIDOMHTMLElement
*);
449 HTMLElement
*HTMLSelectElement_Create(nsIDOMHTMLElement
*);
450 HTMLElement
*HTMLTable_Create(nsIDOMHTMLElement
*);
451 HTMLElement
*HTMLTextAreaElement_Create(nsIDOMHTMLElement
*);
453 void HTMLElement_Init(HTMLElement
*);
454 void HTMLElement2_Init(HTMLElement
*);
455 void HTMLTextContainer_Init(HTMLTextContainer
*);
457 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*,REFIID
,void**);
458 void HTMLDOMNode_destructor(HTMLDOMNode
*);
460 HRESULT
HTMLElement_QI(HTMLDOMNode
*,REFIID
,void**);
461 void HTMLElement_destructor(HTMLDOMNode
*);
463 HTMLDOMNode
*get_node(HTMLDocument
*,nsIDOMNode
*);
464 void release_nodes(HTMLDocument
*);
466 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*);
471 HRESULT (*query
)(HTMLDocument
*,OLECMD
*);
472 HRESULT (*exec
)(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
475 extern const cmdtable_t editmode_cmds
[];
477 void do_ns_command(NSContainer
*,const char*,nsICommandParams
*);
480 #define UPDATE_UI 0x0001
481 #define UPDATE_TITLE 0x0002
483 void update_doc(HTMLDocument
*This
, DWORD flags
);
484 void update_title(HTMLDocument
*);
487 void init_editor(HTMLDocument
*);
488 void set_ns_editmode(NSContainer
*);
489 void handle_edit_event(HTMLDocument
*,nsIDOMEvent
*);
490 HRESULT
editor_exec_copy(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
491 HRESULT
editor_exec_cut(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
492 HRESULT
editor_exec_paste(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
493 void handle_edit_load(HTMLDocument
*);
494 HRESULT
editor_is_dirty(HTMLDocument
*);
495 void set_dirty(HTMLDocument
*,VARIANT_BOOL
);
497 extern DWORD mshtml_tls
;
499 typedef struct task_t
{
503 TASK_SETDOWNLOADSTATE
,
509 BSCallback
*bscallback
;
516 task_t
*task_queue_head
;
517 task_t
*task_queue_tail
;
520 thread_data_t
*get_thread_data(BOOL
);
521 HWND
get_thread_hwnd(void);
522 void push_task(task_t
*);
523 void remove_doc_tasks(const HTMLDocument
*);
531 HRESULT
get_typeinfo(enum tid_t
, ITypeInfo
**);
533 DEFINE_GUID(CLSID_AboutProtocol
, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
534 DEFINE_GUID(CLSID_JSProtocol
, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
535 DEFINE_GUID(CLSID_MailtoProtocol
, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
536 DEFINE_GUID(CLSID_ResProtocol
, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
537 DEFINE_GUID(CLSID_SysimageProtocol
, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
539 DEFINE_GUID(CLSID_CMarkup
,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
541 extern LONG module_ref
;
542 #define LOCK_MODULE() InterlockedIncrement(&module_ref)
543 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
545 /* memory allocation functions */
547 static inline void *heap_alloc(size_t len
)
549 return HeapAlloc(GetProcessHeap(), 0, len
);
552 static inline void *heap_alloc_zero(size_t len
)
554 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
557 static inline void *heap_realloc(void *mem
, size_t len
)
559 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
562 static inline BOOL
heap_free(void *mem
)
564 return HeapFree(GetProcessHeap(), 0, mem
);
567 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
574 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
575 ret
= heap_alloc(size
);
576 memcpy(ret
, str
, size
);
583 HINSTANCE
get_shdoclc(void);
585 extern HINSTANCE hInst
;