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"
46 #define NS_ARRAY_CONTRACTID "@mozilla.org/array;1"
47 #define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
48 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
50 #define APPSTARTUP_TOPIC "app-startup"
52 #define PR_UINT32_MAX 0xffffffff
54 struct nsCStringContainer
{
61 static nsresult (*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
62 static nsresult (*NS_ShutdownXPCOM
)(nsIServiceManager
*);
63 static nsresult (*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
64 static nsresult (*NS_StringContainerInit
)(nsStringContainer
*);
65 static nsresult (*NS_CStringContainerInit
)(nsCStringContainer
*);
66 static nsresult (*NS_StringContainerFinish
)(nsStringContainer
*);
67 static nsresult (*NS_CStringContainerFinish
)(nsCStringContainer
*);
68 static nsresult (*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
69 static nsresult (*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
70 static nsresult (*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
71 static PRUint32 (*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
72 static PRUint32 (*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
74 static HINSTANCE hXPCOM
= NULL
;
76 static nsIServiceManager
*pServMgr
= NULL
;
77 static nsIComponentManager
*pCompMgr
= NULL
;
78 static nsIMemory
*nsmem
= NULL
;
80 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
82 static ATOM nscontainer_class
;
84 #define WM_RESETFOCUS_HACK WM_USER+600
86 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
91 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
93 if(msg
== WM_CREATE
) {
94 This
= *(NSContainer
**)lParam
;
95 SetPropW(hwnd
, wszTHIS
, This
);
97 This
= (NSContainer
*)GetPropW(hwnd
, wszTHIS
);
102 TRACE("(%p)->(WM_SIZE)\n", This
);
104 nsres
= nsIBaseWindow_SetSize(This
->window
,
105 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
107 WARN("SetSize failed: %08x\n", nsres
);
110 case WM_RESETFOCUS_HACK
:
113 * Gecko grabs focus in edit mode and some apps don't like it.
114 * We should somehow prevent grabbing focus.
117 TRACE("WM_RESETFOCUS_HACK\n");
119 if(This
->reset_focus
) {
120 SetFocus(This
->reset_focus
);
121 This
->reset_focus
= NULL
;
123 This
->doc
->focus
= FALSE
;
127 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
131 static void register_nscontainer_class(void)
133 static WNDCLASSEXW wndclass
= {
137 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
141 wndclass
.hInstance
= hInst
;
142 nscontainer_class
= RegisterClassExW(&wndclass
);
145 static BOOL
load_xpcom(const PRUnichar
*gre_path
)
147 WCHAR path_env
[MAX_PATH
];
150 static const WCHAR wszPATH
[] = {'P','A','T','H',0};
151 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
153 TRACE("(%s)\n", debugstr_w(gre_path
));
155 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
156 GetEnvironmentVariableW(wszPATH
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
157 len
= strlenW(path_env
);
158 path_env
[len
++] = ';';
159 strcpyW(path_env
+len
, gre_path
);
160 SetEnvironmentVariableW(wszPATH
, path_env
);
162 hXPCOM
= LoadLibraryW(strXPCOM
);
164 WARN("Could not load XPCOM: %d\n", GetLastError());
168 #define NS_DLSYM(func) \
169 func = (void *)GetProcAddress(hXPCOM, #func); \
171 ERR("Could not GetProcAddress(" #func ") failed\n")
173 NS_DLSYM(NS_InitXPCOM2
);
174 NS_DLSYM(NS_ShutdownXPCOM
);
175 NS_DLSYM(NS_GetComponentRegistrar
);
176 NS_DLSYM(NS_StringContainerInit
);
177 NS_DLSYM(NS_CStringContainerInit
);
178 NS_DLSYM(NS_StringContainerFinish
);
179 NS_DLSYM(NS_CStringContainerFinish
);
180 NS_DLSYM(NS_StringSetData
);
181 NS_DLSYM(NS_CStringSetData
);
182 NS_DLSYM(NS_NewLocalFile
);
183 NS_DLSYM(NS_StringGetData
);
184 NS_DLSYM(NS_CStringGetData
);
191 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
193 WCHAR file_name
[MAX_PATH
];
198 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
200 strcpyW(file_name
, gre_path
);
201 strcatW(file_name
, wszVersion
);
203 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
204 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
205 if(hfile
== INVALID_HANDLE_VALUE
) {
206 ERR("Could not open VERSION file\n");
210 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
214 TRACE("%s\n", debugstr_a(version
));
216 if(strcmp(version
, version_string
)) {
217 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
218 debugstr_a(version_string
));
225 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
226 const char *version
, const char *version_string
)
228 DWORD res
, type
, size
= MAX_PATH
;
229 HKEY hkey
= mshtml_key
;
231 static const WCHAR wszGeckoPath
[] =
232 {'G','e','c','k','o','P','a','t','h',0};
235 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
236 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
237 if(res
!= ERROR_SUCCESS
)
241 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
242 if(hkey
!= mshtml_key
)
244 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
247 if(!check_version(gre_path
, version_string
))
250 return load_xpcom(gre_path
);
253 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
259 static const WCHAR wszMshtmlKey
[] = {
260 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
261 '\\','M','S','H','T','M','L',0};
263 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
264 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszMshtmlKey
, &hkey
);
265 if(res
!= ERROR_SUCCESS
)
268 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
274 static void set_lang(nsIPrefBranch
*pref
)
277 DWORD res
, size
, type
;
281 static const WCHAR international_keyW
[] =
282 {'S','o','f','t','w','a','r','e',
283 '\\','M','i','c','r','o','s','o','f','t',
284 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
285 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
287 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
288 if(res
!= ERROR_SUCCESS
)
291 size
= sizeof(langs
);
292 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
294 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
297 TRACE("Setting lang %s\n", debugstr_a(langs
));
299 nsres
= nsIPrefBranch_SetCharPref(pref
, "intl.accept_languages", langs
);
301 ERR("SetCharPref failed: %08x\n", nsres
);
304 static void set_proxy(nsIPrefBranch
*pref
)
309 DWORD enabled
= 0, res
, size
, type
;
313 static const WCHAR proxy_keyW
[] =
314 {'S','o','f','t','w','a','r','e',
315 '\\','M','i','c','r','o','s','o','f','t',
316 '\\','W','i','n','d','o','w','s',
317 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
318 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
320 res
= RegOpenKeyW(HKEY_CURRENT_USER
, proxy_keyW
, &hkey
);
321 if(res
!= ERROR_SUCCESS
)
324 size
= sizeof(enabled
);
325 res
= RegQueryValueExA(hkey
, "ProxyEnable", 0, &type
, (LPBYTE
)&enabled
, &size
);
326 if(res
!= ERROR_SUCCESS
|| type
!= REG_DWORD
|| enabled
== 0)
332 size
= sizeof(proxy
);
333 res
= RegQueryValueExA(hkey
, "ProxyServer", 0, &type
, (LPBYTE
)proxy
, &size
);
335 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
338 proxy_port
= strchr(proxy
, ':');
343 proxy_port_num
= atoi(proxy_port
+ 1);
344 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy
), proxy_port_num
);
346 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.type", 1);
348 ERR("SetIntPref network.proxy.type failed: %08x\n", nsres
);
349 nsres
= nsIPrefBranch_SetCharPref(pref
, "network.proxy.http", proxy
);
351 ERR("SetCharPref network.proxy.http failed: %08x\n", nsres
);
352 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.http_port", proxy_port_num
);
354 ERR("SetIntPref network.proxy.http_port failed: %08x\n", nsres
);
355 nsres
= nsIPrefBranch_SetCharPref(pref
, "network.proxy.ssl", proxy
);
357 ERR("SetCharPref network.proxy.ssl failed: %08x\n", nsres
);
358 nsres
= nsIPrefBranch_SetIntPref(pref
, "network.proxy.ssl_port", proxy_port_num
);
360 ERR("SetIntPref network.proxy.ssl_port failed: %08x\n", nsres
);
363 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
367 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
369 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
372 static void set_profile(void)
376 PRBool exists
= FALSE
;
379 static const WCHAR wszMSHTML
[] = {'M','S','H','T','M','L',0};
381 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PROFILE_CONTRACTID
,
382 &IID_nsIProfile
, (void**)&profile
);
383 if(NS_FAILED(nsres
)) {
384 ERR("Could not get profile service: %08x\n", nsres
);
388 nsres
= nsIProfile_ProfileExists(profile
, wszMSHTML
, &exists
);
390 nsres
= nsIProfile_CreateNewProfile(profile
, wszMSHTML
, NULL
, NULL
, FALSE
);
392 ERR("CreateNewProfile failed: %08x\n", nsres
);
395 nsres
= nsIProfile_SetCurrentProfile(profile
, wszMSHTML
);
397 ERR("SetCurrentProfile failed: %08x\n", nsres
);
399 nsIProfile_Release(profile
);
401 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
402 &IID_nsIPrefBranch
, (void**)&pref
);
403 if(NS_FAILED(nsres
)) {
404 ERR("Could not get preference service: %08x\n", nsres
);
410 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
411 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
413 nsIPrefBranch_Release(pref
);
416 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
419 nsIObserver
*pStartNotif
;
420 nsIComponentRegistrar
*registrar
= NULL
;
424 nsAString_Init(&path
, gre_path
);
425 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
426 nsAString_Finish(&path
);
427 if(NS_FAILED(nsres
)) {
428 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
433 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
434 if(NS_FAILED(nsres
)) {
435 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
440 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
442 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
444 nsres
= NS_GetComponentRegistrar(®istrar
);
445 if(NS_SUCCEEDED(nsres
)) {
446 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, NULL
);
448 ERR("AutoRegister(NULL) failed: %08x\n", nsres
);
450 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, gre_dir
);
452 ERR("AutoRegister(gre_dir) failed: %08x\n", nsres
);
454 init_nsio(pCompMgr
, registrar
);
456 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
459 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
460 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
461 if(NS_SUCCEEDED(nsres
)) {
462 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
464 ERR("Observe failed: %08x\n", nsres
);
466 nsIObserver_Release(pStartNotif
);
468 ERR("could not get appstartup-notifier: %08x\n", nsres
);
473 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
474 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
476 ERR("Could not get nsIMemory: %08x\n", nsres
);
479 register_nsservice(registrar
, pServMgr
);
480 nsIComponentRegistrar_Release(registrar
);
486 static CRITICAL_SECTION cs_load_gecko
;
487 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
489 0, 0, &cs_load_gecko
,
490 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
491 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
493 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
495 BOOL
load_gecko(BOOL silent
)
497 PRUnichar gre_path
[MAX_PATH
];
500 static LONG loading_thread
;
504 /* load_gecko may be called recursively */
505 if(loading_thread
== GetCurrentThreadId())
506 return pCompMgr
!= NULL
;
508 EnterCriticalSection(&cs_load_gecko
);
510 if(!loading_thread
) {
511 loading_thread
= GetCurrentThreadId();
513 if(load_wine_gecko(gre_path
)
514 || (install_wine_gecko(silent
) && load_wine_gecko(gre_path
)))
515 ret
= init_xpcom(gre_path
);
517 MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
519 ret
= pCompMgr
!= NULL
;
522 LeaveCriticalSection(&cs_load_gecko
);
527 void *nsalloc(size_t size
)
529 return nsIMemory_Alloc(nsmem
, size
);
532 void nsfree(void *mem
)
534 nsIMemory_Free(nsmem
, mem
);
537 void nsACString_Init(nsACString
*str
, const char *data
)
539 NS_CStringContainerInit(str
);
541 nsACString_SetData(str
, data
);
544 void nsACString_SetData(nsACString
*str
, const char *data
)
546 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
549 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
551 return NS_CStringGetData(str
, data
, NULL
);
554 void nsACString_Finish(nsACString
*str
)
556 NS_CStringContainerFinish(str
);
559 void nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
561 NS_StringContainerInit(str
);
563 nsAString_SetData(str
, data
);
566 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
568 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
571 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
573 return NS_StringGetData(str
, data
, NULL
);
576 void nsAString_Finish(nsAString
*str
)
578 NS_StringContainerFinish(str
);
581 nsIInputStream
*create_nsstream(const char *data
, PRInt32 data_len
)
583 nsIStringInputStream
*ret
;
589 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
590 NS_STRINGSTREAM_CONTRACTID
, NULL
, &IID_nsIStringInputStream
,
592 if(NS_FAILED(nsres
)) {
593 ERR("Could not get nsIStringInputStream\n");
597 nsres
= nsIStringInputStream_SetData(ret
, data
, data_len
);
598 if(NS_FAILED(nsres
)) {
599 ERR("AdoptData failed: %08x\n", nsres
);
600 nsIStringInputStream_Release(ret
);
604 return (nsIInputStream
*)ret
;
607 nsIMutableArray
*create_nsarray(void)
609 nsIMutableArray
*ret
;
615 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
616 NS_ARRAY_CONTRACTID
, NULL
, &IID_nsIMutableArray
,
618 if(NS_FAILED(nsres
)) {
619 ERR("Could not get nsIArray: %08x\n", nsres
);
626 nsIWritableVariant
*create_nsvariant(void)
628 nsIWritableVariant
*ret
;
634 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
635 NS_VARIANT_CONTRACTID
, NULL
, &IID_nsIWritableVariant
,
637 if(NS_FAILED(nsres
)) {
638 ERR("Could not get nsIWritableVariant: %08x\n", nsres
);
645 nsICommandParams
*create_nscommand_params(void)
647 nsICommandParams
*ret
= NULL
;
653 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
654 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
657 ERR("Could not get nsICommandParams\n");
662 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
664 nsIInterfaceRequestor
*iface_req
;
667 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
671 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
672 nsIInterfaceRequestor_Release(iface_req
);
677 static void nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
679 nsIDOMNodeList
*node_list
= NULL
;
680 PRBool has_children
= FALSE
;
684 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
686 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
687 if(NS_FAILED(nsres
)) {
688 ERR("GetType failed: %08x\n", nsres
);
694 nsIDOMElement
*nselem
;
695 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
696 nsIContentSerializer_AppendElementStart(serializer
, nselem
, has_children
, str
);
697 nsIDOMElement_Release(nselem
);
702 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&nstext
);
703 nsIContentSerializer_AppendText(serializer
, nstext
, 0, -1, str
);
704 nsIDOMText_Release(nstext
);
708 nsIDOMComment
*nscomment
;
709 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMComment
, (void**)&nscomment
);
710 nsres
= nsIContentSerializer_AppendComment(serializer
, nscomment
, 0, -1, str
);
713 case DOCUMENT_NODE
: {
714 nsIDOMDocument
*nsdoc
;
715 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMDocument
, (void**)&nsdoc
);
716 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
717 nsIDOMDocument_Release(nsdoc
);
720 case DOCUMENT_FRAGMENT_NODE
:
723 FIXME("Unhandled type %u\n", type
);
727 PRUint32 child_cnt
, i
;
728 nsIDOMNode
*child_node
;
730 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
731 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
733 for(i
=0; i
<child_cnt
; i
++) {
734 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
735 if(NS_SUCCEEDED(nsres
)) {
736 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
737 nsIDOMNode_Release(child_node
);
739 ERR("Item failed: %08x\n", nsres
);
743 nsIDOMNodeList_Release(node_list
);
746 if(type
== ELEMENT_NODE
) {
747 nsIDOMElement
*nselem
;
748 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
749 nsIContentSerializer_AppendElementEnd(serializer
, nselem
, str
);
750 nsIDOMElement_Release(nselem
);
754 void nsnode_to_nsstring(nsIDOMNode
*nsdoc
, nsAString
*str
)
756 nsIContentSerializer
*serializer
;
760 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
761 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
762 (void**)&serializer
);
763 if(NS_FAILED(nsres
)) {
764 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
768 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
);
770 ERR("Init failed: %08x\n", nsres
);
772 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMNode
, (void**)&nsnode
);
773 nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
774 nsIDOMNode_Release(nsnode
);
776 nsres
= nsIContentSerializer_Flush(serializer
, str
);
778 ERR("Flush failed: %08x\n", nsres
);
780 nsIContentSerializer_Release(serializer
);
783 void get_editor_controller(NSContainer
*This
)
785 nsIEditingSession
*editing_session
= NULL
;
786 nsIControllerContext
*ctrlctx
;
790 nsIEditor_Release(This
->editor
);
794 if(This
->editor_controller
) {
795 nsIController_Release(This
->editor_controller
);
796 This
->editor_controller
= NULL
;
799 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
800 (void**)&editing_session
);
801 if(NS_FAILED(nsres
)) {
802 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
806 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
807 This
->doc
->window
->nswindow
, &This
->editor
);
808 nsIEditingSession_Release(editing_session
);
809 if(NS_FAILED(nsres
)) {
810 ERR("Could not get editor: %08x\n", nsres
);
814 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
815 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
816 if(NS_SUCCEEDED(nsres
)) {
817 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
819 ERR("SetCommandContext failed: %08x\n", nsres
);
820 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
821 (void**)&This
->editor_controller
);
822 nsIControllerContext_Release(ctrlctx
);
824 ERR("Could not get nsIController interface: %08x\n", nsres
);
826 ERR("Could not create edit controller: %08x\n", nsres
);
830 void set_ns_editmode(NSContainer
*This
)
832 nsIEditingSession
*editing_session
= NULL
;
833 nsIURIContentListener
*listener
= NULL
;
834 nsIDOMWindow
*dom_window
= NULL
;
837 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
838 (void**)&editing_session
);
839 if(NS_FAILED(nsres
)) {
840 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
844 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, &dom_window
);
845 if(NS_FAILED(nsres
)) {
846 ERR("Could not get content DOM window: %08x\n", nsres
);
847 nsIEditingSession_Release(editing_session
);
851 nsres
= nsIEditingSession_MakeWindowEditable(editing_session
, dom_window
, NULL
, FALSE
);
852 nsIEditingSession_Release(editing_session
);
853 nsIDOMWindow_Release(dom_window
);
854 if(NS_FAILED(nsres
)) {
855 ERR("MakeWindowEditable failed: %08x\n", nsres
);
859 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
860 * It seams to be a bug in Gecko. To workaround it we set our content
861 * listener again and Gecko's one as its parent.
863 nsIWebBrowser_GetParentURIContentListener(This
->webbrowser
, &listener
);
864 nsIURIContentListener_SetParentContentListener(NSURICL(This
), listener
);
865 nsIURIContentListener_Release(listener
);
866 nsIWebBrowser_SetParentURIContentListener(This
->webbrowser
, NSURICL(This
));
869 void update_nsdocument(HTMLDocument
*doc
)
871 nsIDOMHTMLDocument
*nsdoc
;
872 nsIDOMDocument
*nsdomdoc
;
875 if(!doc
->nscontainer
|| !doc
->nscontainer
->navigation
)
878 nsres
= nsIWebNavigation_GetDocument(doc
->nscontainer
->navigation
, &nsdomdoc
);
879 if(NS_FAILED(nsres
) || !nsdomdoc
) {
880 ERR("GetDocument failed: %08x\n", nsres
);
884 nsres
= nsIDOMDocument_QueryInterface(nsdomdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nsdoc
);
885 nsIDOMDocument_Release(nsdomdoc
);
886 if(NS_FAILED(nsres
)) {
887 ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres
);
891 if(nsdoc
== doc
->nsdoc
) {
892 nsIDOMHTMLDocument_Release(nsdoc
);
897 nsIDOMHTMLDocument_Release(doc
->nsdoc
);
902 void close_gecko(void)
907 nsIComponentManager_Release(pCompMgr
);
910 nsIServiceManager_Release(pServMgr
);
913 nsIMemory_Release(nsmem
);
919 /**********************************************************
920 * nsIWebBrowserChrome interface
923 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
925 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
926 nsIIDRef riid
, nsQIResult result
)
928 NSContainer
*This
= NSWBCHROME_THIS(iface
);
931 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
932 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
933 *result
= NSWBCHROME(This
);
934 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
935 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
936 *result
= NSWBCHROME(This
);
937 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
938 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
939 *result
= NSCML(This
);
940 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
941 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
942 *result
= NSURICL(This
);
943 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
944 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
945 *result
= NSEMBWNDS(This
);
946 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
947 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
948 *result
= NSTOOLTIP(This
);
949 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
950 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
951 *result
= NSIFACEREQ(This
);
952 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
953 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
954 *result
= NSWEAKREF(This
);
955 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
956 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
957 *result
= NSSUPWEAKREF(This
);
961 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
965 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
966 return NS_NOINTERFACE
;
969 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
971 NSContainer
*This
= NSWBCHROME_THIS(iface
);
972 LONG ref
= InterlockedIncrement(&This
->ref
);
974 TRACE("(%p) ref=%d\n", This
, ref
);
979 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
981 NSContainer
*This
= NSWBCHROME_THIS(iface
);
982 LONG ref
= InterlockedDecrement(&This
->ref
);
984 TRACE("(%p) ref=%d\n", This
, ref
);
988 nsIWebBrowserChrome_Release(NSWBCHROME(This
->parent
));
995 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
996 PRUint32 statusType
, const PRUnichar
*status
)
998 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1000 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
1002 /* FIXME: This hack should be removed when we'll load all pages by URLMoniker */
1004 update_nsdocument(This
->doc
);
1009 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
1010 nsIWebBrowser
**aWebBrowser
)
1012 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1014 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1017 return NS_ERROR_INVALID_ARG
;
1019 if(This
->webbrowser
)
1020 nsIWebBrowser_AddRef(This
->webbrowser
);
1021 *aWebBrowser
= This
->webbrowser
;
1025 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
1026 nsIWebBrowser
*aWebBrowser
)
1028 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1030 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
1032 if(aWebBrowser
!= This
->webbrowser
)
1033 ERR("Wrong nsWebBrowser!\n");
1038 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
1039 PRUint32
*aChromeFlags
)
1041 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1042 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
1043 return NS_ERROR_NOT_IMPLEMENTED
;
1046 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
1047 PRUint32 aChromeFlags
)
1049 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1050 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
1051 return NS_ERROR_NOT_IMPLEMENTED
;
1054 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
1056 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1057 TRACE("(%p)\n", This
);
1058 return NS_ERROR_NOT_IMPLEMENTED
;
1061 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
1062 PRInt32 aCX
, PRInt32 aCY
)
1064 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1065 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
1066 return NS_ERROR_NOT_IMPLEMENTED
;
1069 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
1071 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1072 WARN("(%p)\n", This
);
1073 return NS_ERROR_NOT_IMPLEMENTED
;
1076 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
1078 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1079 WARN("(%p)->(%p)\n", This
, _retval
);
1080 return NS_ERROR_NOT_IMPLEMENTED
;
1083 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
1086 NSContainer
*This
= NSWBCHROME_THIS(iface
);
1087 WARN("(%p)->(%08x)\n", This
, aStatus
);
1088 return NS_ERROR_NOT_IMPLEMENTED
;
1091 #undef NSWBCHROME_THIS
1093 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
1094 nsWebBrowserChrome_QueryInterface
,
1095 nsWebBrowserChrome_AddRef
,
1096 nsWebBrowserChrome_Release
,
1097 nsWebBrowserChrome_SetStatus
,
1098 nsWebBrowserChrome_GetWebBrowser
,
1099 nsWebBrowserChrome_SetWebBrowser
,
1100 nsWebBrowserChrome_GetChromeFlags
,
1101 nsWebBrowserChrome_SetChromeFlags
,
1102 nsWebBrowserChrome_DestroyBrowserWindow
,
1103 nsWebBrowserChrome_SizeBrowserTo
,
1104 nsWebBrowserChrome_ShowAsModal
,
1105 nsWebBrowserChrome_IsWindowModal
,
1106 nsWebBrowserChrome_ExitModalEventLoop
1109 /**********************************************************
1110 * nsIContextMenuListener interface
1113 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1115 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1116 nsIIDRef riid
, nsQIResult result
)
1118 NSContainer
*This
= NSCML_THIS(iface
);
1119 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1122 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1124 NSContainer
*This
= NSCML_THIS(iface
);
1125 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1128 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1130 NSContainer
*This
= NSCML_THIS(iface
);
1131 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1134 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1135 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1137 NSContainer
*This
= NSCML_THIS(iface
);
1138 nsIDOMMouseEvent
*event
;
1140 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1143 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1145 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1146 if(NS_FAILED(nsres
)) {
1147 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1151 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1152 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1153 nsIDOMMouseEvent_Release(event
);
1155 switch(aContextFlags
) {
1157 case CONTEXT_DOCUMENT
:
1159 dwID
= CONTEXT_MENU_DEFAULT
;
1162 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1163 dwID
= CONTEXT_MENU_IMAGE
;
1166 dwID
= CONTEXT_MENU_ANCHOR
;
1169 dwID
= CONTEXT_MENU_CONTROL
;
1172 FIXME("aContextFlags=%08x\n", aContextFlags
);
1175 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)HTMLDOMNODE(get_node(This
->doc
, aNode
, TRUE
)));
1182 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1183 nsContextMenuListener_QueryInterface
,
1184 nsContextMenuListener_AddRef
,
1185 nsContextMenuListener_Release
,
1186 nsContextMenuListener_OnShowContextMenu
1189 /**********************************************************
1190 * nsIURIContentListener interface
1193 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1195 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1196 nsIIDRef riid
, nsQIResult result
)
1198 NSContainer
*This
= NSURICL_THIS(iface
);
1199 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1202 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1204 NSContainer
*This
= NSURICL_THIS(iface
);
1205 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1208 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1210 NSContainer
*This
= NSURICL_THIS(iface
);
1211 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1214 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1215 nsIURI
*aURI
, PRBool
*_retval
)
1217 NSContainer
*This
= NSURICL_THIS(iface
);
1218 nsIWineURI
*wine_uri
;
1219 nsACString spec_str
;
1223 nsACString_Init(&spec_str
, NULL
);
1224 nsIURI_GetSpec(aURI
, &spec_str
);
1225 nsACString_GetData(&spec_str
, &spec
);
1227 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1229 nsACString_Finish(&spec_str
);
1231 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsIWineURI
, (void**)&wine_uri
);
1232 if(NS_FAILED(nsres
)) {
1233 WARN("Could not get nsIWineURI interface: %08x\n", nsres
);
1234 return NS_ERROR_NOT_IMPLEMENTED
;
1237 nsIWineURI_SetNSContainer(wine_uri
, This
);
1238 nsIWineURI_SetIsDocumentURI(wine_uri
, TRUE
);
1240 if(This
->bscallback
) {
1241 IMoniker
*mon
= get_channelbsc_mon(This
->bscallback
);
1247 hres
= IMoniker_GetDisplayName(mon
, NULL
, 0, &wine_url
);
1248 if(SUCCEEDED(hres
)) {
1249 nsIWineURI_SetWineURL(wine_uri
, wine_url
);
1250 CoTaskMemFree(wine_url
);
1252 WARN("GetDisplayName failed: %08x\n", hres
);
1255 IMoniker_Release(mon
);
1259 nsIWineURI_Release(wine_uri
);
1262 return This
->content_listener
1263 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1267 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1268 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1269 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1271 NSContainer
*This
= NSURICL_THIS(iface
);
1273 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1274 aRequest
, aContentHandler
, _retval
);
1276 return This
->content_listener
1277 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1278 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1279 : NS_ERROR_NOT_IMPLEMENTED
;
1282 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1283 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1285 NSContainer
*This
= NSURICL_THIS(iface
);
1287 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1289 /* FIXME: Should we do something here? */
1292 return This
->content_listener
1293 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1294 aDesiredContentType
, _retval
)
1298 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1299 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1302 NSContainer
*This
= NSURICL_THIS(iface
);
1304 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1305 aDesiredContentType
, _retval
);
1307 return This
->content_listener
1308 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1309 aIsContentPreferred
, aDesiredContentType
, _retval
)
1310 : NS_ERROR_NOT_IMPLEMENTED
;
1313 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1314 nsISupports
**aLoadCookie
)
1316 NSContainer
*This
= NSURICL_THIS(iface
);
1318 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1320 return This
->content_listener
1321 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1322 : NS_ERROR_NOT_IMPLEMENTED
;
1325 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1326 nsISupports
*aLoadCookie
)
1328 NSContainer
*This
= NSURICL_THIS(iface
);
1330 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1332 return This
->content_listener
1333 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1334 : NS_ERROR_NOT_IMPLEMENTED
;
1337 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1338 nsIURIContentListener
**aParentContentListener
)
1340 NSContainer
*This
= NSURICL_THIS(iface
);
1342 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1344 if(This
->content_listener
)
1345 nsIURIContentListener_AddRef(This
->content_listener
);
1347 *aParentContentListener
= This
->content_listener
;
1351 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1352 nsIURIContentListener
*aParentContentListener
)
1354 NSContainer
*This
= NSURICL_THIS(iface
);
1356 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1358 if(aParentContentListener
== NSURICL(This
))
1361 if(This
->content_listener
)
1362 nsIURIContentListener_Release(This
->content_listener
);
1364 This
->content_listener
= aParentContentListener
;
1365 if(This
->content_listener
)
1366 nsIURIContentListener_AddRef(This
->content_listener
);
1373 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1374 nsURIContentListener_QueryInterface
,
1375 nsURIContentListener_AddRef
,
1376 nsURIContentListener_Release
,
1377 nsURIContentListener_OnStartURIOpen
,
1378 nsURIContentListener_DoContent
,
1379 nsURIContentListener_IsPreferred
,
1380 nsURIContentListener_CanHandleContent
,
1381 nsURIContentListener_GetLoadCookie
,
1382 nsURIContentListener_SetLoadCookie
,
1383 nsURIContentListener_GetParentContentListener
,
1384 nsURIContentListener_SetParentContentListener
1387 /**********************************************************
1388 * nsIEmbeddinSiteWindow interface
1391 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1393 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1394 nsIIDRef riid
, nsQIResult result
)
1396 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1397 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1400 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1402 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1403 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1406 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1408 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1409 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1412 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1413 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1415 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1416 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1417 return NS_ERROR_NOT_IMPLEMENTED
;
1420 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1421 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1423 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1424 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1425 return NS_ERROR_NOT_IMPLEMENTED
;
1428 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1430 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1432 TRACE("(%p)\n", This
);
1434 if(This
->reset_focus
)
1435 PostMessageW(This
->hwnd
, WM_RESETFOCUS_HACK
, 0, 0);
1437 return nsIBaseWindow_SetFocus(This
->window
);
1440 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1441 PRBool
*aVisibility
)
1443 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1445 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1447 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1451 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1454 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1456 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1461 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1464 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1465 WARN("(%p)->(%p)\n", This
, aTitle
);
1466 return NS_ERROR_NOT_IMPLEMENTED
;
1469 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1470 const PRUnichar
*aTitle
)
1472 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1473 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1474 return NS_ERROR_NOT_IMPLEMENTED
;
1477 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1480 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1482 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1484 *aSiteWindow
= This
->hwnd
;
1488 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1489 nsEmbeddingSiteWindow_QueryInterface
,
1490 nsEmbeddingSiteWindow_AddRef
,
1491 nsEmbeddingSiteWindow_Release
,
1492 nsEmbeddingSiteWindow_SetDimensions
,
1493 nsEmbeddingSiteWindow_GetDimensions
,
1494 nsEmbeddingSiteWindow_SetFocus
,
1495 nsEmbeddingSiteWindow_GetVisibility
,
1496 nsEmbeddingSiteWindow_SetVisibility
,
1497 nsEmbeddingSiteWindow_GetTitle
,
1498 nsEmbeddingSiteWindow_SetTitle
,
1499 nsEmbeddingSiteWindow_GetSiteWindow
1502 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1504 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1507 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1508 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1511 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1513 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1514 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1517 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1519 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1520 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1523 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1524 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1526 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1528 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1533 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1535 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1537 hide_tooltip(This
->doc
);
1542 #undef NSTOOLTIM_THIS
1544 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1545 nsTooltipListener_QueryInterface
,
1546 nsTooltipListener_AddRef
,
1547 nsTooltipListener_Release
,
1548 nsTooltipListener_OnShowTooltip
,
1549 nsTooltipListener_OnHideTooltip
1552 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1554 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1555 nsIIDRef riid
, nsQIResult result
)
1557 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1558 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1561 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1563 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1564 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1567 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1569 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1570 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1573 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1574 nsIIDRef riid
, nsQIResult result
)
1576 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1578 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1579 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1580 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1583 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1586 #undef NSIFACEREQ_THIS
1588 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1589 nsInterfaceRequestor_QueryInterface
,
1590 nsInterfaceRequestor_AddRef
,
1591 nsInterfaceRequestor_Release
,
1592 nsInterfaceRequestor_GetInterface
1595 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1597 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1598 nsIIDRef riid
, nsQIResult result
)
1600 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1601 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1604 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1606 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1607 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1610 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1612 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1613 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1616 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1617 const nsIID
*riid
, void **result
)
1619 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1620 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1623 #undef NSWEAKREF_THIS
1625 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1626 nsWeakReference_QueryInterface
,
1627 nsWeakReference_AddRef
,
1628 nsWeakReference_Release
,
1629 nsWeakReference_QueryReferent
1632 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1634 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1635 nsIIDRef riid
, nsQIResult result
)
1637 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1638 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1641 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1643 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1644 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1647 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1649 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1650 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1653 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1654 nsIWeakReference
**_retval
)
1656 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1658 TRACE("(%p)->(%p)\n", This
, _retval
);
1660 nsIWeakReference_AddRef(NSWEAKREF(This
));
1661 *_retval
= NSWEAKREF(This
);
1665 #undef NSWEAKREF_THIS
1667 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1668 nsSupportsWeakReference_QueryInterface
,
1669 nsSupportsWeakReference_AddRef
,
1670 nsSupportsWeakReference_Release
,
1671 nsSupportsWeakReference_GetWeakReference
1675 NSContainer
*NSContainer_Create(HTMLDocument
*doc
, NSContainer
*parent
)
1677 nsIWebBrowserSetup
*wbsetup
;
1678 nsIScrollable
*scrollable
;
1682 if(!load_gecko(FALSE
))
1685 ret
= heap_alloc_zero(sizeof(NSContainer
));
1687 ret
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
1688 ret
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
1689 ret
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
1690 ret
->lpEmbeddingSiteWindowVtbl
= &nsEmbeddingSiteWindowVtbl
;
1691 ret
->lpTooltipListenerVtbl
= &nsTooltipListenerVtbl
;
1692 ret
->lpInterfaceRequestorVtbl
= &nsInterfaceRequestorVtbl
;
1693 ret
->lpWeakReferenceVtbl
= &nsWeakReferenceVtbl
;
1694 ret
->lpSupportsWeakReferenceVtbl
= &nsSupportsWeakReferenceVtbl
;
1699 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1700 NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
1701 if(NS_FAILED(nsres
)) {
1702 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1708 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent
));
1709 ret
->parent
= parent
;
1711 nsres
= nsIWebBrowser_SetContainerWindow(ret
->webbrowser
, NSWBCHROME(ret
));
1712 if(NS_FAILED(nsres
))
1713 ERR("SetContainerWindow failed: %08x\n", nsres
);
1715 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
1716 (void**)&ret
->window
);
1717 if(NS_FAILED(nsres
))
1718 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1720 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserSetup
,
1722 if(NS_SUCCEEDED(nsres
)) {
1723 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1724 nsIWebBrowserSetup_Release(wbsetup
);
1725 if(NS_FAILED(nsres
))
1726 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1728 ERR("Could not get nsIWebBrowserSetup interface\n");
1731 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
1732 (void**)&ret
->navigation
);
1733 if(NS_FAILED(nsres
))
1734 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1736 nsres
= nsIWebBrowserFocus_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserFocus
,
1737 (void**)&ret
->focus
);
1738 if(NS_FAILED(nsres
))
1739 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1741 if(!nscontainer_class
)
1742 register_nscontainer_class();
1744 ret
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1745 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1746 GetDesktopWindow(), NULL
, hInst
, ret
);
1748 nsres
= nsIBaseWindow_InitWindow(ret
->window
, ret
->hwnd
, NULL
, 0, 0, 100, 100);
1749 if(NS_SUCCEEDED(nsres
)) {
1750 nsres
= nsIBaseWindow_Create(ret
->window
);
1751 if(NS_FAILED(nsres
))
1752 WARN("Creating window failed: %08x\n", nsres
);
1754 nsIBaseWindow_SetVisibility(ret
->window
, FALSE
);
1755 nsIBaseWindow_SetEnabled(ret
->window
, FALSE
);
1757 ERR("InitWindow failed: %08x\n", nsres
);
1760 nsres
= nsIWebBrowser_SetParentURIContentListener(ret
->webbrowser
, NSURICL(ret
));
1761 if(NS_FAILED(nsres
))
1762 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1766 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1767 if(NS_SUCCEEDED(nsres
)) {
1768 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1769 ScrollOrientation_Y
, Scrollbar_Always
);
1770 if(NS_FAILED(nsres
))
1771 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1773 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1774 ScrollOrientation_X
, Scrollbar_Auto
);
1775 if(NS_FAILED(nsres
))
1776 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1778 nsIScrollable_Release(scrollable
);
1780 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1786 void NSContainer_Release(NSContainer
*This
)
1788 TRACE("(%p)\n", This
);
1792 ShowWindow(This
->hwnd
, SW_HIDE
);
1793 SetParent(This
->hwnd
, NULL
);
1795 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1796 nsIBaseWindow_Destroy(This
->window
);
1798 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1800 nsIWebBrowser_Release(This
->webbrowser
);
1801 This
->webbrowser
= NULL
;
1803 nsIWebNavigation_Release(This
->navigation
);
1804 This
->navigation
= NULL
;
1806 nsIBaseWindow_Release(This
->window
);
1807 This
->window
= NULL
;
1809 nsIWebBrowserFocus_Release(This
->focus
);
1812 if(This
->editor_controller
) {
1813 nsIController_Release(This
->editor_controller
);
1814 This
->editor_controller
= NULL
;
1818 nsIEditor_Release(This
->editor
);
1819 This
->editor
= NULL
;
1822 if(This
->content_listener
) {
1823 nsIURIContentListener_Release(This
->content_listener
);
1824 This
->content_listener
= NULL
;
1828 DestroyWindow(This
->hwnd
);
1832 nsIWebBrowserChrome_Release(NSWBCHROME(This
));