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
;
57 typedef struct nsChannelBSC nsChannelBSC
;
60 const IHTMLWindow2Vtbl
*lpHTMLWindow2Vtbl
;
65 nsIDOMWindow
*nswindow
;
77 const IConnectionPointContainerVtbl
*lpConnectionPointContainerVtbl
;
79 ConnectionPoint
*cp_list
;
81 } ConnectionPointContainer
;
83 struct ConnectionPoint
{
84 const IConnectionPointVtbl
*lpConnectionPointVtbl
;
86 IConnectionPointContainer
*container
;
91 IPropertyNotifySink
*propnotif
;
97 ConnectionPoint
*next
;
101 const IHTMLOptionElementFactoryVtbl
*lpHTMLOptionElementFactoryVtbl
;
106 } HTMLOptionElementFactory
;
108 struct HTMLDocument
{
109 const IHTMLDocument2Vtbl
*lpHTMLDocument2Vtbl
;
110 const IHTMLDocument3Vtbl
*lpHTMLDocument3Vtbl
;
111 const IHTMLDocument4Vtbl
*lpHTMLDocument4Vtbl
;
112 const IHTMLDocument5Vtbl
*lpHTMLDocument5Vtbl
;
113 const IPersistMonikerVtbl
*lpPersistMonikerVtbl
;
114 const IPersistFileVtbl
*lpPersistFileVtbl
;
115 const IMonikerPropVtbl
*lpMonikerPropVtbl
;
116 const IOleObjectVtbl
*lpOleObjectVtbl
;
117 const IOleDocumentVtbl
*lpOleDocumentVtbl
;
118 const IOleDocumentViewVtbl
*lpOleDocumentViewVtbl
;
119 const IOleInPlaceActiveObjectVtbl
*lpOleInPlaceActiveObjectVtbl
;
120 const IViewObject2Vtbl
*lpViewObject2Vtbl
;
121 const IOleInPlaceObjectWindowlessVtbl
*lpOleInPlaceObjectWindowlessVtbl
;
122 const IServiceProviderVtbl
*lpServiceProviderVtbl
;
123 const IOleCommandTargetVtbl
*lpOleCommandTargetVtbl
;
124 const IOleControlVtbl
*lpOleControlVtbl
;
125 const IHlinkTargetVtbl
*lpHlinkTargetVtbl
;
126 const IPersistStreamInitVtbl
*lpPersistStreamInitVtbl
;
127 const ICustomDocVtbl
*lpCustomDocVtbl
;
131 NSContainer
*nscontainer
;
134 IOleClientSite
*client
;
135 IDocHostUIHandler
*hostui
;
136 IOleInPlaceSite
*ipsite
;
137 IOleInPlaceFrame
*frame
;
138 IOleInPlaceUIWindow
*ip_window
;
140 IOleUndoManager
*undomgr
;
142 nsChannelBSC
*bscallback
;
145 struct list bindings
;
150 DOCHOSTUIINFO hostinfo
;
153 READYSTATE readystate
;
154 BOOL in_place_active
;
158 BOOL container_locked
;
164 ConnectionPointContainer cp_container
;
165 ConnectionPoint cp_htmldocevents
;
166 ConnectionPoint cp_htmldocevents2
;
167 ConnectionPoint cp_propnotif
;
169 HTMLOptionElementFactory
*option_factory
;
171 struct list selection_list
;
172 struct list range_list
;
178 const nsIDOMEventListenerVtbl
*lpDOMEventListenerVtbl
;
183 const nsIWebBrowserChromeVtbl
*lpWebBrowserChromeVtbl
;
184 const nsIContextMenuListenerVtbl
*lpContextMenuListenerVtbl
;
185 const nsIURIContentListenerVtbl
*lpURIContentListenerVtbl
;
186 const nsIEmbeddingSiteWindowVtbl
*lpEmbeddingSiteWindowVtbl
;
187 const nsITooltipListenerVtbl
*lpTooltipListenerVtbl
;
188 const nsIInterfaceRequestorVtbl
*lpInterfaceRequestorVtbl
;
189 const nsIWeakReferenceVtbl
*lpWeakReferenceVtbl
;
190 const nsISupportsWeakReferenceVtbl
*lpSupportsWeakReferenceVtbl
;
192 nsEventListener blur_listener
;
193 nsEventListener focus_listener
;
194 nsEventListener keypress_listener
;
195 nsEventListener load_listener
;
196 nsEventListener node_insert_listener
;
198 nsIWebBrowser
*webbrowser
;
199 nsIWebNavigation
*navigation
;
200 nsIBaseWindow
*window
;
201 nsIWebBrowserFocus
*focus
;
204 nsIController
*editor_controller
;
211 nsIURIContentListener
*content_listener
;
215 nsChannelBSC
*bscallback
; /* hack */
216 HWND reset_focus
; /* hack */
220 const nsIHttpChannelVtbl
*lpHttpChannelVtbl
;
221 const nsIUploadChannelVtbl
*lpUploadChannelVtbl
;
226 nsIHttpChannel
*http_channel
;
228 nsIInputStream
*post_data_stream
;
229 nsILoadGroup
*load_group
;
230 nsIInterfaceRequestor
*notif_callback
;
231 nsLoadFlags load_flags
;
232 nsIURI
*original_uri
;
238 HRESULT (*qi
)(HTMLDOMNode
*,REFIID
,void**);
239 void (*destructor
)(HTMLDOMNode
*);
243 const IHTMLDOMNodeVtbl
*lpHTMLDOMNodeVtbl
;
244 const NodeImplVtbl
*vtbl
;
256 ConnectionPointContainer cp_container
;
258 const IHTMLElementVtbl
*lpHTMLElementVtbl
;
259 const IHTMLElement2Vtbl
*lpHTMLElement2Vtbl
;
261 nsIDOMHTMLElement
*nselem
;
267 const IHTMLTextContainerVtbl
*lpHTMLTextContainerVtbl
;
272 #define HTMLWINDOW2(x) ((IHTMLWindow2*) &(x)->lpHTMLWindow2Vtbl)
274 #define HTMLDOC(x) ((IHTMLDocument2*) &(x)->lpHTMLDocument2Vtbl)
275 #define HTMLDOC3(x) ((IHTMLDocument3*) &(x)->lpHTMLDocument3Vtbl)
276 #define HTMLDOC4(x) ((IHTMLDocument4*) &(x)->lpHTMLDocument4Vtbl)
277 #define HTMLDOC5(x) ((IHTMLDocument5*) &(x)->lpHTMLDocument5Vtbl)
278 #define PERSIST(x) ((IPersist*) &(x)->lpPersistFileVtbl)
279 #define PERSISTMON(x) ((IPersistMoniker*) &(x)->lpPersistMonikerVtbl)
280 #define PERSISTFILE(x) ((IPersistFile*) &(x)->lpPersistFileVtbl)
281 #define MONPROP(x) ((IMonikerProp*) &(x)->lpMonikerPropVtbl)
282 #define OLEOBJ(x) ((IOleObject*) &(x)->lpOleObjectVtbl)
283 #define OLEDOC(x) ((IOleDocument*) &(x)->lpOleDocumentVtbl)
284 #define DOCVIEW(x) ((IOleDocumentView*) &(x)->lpOleDocumentViewVtbl)
285 #define OLEWIN(x) ((IOleWindow*) &(x)->lpOleInPlaceActiveObjectVtbl)
286 #define ACTOBJ(x) ((IOleInPlaceActiveObject*) &(x)->lpOleInPlaceActiveObjectVtbl)
287 #define VIEWOBJ(x) ((IViewObject*) &(x)->lpViewObject2Vtbl)
288 #define VIEWOBJ2(x) ((IViewObject2*) &(x)->lpViewObject2Vtbl)
289 #define INPLACEOBJ(x) ((IOleInPlaceObject*) &(x)->lpOleInPlaceObjectWindowlessVtbl)
290 #define INPLACEWIN(x) ((IOleInPlaceObjectWindowless*) &(x)->lpOleInPlaceObjectWindowlessVtbl)
291 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
292 #define CMDTARGET(x) ((IOleCommandTarget*) &(x)->lpOleCommandTargetVtbl)
293 #define CONTROL(x) ((IOleControl*) &(x)->lpOleControlVtbl)
294 #define HLNKTARGET(x) ((IHlinkTarget*) &(x)->lpHlinkTargetVtbl)
295 #define CONPTCONT(x) ((IConnectionPointContainer*) &(x)->lpConnectionPointContainerVtbl)
296 #define PERSTRINIT(x) ((IPersistStreamInit*) &(x)->lpPersistStreamInitVtbl)
297 #define CUSTOMDOC(x) ((ICustomDoc*) &(x)->lpCustomDocVtbl)
299 #define NSWBCHROME(x) ((nsIWebBrowserChrome*) &(x)->lpWebBrowserChromeVtbl)
300 #define NSCML(x) ((nsIContextMenuListener*) &(x)->lpContextMenuListenerVtbl)
301 #define NSURICL(x) ((nsIURIContentListener*) &(x)->lpURIContentListenerVtbl)
302 #define NSEMBWNDS(x) ((nsIEmbeddingSiteWindow*) &(x)->lpEmbeddingSiteWindowVtbl)
303 #define NSIFACEREQ(x) ((nsIInterfaceRequestor*) &(x)->lpInterfaceRequestorVtbl)
304 #define NSTOOLTIP(x) ((nsITooltipListener*) &(x)->lpTooltipListenerVtbl)
305 #define NSEVENTLIST(x) ((nsIDOMEventListener*) &(x)->lpDOMEventListenerVtbl)
306 #define NSWEAKREF(x) ((nsIWeakReference*) &(x)->lpWeakReferenceVtbl)
307 #define NSSUPWEAKREF(x) ((nsISupportsWeakReference*) &(x)->lpSupportsWeakReferenceVtbl)
309 #define NSCHANNEL(x) ((nsIChannel*) &(x)->lpHttpChannelVtbl)
310 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*) &(x)->lpHttpChannelVtbl)
311 #define NSUPCHANNEL(x) ((nsIUploadChannel*) &(x)->lpUploadChannelVtbl)
313 #define HTTPNEG(x) ((IHttpNegotiate2*) &(x)->lpHttpNegotiate2Vtbl)
314 #define STATUSCLB(x) ((IBindStatusCallback*) &(x)->lpBindStatusCallbackVtbl)
315 #define BINDINFO(x) ((IInternetBindInfo*) &(x)->lpInternetBindInfoVtbl);
317 #define HTMLELEM(x) ((IHTMLElement*) &(x)->lpHTMLElementVtbl)
318 #define HTMLELEM2(x) ((IHTMLElement2*) &(x)->lpHTMLElement2Vtbl)
319 #define HTMLDOMNODE(x) ((IHTMLDOMNode*) &(x)->lpHTMLDOMNodeVtbl)
321 #define HTMLTEXTCONT(x) ((IHTMLTextContainer*) &(x)->lpHTMLTextContainerVtbl)
323 #define HTMLOPTFACTORY(x) ((IHTMLOptionElementFactory*) &(x)->lpHTMLOptionElementFactoryVtbl)
325 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
326 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
328 HRESULT
HTMLDocument_Create(IUnknown
*,REFIID
,void**);
329 HRESULT
HTMLLoadOptions_Create(IUnknown
*,REFIID
,void**);
331 HTMLWindow
*HTMLWindow_Create(HTMLDocument
*);
332 HTMLWindow
*nswindow_to_window(const nsIDOMWindow
*);
333 HTMLOptionElementFactory
*HTMLOptionElementFactory_Create(HTMLDocument
*);
334 void setup_nswindow(HTMLWindow
*);
336 void HTMLDocument_HTMLDocument3_Init(HTMLDocument
*);
337 void HTMLDocument_HTMLDocument5_Init(HTMLDocument
*);
338 void HTMLDocument_Persist_Init(HTMLDocument
*);
339 void HTMLDocument_OleCmd_Init(HTMLDocument
*);
340 void HTMLDocument_OleObj_Init(HTMLDocument
*);
341 void HTMLDocument_View_Init(HTMLDocument
*);
342 void HTMLDocument_Window_Init(HTMLDocument
*);
343 void HTMLDocument_Service_Init(HTMLDocument
*);
344 void HTMLDocument_Hlink_Init(HTMLDocument
*);
346 void ConnectionPoint_Init(ConnectionPoint
*,ConnectionPointContainer
*,REFIID
);
347 void ConnectionPointContainer_Init(ConnectionPointContainer
*,IUnknown
*);
348 void ConnectionPointContainer_Destroy(ConnectionPointContainer
*);
350 NSContainer
*NSContainer_Create(HTMLDocument
*,NSContainer
*);
351 void NSContainer_Release(NSContainer
*);
353 void HTMLDocument_LockContainer(HTMLDocument
*,BOOL
);
354 void show_context_menu(HTMLDocument
*,DWORD
,POINT
*,IDispatch
*);
355 void notif_focus(HTMLDocument
*);
357 void show_tooltip(HTMLDocument
*,DWORD
,DWORD
,LPCWSTR
);
358 void hide_tooltip(HTMLDocument
*);
359 HRESULT
get_client_disp_property(IOleClientSite
*,DISPID
,VARIANT
*);
361 HRESULT
ProtocolFactory_Create(REFCLSID
,REFIID
,void**);
363 BOOL
load_gecko(BOOL
);
364 void close_gecko(void);
365 void register_nsservice(nsIComponentRegistrar
*,nsIServiceManager
*);
366 void init_nsio(nsIComponentManager
*,nsIComponentRegistrar
*);
367 BOOL
install_wine_gecko(BOOL
);
369 void hlink_frame_navigate(HTMLDocument
*,IHlinkFrame
*,LPCWSTR
,nsIInputStream
*,DWORD
);
371 void call_property_onchanged(ConnectionPoint
*,DISPID
);
372 HRESULT
call_set_active_object(IOleInPlaceUIWindow
*,IOleInPlaceActiveObject
*);
374 void *nsalloc(size_t);
377 void nsACString_Init(nsACString
*,const char*);
378 void nsACString_SetData(nsACString
*,const char*);
379 PRUint32
nsACString_GetData(const nsACString
*,const char**);
380 void nsACString_Finish(nsACString
*);
382 void nsAString_Init(nsAString
*,const PRUnichar
*);
383 void nsAString_SetData(nsAString
*,const PRUnichar
*);
384 PRUint32
nsAString_GetData(const nsAString
*,const PRUnichar
**);
385 void nsAString_Finish(nsAString
*);
387 nsIInputStream
*create_nsstream(const char*,PRInt32
);
388 nsICommandParams
*create_nscommand_params(void);
389 nsIMutableArray
*create_nsarray(void);
390 nsIWritableVariant
*create_nsvariant(void);
391 void nsnode_to_nsstring(nsIDOMNode
*,nsAString
*);
392 void get_editor_controller(NSContainer
*);
393 void init_nsevents(NSContainer
*);
394 nsresult
get_nsinterface(nsISupports
*,REFIID
,void**);
396 void set_document_bscallback(HTMLDocument
*,nsChannelBSC
*);
397 void set_current_mon(HTMLDocument
*,IMoniker
*);
398 HRESULT
start_binding(HTMLDocument
*,BSCallback
*,IBindCtx
*);
400 HRESULT
bind_mon_to_buffer(HTMLDocument
*,IMoniker
*,void**);
402 nsChannelBSC
*create_channelbsc(IMoniker
*);
403 HRESULT
channelbsc_load_stream(nsChannelBSC
*,IStream
*);
404 void channelbsc_set_channel(nsChannelBSC
*,nsChannel
*,nsIStreamListener
*,nsISupports
*);
405 IMoniker
*get_channelbsc_mon(nsChannelBSC
*);
407 IHTMLSelectionObject
*HTMLSelectionObject_Create(HTMLDocument
*,nsISelection
*);
408 IHTMLTxtRange
*HTMLTxtRange_Create(HTMLDocument
*,nsIDOMRange
*);
409 IHTMLStyle
*HTMLStyle_Create(nsIDOMCSSStyleDeclaration
*);
410 IHTMLStyleSheet
*HTMLStyleSheet_Create(nsIDOMStyleSheet
*);
411 IHTMLStyleSheetsCollection
*HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList
*);
413 void detach_selection(HTMLDocument
*);
414 void detach_ranges(HTMLDocument
*);
416 HTMLElement
*HTMLElement_Create(nsIDOMNode
*);
417 HTMLElement
*HTMLAnchorElement_Create(nsIDOMHTMLElement
*);
418 HTMLElement
*HTMLBodyElement_Create(nsIDOMHTMLElement
*);
419 HTMLElement
*HTMLInputElement_Create(nsIDOMHTMLElement
*);
420 HTMLElement
*HTMLOptionElement_Create(nsIDOMHTMLElement
*);
421 HTMLElement
*HTMLScriptElement_Create(nsIDOMHTMLElement
*);
422 HTMLElement
*HTMLSelectElement_Create(nsIDOMHTMLElement
*);
423 HTMLElement
*HTMLTable_Create(nsIDOMHTMLElement
*);
424 HTMLElement
*HTMLTextAreaElement_Create(nsIDOMHTMLElement
*);
426 void HTMLElement_Init(HTMLElement
*);
427 void HTMLElement2_Init(HTMLElement
*);
428 void HTMLTextContainer_Init(HTMLTextContainer
*);
430 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*,REFIID
,void**);
431 void HTMLDOMNode_destructor(HTMLDOMNode
*);
433 HRESULT
HTMLElement_QI(HTMLDOMNode
*,REFIID
,void**);
434 void HTMLElement_destructor(HTMLDOMNode
*);
436 HTMLDOMNode
*get_node(HTMLDocument
*,nsIDOMNode
*);
437 void release_nodes(HTMLDocument
*);
439 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*);
444 HRESULT (*query
)(HTMLDocument
*,OLECMD
*);
445 HRESULT (*exec
)(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
448 extern const cmdtable_t editmode_cmds
[];
450 void do_ns_command(NSContainer
*,const char*,nsICommandParams
*);
453 #define UPDATE_UI 0x0001
454 #define UPDATE_TITLE 0x0002
456 void update_doc(HTMLDocument
*This
, DWORD flags
);
457 void update_title(HTMLDocument
*);
460 void init_editor(HTMLDocument
*);
461 void set_ns_editmode(NSContainer
*);
462 void handle_edit_event(HTMLDocument
*,nsIDOMEvent
*);
463 HRESULT
editor_exec_copy(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
464 HRESULT
editor_exec_cut(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
465 HRESULT
editor_exec_paste(HTMLDocument
*,DWORD
,VARIANT
*,VARIANT
*);
466 void handle_edit_load(HTMLDocument
*);
467 HRESULT
editor_is_dirty(HTMLDocument
*);
468 void set_dirty(HTMLDocument
*,VARIANT_BOOL
);
470 extern DWORD mshtml_tls
;
472 typedef struct task_t
{
476 TASK_SETDOWNLOADSTATE
,
482 nsChannelBSC
*bscallback
;
489 task_t
*task_queue_head
;
490 task_t
*task_queue_tail
;
493 thread_data_t
*get_thread_data(BOOL
);
494 HWND
get_thread_hwnd(void);
495 void push_task(task_t
*);
496 void remove_doc_tasks(const HTMLDocument
*);
504 HRESULT
get_typeinfo(enum tid_t
, ITypeInfo
**);
506 DEFINE_GUID(CLSID_AboutProtocol
, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
507 DEFINE_GUID(CLSID_JSProtocol
, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
508 DEFINE_GUID(CLSID_MailtoProtocol
, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
509 DEFINE_GUID(CLSID_ResProtocol
, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
510 DEFINE_GUID(CLSID_SysimageProtocol
, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
512 DEFINE_GUID(CLSID_CMarkup
,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
514 extern LONG module_ref
;
515 #define LOCK_MODULE() InterlockedIncrement(&module_ref)
516 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
518 /* memory allocation functions */
520 static inline void *heap_alloc(size_t len
)
522 return HeapAlloc(GetProcessHeap(), 0, len
);
525 static inline void *heap_alloc_zero(size_t len
)
527 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
530 static inline void *heap_realloc(void *mem
, size_t len
)
532 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
535 static inline BOOL
heap_free(void *mem
)
537 return HeapFree(GetProcessHeap(), 0, mem
);
540 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
547 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
548 ret
= heap_alloc(size
);
549 memcpy(ret
, str
, size
);
555 static inline WCHAR
*heap_strdupAtoW(const char *str
)
562 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
563 ret
= heap_alloc(len
*sizeof(WCHAR
));
564 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, -1);
570 HINSTANCE
get_shdoclc(void);
572 extern HINSTANCE hInst
;