2 * Copyright 2005-2007 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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
39 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
40 #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
41 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
42 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
43 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
44 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
45 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
47 #define APPSTARTUP_TOPIC "app-startup"
49 #define PR_UINT32_MAX 0xffffffff
51 struct nsCStringContainer
{
58 static nsresult (*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
59 static nsresult (*NS_ShutdownXPCOM
)(nsIServiceManager
*);
60 static nsresult (*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
61 static nsresult (*NS_StringContainerInit
)(nsStringContainer
*);
62 static nsresult (*NS_CStringContainerInit
)(nsCStringContainer
*);
63 static nsresult (*NS_StringContainerFinish
)(nsStringContainer
*);
64 static nsresult (*NS_CStringContainerFinish
)(nsCStringContainer
*);
65 static nsresult (*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
66 static nsresult (*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
67 static nsresult (*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
68 static PRUint32 (*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
69 static PRUint32 (*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
71 static HINSTANCE hXPCOM
= NULL
;
73 static nsIServiceManager
*pServMgr
= NULL
;
74 static nsIComponentManager
*pCompMgr
= NULL
;
75 static nsIMemory
*nsmem
= NULL
;
77 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
79 static ATOM nscontainer_class
;
81 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
86 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
88 if(msg
== WM_CREATE
) {
89 This
= *(NSContainer
**)lParam
;
90 SetPropW(hwnd
, wszTHIS
, This
);
92 This
= (NSContainer
*)GetPropW(hwnd
, wszTHIS
);
97 TRACE("(%p)->(WM_SIZE)\n", This
);
99 nsres
= nsIBaseWindow_SetSize(This
->window
,
100 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
102 WARN("SetSize failed: %08x\n", nsres
);
105 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
109 static void register_nscontainer_class(void)
111 static WNDCLASSEXW wndclass
= {
115 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
119 wndclass
.hInstance
= hInst
;
120 nscontainer_class
= RegisterClassExW(&wndclass
);
123 static BOOL
load_xpcom(const PRUnichar
*gre_path
)
125 WCHAR path_env
[MAX_PATH
];
128 static const WCHAR wszPATH
[] = {'P','A','T','H',0};
129 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
131 TRACE("(%s)\n", debugstr_w(gre_path
));
133 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
134 GetEnvironmentVariableW(wszPATH
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
135 len
= strlenW(path_env
);
136 path_env
[len
++] = ';';
137 strcpyW(path_env
+len
, gre_path
);
138 SetEnvironmentVariableW(wszPATH
, path_env
);
140 hXPCOM
= LoadLibraryW(strXPCOM
);
142 WARN("Could not load XPCOM: %d\n", GetLastError());
146 #define NS_DLSYM(func) \
147 func = (typeof(func))GetProcAddress(hXPCOM, #func); \
149 ERR("Could not GetProcAddress(" #func ") failed\n")
151 NS_DLSYM(NS_InitXPCOM2
);
152 NS_DLSYM(NS_ShutdownXPCOM
);
153 NS_DLSYM(NS_GetComponentRegistrar
);
154 NS_DLSYM(NS_StringContainerInit
);
155 NS_DLSYM(NS_CStringContainerInit
);
156 NS_DLSYM(NS_StringContainerFinish
);
157 NS_DLSYM(NS_CStringContainerFinish
);
158 NS_DLSYM(NS_StringSetData
);
159 NS_DLSYM(NS_CStringSetData
);
160 NS_DLSYM(NS_NewLocalFile
);
161 NS_DLSYM(NS_StringGetData
);
162 NS_DLSYM(NS_CStringGetData
);
169 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
171 WCHAR file_name
[MAX_PATH
];
176 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
178 strcpyW(file_name
, gre_path
);
179 strcatW(file_name
, wszVersion
);
181 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
182 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
183 if(hfile
== INVALID_HANDLE_VALUE
) {
184 ERR("Could not open VERSION file\n");
188 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
192 TRACE("%s\n", debugstr_a(version
));
194 if(strcmp(version
, version_string
)) {
195 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
196 debugstr_a(version_string
));
203 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
204 const char *version
, const char *version_string
)
206 DWORD res
, type
, size
= MAX_PATH
;
207 HKEY hkey
= mshtml_key
;
209 static const WCHAR wszGeckoPath
[] =
210 {'G','e','c','k','o','P','a','t','h',0};
213 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
214 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
215 if(res
!= ERROR_SUCCESS
)
219 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
220 if(hkey
!= mshtml_key
)
222 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
225 if(!check_version(gre_path
, version_string
))
228 return load_xpcom(gre_path
);
231 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
237 static const WCHAR wszMshtmlKey
[] = {
238 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
239 '\\','M','S','H','T','M','L',0};
241 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
242 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszMshtmlKey
, &hkey
);
243 if(res
!= ERROR_SUCCESS
)
246 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
)
247 || load_wine_gecko_v(gre_path
, hkey
, "0.0.1", "Wine Gecko 0.0.1\n")
248 || load_wine_gecko_v(gre_path
, hkey
, NULL
, "Wine Gecko 0.0.1\n");
254 static void set_profile(void)
257 PRBool exists
= FALSE
;
260 static const WCHAR wszMSHTML
[] = {'M','S','H','T','M','L',0};
262 nsres
= nsIServiceManager_GetServiceByContactID(pServMgr
, NS_PROFILE_CONTRACTID
,
263 &IID_nsIProfile
, (void**)&profile
);
264 if(NS_FAILED(nsres
)) {
265 ERR("Could not get profile service: %08x\n", nsres
);
269 nsres
= nsIProfile_ProfileExists(profile
, wszMSHTML
, &exists
);
271 nsres
= nsIProfile_CreateNewProfile(profile
, wszMSHTML
, NULL
, NULL
, FALSE
);
273 ERR("CreateNewProfile failed: %08x\n", nsres
);
276 nsres
= nsIProfile_SetCurrentProfile(profile
, wszMSHTML
);
278 ERR("SetCurrentProfile failed: %08x\n", nsres
);
280 nsIProfile_Release(profile
);
283 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
286 nsIObserver
*pStartNotif
;
287 nsIComponentRegistrar
*registrar
= NULL
;
291 nsAString_Init(&path
, gre_path
);
292 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
293 nsAString_Finish(&path
);
294 if(NS_FAILED(nsres
)) {
295 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
300 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
301 if(NS_FAILED(nsres
)) {
302 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
307 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
309 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
311 nsres
= NS_GetComponentRegistrar(®istrar
);
312 if(NS_SUCCEEDED(nsres
)) {
313 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, NULL
);
315 ERR("AutoRegister(NULL) failed: %08x\n", nsres
);
317 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, gre_dir
);
319 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres
);
321 init_nsio(pCompMgr
, registrar
);
323 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
326 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
327 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
328 if(NS_SUCCEEDED(nsres
)) {
329 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
331 ERR("Observe failed: %08x\n", nsres
);
333 nsIObserver_Release(pStartNotif
);
335 ERR("could not get appstartup-notifier: %08x\n", nsres
);
340 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
341 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
343 ERR("Could not get nsIMemory: %08x\n", nsres
);
346 register_nsservice(registrar
, pServMgr
);
347 nsIComponentRegistrar_Release(registrar
);
353 static CRITICAL_SECTION cs_load_gecko
;
354 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
356 0, 0, &cs_load_gecko
,
357 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
358 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
360 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
362 static BOOL
load_gecko(void)
364 PRUnichar gre_path
[MAX_PATH
];
367 static LONG loading_thread
;
371 /* load_gecko may be called recursively */
372 if(loading_thread
== GetCurrentThreadId())
373 return pCompMgr
!= NULL
;
375 EnterCriticalSection(&cs_load_gecko
);
377 if(!loading_thread
) {
378 loading_thread
= GetCurrentThreadId();
380 if(load_wine_gecko(gre_path
)
381 || (install_wine_gecko() && load_wine_gecko(gre_path
)))
382 ret
= init_xpcom(gre_path
);
384 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
386 ret
= pCompMgr
!= NULL
;
389 LeaveCriticalSection(&cs_load_gecko
);
394 void *nsalloc(size_t size
)
396 return nsIMemory_Alloc(nsmem
, size
);
399 void nsfree(void *mem
)
401 nsIMemory_Free(nsmem
, mem
);
404 void nsACString_Init(nsACString
*str
, const char *data
)
406 NS_CStringContainerInit(str
);
408 nsACString_SetData(str
, data
);
411 void nsACString_SetData(nsACString
*str
, const char *data
)
413 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
416 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
, PRBool
*termited
)
418 return NS_CStringGetData(str
, data
, termited
);
421 void nsACString_Finish(nsACString
*str
)
423 NS_CStringContainerFinish(str
);
426 void nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
428 NS_StringContainerInit(str
);
430 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
433 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
, PRBool
*termited
)
435 return NS_StringGetData(str
, data
, termited
);
438 void nsAString_Finish(nsAString
*str
)
440 NS_StringContainerFinish(str
);
443 nsIInputStream
*create_nsstream(const char *data
, PRInt32 data_len
)
445 nsIStringInputStream
*ret
;
451 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
452 NS_STRINGSTREAM_CONTRACTID
, NULL
, &IID_nsIStringInputStream
,
454 if(NS_FAILED(nsres
)) {
455 ERR("Could not get nsIStringInputStream\n");
459 nsres
= nsIStringInputStream_SetData(ret
, data
, data_len
);
460 if(NS_FAILED(nsres
)) {
461 ERR("AdoptData failed: %08x\n", nsres
);
462 nsIStringInputStream_Release(ret
);
466 return (nsIInputStream
*)ret
;
469 nsICommandParams
*create_nscommand_params(void)
471 nsICommandParams
*ret
= NULL
;
477 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
478 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
481 ERR("Could not get nsICommandParams\n");
486 static void nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
488 nsIDOMNodeList
*node_list
= NULL
;
489 PRBool has_children
= FALSE
;
493 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
495 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
496 if(NS_FAILED(nsres
)) {
497 ERR("GetType failed: %08x\n", nsres
);
503 nsIDOMElement
*nselem
;
504 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
505 nsIContentSerializer_AppendElementStart(serializer
, nselem
, has_children
, str
);
506 nsIDOMElement_Release(nselem
);
511 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&nstext
);
512 nsIContentSerializer_AppendText(serializer
, nstext
, 0, -1, str
);
513 nsIDOMText_Release(nstext
);
517 nsIDOMComment
*nscomment
;
518 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMComment
, (void**)&nscomment
);
519 nsres
= nsIContentSerializer_AppendComment(serializer
, nscomment
, 0, -1, str
);
522 case DOCUMENT_NODE
: {
523 nsIDOMDocument
*nsdoc
;
524 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMDocument
, (void**)&nsdoc
);
525 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
526 nsIDOMDocument_Release(nsdoc
);
529 case DOCUMENT_FRAGMENT_NODE
:
532 FIXME("Unhandled type %u\n", type
);
536 PRUint32 child_cnt
, i
;
537 nsIDOMNode
*child_node
;
539 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
540 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
542 for(i
=0; i
<child_cnt
; i
++) {
543 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
544 if(NS_SUCCEEDED(nsres
)) {
545 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
546 nsIDOMNode_Release(child_node
);
548 ERR("Item failed: %08x\n", nsres
);
552 nsIDOMNodeList_Release(node_list
);
555 if(type
== ELEMENT_NODE
) {
556 nsIDOMElement
*nselem
;
557 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
558 nsIContentSerializer_AppendElementEnd(serializer
, nselem
, str
);
559 nsIDOMElement_Release(nselem
);
563 void nsnode_to_nsstring(nsIDOMNode
*nsdoc
, nsAString
*str
)
565 nsIContentSerializer
*serializer
;
569 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
570 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
571 (void**)&serializer
);
572 if(NS_FAILED(nsres
)) {
573 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
577 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
);
579 ERR("Init failed: %08x\n", nsres
);
581 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
582 nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
583 nsIDOMNode_Release(nsnode
);
585 nsres
= nsIContentSerializer_Flush(serializer
, str
);
587 ERR("Flush failed: %08x\n", nsres
);
589 nsIContentSerializer_Release(serializer
);
592 static nsIController
*get_editor_controller(NSContainer
*This
)
594 nsIController
*ret
= NULL
;
595 nsIEditingSession
*editing_session
= NULL
;
596 nsIInterfaceRequestor
*iface_req
;
597 nsIControllerContext
*ctrlctx
;
598 nsIEditor
*editor
= NULL
;
601 nsres
= nsIWebBrowser_QueryInterface(This
->webbrowser
,
602 &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
603 if(NS_FAILED(nsres
)) {
604 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres
);
608 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, &IID_nsIEditingSession
,
609 (void**)&editing_session
);
610 nsIInterfaceRequestor_Release(iface_req
);
611 if(NS_FAILED(nsres
)) {
612 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
616 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
617 This
->doc
->window
->nswindow
, &editor
);
618 nsIEditingSession_Release(editing_session
);
619 if(NS_FAILED(nsres
)) {
620 ERR("Could not get editor: %08x\n", nsres
);
624 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
625 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
626 if(NS_SUCCEEDED(nsres
)) {
627 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, editor
);
629 ERR("SetCommandContext failed: %08x\n", nsres
);
630 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
632 nsIControllerContext_Release(ctrlctx
);
634 ERR("Could not get nsIController interface: %08x\n", nsres
);
636 ERR("Could not create edit controller: %08x\n", nsres
);
639 nsISupports_Release(editor
);
644 void set_ns_editmode(NSContainer
*This
)
646 nsIInterfaceRequestor
*iface_req
;
647 nsIEditingSession
*editing_session
= NULL
;
648 nsIURIContentListener
*listener
= NULL
;
649 nsIDOMWindow
*dom_window
= NULL
;
652 nsres
= nsIWebBrowser_QueryInterface(This
->webbrowser
,
653 &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
654 if(NS_FAILED(nsres
)) {
655 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres
);
659 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, &IID_nsIEditingSession
,
660 (void**)&editing_session
);
661 nsIInterfaceRequestor_Release(iface_req
);
662 if(NS_FAILED(nsres
)) {
663 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
667 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, &dom_window
);
668 if(NS_FAILED(nsres
)) {
669 ERR("Could not get content DOM window: %08x\n", nsres
);
670 nsIEditingSession_Release(editing_session
);
674 nsres
= nsIEditingSession_MakeWindowEditable(editing_session
, dom_window
, NULL
, FALSE
);
675 nsIEditingSession_Release(editing_session
);
676 nsIDOMWindow_Release(dom_window
);
677 if(NS_FAILED(nsres
)) {
678 ERR("MakeWindowEditable failed: %08x\n", nsres
);
682 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
683 * It seams to be a bug in Gecko. To workaround it we set our content
684 * listener again and Gecko's one as its parent.
686 nsIWebBrowser_GetParentURIContentListener(This
->webbrowser
, &listener
);
687 nsIURIContentListener_SetParentContentListener(NSURICL(This
), listener
);
688 nsIURIContentListener_Release(listener
);
689 nsIWebBrowser_SetParentURIContentListener(This
->webbrowser
, NSURICL(This
));
692 static void handle_load_event(NSContainer
*This
, nsIDOMEvent
*event
)
696 TRACE("(%p)\n", This
);
701 if(This
->editor_controller
) {
702 nsIController_Release(This
->editor_controller
);
703 This
->editor_controller
= NULL
;
706 if(This
->doc
->usermode
== EDITMODE
)
707 This
->editor_controller
= get_editor_controller(This
);
709 task
= mshtml_alloc(sizeof(task_t
));
711 task
->doc
= This
->doc
;
712 task
->task_id
= TASK_PARSECOMPLETE
;
716 * This should be done in the worker thread that parses HTML,
717 * but we don't have such thread (Gecko parses HTML for us).
722 void close_gecko(void)
727 nsIComponentManager_Release(pCompMgr
);
730 nsIServiceManager_Release(pServMgr
);
733 nsIMemory_Release(nsmem
);
739 /**********************************************************
740 * nsIWebBrowserChrome interface
743 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
745 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
746 nsIIDRef riid
, nsQIResult result
)
748 NSContainer
*This
= NSWBCHROME_THIS(iface
);
751 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
752 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
753 *result
= NSWBCHROME(This
);
754 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
755 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
756 *result
= NSWBCHROME(This
);
757 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
758 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
759 *result
= NSCML(This
);
760 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
761 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
762 *result
= NSURICL(This
);
763 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
764 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
765 *result
= NSEMBWNDS(This
);
766 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
767 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
768 *result
= NSTOOLTIP(This
);
769 }else if(IsEqualGUID(&IID_nsIDOMEventListener
, riid
)) {
770 TRACE("(%p)->(IID_nsIDOMEventListener %p)\n", This
, result
);
771 *result
= NSEVENTLIST(This
);
772 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
773 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
774 *result
= NSIFACEREQ(This
);
775 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
776 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
777 *result
= NSWEAKREF(This
);
778 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
779 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
780 *result
= NSSUPWEAKREF(This
);
784 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
788 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
789 return NS_NOINTERFACE
;
792 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
794 NSContainer
*This
= NSWBCHROME_THIS(iface
);
795 LONG ref
= InterlockedIncrement(&This
->ref
);
797 TRACE("(%p) ref=%d\n", This
, ref
);
802 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
804 NSContainer
*This
= NSWBCHROME_THIS(iface
);
805 LONG ref
= InterlockedDecrement(&This
->ref
);
807 TRACE("(%p) ref=%d\n", This
, ref
);
811 nsIWebBrowserChrome_Release(NSWBCHROME(This
->parent
));
818 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
819 PRUint32 statusType
, const PRUnichar
*status
)
821 NSContainer
*This
= NSWBCHROME_THIS(iface
);
822 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
823 return NS_ERROR_NOT_IMPLEMENTED
;
826 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
827 nsIWebBrowser
**aWebBrowser
)
829 NSContainer
*This
= NSWBCHROME_THIS(iface
);
831 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
834 return NS_ERROR_INVALID_ARG
;
837 nsIWebBrowser_AddRef(This
->webbrowser
);
838 *aWebBrowser
= This
->webbrowser
;
842 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
843 nsIWebBrowser
*aWebBrowser
)
845 NSContainer
*This
= NSWBCHROME_THIS(iface
);
847 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
849 if(aWebBrowser
!= This
->webbrowser
)
850 ERR("Wrong nsWebBrowser!\n");
855 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
856 PRUint32
*aChromeFlags
)
858 NSContainer
*This
= NSWBCHROME_THIS(iface
);
859 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
860 return NS_ERROR_NOT_IMPLEMENTED
;
863 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
864 PRUint32 aChromeFlags
)
866 NSContainer
*This
= NSWBCHROME_THIS(iface
);
867 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
868 return NS_ERROR_NOT_IMPLEMENTED
;
871 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
873 NSContainer
*This
= NSWBCHROME_THIS(iface
);
874 TRACE("(%p)\n", This
);
875 return NS_ERROR_NOT_IMPLEMENTED
;
878 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
879 PRInt32 aCX
, PRInt32 aCY
)
881 NSContainer
*This
= NSWBCHROME_THIS(iface
);
882 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
883 return NS_ERROR_NOT_IMPLEMENTED
;
886 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
888 NSContainer
*This
= NSWBCHROME_THIS(iface
);
889 WARN("(%p)\n", This
);
890 return NS_ERROR_NOT_IMPLEMENTED
;
893 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
895 NSContainer
*This
= NSWBCHROME_THIS(iface
);
896 WARN("(%p)->(%p)\n", This
, _retval
);
897 return NS_ERROR_NOT_IMPLEMENTED
;
900 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
903 NSContainer
*This
= NSWBCHROME_THIS(iface
);
904 WARN("(%p)->(%08x)\n", This
, aStatus
);
905 return NS_ERROR_NOT_IMPLEMENTED
;
908 #undef NSWBCHROME_THIS
910 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
911 nsWebBrowserChrome_QueryInterface
,
912 nsWebBrowserChrome_AddRef
,
913 nsWebBrowserChrome_Release
,
914 nsWebBrowserChrome_SetStatus
,
915 nsWebBrowserChrome_GetWebBrowser
,
916 nsWebBrowserChrome_SetWebBrowser
,
917 nsWebBrowserChrome_GetChromeFlags
,
918 nsWebBrowserChrome_SetChromeFlags
,
919 nsWebBrowserChrome_DestroyBrowserWindow
,
920 nsWebBrowserChrome_SizeBrowserTo
,
921 nsWebBrowserChrome_ShowAsModal
,
922 nsWebBrowserChrome_IsWindowModal
,
923 nsWebBrowserChrome_ExitModalEventLoop
926 /**********************************************************
927 * nsIContextMenuListener interface
930 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
932 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
933 nsIIDRef riid
, nsQIResult result
)
935 NSContainer
*This
= NSCML_THIS(iface
);
936 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
939 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
941 NSContainer
*This
= NSCML_THIS(iface
);
942 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
945 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
947 NSContainer
*This
= NSCML_THIS(iface
);
948 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
951 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
952 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
954 NSContainer
*This
= NSCML_THIS(iface
);
955 nsIDOMMouseEvent
*event
;
957 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
960 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
962 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
963 if(NS_FAILED(nsres
)) {
964 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
968 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
969 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
970 nsIDOMMouseEvent_Release(event
);
972 switch(aContextFlags
) {
974 case CONTEXT_DOCUMENT
:
976 dwID
= CONTEXT_MENU_DEFAULT
;
979 case CONTEXT_IMAGE
|CONTEXT_LINK
:
980 dwID
= CONTEXT_MENU_IMAGE
;
983 dwID
= CONTEXT_MENU_ANCHOR
;
986 dwID
= CONTEXT_MENU_CONTROL
;
989 FIXME("aContextFlags=%08x\n", aContextFlags
);
992 show_context_menu(This
->doc
, dwID
, &pt
);
999 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1000 nsContextMenuListener_QueryInterface
,
1001 nsContextMenuListener_AddRef
,
1002 nsContextMenuListener_Release
,
1003 nsContextMenuListener_OnShowContextMenu
1006 /**********************************************************
1007 * nsIURIContentListener interface
1010 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1012 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1013 nsIIDRef riid
, nsQIResult result
)
1015 NSContainer
*This
= NSURICL_THIS(iface
);
1016 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1019 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1021 NSContainer
*This
= NSURICL_THIS(iface
);
1022 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1025 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1027 NSContainer
*This
= NSURICL_THIS(iface
);
1028 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1031 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1032 nsIURI
*aURI
, PRBool
*_retval
)
1034 NSContainer
*This
= NSURICL_THIS(iface
);
1035 nsIWineURI
*wine_uri
;
1036 nsACString spec_str
;
1040 nsACString_Init(&spec_str
, NULL
);
1041 nsIURI_GetSpec(aURI
, &spec_str
);
1042 nsACString_GetData(&spec_str
, &spec
, NULL
);
1044 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1046 nsACString_Finish(&spec_str
);
1048 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsIWineURI
, (void**)&wine_uri
);
1049 if(NS_FAILED(nsres
)) {
1050 WARN("Could not get nsIWineURI interface: %08x\n", nsres
);
1051 return NS_ERROR_NOT_IMPLEMENTED
;
1054 nsIWineURI_SetNSContainer(wine_uri
, This
);
1055 nsIWineURI_SetIsDocumentURI(wine_uri
, TRUE
);
1057 if(This
->bscallback
&& This
->bscallback
->mon
) {
1061 hres
= IMoniker_GetDisplayName(This
->bscallback
->mon
, NULL
, 0, &wine_url
);
1062 if(SUCCEEDED(hres
)) {
1063 nsIWineURI_SetWineURL(wine_uri
, wine_url
);
1064 CoTaskMemFree(wine_url
);
1066 WARN("GetDisplayName failed: %08x\n", hres
);
1070 nsIWineURI_Release(wine_uri
);
1073 return This
->content_listener
1074 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1078 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1079 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1080 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1082 NSContainer
*This
= NSURICL_THIS(iface
);
1084 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1085 aRequest
, aContentHandler
, _retval
);
1087 return This
->content_listener
1088 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1089 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1090 : NS_ERROR_NOT_IMPLEMENTED
;
1093 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1094 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1096 NSContainer
*This
= NSURICL_THIS(iface
);
1098 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1100 /* FIXME: Should we do something here? */
1103 return This
->content_listener
1104 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1105 aDesiredContentType
, _retval
)
1109 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1110 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1113 NSContainer
*This
= NSURICL_THIS(iface
);
1115 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1116 aDesiredContentType
, _retval
);
1118 return This
->content_listener
1119 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1120 aIsContentPreferred
, aDesiredContentType
, _retval
)
1121 : NS_ERROR_NOT_IMPLEMENTED
;
1124 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1125 nsISupports
**aLoadCookie
)
1127 NSContainer
*This
= NSURICL_THIS(iface
);
1129 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1131 return This
->content_listener
1132 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1133 : NS_ERROR_NOT_IMPLEMENTED
;
1136 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1137 nsISupports
*aLoadCookie
)
1139 NSContainer
*This
= NSURICL_THIS(iface
);
1141 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1143 return This
->content_listener
1144 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1145 : NS_ERROR_NOT_IMPLEMENTED
;
1148 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1149 nsIURIContentListener
**aParentContentListener
)
1151 NSContainer
*This
= NSURICL_THIS(iface
);
1153 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1155 if(This
->content_listener
)
1156 nsIURIContentListener_AddRef(This
->content_listener
);
1158 *aParentContentListener
= This
->content_listener
;
1162 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1163 nsIURIContentListener
*aParentContentListener
)
1165 NSContainer
*This
= NSURICL_THIS(iface
);
1167 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1169 if(aParentContentListener
== NSURICL(This
))
1172 if(This
->content_listener
)
1173 nsIURIContentListener_Release(This
->content_listener
);
1175 This
->content_listener
= aParentContentListener
;
1176 if(This
->content_listener
)
1177 nsIURIContentListener_AddRef(This
->content_listener
);
1184 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1185 nsURIContentListener_QueryInterface
,
1186 nsURIContentListener_AddRef
,
1187 nsURIContentListener_Release
,
1188 nsURIContentListener_OnStartURIOpen
,
1189 nsURIContentListener_DoContent
,
1190 nsURIContentListener_IsPreferred
,
1191 nsURIContentListener_CanHandleContent
,
1192 nsURIContentListener_GetLoadCookie
,
1193 nsURIContentListener_SetLoadCookie
,
1194 nsURIContentListener_GetParentContentListener
,
1195 nsURIContentListener_SetParentContentListener
1198 /**********************************************************
1199 * nsIEmbeddinSiteWindow interface
1202 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1204 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1205 nsIIDRef riid
, nsQIResult result
)
1207 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1208 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1211 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1213 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1214 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1217 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1219 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1220 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1223 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1224 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1226 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1227 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1228 return NS_ERROR_NOT_IMPLEMENTED
;
1231 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1232 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1234 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1235 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1236 return NS_ERROR_NOT_IMPLEMENTED
;
1239 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1241 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1242 WARN("(%p)\n", This
);
1243 return NS_ERROR_NOT_IMPLEMENTED
;
1246 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1247 PRBool
*aVisibility
)
1249 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1250 WARN("(%p)->(%p)\n", This
, aVisibility
);
1251 return NS_ERROR_NOT_IMPLEMENTED
;
1254 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1257 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1258 WARN("(%p)->(%x)\n", This
, aVisibility
);
1259 return NS_ERROR_NOT_IMPLEMENTED
;
1262 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1265 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1266 WARN("(%p)->(%p)\n", This
, aTitle
);
1267 return NS_ERROR_NOT_IMPLEMENTED
;
1270 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1271 const PRUnichar
*aTitle
)
1273 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1274 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1275 return NS_ERROR_NOT_IMPLEMENTED
;
1278 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1281 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1283 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1285 *aSiteWindow
= This
->hwnd
;
1289 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1290 nsEmbeddingSiteWindow_QueryInterface
,
1291 nsEmbeddingSiteWindow_AddRef
,
1292 nsEmbeddingSiteWindow_Release
,
1293 nsEmbeddingSiteWindow_SetDimensions
,
1294 nsEmbeddingSiteWindow_GetDimensions
,
1295 nsEmbeddingSiteWindow_SetFocus
,
1296 nsEmbeddingSiteWindow_GetVisibility
,
1297 nsEmbeddingSiteWindow_SetVisibility
,
1298 nsEmbeddingSiteWindow_GetTitle
,
1299 nsEmbeddingSiteWindow_SetTitle
,
1300 nsEmbeddingSiteWindow_GetSiteWindow
1303 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1305 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1308 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1309 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1312 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1314 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1315 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1318 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1320 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1321 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1324 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1325 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1327 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1329 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1334 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1336 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1338 hide_tooltip(This
->doc
);
1343 #undef NSTOOLTIM_THIS
1345 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1346 nsTooltipListener_QueryInterface
,
1347 nsTooltipListener_AddRef
,
1348 nsTooltipListener_Release
,
1349 nsTooltipListener_OnShowTooltip
,
1350 nsTooltipListener_OnHideTooltip
1353 #define NSEVENTLIST_THIS(iface) DEFINE_THIS(NSContainer, DOMEventListener, iface)
1355 static nsresult NSAPI
nsDOMEventListener_QueryInterface(nsIDOMEventListener
*iface
,
1356 nsIIDRef riid
, nsQIResult result
)
1358 NSContainer
*This
= NSEVENTLIST_THIS(iface
);
1359 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1362 static nsrefcnt NSAPI
nsDOMEventListener_AddRef(nsIDOMEventListener
*iface
)
1364 NSContainer
*This
= NSEVENTLIST_THIS(iface
);
1365 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1368 static nsrefcnt NSAPI
nsDOMEventListener_Release(nsIDOMEventListener
*iface
)
1370 NSContainer
*This
= NSEVENTLIST_THIS(iface
);
1371 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1374 static nsresult NSAPI
nsDOMEventListener_HandleEvent(nsIDOMEventListener
*iface
, nsIDOMEvent
*event
)
1376 NSContainer
*This
= NSEVENTLIST_THIS(iface
);
1378 const PRUnichar
*type
;
1380 static const PRUnichar loadW
[] = {'l','o','a','d',0};
1382 nsAString_Init(&type_str
, NULL
);
1383 nsIDOMEvent_GetType(event
, &type_str
);
1384 nsAString_GetData(&type_str
, &type
, NULL
);
1386 TRACE("(%p)->(%p) %s\n", This
, event
, debugstr_w(type
));
1388 if(!strcmpW(loadW
, type
)) {
1389 handle_load_event(This
, event
);
1390 }else if(This
->doc
) {
1391 update_doc(This
->doc
, UPDATE_UI
);
1392 if(This
->doc
->usermode
== EDITMODE
)
1393 handle_edit_event(This
->doc
, event
);
1396 nsAString_Finish(&type_str
);
1401 #undef NSEVENTLIST_THIS
1403 static const nsIDOMEventListenerVtbl nsDOMEventListenerVtbl
= {
1404 nsDOMEventListener_QueryInterface
,
1405 nsDOMEventListener_AddRef
,
1406 nsDOMEventListener_Release
,
1407 nsDOMEventListener_HandleEvent
1410 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1412 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1413 nsIIDRef riid
, nsQIResult result
)
1415 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1416 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1419 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1421 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1422 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1425 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1427 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1428 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1431 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1432 nsIIDRef riid
, nsQIResult result
)
1434 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1436 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1437 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1438 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1441 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1444 #undef NSIFACEREQ_THIS
1446 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1447 nsInterfaceRequestor_QueryInterface
,
1448 nsInterfaceRequestor_AddRef
,
1449 nsInterfaceRequestor_Release
,
1450 nsInterfaceRequestor_GetInterface
1453 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1455 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1456 nsIIDRef riid
, nsQIResult result
)
1458 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1459 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1462 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1464 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1465 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1468 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1470 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1471 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1474 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1475 const nsIID
*riid
, void **result
)
1477 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1478 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1481 #undef NSWEAKREF_THIS
1483 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1484 nsWeakReference_QueryInterface
,
1485 nsWeakReference_AddRef
,
1486 nsWeakReference_Release
,
1487 nsWeakReference_QueryReferent
1490 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1492 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1493 nsIIDRef riid
, nsQIResult result
)
1495 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1496 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1499 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1501 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1502 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1505 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1507 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1508 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1511 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1512 nsIWeakReference
**_retval
)
1514 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1516 TRACE("(%p)->(%p)\n", This
, _retval
);
1518 nsIWeakReference_AddRef(NSWEAKREF(This
));
1519 *_retval
= NSWEAKREF(This
);
1523 #undef NSWEAKREF_THIS
1525 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1526 nsSupportsWeakReference_QueryInterface
,
1527 nsSupportsWeakReference_AddRef
,
1528 nsSupportsWeakReference_Release
,
1529 nsSupportsWeakReference_GetWeakReference
1533 NSContainer
*NSContainer_Create(HTMLDocument
*doc
, NSContainer
*parent
)
1535 nsIDOMWindow
*dom_window
;
1536 nsIWebBrowserSetup
*wbsetup
;
1537 nsIScrollable
*scrollable
;
1544 ret
= mshtml_alloc(sizeof(NSContainer
));
1546 ret
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
1547 ret
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
1548 ret
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
1549 ret
->lpEmbeddingSiteWindowVtbl
= &nsEmbeddingSiteWindowVtbl
;
1550 ret
->lpTooltipListenerVtbl
= &nsTooltipListenerVtbl
;
1551 ret
->lpInterfaceRequestorVtbl
= &nsInterfaceRequestorVtbl
;
1552 ret
->lpWeakReferenceVtbl
= &nsWeakReferenceVtbl
;
1553 ret
->lpSupportsWeakReferenceVtbl
= &nsSupportsWeakReferenceVtbl
;
1554 ret
->lpDOMEventListenerVtbl
= &nsDOMEventListenerVtbl
;
1558 ret
->bscallback
= NULL
;
1559 ret
->content_listener
= NULL
;
1560 ret
->editor_controller
= NULL
;
1563 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent
));
1564 ret
->parent
= parent
;
1566 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1567 NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
1568 if(NS_FAILED(nsres
))
1569 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1571 nsres
= nsIWebBrowser_SetContainerWindow(ret
->webbrowser
, NSWBCHROME(ret
));
1572 if(NS_FAILED(nsres
))
1573 ERR("SetContainerWindow failed: %08x\n", nsres
);
1575 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
1576 (void**)&ret
->window
);
1577 if(NS_FAILED(nsres
))
1578 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1580 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserSetup
,
1582 if(NS_SUCCEEDED(nsres
)) {
1583 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, TRUE
);
1584 nsIWebBrowserSetup_Release(wbsetup
);
1585 if(NS_FAILED(nsres
))
1586 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1588 ERR("Could not get nsIWebBrowserSetup interface\n");
1591 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
1592 (void**)&ret
->navigation
);
1593 if(NS_FAILED(nsres
))
1594 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1596 nsres
= nsIWebBrowserFocus_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserFocus
,
1597 (void**)&ret
->focus
);
1598 if(NS_FAILED(nsres
))
1599 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1601 if(!nscontainer_class
)
1602 register_nscontainer_class();
1604 ret
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1605 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1606 GetDesktopWindow(), NULL
, hInst
, ret
);
1608 nsres
= nsIBaseWindow_InitWindow(ret
->window
, ret
->hwnd
, NULL
, 0, 0, 100, 100);
1609 if(NS_SUCCEEDED(nsres
)) {
1610 nsres
= nsIBaseWindow_Create(ret
->window
);
1611 if(NS_FAILED(nsres
))
1612 WARN("Creating window failed: %08x\n", nsres
);
1614 nsIBaseWindow_SetVisibility(ret
->window
, FALSE
);
1615 nsIBaseWindow_SetEnabled(ret
->window
, FALSE
);
1617 ERR("InitWindow failed: %08x\n", nsres
);
1620 nsres
= nsIWebBrowser_SetParentURIContentListener(ret
->webbrowser
, NSURICL(ret
));
1621 if(NS_FAILED(nsres
))
1622 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1624 nsres
= nsIWebBrowser_GetContentDOMWindow(ret
->webbrowser
, &dom_window
);
1625 if(NS_SUCCEEDED(nsres
)) {
1626 nsIDOMEventTarget
*target
;
1627 nsres
= nsIDOMWindow_QueryInterface(dom_window
, &IID_nsIDOMEventTarget
, (void**)&target
);
1628 nsIDOMWindow_Release(dom_window
);
1629 if(NS_SUCCEEDED(nsres
)) {
1630 nsAString keypress_str
, load_str
;
1631 static const PRUnichar wsz_keypress
[] = {'k','e','y','p','r','e','s','s',0};
1632 static const PRUnichar wsz_load
[] = {'l','o','a','d',0};
1634 nsAString_Init(&keypress_str
, wsz_keypress
);
1635 nsres
= nsIDOMEventTarget_AddEventListener(target
, &keypress_str
, NSEVENTLIST(ret
), FALSE
);
1636 nsAString_Finish(&keypress_str
);
1637 if(NS_FAILED(nsres
))
1638 ERR("AddEventTarget failed: %08x\n", nsres
);
1640 nsAString_Init(&load_str
, wsz_load
);
1641 nsres
= nsIDOMEventTarget_AddEventListener(target
, &load_str
, NSEVENTLIST(ret
), TRUE
);
1642 nsAString_Finish(&load_str
);
1643 if(NS_FAILED(nsres
))
1644 ERR("AddEventTarget failed: %08x\n", nsres
);
1646 nsIDOMEventTarget_Release(target
);
1648 ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres
);
1651 ERR("GetContentDOMWindow failed: %08x\n", nsres
);
1654 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1655 if(NS_SUCCEEDED(nsres
)) {
1656 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1657 ScrollOrientation_Y
, Scrollbar_Always
);
1658 if(NS_FAILED(nsres
))
1659 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1661 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1662 ScrollOrientation_X
, Scrollbar_Auto
);
1663 if(NS_FAILED(nsres
))
1664 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1666 nsIScrollable_Release(scrollable
);
1668 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1674 void NSContainer_Release(NSContainer
*This
)
1676 TRACE("(%p)\n", This
);
1678 ShowWindow(This
->hwnd
, SW_HIDE
);
1679 SetParent(This
->hwnd
, NULL
);
1681 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1682 nsIBaseWindow_Destroy(This
->window
);
1684 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1686 nsIWebBrowser_Release(This
->webbrowser
);
1687 This
->webbrowser
= NULL
;
1689 nsIWebNavigation_Release(This
->navigation
);
1690 This
->navigation
= NULL
;
1692 nsIBaseWindow_Release(This
->window
);
1693 This
->window
= NULL
;
1695 nsIWebBrowserFocus_Release(This
->focus
);
1698 if(This
->editor_controller
) {
1699 nsIController_Release(This
->editor_controller
);
1700 This
->editor_controller
= NULL
;
1703 if(This
->content_listener
) {
1704 nsIURIContentListener_Release(This
->content_listener
);
1705 This
->content_listener
= NULL
;
1709 DestroyWindow(This
->hwnd
);
1713 nsIWebBrowserChrome_Release(NSWBCHROME(This
));