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
);
37 WINE_DECLARE_DEBUG_CHANNEL(gecko
);
39 #define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1"
40 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
41 #define NS_PROFILE_CONTRACTID "@mozilla.org/profile/manager;1"
42 #define NS_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
43 #define NS_STRINGSTREAM_CONTRACTID "@mozilla.org/io/string-input-stream;1"
44 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
45 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
46 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
47 #define NS_ARRAY_CONTRACTID "@mozilla.org/array;1"
48 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
49 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
51 #define APPSTARTUP_TOPIC "app-startup"
53 #define PR_UINT32_MAX 0xffffffff
55 struct nsCStringContainer
{
62 static nsresult (*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
63 static nsresult (*NS_ShutdownXPCOM
)(nsIServiceManager
*);
64 static nsresult (*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
65 static nsresult (*NS_StringContainerInit
)(nsStringContainer
*);
66 static nsresult (*NS_CStringContainerInit
)(nsCStringContainer
*);
67 static nsresult (*NS_StringContainerFinish
)(nsStringContainer
*);
68 static nsresult (*NS_CStringContainerFinish
)(nsCStringContainer
*);
69 static nsresult (*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
70 static nsresult (*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
71 static nsresult (*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
72 static PRUint32 (*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
73 static PRUint32 (*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
75 static HINSTANCE hXPCOM
= NULL
;
77 static nsIServiceManager
*pServMgr
= NULL
;
78 static nsIComponentManager
*pCompMgr
= NULL
;
79 static nsIMemory
*nsmem
= NULL
;
81 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
83 static ATOM nscontainer_class
;
85 #define WM_RESETFOCUS_HACK WM_USER+600
87 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
92 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
94 if(msg
== WM_CREATE
) {
95 This
= *(NSContainer
**)lParam
;
96 SetPropW(hwnd
, wszTHIS
, This
);
98 This
= GetPropW(hwnd
, wszTHIS
);
103 TRACE("(%p)->(WM_SIZE)\n", This
);
105 nsres
= nsIBaseWindow_SetSize(This
->window
,
106 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
108 WARN("SetSize failed: %08x\n", nsres
);
111 case WM_RESETFOCUS_HACK
:
114 * Gecko grabs focus in edit mode and some apps don't like it.
115 * We should somehow prevent grabbing focus.
118 TRACE("WM_RESETFOCUS_HACK\n");
120 if(This
->reset_focus
) {
121 SetFocus(This
->reset_focus
);
122 This
->reset_focus
= NULL
;
124 This
->doc
->focus
= FALSE
;
128 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
132 static void register_nscontainer_class(void)
134 static WNDCLASSEXW wndclass
= {
138 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
142 wndclass
.hInstance
= hInst
;
143 nscontainer_class
= RegisterClassExW(&wndclass
);
146 static void set_environment(LPCWSTR gre_path
)
148 WCHAR path_env
[MAX_PATH
], buf
[20];
149 int len
, debug_level
= 0;
151 static const WCHAR pathW
[] = {'P','A','T','H',0};
152 static const WCHAR warnW
[] = {'w','a','r','n',0};
153 static const WCHAR xpcom_debug_breakW
[] =
154 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
155 static const WCHAR nspr_log_modulesW
[] =
156 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
157 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
159 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
160 GetEnvironmentVariableW(pathW
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
161 len
= strlenW(path_env
);
162 path_env
[len
++] = ';';
163 strcpyW(path_env
+len
, gre_path
);
164 SetEnvironmentVariableW(pathW
, path_env
);
166 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
170 else if(WARN_ON(gecko
))
172 else if(ERR_ON(gecko
))
175 sprintfW(buf
, debug_formatW
, debug_level
);
176 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
179 static BOOL
load_xpcom(const PRUnichar
*gre_path
)
181 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
183 TRACE("(%s)\n", debugstr_w(gre_path
));
185 set_environment(gre_path
);
187 hXPCOM
= LoadLibraryW(strXPCOM
);
189 WARN("Could not load XPCOM: %d\n", GetLastError());
193 #define NS_DLSYM(func) \
194 func = (void *)GetProcAddress(hXPCOM, #func); \
196 ERR("Could not GetProcAddress(" #func ") failed\n")
198 NS_DLSYM(NS_InitXPCOM2
);
199 NS_DLSYM(NS_ShutdownXPCOM
);
200 NS_DLSYM(NS_GetComponentRegistrar
);
201 NS_DLSYM(NS_StringContainerInit
);
202 NS_DLSYM(NS_CStringContainerInit
);
203 NS_DLSYM(NS_StringContainerFinish
);
204 NS_DLSYM(NS_CStringContainerFinish
);
205 NS_DLSYM(NS_StringSetData
);
206 NS_DLSYM(NS_CStringSetData
);
207 NS_DLSYM(NS_NewLocalFile
);
208 NS_DLSYM(NS_StringGetData
);
209 NS_DLSYM(NS_CStringGetData
);
216 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
218 WCHAR file_name
[MAX_PATH
];
223 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
225 strcpyW(file_name
, gre_path
);
226 strcatW(file_name
, wszVersion
);
228 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
229 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
230 if(hfile
== INVALID_HANDLE_VALUE
) {
231 ERR("Could not open VERSION file\n");
235 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
239 TRACE("%s\n", debugstr_a(version
));
241 if(strcmp(version
, version_string
)) {
242 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
243 debugstr_a(version_string
));
250 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
251 const char *version
, const char *version_string
)
253 DWORD res
, type
, size
= MAX_PATH
;
254 HKEY hkey
= mshtml_key
;
256 static const WCHAR wszGeckoPath
[] =
257 {'G','e','c','k','o','P','a','t','h',0};
260 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
261 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
262 if(res
!= ERROR_SUCCESS
)
266 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
267 if(hkey
!= mshtml_key
)
269 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
272 if(!check_version(gre_path
, version_string
))
275 return load_xpcom(gre_path
);
278 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
284 static const WCHAR wszMshtmlKey
[] = {
285 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
286 '\\','M','S','H','T','M','L',0};
288 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
289 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszMshtmlKey
, &hkey
);
290 if(res
!= ERROR_SUCCESS
)
293 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
299 static void set_lang(nsIPrefBranch
*pref
)
302 DWORD res
, size
, type
;
306 static const WCHAR international_keyW
[] =
307 {'S','o','f','t','w','a','r','e',
308 '\\','M','i','c','r','o','s','o','f','t',
309 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
310 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
312 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
313 if(res
!= ERROR_SUCCESS
)
316 size
= sizeof(langs
);
317 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
319 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
322 TRACE("Setting lang %s\n", debugstr_a(langs
));
324 nsres
= nsIPrefBranch_SetCharPref(pref
, "intl.accept_languages", langs
);
326 ERR("SetCharPref failed: %08x\n", nsres
);
329 static void set_proxy(nsIPrefBranch
*pref
)
334 DWORD enabled
= 0, res
, size
, type
;
338 static const WCHAR proxy_keyW
[] =
339 {'S','o','f','t','w','a','r','e',
340 '\\','M','i','c','r','o','s','o','f','t',
341 '\\','W','i','n','d','o','w','s',
342 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
343 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
345 res
= RegOpenKeyW(HKEY_CURRENT_USER
, proxy_keyW
, &hkey
);
346 if(res
!= ERROR_SUCCESS
)
349 size
= sizeof(enabled
);
350 res
= RegQueryValueExA(hkey
, "ProxyEnable", 0, &type
, (LPBYTE
)&enabled
, &size
);
351 if(res
!= ERROR_SUCCESS
|| type
!= REG_DWORD
|| enabled
== 0)
357 size
= sizeof(proxy
);
358 res
= RegQueryValueExA(hkey
, "ProxyServer", 0, &type
, (LPBYTE
)proxy
, &size
);
360 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
363 proxy_port
= strchr(proxy
, ':');
368 proxy_port_num
= atoi(proxy_port
+ 1);
369 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy
), proxy_port_num
);
371 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.type", 1);
373 ERR("SetIntPref network.proxy.type failed: %08x\n", nsres
);
374 nsres
= nsIPrefBranch_SetCharPref(pref
, "network.proxy.http", proxy
);
376 ERR("SetCharPref network.proxy.http failed: %08x\n", nsres
);
377 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.http_port", proxy_port_num
);
379 ERR("SetIntPref network.proxy.http_port failed: %08x\n", nsres
);
380 nsres
= nsIPrefBranch_SetCharPref(pref
, "network.proxy.ssl", proxy
);
382 ERR("SetCharPref network.proxy.ssl failed: %08x\n", nsres
);
383 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.ssl_port", proxy_port_num
);
385 ERR("SetIntPref network.proxy.ssl_port failed: %08x\n", nsres
);
388 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
392 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
394 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
397 static void set_preferences(void)
402 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
403 &IID_nsIPrefBranch
, (void**)&pref
);
404 if(NS_FAILED(nsres
)) {
405 ERR("Could not get preference service: %08x\n", nsres
);
411 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
412 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
414 nsIPrefBranch_Release(pref
);
417 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
420 nsIObserver
*pStartNotif
;
421 nsIComponentRegistrar
*registrar
= NULL
;
425 nsAString_Init(&path
, gre_path
);
426 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
427 nsAString_Finish(&path
);
428 if(NS_FAILED(nsres
)) {
429 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
434 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
435 if(NS_FAILED(nsres
)) {
436 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
441 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
443 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
445 nsres
= NS_GetComponentRegistrar(®istrar
);
446 if(NS_SUCCEEDED(nsres
)) {
447 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, NULL
);
449 ERR("AutoRegister(NULL) failed: %08x\n", nsres
);
451 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, gre_dir
);
453 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres
);
455 init_nsio(pCompMgr
, registrar
);
457 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
460 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
461 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
462 if(NS_SUCCEEDED(nsres
)) {
463 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
465 ERR("Observe failed: %08x\n", nsres
);
467 nsIObserver_Release(pStartNotif
);
469 ERR("could not get appstartup-notifier: %08x\n", nsres
);
474 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
475 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
477 ERR("Could not get nsIMemory: %08x\n", nsres
);
480 register_nsservice(registrar
, pServMgr
);
481 nsIComponentRegistrar_Release(registrar
);
487 static CRITICAL_SECTION cs_load_gecko
;
488 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
490 0, 0, &cs_load_gecko
,
491 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
492 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
494 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
496 BOOL
load_gecko(BOOL silent
)
498 PRUnichar gre_path
[MAX_PATH
];
501 static DWORD loading_thread
;
505 /* load_gecko may be called recursively */
506 if(loading_thread
== GetCurrentThreadId())
507 return pCompMgr
!= NULL
;
509 EnterCriticalSection(&cs_load_gecko
);
511 if(!loading_thread
) {
512 loading_thread
= GetCurrentThreadId();
514 if(load_wine_gecko(gre_path
)
515 || (install_wine_gecko(silent
) && load_wine_gecko(gre_path
)))
516 ret
= init_xpcom(gre_path
);
518 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
520 ret
= pCompMgr
!= NULL
;
523 LeaveCriticalSection(&cs_load_gecko
);
528 void *nsalloc(size_t size
)
530 return nsIMemory_Alloc(nsmem
, size
);
533 void nsfree(void *mem
)
535 nsIMemory_Free(nsmem
, mem
);
538 void nsACString_Init(nsACString
*str
, const char *data
)
540 NS_CStringContainerInit(str
);
542 nsACString_SetData(str
, data
);
545 void nsACString_SetData(nsACString
*str
, const char *data
)
547 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
550 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
552 return NS_CStringGetData(str
, data
, NULL
);
555 void nsACString_Finish(nsACString
*str
)
557 NS_CStringContainerFinish(str
);
560 void nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
562 NS_StringContainerInit(str
);
564 nsAString_SetData(str
, data
);
567 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
569 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
572 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
574 return NS_StringGetData(str
, data
, NULL
);
577 void nsAString_Finish(nsAString
*str
)
579 NS_StringContainerFinish(str
);
582 nsIInputStream
*create_nsstream(const char *data
, PRInt32 data_len
)
584 nsIStringInputStream
*ret
;
590 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
591 NS_STRINGSTREAM_CONTRACTID
, NULL
, &IID_nsIStringInputStream
,
593 if(NS_FAILED(nsres
)) {
594 ERR("Could not get nsIStringInputStream\n");
598 nsres
= nsIStringInputStream_SetData(ret
, data
, data_len
);
599 if(NS_FAILED(nsres
)) {
600 ERR("AdoptData failed: %08x\n", nsres
);
601 nsIStringInputStream_Release(ret
);
605 return (nsIInputStream
*)ret
;
608 nsICommandParams
*create_nscommand_params(void)
610 nsICommandParams
*ret
= NULL
;
616 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
617 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
620 ERR("Could not get nsICommandParams\n");
625 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
627 nsIInterfaceRequestor
*iface_req
;
630 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
634 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
635 nsIInterfaceRequestor_Release(iface_req
);
640 static void nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
642 nsIDOMNodeList
*node_list
= NULL
;
643 PRBool has_children
= FALSE
;
647 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
649 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
650 if(NS_FAILED(nsres
)) {
651 ERR("GetType failed: %08x\n", nsres
);
657 nsIDOMElement
*nselem
;
658 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
659 nsIContentSerializer_AppendElementStart(serializer
, nselem
, nselem
, str
);
660 nsIDOMElement_Release(nselem
);
665 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&nstext
);
666 nsIContentSerializer_AppendText(serializer
, nstext
, 0, -1, str
);
667 nsIDOMText_Release(nstext
);
671 nsIDOMComment
*nscomment
;
672 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMComment
, (void**)&nscomment
);
673 nsres
= nsIContentSerializer_AppendComment(serializer
, nscomment
, 0, -1, str
);
676 case DOCUMENT_NODE
: {
677 nsIDOMDocument
*nsdoc
;
678 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMDocument
, (void**)&nsdoc
);
679 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
680 nsIDOMDocument_Release(nsdoc
);
683 case DOCUMENT_FRAGMENT_NODE
:
686 FIXME("Unhandled type %u\n", type
);
690 PRUint32 child_cnt
, i
;
691 nsIDOMNode
*child_node
;
693 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
694 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
696 for(i
=0; i
<child_cnt
; i
++) {
697 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
698 if(NS_SUCCEEDED(nsres
)) {
699 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
700 nsIDOMNode_Release(child_node
);
702 ERR("Item failed: %08x\n", nsres
);
706 nsIDOMNodeList_Release(node_list
);
709 if(type
== ELEMENT_NODE
) {
710 nsIDOMElement
*nselem
;
711 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
712 nsIContentSerializer_AppendElementEnd(serializer
, nselem
, str
);
713 nsIDOMElement_Release(nselem
);
717 void nsnode_to_nsstring(nsIDOMNode
*nsdoc
, nsAString
*str
)
719 nsIContentSerializer
*serializer
;
723 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
724 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
725 (void**)&serializer
);
726 if(NS_FAILED(nsres
)) {
727 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
731 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
733 ERR("Init failed: %08x\n", nsres
);
735 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
736 nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
737 nsIDOMNode_Release(nsnode
);
739 nsres
= nsIContentSerializer_Flush(serializer
, str
);
741 ERR("Flush failed: %08x\n", nsres
);
743 nsIContentSerializer_Release(serializer
);
746 void get_editor_controller(NSContainer
*This
)
748 nsIEditingSession
*editing_session
= NULL
;
749 nsIControllerContext
*ctrlctx
;
753 nsIEditor_Release(This
->editor
);
757 if(This
->editor_controller
) {
758 nsIController_Release(This
->editor_controller
);
759 This
->editor_controller
= NULL
;
762 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
763 (void**)&editing_session
);
764 if(NS_FAILED(nsres
)) {
765 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
769 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
770 This
->doc
->window
->nswindow
, &This
->editor
);
771 nsIEditingSession_Release(editing_session
);
772 if(NS_FAILED(nsres
)) {
773 ERR("Could not get editor: %08x\n", nsres
);
777 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
778 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
779 if(NS_SUCCEEDED(nsres
)) {
780 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
782 ERR("SetCommandContext failed: %08x\n", nsres
);
783 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
784 (void**)&This
->editor_controller
);
785 nsIControllerContext_Release(ctrlctx
);
787 ERR("Could not get nsIController interface: %08x\n", nsres
);
789 ERR("Could not create edit controller: %08x\n", nsres
);
793 void set_ns_editmode(NSContainer
*This
)
795 nsIEditingSession
*editing_session
= NULL
;
796 nsIURIContentListener
*listener
= NULL
;
797 nsIDOMWindow
*dom_window
= NULL
;
800 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
801 (void**)&editing_session
);
802 if(NS_FAILED(nsres
)) {
803 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
807 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, &dom_window
);
808 if(NS_FAILED(nsres
)) {
809 ERR("Could not get content DOM window: %08x\n", nsres
);
810 nsIEditingSession_Release(editing_session
);
814 nsres
= nsIEditingSession_MakeWindowEditable(editing_session
, dom_window
,
815 NULL
, FALSE
, TRUE
, TRUE
);
816 nsIEditingSession_Release(editing_session
);
817 nsIDOMWindow_Release(dom_window
);
818 if(NS_FAILED(nsres
)) {
819 ERR("MakeWindowEditable failed: %08x\n", nsres
);
823 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
824 * It seams to be a bug in Gecko. To workaround it we set our content
825 * listener again and Gecko's one as its parent.
827 nsIWebBrowser_GetParentURIContentListener(This
->webbrowser
, &listener
);
828 nsIURIContentListener_SetParentContentListener(NSURICL(This
), listener
);
829 nsIURIContentListener_Release(listener
);
830 nsIWebBrowser_SetParentURIContentListener(This
->webbrowser
, NSURICL(This
));
833 void update_nsdocument(HTMLDocument
*doc
)
835 nsIDOMHTMLDocument
*nsdoc
;
836 nsIDOMDocument
*nsdomdoc
;
839 if(!doc
->nscontainer
|| !doc
->nscontainer
->navigation
)
842 nsres
= nsIWebNavigation_GetDocument(doc
->nscontainer
->navigation
, &nsdomdoc
);
843 if(NS_FAILED(nsres
) || !nsdomdoc
) {
844 ERR("GetDocument failed: %08x\n", nsres
);
848 nsres
= nsIDOMDocument_QueryInterface(nsdomdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nsdoc
);
849 nsIDOMDocument_Release(nsdomdoc
);
850 if(NS_FAILED(nsres
)) {
851 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres
);
855 if(nsdoc
== doc
->nsdoc
) {
856 nsIDOMHTMLDocument_Release(nsdoc
);
861 nsIDOMHTMLDocument_Release(doc
->nsdoc
);
866 set_mutation_observer(doc
->nscontainer
, nsdoc
);
869 void close_gecko(void)
876 nsIComponentManager_Release(pCompMgr
);
879 nsIServiceManager_Release(pServMgr
);
882 nsIMemory_Release(nsmem
);
888 /**********************************************************
889 * nsIWebBrowserChrome interface
892 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
894 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
895 nsIIDRef riid
, nsQIResult result
)
897 NSContainer
*This
= NSWBCHROME_THIS(iface
);
900 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
901 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
902 *result
= NSWBCHROME(This
);
903 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
904 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
905 *result
= NSWBCHROME(This
);
906 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
907 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
908 *result
= NSCML(This
);
909 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
910 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
911 *result
= NSURICL(This
);
912 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
913 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
914 *result
= NSEMBWNDS(This
);
915 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
916 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
917 *result
= NSTOOLTIP(This
);
918 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
919 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
920 *result
= NSIFACEREQ(This
);
921 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
922 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
923 *result
= NSWEAKREF(This
);
924 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
925 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
926 *result
= NSSUPWEAKREF(This
);
930 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
934 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
935 return NS_NOINTERFACE
;
938 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
940 NSContainer
*This
= NSWBCHROME_THIS(iface
);
941 LONG ref
= InterlockedIncrement(&This
->ref
);
943 TRACE("(%p) ref=%d\n", This
, ref
);
948 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
950 NSContainer
*This
= NSWBCHROME_THIS(iface
);
951 LONG ref
= InterlockedDecrement(&This
->ref
);
953 TRACE("(%p) ref=%d\n", This
, ref
);
956 heap_free(This
->event_vector
);
958 nsIWebBrowserChrome_Release(NSWBCHROME(This
->parent
));
965 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
966 PRUint32 statusType
, const PRUnichar
*status
)
968 NSContainer
*This
= NSWBCHROME_THIS(iface
);
970 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
972 /* FIXME: This hack should be removed when we'll load all pages by URLMoniker */
974 update_nsdocument(This
->doc
);
979 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
980 nsIWebBrowser
**aWebBrowser
)
982 NSContainer
*This
= NSWBCHROME_THIS(iface
);
984 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
987 return NS_ERROR_INVALID_ARG
;
990 nsIWebBrowser_AddRef(This
->webbrowser
);
991 *aWebBrowser
= This
->webbrowser
;
995 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
996 nsIWebBrowser
*aWebBrowser
)
998 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1000 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1002 if(aWebBrowser
!= This
->webbrowser
)
1003 ERR("Wrong nsWebBrowser!\n");
1008 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1009 PRUint32
*aChromeFlags
)
1011 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1012 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1013 return NS_ERROR_NOT_IMPLEMENTED
;
1016 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1017 PRUint32 aChromeFlags
)
1019 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1020 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1021 return NS_ERROR_NOT_IMPLEMENTED
;
1024 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1026 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1027 TRACE("(%p)\n", This
);
1028 return NS_ERROR_NOT_IMPLEMENTED
;
1031 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1032 PRInt32 aCX
, PRInt32 aCY
)
1034 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1035 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1036 return NS_ERROR_NOT_IMPLEMENTED
;
1039 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1041 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1042 WARN("(%p)\n", This
);
1043 return NS_ERROR_NOT_IMPLEMENTED
;
1046 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
1048 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1049 WARN("(%p)->(%p)\n", This
, _retval
);
1050 return NS_ERROR_NOT_IMPLEMENTED
;
1053 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1056 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1057 WARN("(%p)->(%08x)\n", This
, aStatus
);
1058 return NS_ERROR_NOT_IMPLEMENTED
;
1061 #undef NSWBCHROME_THIS
1063 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1064 nsWebBrowserChrome_QueryInterface
,
1065 nsWebBrowserChrome_AddRef
,
1066 nsWebBrowserChrome_Release
,
1067 nsWebBrowserChrome_SetStatus
,
1068 nsWebBrowserChrome_GetWebBrowser
,
1069 nsWebBrowserChrome_SetWebBrowser
,
1070 nsWebBrowserChrome_GetChromeFlags
,
1071 nsWebBrowserChrome_SetChromeFlags
,
1072 nsWebBrowserChrome_DestroyBrowserWindow
,
1073 nsWebBrowserChrome_SizeBrowserTo
,
1074 nsWebBrowserChrome_ShowAsModal
,
1075 nsWebBrowserChrome_IsWindowModal
,
1076 nsWebBrowserChrome_ExitModalEventLoop
1079 /**********************************************************
1080 * nsIContextMenuListener interface
1083 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1085 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1086 nsIIDRef riid
, nsQIResult result
)
1088 NSContainer
*This
= NSCML_THIS(iface
);
1089 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1092 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1094 NSContainer
*This
= NSCML_THIS(iface
);
1095 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1098 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1100 NSContainer
*This
= NSCML_THIS(iface
);
1101 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1104 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1105 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1107 NSContainer
*This
= NSCML_THIS(iface
);
1108 nsIDOMMouseEvent
*event
;
1110 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1113 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1115 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1116 if(NS_FAILED(nsres
)) {
1117 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1121 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1122 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1123 nsIDOMMouseEvent_Release(event
);
1125 switch(aContextFlags
) {
1127 case CONTEXT_DOCUMENT
:
1129 dwID
= CONTEXT_MENU_DEFAULT
;
1132 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1133 dwID
= CONTEXT_MENU_IMAGE
;
1136 dwID
= CONTEXT_MENU_ANCHOR
;
1139 dwID
= CONTEXT_MENU_CONTROL
;
1142 FIXME("aContextFlags=%08x\n", aContextFlags
);
1145 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)HTMLDOMNODE(get_node(This
->doc
, aNode
, TRUE
)));
1152 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1153 nsContextMenuListener_QueryInterface
,
1154 nsContextMenuListener_AddRef
,
1155 nsContextMenuListener_Release
,
1156 nsContextMenuListener_OnShowContextMenu
1159 /**********************************************************
1160 * nsIURIContentListener interface
1163 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1165 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1166 nsIIDRef riid
, nsQIResult result
)
1168 NSContainer
*This
= NSURICL_THIS(iface
);
1169 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1172 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1174 NSContainer
*This
= NSURICL_THIS(iface
);
1175 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1178 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1180 NSContainer
*This
= NSURICL_THIS(iface
);
1181 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1184 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1185 nsIURI
*aURI
, PRBool
*_retval
)
1187 NSContainer
*This
= NSURICL_THIS(iface
);
1188 nsIWineURI
*wine_uri
;
1189 nsACString spec_str
;
1193 nsACString_Init(&spec_str
, NULL
);
1194 nsIURI_GetSpec(aURI
, &spec_str
);
1195 nsACString_GetData(&spec_str
, &spec
);
1197 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1199 nsACString_Finish(&spec_str
);
1201 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsIWineURI
, (void**)&wine_uri
);
1202 if(NS_FAILED(nsres
)) {
1203 WARN("Could not get nsIWineURI interface: %08x\n", nsres
);
1204 return NS_ERROR_NOT_IMPLEMENTED
;
1207 nsIWineURI_SetNSContainer(wine_uri
, This
);
1208 nsIWineURI_SetIsDocumentURI(wine_uri
, TRUE
);
1210 if(This
->bscallback
) {
1211 IMoniker
*mon
= get_channelbsc_mon(This
->bscallback
);
1217 hres
= IMoniker_GetDisplayName(mon
, NULL
, 0, &wine_url
);
1218 if(SUCCEEDED(hres
)) {
1219 nsIWineURI_SetWineURL(wine_uri
, wine_url
);
1220 CoTaskMemFree(wine_url
);
1222 WARN("GetDisplayName failed: %08x\n", hres
);
1225 IMoniker_Release(mon
);
1229 nsIWineURI_Release(wine_uri
);
1232 return This
->content_listener
1233 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1237 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1238 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1239 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1241 NSContainer
*This
= NSURICL_THIS(iface
);
1243 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1244 aRequest
, aContentHandler
, _retval
);
1246 return This
->content_listener
1247 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1248 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1249 : NS_ERROR_NOT_IMPLEMENTED
;
1252 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1253 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1255 NSContainer
*This
= NSURICL_THIS(iface
);
1257 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1259 /* FIXME: Should we do something here? */
1262 return This
->content_listener
1263 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1264 aDesiredContentType
, _retval
)
1268 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1269 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1272 NSContainer
*This
= NSURICL_THIS(iface
);
1274 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1275 aDesiredContentType
, _retval
);
1277 return This
->content_listener
1278 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1279 aIsContentPreferred
, aDesiredContentType
, _retval
)
1280 : NS_ERROR_NOT_IMPLEMENTED
;
1283 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1284 nsISupports
**aLoadCookie
)
1286 NSContainer
*This
= NSURICL_THIS(iface
);
1288 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1290 return This
->content_listener
1291 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1292 : NS_ERROR_NOT_IMPLEMENTED
;
1295 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1296 nsISupports
*aLoadCookie
)
1298 NSContainer
*This
= NSURICL_THIS(iface
);
1300 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1302 return This
->content_listener
1303 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1304 : NS_ERROR_NOT_IMPLEMENTED
;
1307 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1308 nsIURIContentListener
**aParentContentListener
)
1310 NSContainer
*This
= NSURICL_THIS(iface
);
1312 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1314 if(This
->content_listener
)
1315 nsIURIContentListener_AddRef(This
->content_listener
);
1317 *aParentContentListener
= This
->content_listener
;
1321 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1322 nsIURIContentListener
*aParentContentListener
)
1324 NSContainer
*This
= NSURICL_THIS(iface
);
1326 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1328 if(aParentContentListener
== NSURICL(This
))
1331 if(This
->content_listener
)
1332 nsIURIContentListener_Release(This
->content_listener
);
1334 This
->content_listener
= aParentContentListener
;
1335 if(This
->content_listener
)
1336 nsIURIContentListener_AddRef(This
->content_listener
);
1343 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1344 nsURIContentListener_QueryInterface
,
1345 nsURIContentListener_AddRef
,
1346 nsURIContentListener_Release
,
1347 nsURIContentListener_OnStartURIOpen
,
1348 nsURIContentListener_DoContent
,
1349 nsURIContentListener_IsPreferred
,
1350 nsURIContentListener_CanHandleContent
,
1351 nsURIContentListener_GetLoadCookie
,
1352 nsURIContentListener_SetLoadCookie
,
1353 nsURIContentListener_GetParentContentListener
,
1354 nsURIContentListener_SetParentContentListener
1357 /**********************************************************
1358 * nsIEmbeddinSiteWindow interface
1361 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1363 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1364 nsIIDRef riid
, nsQIResult result
)
1366 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1367 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1370 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1372 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1373 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1376 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1378 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1379 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1382 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1383 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1385 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1386 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1387 return NS_ERROR_NOT_IMPLEMENTED
;
1390 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1391 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1393 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1394 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1395 return NS_ERROR_NOT_IMPLEMENTED
;
1398 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1400 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1402 TRACE("(%p)\n", This
);
1404 if(This
->reset_focus
)
1405 PostMessageW(This
->hwnd
, WM_RESETFOCUS_HACK
, 0, 0);
1407 return nsIBaseWindow_SetFocus(This
->window
);
1410 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1411 PRBool
*aVisibility
)
1413 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1415 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1417 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1421 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1424 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1426 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1431 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1434 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1435 WARN("(%p)->(%p)\n", This
, aTitle
);
1436 return NS_ERROR_NOT_IMPLEMENTED
;
1439 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1440 const PRUnichar
*aTitle
)
1442 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1443 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1444 return NS_ERROR_NOT_IMPLEMENTED
;
1447 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1450 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1452 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1454 *aSiteWindow
= This
->hwnd
;
1458 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1459 nsEmbeddingSiteWindow_QueryInterface
,
1460 nsEmbeddingSiteWindow_AddRef
,
1461 nsEmbeddingSiteWindow_Release
,
1462 nsEmbeddingSiteWindow_SetDimensions
,
1463 nsEmbeddingSiteWindow_GetDimensions
,
1464 nsEmbeddingSiteWindow_SetFocus
,
1465 nsEmbeddingSiteWindow_GetVisibility
,
1466 nsEmbeddingSiteWindow_SetVisibility
,
1467 nsEmbeddingSiteWindow_GetTitle
,
1468 nsEmbeddingSiteWindow_SetTitle
,
1469 nsEmbeddingSiteWindow_GetSiteWindow
1472 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1474 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1477 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1478 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1481 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1483 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1484 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1487 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1489 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1490 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1493 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1494 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1496 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1499 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1504 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1506 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1509 hide_tooltip(This
->doc
);
1514 #undef NSTOOLTIM_THIS
1516 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1517 nsTooltipListener_QueryInterface
,
1518 nsTooltipListener_AddRef
,
1519 nsTooltipListener_Release
,
1520 nsTooltipListener_OnShowTooltip
,
1521 nsTooltipListener_OnHideTooltip
1524 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1526 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1527 nsIIDRef riid
, nsQIResult result
)
1529 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1530 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1533 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1535 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1536 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1539 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1541 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1542 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1545 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1546 nsIIDRef riid
, nsQIResult result
)
1548 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1550 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1551 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1552 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1555 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1558 #undef NSIFACEREQ_THIS
1560 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1561 nsInterfaceRequestor_QueryInterface
,
1562 nsInterfaceRequestor_AddRef
,
1563 nsInterfaceRequestor_Release
,
1564 nsInterfaceRequestor_GetInterface
1567 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1569 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1570 nsIIDRef riid
, nsQIResult result
)
1572 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1573 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1576 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1578 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1579 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1582 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1584 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1585 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1588 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1589 const nsIID
*riid
, void **result
)
1591 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1592 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1595 #undef NSWEAKREF_THIS
1597 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1598 nsWeakReference_QueryInterface
,
1599 nsWeakReference_AddRef
,
1600 nsWeakReference_Release
,
1601 nsWeakReference_QueryReferent
1604 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1606 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1607 nsIIDRef riid
, nsQIResult result
)
1609 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1610 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1613 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1615 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1616 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1619 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1621 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1622 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1625 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1626 nsIWeakReference
**_retval
)
1628 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1630 TRACE("(%p)->(%p)\n", This
, _retval
);
1632 nsIWeakReference_AddRef(NSWEAKREF(This
));
1633 *_retval
= NSWEAKREF(This
);
1637 #undef NSWEAKREF_THIS
1639 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1640 nsSupportsWeakReference_QueryInterface
,
1641 nsSupportsWeakReference_AddRef
,
1642 nsSupportsWeakReference_Release
,
1643 nsSupportsWeakReference_GetWeakReference
1647 NSContainer
*NSContainer_Create(HTMLDocument
*doc
, NSContainer
*parent
)
1649 nsIWebBrowserSetup
*wbsetup
;
1650 nsIScrollable
*scrollable
;
1654 if(!load_gecko(FALSE
))
1657 ret
= heap_alloc_zero(sizeof(NSContainer
));
1659 ret
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
1660 ret
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
1661 ret
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
1662 ret
->lpEmbeddingSiteWindowVtbl
= &nsEmbeddingSiteWindowVtbl
;
1663 ret
->lpTooltipListenerVtbl
= &nsTooltipListenerVtbl
;
1664 ret
->lpInterfaceRequestorVtbl
= &nsInterfaceRequestorVtbl
;
1665 ret
->lpWeakReferenceVtbl
= &nsWeakReferenceVtbl
;
1666 ret
->lpSupportsWeakReferenceVtbl
= &nsSupportsWeakReferenceVtbl
;
1672 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1673 NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
1674 if(NS_FAILED(nsres
)) {
1675 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1681 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent
));
1682 ret
->parent
= parent
;
1684 nsres
= nsIWebBrowser_SetContainerWindow(ret
->webbrowser
, NSWBCHROME(ret
));
1685 if(NS_FAILED(nsres
))
1686 ERR("SetContainerWindow failed: %08x\n", nsres
);
1688 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
1689 (void**)&ret
->window
);
1690 if(NS_FAILED(nsres
))
1691 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1693 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserSetup
,
1695 if(NS_SUCCEEDED(nsres
)) {
1696 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1697 nsIWebBrowserSetup_Release(wbsetup
);
1698 if(NS_FAILED(nsres
))
1699 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1701 ERR("Could not get nsIWebBrowserSetup interface\n");
1704 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
1705 (void**)&ret
->navigation
);
1706 if(NS_FAILED(nsres
))
1707 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1709 nsres
= nsIWebBrowserFocus_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserFocus
,
1710 (void**)&ret
->focus
);
1711 if(NS_FAILED(nsres
))
1712 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1714 if(!nscontainer_class
)
1715 register_nscontainer_class();
1717 ret
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1718 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1719 GetDesktopWindow(), NULL
, hInst
, ret
);
1721 nsres
= nsIBaseWindow_InitWindow(ret
->window
, ret
->hwnd
, NULL
, 0, 0, 100, 100);
1722 if(NS_SUCCEEDED(nsres
)) {
1723 nsres
= nsIBaseWindow_Create(ret
->window
);
1724 if(NS_FAILED(nsres
))
1725 WARN("Creating window failed: %08x\n", nsres
);
1727 nsIBaseWindow_SetVisibility(ret
->window
, FALSE
);
1728 nsIBaseWindow_SetEnabled(ret
->window
, FALSE
);
1730 ERR("InitWindow failed: %08x\n", nsres
);
1733 nsres
= nsIWebBrowser_SetParentURIContentListener(ret
->webbrowser
, NSURICL(ret
));
1734 if(NS_FAILED(nsres
))
1735 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1739 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1740 if(NS_SUCCEEDED(nsres
)) {
1741 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1742 ScrollOrientation_Y
, Scrollbar_Always
);
1743 if(NS_FAILED(nsres
))
1744 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1746 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1747 ScrollOrientation_X
, Scrollbar_Auto
);
1748 if(NS_FAILED(nsres
))
1749 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1751 nsIScrollable_Release(scrollable
);
1753 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1759 void NSContainer_Release(NSContainer
*This
)
1761 TRACE("(%p)\n", This
);
1765 ShowWindow(This
->hwnd
, SW_HIDE
);
1766 SetParent(This
->hwnd
, NULL
);
1768 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1769 nsIBaseWindow_Destroy(This
->window
);
1771 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1773 nsIWebBrowser_Release(This
->webbrowser
);
1774 This
->webbrowser
= NULL
;
1776 nsIWebNavigation_Release(This
->navigation
);
1777 This
->navigation
= NULL
;
1779 nsIBaseWindow_Release(This
->window
);
1780 This
->window
= NULL
;
1782 nsIWebBrowserFocus_Release(This
->focus
);
1785 if(This
->editor_controller
) {
1786 nsIController_Release(This
->editor_controller
);
1787 This
->editor_controller
= NULL
;
1791 nsIEditor_Release(This
->editor
);
1792 This
->editor
= NULL
;
1795 if(This
->content_listener
) {
1796 nsIURIContentListener_Release(This
->content_listener
);
1797 This
->content_listener
= NULL
;
1801 DestroyWindow(This
->hwnd
);
1805 nsIWebBrowserChrome_Release(NSWBCHROME(This
));