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_MEMORY_CONTRACTID "@mozilla.org/xpcom/memory-service;1"
42 #define NS_COMMANDPARAMS_CONTRACTID "@mozilla.org/embedcomp/command-params;1"
43 #define NS_HTMLSERIALIZER_CONTRACTID "@mozilla.org/layout/contentserializer;1?mimetype=text/html"
44 #define NS_EDITORCONTROLLER_CONTRACTID "@mozilla.org/editor/editorcontroller;1"
45 #define NS_PREFERENCES_CONTRACTID "@mozilla.org/preferences;1"
47 #define APPSTARTUP_TOPIC "app-startup"
49 #define PR_UINT32_MAX 0xffffffff
51 #define NS_STRING_CONTAINER_INIT_DEPEND 0x0002
52 #define NS_CSTRING_CONTAINER_INIT_DEPEND 0x0002
54 static nsresult (*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
55 static nsresult (*NS_ShutdownXPCOM
)(nsIServiceManager
*);
56 static nsresult (*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
57 static nsresult (*NS_StringContainerInit2
)(nsStringContainer
*,const PRUnichar
*,PRUint32
,PRUint32
);
58 static nsresult (*NS_CStringContainerInit2
)(nsCStringContainer
*,const char*,PRUint32
,PRUint32
);
59 static nsresult (*NS_StringContainerFinish
)(nsStringContainer
*);
60 static nsresult (*NS_CStringContainerFinish
)(nsCStringContainer
*);
61 static nsresult (*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
62 static nsresult (*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
63 static nsresult (*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
64 static PRUint32 (*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
65 static PRUint32 (*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
67 static HINSTANCE hXPCOM
= NULL
;
69 static nsIServiceManager
*pServMgr
= NULL
;
70 static nsIComponentManager
*pCompMgr
= NULL
;
71 static nsIMemory
*nsmem
= NULL
;
73 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
75 static ATOM nscontainer_class
;
77 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
82 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
84 if(msg
== WM_CREATE
) {
85 This
= *(NSContainer
**)lParam
;
86 SetPropW(hwnd
, wszTHIS
, This
);
88 This
= GetPropW(hwnd
, wszTHIS
);
93 TRACE("(%p)->(WM_SIZE)\n", This
);
95 nsres
= nsIBaseWindow_SetSize(This
->window
,
96 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
98 WARN("SetSize failed: %08x\n", nsres
);
101 case WM_PARENTNOTIFY
:
102 TRACE("WM_PARENTNOTIFY %x\n", (unsigned)wParam
);
107 nsIWebBrowserFocus_Activate(This
->focus
);
111 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
115 static void register_nscontainer_class(void)
117 static WNDCLASSEXW wndclass
= {
121 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
125 wndclass
.hInstance
= hInst
;
126 nscontainer_class
= RegisterClassExW(&wndclass
);
129 static void set_environment(LPCWSTR gre_path
)
131 WCHAR path_env
[MAX_PATH
], buf
[20];
132 int len
, debug_level
= 0;
134 static const WCHAR pathW
[] = {'P','A','T','H',0};
135 static const WCHAR warnW
[] = {'w','a','r','n',0};
136 static const WCHAR xpcom_debug_breakW
[] =
137 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
138 static const WCHAR nspr_log_modulesW
[] =
139 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
140 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
142 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
143 GetEnvironmentVariableW(pathW
, path_env
, sizeof(path_env
)/sizeof(WCHAR
));
144 len
= strlenW(path_env
);
145 path_env
[len
++] = ';';
146 strcpyW(path_env
+len
, gre_path
);
147 SetEnvironmentVariableW(pathW
, path_env
);
149 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
153 else if(WARN_ON(gecko
))
155 else if(ERR_ON(gecko
))
158 sprintfW(buf
, debug_formatW
, debug_level
);
159 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
162 static BOOL
load_xpcom(const PRUnichar
*gre_path
)
164 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
166 TRACE("(%s)\n", debugstr_w(gre_path
));
168 set_environment(gre_path
);
170 hXPCOM
= LoadLibraryW(strXPCOM
);
172 WARN("Could not load XPCOM: %d\n", GetLastError());
176 #define NS_DLSYM(func) \
177 func = (void *)GetProcAddress(hXPCOM, #func); \
179 ERR("Could not GetProcAddress(" #func ") failed\n")
181 NS_DLSYM(NS_InitXPCOM2
);
182 NS_DLSYM(NS_ShutdownXPCOM
);
183 NS_DLSYM(NS_GetComponentRegistrar
);
184 NS_DLSYM(NS_StringContainerInit2
);
185 NS_DLSYM(NS_CStringContainerInit2
);
186 NS_DLSYM(NS_StringContainerFinish
);
187 NS_DLSYM(NS_CStringContainerFinish
);
188 NS_DLSYM(NS_StringSetData
);
189 NS_DLSYM(NS_CStringSetData
);
190 NS_DLSYM(NS_NewLocalFile
);
191 NS_DLSYM(NS_StringGetData
);
192 NS_DLSYM(NS_CStringGetData
);
199 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
201 WCHAR file_name
[MAX_PATH
];
206 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
208 strcpyW(file_name
, gre_path
);
209 strcatW(file_name
, wszVersion
);
211 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
212 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
213 if(hfile
== INVALID_HANDLE_VALUE
) {
214 ERR("Could not open VERSION file\n");
218 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
222 TRACE("%s\n", debugstr_a(version
));
224 if(strcmp(version
, version_string
)) {
225 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
226 debugstr_a(version_string
));
233 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
234 const char *version
, const char *version_string
)
236 DWORD res
, type
, size
= MAX_PATH
;
237 HKEY hkey
= mshtml_key
;
239 static const WCHAR wszGeckoPath
[] =
240 {'G','e','c','k','o','P','a','t','h',0};
243 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
244 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
245 if(res
!= ERROR_SUCCESS
)
249 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
250 if(hkey
!= mshtml_key
)
252 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
255 if(!check_version(gre_path
, version_string
))
258 return load_xpcom(gre_path
);
261 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
267 static const WCHAR wszMshtmlKey
[] = {
268 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
269 '\\','M','S','H','T','M','L',0};
271 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
272 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszMshtmlKey
, &hkey
);
273 if(res
!= ERROR_SUCCESS
)
276 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
282 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
286 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
288 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
291 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
295 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
297 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
300 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
304 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
306 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
309 static void set_lang(nsIPrefBranch
*pref
)
312 DWORD res
, size
, type
;
315 static const WCHAR international_keyW
[] =
316 {'S','o','f','t','w','a','r','e',
317 '\\','M','i','c','r','o','s','o','f','t',
318 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
319 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
321 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
322 if(res
!= ERROR_SUCCESS
)
325 size
= sizeof(langs
);
326 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
328 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
331 TRACE("Setting lang %s\n", debugstr_a(langs
));
333 set_string_pref(pref
, "intl.accept_languages", langs
);
336 static void set_proxy(nsIPrefBranch
*pref
)
341 DWORD enabled
= 0, res
, size
, type
;
344 static const WCHAR proxy_keyW
[] =
345 {'S','o','f','t','w','a','r','e',
346 '\\','M','i','c','r','o','s','o','f','t',
347 '\\','W','i','n','d','o','w','s',
348 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
349 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
351 res
= RegOpenKeyW(HKEY_CURRENT_USER
, proxy_keyW
, &hkey
);
352 if(res
!= ERROR_SUCCESS
)
355 size
= sizeof(enabled
);
356 res
= RegQueryValueExA(hkey
, "ProxyEnable", 0, &type
, (LPBYTE
)&enabled
, &size
);
357 if(res
!= ERROR_SUCCESS
|| type
!= REG_DWORD
|| enabled
== 0)
363 size
= sizeof(proxy
);
364 res
= RegQueryValueExA(hkey
, "ProxyServer", 0, &type
, (LPBYTE
)proxy
, &size
);
366 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
369 proxy_port
= strchr(proxy
, ':');
374 proxy_port_num
= atoi(proxy_port
+ 1);
375 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy
), proxy_port_num
);
377 set_string_pref(pref
, "network.proxy.http", proxy
);
378 set_string_pref(pref
, "network.proxy.ssl", proxy
);
380 set_int_pref(pref
, "network.proxy.type", 1);
381 set_int_pref(pref
, "network.proxy.http_port", proxy_port_num
);
382 set_int_pref(pref
, "network.proxy.ssl_port", proxy_port_num
);
385 static void set_preferences(void)
390 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
391 &IID_nsIPrefBranch
, (void**)&pref
);
392 if(NS_FAILED(nsres
)) {
393 ERR("Could not get preference service: %08x\n", nsres
);
399 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
400 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
401 set_int_pref(pref
, "layout.spellcheckDefault", 0);
403 nsIPrefBranch_Release(pref
);
406 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
409 nsIObserver
*pStartNotif
;
410 nsIComponentRegistrar
*registrar
= NULL
;
414 nsAString_InitDepend(&path
, gre_path
);
415 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
416 nsAString_Finish(&path
);
417 if(NS_FAILED(nsres
)) {
418 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
423 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
424 if(NS_FAILED(nsres
)) {
425 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
430 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
432 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
434 nsres
= NS_GetComponentRegistrar(®istrar
);
435 if(NS_SUCCEEDED(nsres
)) {
436 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, NULL
);
438 ERR("AutoRegister(NULL) failed: %08x\n", nsres
);
440 init_nsio(pCompMgr
, registrar
);
442 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
445 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
446 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
447 if(NS_SUCCEEDED(nsres
)) {
448 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
450 ERR("Observe failed: %08x\n", nsres
);
452 nsIObserver_Release(pStartNotif
);
454 ERR("could not get appstartup-notifier: %08x\n", nsres
);
459 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
460 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
462 ERR("Could not get nsIMemory: %08x\n", nsres
);
465 register_nsservice(registrar
, pServMgr
);
466 nsIComponentRegistrar_Release(registrar
);
472 static CRITICAL_SECTION cs_load_gecko
;
473 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
475 0, 0, &cs_load_gecko
,
476 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
477 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
479 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
481 BOOL
load_gecko(BOOL silent
)
483 PRUnichar gre_path
[MAX_PATH
];
486 static DWORD loading_thread
;
490 /* load_gecko may be called recursively */
491 if(loading_thread
== GetCurrentThreadId())
492 return pCompMgr
!= NULL
;
494 EnterCriticalSection(&cs_load_gecko
);
496 if(!loading_thread
) {
497 loading_thread
= GetCurrentThreadId();
499 if(load_wine_gecko(gre_path
)
500 || (install_wine_gecko(silent
) && load_wine_gecko(gre_path
)))
501 ret
= init_xpcom(gre_path
);
503 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
505 ret
= pCompMgr
!= NULL
;
508 LeaveCriticalSection(&cs_load_gecko
);
513 void *nsalloc(size_t size
)
515 return nsIMemory_Alloc(nsmem
, size
);
518 void nsfree(void *mem
)
520 nsIMemory_Free(nsmem
, mem
);
523 static BOOL
nsACString_Init(nsACString
*str
, const char *data
)
525 return NS_SUCCEEDED(NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
529 * Initializes nsACString with data owned by caller.
530 * Caller must ensure that data is valid during lifetime of string object.
532 void nsACString_InitDepend(nsACString
*str
, const char *data
)
534 NS_CStringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_CSTRING_CONTAINER_INIT_DEPEND
);
537 void nsACString_SetData(nsACString
*str
, const char *data
)
539 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
542 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
544 return NS_CStringGetData(str
, data
, NULL
);
547 void nsACString_Finish(nsACString
*str
)
549 NS_CStringContainerFinish(str
);
552 BOOL
nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
554 return NS_SUCCEEDED(NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, 0));
558 * Initializes nsAString with data owned by caller.
559 * Caller must ensure that data is valid during lifetime of string object.
561 void nsAString_InitDepend(nsAString
*str
, const PRUnichar
*data
)
563 NS_StringContainerInit2(str
, data
, PR_UINT32_MAX
, NS_STRING_CONTAINER_INIT_DEPEND
);
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 nsICommandParams
*create_nscommand_params(void)
583 nsICommandParams
*ret
= NULL
;
589 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
590 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
593 ERR("Could not get nsICommandParams\n");
598 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
600 nsIInterfaceRequestor
*iface_req
;
603 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
607 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
608 nsIInterfaceRequestor_Release(iface_req
);
613 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
615 nsIDOMNodeList
*node_list
= NULL
;
616 PRBool has_children
= FALSE
;
620 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
622 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
623 if(NS_FAILED(nsres
)) {
624 ERR("GetType failed: %08x\n", nsres
);
630 nsIDOMElement
*nselem
;
631 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
632 nsIContentSerializer_AppendElementStart(serializer
, nselem
, nselem
, str
);
633 nsIDOMElement_Release(nselem
);
638 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&nstext
);
639 nsIContentSerializer_AppendText(serializer
, nstext
, 0, -1, str
);
640 nsIDOMText_Release(nstext
);
644 nsIDOMComment
*nscomment
;
645 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMComment
, (void**)&nscomment
);
646 nsres
= nsIContentSerializer_AppendComment(serializer
, nscomment
, 0, -1, str
);
649 case DOCUMENT_NODE
: {
650 nsIDOMDocument
*nsdoc
;
651 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMDocument
, (void**)&nsdoc
);
652 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
653 nsIDOMDocument_Release(nsdoc
);
656 case DOCUMENT_TYPE_NODE
:
657 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
659 case DOCUMENT_FRAGMENT_NODE
:
662 FIXME("Unhandled type %u\n", type
);
666 PRUint32 child_cnt
, i
;
667 nsIDOMNode
*child_node
;
669 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
670 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
672 for(i
=0; i
<child_cnt
; i
++) {
673 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
674 if(NS_SUCCEEDED(nsres
)) {
675 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
676 nsIDOMNode_Release(child_node
);
678 ERR("Item failed: %08x\n", nsres
);
682 nsIDOMNodeList_Release(node_list
);
685 if(type
== ELEMENT_NODE
) {
686 nsIDOMElement
*nselem
;
687 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
688 nsIContentSerializer_AppendElementEnd(serializer
, nselem
, str
);
689 nsIDOMElement_Release(nselem
);
695 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
697 nsIContentSerializer
*serializer
;
701 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
702 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
703 (void**)&serializer
);
704 if(NS_FAILED(nsres
)) {
705 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
709 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
711 ERR("Init failed: %08x\n", nsres
);
713 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
714 if(SUCCEEDED(hres
)) {
715 nsres
= nsIContentSerializer_Flush(serializer
, str
);
717 ERR("Flush failed: %08x\n", nsres
);
720 nsIContentSerializer_Release(serializer
);
724 void get_editor_controller(NSContainer
*This
)
726 nsIEditingSession
*editing_session
= NULL
;
727 nsIControllerContext
*ctrlctx
;
731 nsIEditor_Release(This
->editor
);
735 if(This
->editor_controller
) {
736 nsIController_Release(This
->editor_controller
);
737 This
->editor_controller
= NULL
;
740 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
741 (void**)&editing_session
);
742 if(NS_FAILED(nsres
)) {
743 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
747 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
748 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
749 nsIEditingSession_Release(editing_session
);
750 if(NS_FAILED(nsres
)) {
751 ERR("Could not get editor: %08x\n", nsres
);
755 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
756 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
757 if(NS_SUCCEEDED(nsres
)) {
758 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
760 ERR("SetCommandContext failed: %08x\n", nsres
);
761 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
762 (void**)&This
->editor_controller
);
763 nsIControllerContext_Release(ctrlctx
);
765 ERR("Could not get nsIController interface: %08x\n", nsres
);
767 ERR("Could not create edit controller: %08x\n", nsres
);
771 void close_gecko(void)
778 nsIComponentManager_Release(pCompMgr
);
781 nsIServiceManager_Release(pServMgr
);
784 nsIMemory_Release(nsmem
);
786 /* Gecko doesn't really support being unloaded */
787 /* if (hXPCOM) FreeLibrary(hXPCOM); */
790 /**********************************************************
791 * nsIWebBrowserChrome interface
794 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
796 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
797 nsIIDRef riid
, nsQIResult result
)
799 NSContainer
*This
= NSWBCHROME_THIS(iface
);
802 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
803 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
804 *result
= NSWBCHROME(This
);
805 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
806 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
807 *result
= NSWBCHROME(This
);
808 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
809 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
810 *result
= NSCML(This
);
811 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
812 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
813 *result
= NSURICL(This
);
814 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
815 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
816 *result
= NSEMBWNDS(This
);
817 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
818 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
819 *result
= NSTOOLTIP(This
);
820 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
821 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
822 *result
= NSIFACEREQ(This
);
823 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
824 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
825 *result
= NSWEAKREF(This
);
826 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
827 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
828 *result
= NSSUPWEAKREF(This
);
832 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
836 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
837 return NS_NOINTERFACE
;
840 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
842 NSContainer
*This
= NSWBCHROME_THIS(iface
);
843 LONG ref
= InterlockedIncrement(&This
->ref
);
845 TRACE("(%p) ref=%d\n", This
, ref
);
850 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
852 NSContainer
*This
= NSWBCHROME_THIS(iface
);
853 LONG ref
= InterlockedDecrement(&This
->ref
);
855 TRACE("(%p) ref=%d\n", This
, ref
);
859 nsIWebBrowserChrome_Release(NSWBCHROME(This
->parent
));
866 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
867 PRUint32 statusType
, const PRUnichar
*status
)
869 NSContainer
*This
= NSWBCHROME_THIS(iface
);
870 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
874 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
875 nsIWebBrowser
**aWebBrowser
)
877 NSContainer
*This
= NSWBCHROME_THIS(iface
);
879 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
882 return NS_ERROR_INVALID_ARG
;
885 nsIWebBrowser_AddRef(This
->webbrowser
);
886 *aWebBrowser
= This
->webbrowser
;
890 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
891 nsIWebBrowser
*aWebBrowser
)
893 NSContainer
*This
= NSWBCHROME_THIS(iface
);
895 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
897 if(aWebBrowser
!= This
->webbrowser
)
898 ERR("Wrong nsWebBrowser!\n");
903 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
904 PRUint32
*aChromeFlags
)
906 NSContainer
*This
= NSWBCHROME_THIS(iface
);
907 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
908 return NS_ERROR_NOT_IMPLEMENTED
;
911 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
912 PRUint32 aChromeFlags
)
914 NSContainer
*This
= NSWBCHROME_THIS(iface
);
915 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
916 return NS_ERROR_NOT_IMPLEMENTED
;
919 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
921 NSContainer
*This
= NSWBCHROME_THIS(iface
);
922 TRACE("(%p)\n", This
);
923 return NS_ERROR_NOT_IMPLEMENTED
;
926 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
927 PRInt32 aCX
, PRInt32 aCY
)
929 NSContainer
*This
= NSWBCHROME_THIS(iface
);
930 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
931 return NS_ERROR_NOT_IMPLEMENTED
;
934 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
936 NSContainer
*This
= NSWBCHROME_THIS(iface
);
937 WARN("(%p)\n", This
);
938 return NS_ERROR_NOT_IMPLEMENTED
;
941 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
943 NSContainer
*This
= NSWBCHROME_THIS(iface
);
944 WARN("(%p)->(%p)\n", This
, _retval
);
945 return NS_ERROR_NOT_IMPLEMENTED
;
948 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
951 NSContainer
*This
= NSWBCHROME_THIS(iface
);
952 WARN("(%p)->(%08x)\n", This
, aStatus
);
953 return NS_ERROR_NOT_IMPLEMENTED
;
956 #undef NSWBCHROME_THIS
958 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
959 nsWebBrowserChrome_QueryInterface
,
960 nsWebBrowserChrome_AddRef
,
961 nsWebBrowserChrome_Release
,
962 nsWebBrowserChrome_SetStatus
,
963 nsWebBrowserChrome_GetWebBrowser
,
964 nsWebBrowserChrome_SetWebBrowser
,
965 nsWebBrowserChrome_GetChromeFlags
,
966 nsWebBrowserChrome_SetChromeFlags
,
967 nsWebBrowserChrome_DestroyBrowserWindow
,
968 nsWebBrowserChrome_SizeBrowserTo
,
969 nsWebBrowserChrome_ShowAsModal
,
970 nsWebBrowserChrome_IsWindowModal
,
971 nsWebBrowserChrome_ExitModalEventLoop
974 /**********************************************************
975 * nsIContextMenuListener interface
978 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
980 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
981 nsIIDRef riid
, nsQIResult result
)
983 NSContainer
*This
= NSCML_THIS(iface
);
984 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
987 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
989 NSContainer
*This
= NSCML_THIS(iface
);
990 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
993 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
995 NSContainer
*This
= NSCML_THIS(iface
);
996 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
999 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1000 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1002 NSContainer
*This
= NSCML_THIS(iface
);
1003 nsIDOMMouseEvent
*event
;
1005 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1008 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1010 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1011 if(NS_FAILED(nsres
)) {
1012 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1016 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1017 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1018 nsIDOMMouseEvent_Release(event
);
1020 switch(aContextFlags
) {
1022 case CONTEXT_DOCUMENT
:
1024 dwID
= CONTEXT_MENU_DEFAULT
;
1027 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1028 dwID
= CONTEXT_MENU_IMAGE
;
1031 dwID
= CONTEXT_MENU_ANCHOR
;
1034 dwID
= CONTEXT_MENU_CONTROL
;
1037 FIXME("aContextFlags=%08x\n", aContextFlags
);
1040 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)HTMLDOMNODE(get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
)));
1047 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1048 nsContextMenuListener_QueryInterface
,
1049 nsContextMenuListener_AddRef
,
1050 nsContextMenuListener_Release
,
1051 nsContextMenuListener_OnShowContextMenu
1054 /**********************************************************
1055 * nsIURIContentListener interface
1058 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1060 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1061 nsIIDRef riid
, nsQIResult result
)
1063 NSContainer
*This
= NSURICL_THIS(iface
);
1064 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1067 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1069 NSContainer
*This
= NSURICL_THIS(iface
);
1070 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1073 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1075 NSContainer
*This
= NSURICL_THIS(iface
);
1076 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1079 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1080 nsIURI
*aURI
, PRBool
*_retval
)
1082 NSContainer
*This
= NSURICL_THIS(iface
);
1083 nsACString spec_str
;
1087 nsACString_Init(&spec_str
, NULL
);
1088 nsIURI_GetSpec(aURI
, &spec_str
);
1089 nsACString_GetData(&spec_str
, &spec
);
1091 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1093 nsACString_Finish(&spec_str
);
1095 nsres
= on_start_uri_open(This
, aURI
, _retval
);
1096 if(NS_FAILED(nsres
))
1099 return !*_retval
&& This
->content_listener
1100 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1104 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1105 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1106 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1108 NSContainer
*This
= NSURICL_THIS(iface
);
1110 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1111 aRequest
, aContentHandler
, _retval
);
1113 return This
->content_listener
1114 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1115 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1116 : NS_ERROR_NOT_IMPLEMENTED
;
1119 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1120 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1122 NSContainer
*This
= NSURICL_THIS(iface
);
1124 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1126 /* FIXME: Should we do something here? */
1129 return This
->content_listener
1130 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1131 aDesiredContentType
, _retval
)
1135 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1136 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1139 NSContainer
*This
= NSURICL_THIS(iface
);
1141 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1142 aDesiredContentType
, _retval
);
1144 return This
->content_listener
1145 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1146 aIsContentPreferred
, aDesiredContentType
, _retval
)
1147 : NS_ERROR_NOT_IMPLEMENTED
;
1150 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1151 nsISupports
**aLoadCookie
)
1153 NSContainer
*This
= NSURICL_THIS(iface
);
1155 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1157 return This
->content_listener
1158 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1159 : NS_ERROR_NOT_IMPLEMENTED
;
1162 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1163 nsISupports
*aLoadCookie
)
1165 NSContainer
*This
= NSURICL_THIS(iface
);
1167 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1169 return This
->content_listener
1170 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1171 : NS_ERROR_NOT_IMPLEMENTED
;
1174 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1175 nsIURIContentListener
**aParentContentListener
)
1177 NSContainer
*This
= NSURICL_THIS(iface
);
1179 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1181 if(This
->content_listener
)
1182 nsIURIContentListener_AddRef(This
->content_listener
);
1184 *aParentContentListener
= This
->content_listener
;
1188 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1189 nsIURIContentListener
*aParentContentListener
)
1191 NSContainer
*This
= NSURICL_THIS(iface
);
1193 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1195 if(aParentContentListener
== NSURICL(This
))
1198 if(This
->content_listener
)
1199 nsIURIContentListener_Release(This
->content_listener
);
1201 This
->content_listener
= aParentContentListener
;
1202 if(This
->content_listener
)
1203 nsIURIContentListener_AddRef(This
->content_listener
);
1210 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1211 nsURIContentListener_QueryInterface
,
1212 nsURIContentListener_AddRef
,
1213 nsURIContentListener_Release
,
1214 nsURIContentListener_OnStartURIOpen
,
1215 nsURIContentListener_DoContent
,
1216 nsURIContentListener_IsPreferred
,
1217 nsURIContentListener_CanHandleContent
,
1218 nsURIContentListener_GetLoadCookie
,
1219 nsURIContentListener_SetLoadCookie
,
1220 nsURIContentListener_GetParentContentListener
,
1221 nsURIContentListener_SetParentContentListener
1224 /**********************************************************
1225 * nsIEmbeddinSiteWindow interface
1228 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1230 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1231 nsIIDRef riid
, nsQIResult result
)
1233 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1234 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1237 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1239 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1240 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1243 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1245 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1246 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1249 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1250 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1252 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1253 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1254 return NS_ERROR_NOT_IMPLEMENTED
;
1257 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1258 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1260 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1261 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1262 return NS_ERROR_NOT_IMPLEMENTED
;
1265 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1267 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1269 TRACE("(%p)\n", This
);
1271 return nsIBaseWindow_SetFocus(This
->window
);
1274 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1275 PRBool
*aVisibility
)
1277 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1279 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1281 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1285 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1288 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1290 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1295 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1298 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1299 WARN("(%p)->(%p)\n", This
, aTitle
);
1300 return NS_ERROR_NOT_IMPLEMENTED
;
1303 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1304 const PRUnichar
*aTitle
)
1306 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1307 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1308 return NS_ERROR_NOT_IMPLEMENTED
;
1311 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1314 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1316 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1318 *aSiteWindow
= This
->hwnd
;
1322 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1323 nsEmbeddingSiteWindow_QueryInterface
,
1324 nsEmbeddingSiteWindow_AddRef
,
1325 nsEmbeddingSiteWindow_Release
,
1326 nsEmbeddingSiteWindow_SetDimensions
,
1327 nsEmbeddingSiteWindow_GetDimensions
,
1328 nsEmbeddingSiteWindow_SetFocus
,
1329 nsEmbeddingSiteWindow_GetVisibility
,
1330 nsEmbeddingSiteWindow_SetVisibility
,
1331 nsEmbeddingSiteWindow_GetTitle
,
1332 nsEmbeddingSiteWindow_SetTitle
,
1333 nsEmbeddingSiteWindow_GetSiteWindow
1336 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1338 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1341 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1342 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1345 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1347 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1348 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1351 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1353 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1354 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1357 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1358 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1360 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1363 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1368 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1370 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1373 hide_tooltip(This
->doc
);
1378 #undef NSTOOLTIM_THIS
1380 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1381 nsTooltipListener_QueryInterface
,
1382 nsTooltipListener_AddRef
,
1383 nsTooltipListener_Release
,
1384 nsTooltipListener_OnShowTooltip
,
1385 nsTooltipListener_OnHideTooltip
1388 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1390 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1391 nsIIDRef riid
, nsQIResult result
)
1393 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1394 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1397 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1399 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1400 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1403 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1405 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1406 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1409 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1410 nsIIDRef riid
, nsQIResult result
)
1412 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1414 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1415 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1416 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1419 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1422 #undef NSIFACEREQ_THIS
1424 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1425 nsInterfaceRequestor_QueryInterface
,
1426 nsInterfaceRequestor_AddRef
,
1427 nsInterfaceRequestor_Release
,
1428 nsInterfaceRequestor_GetInterface
1431 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1433 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1434 nsIIDRef riid
, nsQIResult result
)
1436 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1437 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1440 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1442 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1443 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1446 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1448 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1449 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1452 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1453 const nsIID
*riid
, void **result
)
1455 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1456 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1459 #undef NSWEAKREF_THIS
1461 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1462 nsWeakReference_QueryInterface
,
1463 nsWeakReference_AddRef
,
1464 nsWeakReference_Release
,
1465 nsWeakReference_QueryReferent
1468 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1470 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1471 nsIIDRef riid
, nsQIResult result
)
1473 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1474 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1477 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1479 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1480 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1483 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1485 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1486 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1489 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1490 nsIWeakReference
**_retval
)
1492 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1494 TRACE("(%p)->(%p)\n", This
, _retval
);
1496 nsIWeakReference_AddRef(NSWEAKREF(This
));
1497 *_retval
= NSWEAKREF(This
);
1501 #undef NSWEAKREF_THIS
1503 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1504 nsSupportsWeakReference_QueryInterface
,
1505 nsSupportsWeakReference_AddRef
,
1506 nsSupportsWeakReference_Release
,
1507 nsSupportsWeakReference_GetWeakReference
1511 NSContainer
*NSContainer_Create(HTMLDocumentObj
*doc
, NSContainer
*parent
)
1513 nsIWebBrowserSetup
*wbsetup
;
1514 nsIScrollable
*scrollable
;
1518 if(!load_gecko(TRUE
))
1521 ret
= heap_alloc_zero(sizeof(NSContainer
));
1523 ret
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
1524 ret
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
1525 ret
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
1526 ret
->lpEmbeddingSiteWindowVtbl
= &nsEmbeddingSiteWindowVtbl
;
1527 ret
->lpTooltipListenerVtbl
= &nsTooltipListenerVtbl
;
1528 ret
->lpInterfaceRequestorVtbl
= &nsInterfaceRequestorVtbl
;
1529 ret
->lpWeakReferenceVtbl
= &nsWeakReferenceVtbl
;
1530 ret
->lpSupportsWeakReferenceVtbl
= &nsSupportsWeakReferenceVtbl
;
1535 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1536 NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
1537 if(NS_FAILED(nsres
)) {
1538 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1544 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent
));
1545 ret
->parent
= parent
;
1547 nsres
= nsIWebBrowser_SetContainerWindow(ret
->webbrowser
, NSWBCHROME(ret
));
1548 if(NS_FAILED(nsres
))
1549 ERR("SetContainerWindow failed: %08x\n", nsres
);
1551 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
1552 (void**)&ret
->window
);
1553 if(NS_FAILED(nsres
))
1554 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1556 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserSetup
,
1558 if(NS_SUCCEEDED(nsres
)) {
1559 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1560 nsIWebBrowserSetup_Release(wbsetup
);
1561 if(NS_FAILED(nsres
))
1562 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1564 ERR("Could not get nsIWebBrowserSetup interface\n");
1567 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
1568 (void**)&ret
->navigation
);
1569 if(NS_FAILED(nsres
))
1570 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1572 nsres
= nsIWebBrowserFocus_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserFocus
,
1573 (void**)&ret
->focus
);
1574 if(NS_FAILED(nsres
))
1575 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1577 if(!nscontainer_class
)
1578 register_nscontainer_class();
1580 ret
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1581 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1582 GetDesktopWindow(), NULL
, hInst
, ret
);
1584 nsres
= nsIBaseWindow_InitWindow(ret
->window
, ret
->hwnd
, NULL
, 0, 0, 100, 100);
1585 if(NS_SUCCEEDED(nsres
)) {
1586 nsres
= nsIBaseWindow_Create(ret
->window
);
1587 if(NS_FAILED(nsres
))
1588 WARN("Creating window failed: %08x\n", nsres
);
1590 nsIBaseWindow_SetVisibility(ret
->window
, FALSE
);
1591 nsIBaseWindow_SetEnabled(ret
->window
, FALSE
);
1593 ERR("InitWindow failed: %08x\n", nsres
);
1596 nsres
= nsIWebBrowser_SetParentURIContentListener(ret
->webbrowser
, NSURICL(ret
));
1597 if(NS_FAILED(nsres
))
1598 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1600 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1601 if(NS_SUCCEEDED(nsres
)) {
1602 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1603 ScrollOrientation_Y
, Scrollbar_Always
);
1604 if(NS_FAILED(nsres
))
1605 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1607 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1608 ScrollOrientation_X
, Scrollbar_Auto
);
1609 if(NS_FAILED(nsres
))
1610 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1612 nsIScrollable_Release(scrollable
);
1614 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1620 void NSContainer_Release(NSContainer
*This
)
1622 TRACE("(%p)\n", This
);
1626 ShowWindow(This
->hwnd
, SW_HIDE
);
1627 SetParent(This
->hwnd
, NULL
);
1629 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1630 nsIBaseWindow_Destroy(This
->window
);
1632 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1634 nsIWebBrowser_Release(This
->webbrowser
);
1635 This
->webbrowser
= NULL
;
1637 nsIWebNavigation_Release(This
->navigation
);
1638 This
->navigation
= NULL
;
1640 nsIBaseWindow_Release(This
->window
);
1641 This
->window
= NULL
;
1643 nsIWebBrowserFocus_Release(This
->focus
);
1646 if(This
->editor_controller
) {
1647 nsIController_Release(This
->editor_controller
);
1648 This
->editor_controller
= NULL
;
1652 nsIEditor_Release(This
->editor
);
1653 This
->editor
= NULL
;
1656 if(This
->content_listener
) {
1657 nsIURIContentListener_Release(This
->content_listener
);
1658 This
->content_listener
= NULL
;
1662 DestroyWindow(This
->hwnd
);
1666 nsIWebBrowserChrome_Release(NSWBCHROME(This
));