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 struct nsCStringContainer
{
58 static nsresult (*NS_InitXPCOM2
)(nsIServiceManager
**,void*,void*);
59 static nsresult (*NS_ShutdownXPCOM
)(nsIServiceManager
*);
60 static nsresult (*NS_GetComponentRegistrar
)(nsIComponentRegistrar
**);
61 static nsresult (*NS_StringContainerInit
)(nsStringContainer
*);
62 static nsresult (*NS_CStringContainerInit
)(nsCStringContainer
*);
63 static nsresult (*NS_StringContainerFinish
)(nsStringContainer
*);
64 static nsresult (*NS_CStringContainerFinish
)(nsCStringContainer
*);
65 static nsresult (*NS_StringSetData
)(nsAString
*,const PRUnichar
*,PRUint32
);
66 static nsresult (*NS_CStringSetData
)(nsACString
*,const char*,PRUint32
);
67 static nsresult (*NS_NewLocalFile
)(const nsAString
*,PRBool
,nsIFile
**);
68 static PRUint32 (*NS_StringGetData
)(const nsAString
*,const PRUnichar
**,PRBool
*);
69 static PRUint32 (*NS_CStringGetData
)(const nsACString
*,const char**,PRBool
*);
71 static HINSTANCE hXPCOM
= NULL
;
73 static nsIServiceManager
*pServMgr
= NULL
;
74 static nsIComponentManager
*pCompMgr
= NULL
;
75 static nsIMemory
*nsmem
= NULL
;
77 static const WCHAR wszNsContainer
[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
79 static ATOM nscontainer_class
;
81 #define WM_RESETFOCUS_HACK WM_USER+600
83 static LRESULT WINAPI
nsembed_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
88 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
90 if(msg
== WM_CREATE
) {
91 This
= *(NSContainer
**)lParam
;
92 SetPropW(hwnd
, wszTHIS
, This
);
94 This
= GetPropW(hwnd
, wszTHIS
);
99 TRACE("(%p)->(WM_SIZE)\n", This
);
101 nsres
= nsIBaseWindow_SetSize(This
->window
,
102 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
104 WARN("SetSize failed: %08x\n", nsres
);
107 case WM_RESETFOCUS_HACK
:
110 * Gecko grabs focus in edit mode and some apps don't like it.
111 * We should somehow prevent grabbing focus.
114 TRACE("WM_RESETFOCUS_HACK\n");
116 if(This
->reset_focus
) {
117 SetFocus(This
->reset_focus
);
118 This
->reset_focus
= NULL
;
120 This
->doc
->focus
= FALSE
;
124 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
128 static void register_nscontainer_class(void)
130 static WNDCLASSEXW wndclass
= {
134 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
138 wndclass
.hInstance
= hInst
;
139 nscontainer_class
= RegisterClassExW(&wndclass
);
142 static void set_environment(LPCWSTR gre_path
)
144 WCHAR path_env
[MAX_PATH
], buf
[20];
145 int len
, debug_level
= 0;
147 static const WCHAR pathW
[] = {'P','A','T','H',0};
148 static const WCHAR warnW
[] = {'w','a','r','n',0};
149 static const WCHAR xpcom_debug_breakW
[] =
150 {'X','P','C','O','M','_','D','E','B','U','G','_','B','R','E','A','K',0};
151 static const WCHAR nspr_log_modulesW
[] =
152 {'N','S','P','R','_','L','O','G','_','M','O','D','U','L','E','S',0};
153 static const WCHAR debug_formatW
[] = {'a','l','l',':','%','d',0};
155 /* We have to modify PATH as XPCOM loads other DLLs from this directory. */
156 GetEnvironmentVariableW(pathW
, 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(pathW
, path_env
);
162 SetEnvironmentVariableW(xpcom_debug_breakW
, warnW
);
166 else if(WARN_ON(gecko
))
168 else if(ERR_ON(gecko
))
171 sprintfW(buf
, debug_formatW
, debug_level
);
172 SetEnvironmentVariableW(nspr_log_modulesW
, buf
);
175 static BOOL
load_xpcom(const PRUnichar
*gre_path
)
177 static const WCHAR strXPCOM
[] = {'x','p','c','o','m','.','d','l','l',0};
179 TRACE("(%s)\n", debugstr_w(gre_path
));
181 set_environment(gre_path
);
183 hXPCOM
= LoadLibraryW(strXPCOM
);
185 WARN("Could not load XPCOM: %d\n", GetLastError());
189 #define NS_DLSYM(func) \
190 func = (void *)GetProcAddress(hXPCOM, #func); \
192 ERR("Could not GetProcAddress(" #func ") failed\n")
194 NS_DLSYM(NS_InitXPCOM2
);
195 NS_DLSYM(NS_ShutdownXPCOM
);
196 NS_DLSYM(NS_GetComponentRegistrar
);
197 NS_DLSYM(NS_StringContainerInit
);
198 NS_DLSYM(NS_CStringContainerInit
);
199 NS_DLSYM(NS_StringContainerFinish
);
200 NS_DLSYM(NS_CStringContainerFinish
);
201 NS_DLSYM(NS_StringSetData
);
202 NS_DLSYM(NS_CStringSetData
);
203 NS_DLSYM(NS_NewLocalFile
);
204 NS_DLSYM(NS_StringGetData
);
205 NS_DLSYM(NS_CStringGetData
);
212 static BOOL
check_version(LPCWSTR gre_path
, const char *version_string
)
214 WCHAR file_name
[MAX_PATH
];
219 static const WCHAR wszVersion
[] = {'\\','V','E','R','S','I','O','N',0};
221 strcpyW(file_name
, gre_path
);
222 strcatW(file_name
, wszVersion
);
224 hfile
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
225 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
226 if(hfile
== INVALID_HANDLE_VALUE
) {
227 ERR("Could not open VERSION file\n");
231 ReadFile(hfile
, version
, sizeof(version
), &read
, NULL
);
235 TRACE("%s\n", debugstr_a(version
));
237 if(strcmp(version
, version_string
)) {
238 ERR("Unexpected version %s, expected %s\n", debugstr_a(version
),
239 debugstr_a(version_string
));
246 static BOOL
load_wine_gecko_v(PRUnichar
*gre_path
, HKEY mshtml_key
,
247 const char *version
, const char *version_string
)
249 DWORD res
, type
, size
= MAX_PATH
;
250 HKEY hkey
= mshtml_key
;
252 static const WCHAR wszGeckoPath
[] =
253 {'G','e','c','k','o','P','a','t','h',0};
256 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML\<version> */
257 res
= RegOpenKeyA(mshtml_key
, version
, &hkey
);
258 if(res
!= ERROR_SUCCESS
)
262 res
= RegQueryValueExW(hkey
, wszGeckoPath
, NULL
, &type
, (LPBYTE
)gre_path
, &size
);
263 if(hkey
!= mshtml_key
)
265 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
268 if(!check_version(gre_path
, version_string
))
271 return load_xpcom(gre_path
);
274 static BOOL
load_wine_gecko(PRUnichar
*gre_path
)
280 static const WCHAR wszMshtmlKey
[] = {
281 'S','o','f','t','w','a','r','e','\\','W','i','n','e',
282 '\\','M','S','H','T','M','L',0};
284 /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
285 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszMshtmlKey
, &hkey
);
286 if(res
!= ERROR_SUCCESS
)
289 ret
= load_wine_gecko_v(gre_path
, hkey
, GECKO_VERSION
, GECKO_VERSION_STRING
);
295 static void set_bool_pref(nsIPrefBranch
*pref
, const char *pref_name
, BOOL val
)
299 nsres
= nsIPrefBranch_SetBoolPref(pref
, pref_name
, val
);
301 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
304 static void set_int_pref(nsIPrefBranch
*pref
, const char *pref_name
, int val
)
308 nsres
= nsIPrefBranch_SetIntPref(pref
, pref_name
, val
);
310 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
313 static void set_string_pref(nsIPrefBranch
*pref
, const char *pref_name
, const char *val
)
317 nsres
= nsIPrefBranch_SetCharPref(pref
, pref_name
, val
);
319 ERR("Could not set pref %s\n", debugstr_a(pref_name
));
322 static void set_lang(nsIPrefBranch
*pref
)
325 DWORD res
, size
, type
;
328 static const WCHAR international_keyW
[] =
329 {'S','o','f','t','w','a','r','e',
330 '\\','M','i','c','r','o','s','o','f','t',
331 '\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
332 '\\','I','n','t','e','r','n','a','t','i','o','n','a','l',0};
334 res
= RegOpenKeyW(HKEY_CURRENT_USER
, international_keyW
, &hkey
);
335 if(res
!= ERROR_SUCCESS
)
338 size
= sizeof(langs
);
339 res
= RegQueryValueExA(hkey
, "AcceptLanguage", 0, &type
, (LPBYTE
)langs
, &size
);
341 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
344 TRACE("Setting lang %s\n", debugstr_a(langs
));
346 set_string_pref(pref
, "intl.accept_languages", langs
);
349 static void set_proxy(nsIPrefBranch
*pref
)
354 DWORD enabled
= 0, res
, size
, type
;
357 static const WCHAR proxy_keyW
[] =
358 {'S','o','f','t','w','a','r','e',
359 '\\','M','i','c','r','o','s','o','f','t',
360 '\\','W','i','n','d','o','w','s',
361 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
362 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
364 res
= RegOpenKeyW(HKEY_CURRENT_USER
, proxy_keyW
, &hkey
);
365 if(res
!= ERROR_SUCCESS
)
368 size
= sizeof(enabled
);
369 res
= RegQueryValueExA(hkey
, "ProxyEnable", 0, &type
, (LPBYTE
)&enabled
, &size
);
370 if(res
!= ERROR_SUCCESS
|| type
!= REG_DWORD
|| enabled
== 0)
376 size
= sizeof(proxy
);
377 res
= RegQueryValueExA(hkey
, "ProxyServer", 0, &type
, (LPBYTE
)proxy
, &size
);
379 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
382 proxy_port
= strchr(proxy
, ':');
387 proxy_port_num
= atoi(proxy_port
+ 1);
388 TRACE("Setting proxy to %s, port %d\n", debugstr_a(proxy
), proxy_port_num
);
390 set_string_pref(pref
, "network.proxy.http", proxy
);
391 set_string_pref(pref
, "network.proxy.ssl", proxy
);
393 set_int_pref(pref
, "network.proxy.type", 1);
394 set_int_pref(pref
, "network.proxy.http_port", proxy_port_num
);
395 set_int_pref(pref
, "network.proxy.ssl_port", proxy_port_num
);
398 static void set_preferences(void)
403 nsres
= nsIServiceManager_GetServiceByContractID(pServMgr
, NS_PREFERENCES_CONTRACTID
,
404 &IID_nsIPrefBranch
, (void**)&pref
);
405 if(NS_FAILED(nsres
)) {
406 ERR("Could not get preference service: %08x\n", nsres
);
412 set_bool_pref(pref
, "security.warn_entering_secure", FALSE
);
413 set_bool_pref(pref
, "security.warn_submit_insecure", FALSE
);
414 set_int_pref(pref
, "layout.spellcheckDefault", 0);
416 nsIPrefBranch_Release(pref
);
419 static BOOL
init_xpcom(const PRUnichar
*gre_path
)
422 nsIObserver
*pStartNotif
;
423 nsIComponentRegistrar
*registrar
= NULL
;
427 nsAString_Init(&path
, gre_path
);
428 nsres
= NS_NewLocalFile(&path
, FALSE
, &gre_dir
);
429 nsAString_Finish(&path
);
430 if(NS_FAILED(nsres
)) {
431 ERR("NS_NewLocalFile failed: %08x\n", nsres
);
436 nsres
= NS_InitXPCOM2(&pServMgr
, gre_dir
, NULL
);
437 if(NS_FAILED(nsres
)) {
438 ERR("NS_InitXPCOM2 failed: %08x\n", nsres
);
443 nsres
= nsIServiceManager_QueryInterface(pServMgr
, &IID_nsIComponentManager
, (void**)&pCompMgr
);
445 ERR("Could not get nsIComponentManager: %08x\n", nsres
);
447 nsres
= NS_GetComponentRegistrar(®istrar
);
448 if(NS_SUCCEEDED(nsres
)) {
449 nsres
= nsIComponentRegistrar_AutoRegister(registrar
, NULL
);
451 ERR("AutoRegister(NULL) failed: %08x\n", nsres
);
453 init_nsio(pCompMgr
, registrar
);
455 ERR("NS_GetComponentRegistrar failed: %08x\n", nsres
);
458 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_APPSTARTUPNOTIFIER_CONTRACTID
,
459 NULL
, &IID_nsIObserver
, (void**)&pStartNotif
);
460 if(NS_SUCCEEDED(nsres
)) {
461 nsres
= nsIObserver_Observe(pStartNotif
, NULL
, APPSTARTUP_TOPIC
, NULL
);
463 ERR("Observe failed: %08x\n", nsres
);
465 nsIObserver_Release(pStartNotif
);
467 ERR("could not get appstartup-notifier: %08x\n", nsres
);
472 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_MEMORY_CONTRACTID
,
473 NULL
, &IID_nsIMemory
, (void**)&nsmem
);
475 ERR("Could not get nsIMemory: %08x\n", nsres
);
478 register_nsservice(registrar
, pServMgr
);
479 nsIComponentRegistrar_Release(registrar
);
485 static CRITICAL_SECTION cs_load_gecko
;
486 static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg
=
488 0, 0, &cs_load_gecko
,
489 { &cs_load_gecko_dbg
.ProcessLocksList
, &cs_load_gecko_dbg
.ProcessLocksList
},
490 0, 0, { (DWORD_PTR
)(__FILE__
": load_gecko") }
492 static CRITICAL_SECTION cs_load_gecko
= { &cs_load_gecko_dbg
, -1, 0, 0, 0, 0 };
494 BOOL
load_gecko(BOOL silent
)
496 PRUnichar gre_path
[MAX_PATH
];
499 static DWORD loading_thread
;
503 /* load_gecko may be called recursively */
504 if(loading_thread
== GetCurrentThreadId())
505 return pCompMgr
!= NULL
;
507 EnterCriticalSection(&cs_load_gecko
);
509 if(!loading_thread
) {
510 loading_thread
= GetCurrentThreadId();
512 if(load_wine_gecko(gre_path
)
513 || (install_wine_gecko(silent
) && load_wine_gecko(gre_path
)))
514 ret
= init_xpcom(gre_path
);
516 MESSAGE("Could not load wine-gecko. HTML rendering will be disabled.\n");
518 ret
= pCompMgr
!= NULL
;
521 LeaveCriticalSection(&cs_load_gecko
);
526 void *nsalloc(size_t size
)
528 return nsIMemory_Alloc(nsmem
, size
);
531 void nsfree(void *mem
)
533 nsIMemory_Free(nsmem
, mem
);
536 static void nsACString_Init(nsACString
*str
, const char *data
)
538 NS_CStringContainerInit(str
);
540 nsACString_SetData(str
, data
);
543 void nsACString_SetData(nsACString
*str
, const char *data
)
545 NS_CStringSetData(str
, data
, PR_UINT32_MAX
);
548 PRUint32
nsACString_GetData(const nsACString
*str
, const char **data
)
550 return NS_CStringGetData(str
, data
, NULL
);
553 static void nsACString_Finish(nsACString
*str
)
555 NS_CStringContainerFinish(str
);
558 void nsAString_Init(nsAString
*str
, const PRUnichar
*data
)
560 NS_StringContainerInit(str
);
562 nsAString_SetData(str
, data
);
565 void nsAString_SetData(nsAString
*str
, const PRUnichar
*data
)
567 NS_StringSetData(str
, data
, PR_UINT32_MAX
);
570 PRUint32
nsAString_GetData(const nsAString
*str
, const PRUnichar
**data
)
572 return NS_StringGetData(str
, data
, NULL
);
575 void nsAString_Finish(nsAString
*str
)
577 NS_StringContainerFinish(str
);
580 nsICommandParams
*create_nscommand_params(void)
582 nsICommandParams
*ret
= NULL
;
588 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
589 NS_COMMANDPARAMS_CONTRACTID
, NULL
, &IID_nsICommandParams
,
592 ERR("Could not get nsICommandParams\n");
597 nsresult
get_nsinterface(nsISupports
*iface
, REFIID riid
, void **ppv
)
599 nsIInterfaceRequestor
*iface_req
;
602 nsres
= nsISupports_QueryInterface(iface
, &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
606 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, riid
, ppv
);
607 nsIInterfaceRequestor_Release(iface_req
);
612 static HRESULT
nsnode_to_nsstring_rec(nsIContentSerializer
*serializer
, nsIDOMNode
*nsnode
, nsAString
*str
)
614 nsIDOMNodeList
*node_list
= NULL
;
615 PRBool has_children
= FALSE
;
619 nsIDOMNode_HasChildNodes(nsnode
, &has_children
);
621 nsres
= nsIDOMNode_GetNodeType(nsnode
, &type
);
622 if(NS_FAILED(nsres
)) {
623 ERR("GetType failed: %08x\n", nsres
);
629 nsIDOMElement
*nselem
;
630 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
631 nsIContentSerializer_AppendElementStart(serializer
, nselem
, nselem
, str
);
632 nsIDOMElement_Release(nselem
);
637 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&nstext
);
638 nsIContentSerializer_AppendText(serializer
, nstext
, 0, -1, str
);
639 nsIDOMText_Release(nstext
);
643 nsIDOMComment
*nscomment
;
644 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMComment
, (void**)&nscomment
);
645 nsres
= nsIContentSerializer_AppendComment(serializer
, nscomment
, 0, -1, str
);
648 case DOCUMENT_NODE
: {
649 nsIDOMDocument
*nsdoc
;
650 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMDocument
, (void**)&nsdoc
);
651 nsIContentSerializer_AppendDocumentStart(serializer
, nsdoc
, str
);
652 nsIDOMDocument_Release(nsdoc
);
655 case DOCUMENT_TYPE_NODE
:
656 WARN("Ignoring DOCUMENT_TYPE_NODE\n");
658 case DOCUMENT_FRAGMENT_NODE
:
661 FIXME("Unhandled type %u\n", type
);
665 PRUint32 child_cnt
, i
;
666 nsIDOMNode
*child_node
;
668 nsIDOMNode_GetChildNodes(nsnode
, &node_list
);
669 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
671 for(i
=0; i
<child_cnt
; i
++) {
672 nsres
= nsIDOMNodeList_Item(node_list
, i
, &child_node
);
673 if(NS_SUCCEEDED(nsres
)) {
674 nsnode_to_nsstring_rec(serializer
, child_node
, str
);
675 nsIDOMNode_Release(child_node
);
677 ERR("Item failed: %08x\n", nsres
);
681 nsIDOMNodeList_Release(node_list
);
684 if(type
== ELEMENT_NODE
) {
685 nsIDOMElement
*nselem
;
686 nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMElement
, (void**)&nselem
);
687 nsIContentSerializer_AppendElementEnd(serializer
, nselem
, str
);
688 nsIDOMElement_Release(nselem
);
694 HRESULT
nsnode_to_nsstring(nsIDOMNode
*nsnode
, nsAString
*str
)
696 nsIContentSerializer
*serializer
;
700 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
701 NS_HTMLSERIALIZER_CONTRACTID
, NULL
, &IID_nsIContentSerializer
,
702 (void**)&serializer
);
703 if(NS_FAILED(nsres
)) {
704 ERR("Could not get nsIContentSerializer: %08x\n", nsres
);
708 nsres
= nsIContentSerializer_Init(serializer
, 0, 100, NULL
, FALSE
, FALSE
/* FIXME */);
710 ERR("Init failed: %08x\n", nsres
);
712 hres
= nsnode_to_nsstring_rec(serializer
, nsnode
, str
);
713 if(SUCCEEDED(hres
)) {
714 nsres
= nsIContentSerializer_Flush(serializer
, str
);
716 ERR("Flush failed: %08x\n", nsres
);
719 nsIContentSerializer_Release(serializer
);
723 void get_editor_controller(NSContainer
*This
)
725 nsIEditingSession
*editing_session
= NULL
;
726 nsIControllerContext
*ctrlctx
;
730 nsIEditor_Release(This
->editor
);
734 if(This
->editor_controller
) {
735 nsIController_Release(This
->editor_controller
);
736 This
->editor_controller
= NULL
;
739 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
740 (void**)&editing_session
);
741 if(NS_FAILED(nsres
)) {
742 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
746 nsres
= nsIEditingSession_GetEditorForWindow(editing_session
,
747 This
->doc
->basedoc
.window
->nswindow
, &This
->editor
);
748 nsIEditingSession_Release(editing_session
);
749 if(NS_FAILED(nsres
)) {
750 ERR("Could not get editor: %08x\n", nsres
);
754 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
,
755 NS_EDITORCONTROLLER_CONTRACTID
, NULL
, &IID_nsIControllerContext
, (void**)&ctrlctx
);
756 if(NS_SUCCEEDED(nsres
)) {
757 nsres
= nsIControllerContext_SetCommandContext(ctrlctx
, (nsISupports
*)This
->editor
);
759 ERR("SetCommandContext failed: %08x\n", nsres
);
760 nsres
= nsIControllerContext_QueryInterface(ctrlctx
, &IID_nsIController
,
761 (void**)&This
->editor_controller
);
762 nsIControllerContext_Release(ctrlctx
);
764 ERR("Could not get nsIController interface: %08x\n", nsres
);
766 ERR("Could not create edit controller: %08x\n", nsres
);
770 void set_ns_editmode(NSContainer
*This
)
772 nsIEditingSession
*editing_session
= NULL
;
773 nsIURIContentListener
*listener
= NULL
;
774 nsIDOMWindow
*dom_window
= NULL
;
777 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsIEditingSession
,
778 (void**)&editing_session
);
779 if(NS_FAILED(nsres
)) {
780 ERR("Could not get nsIEditingSession: %08x\n", nsres
);
784 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, &dom_window
);
785 if(NS_FAILED(nsres
)) {
786 ERR("Could not get content DOM window: %08x\n", nsres
);
787 nsIEditingSession_Release(editing_session
);
791 nsres
= nsIEditingSession_MakeWindowEditable(editing_session
, dom_window
,
792 NULL
, FALSE
, TRUE
, TRUE
);
793 nsIEditingSession_Release(editing_session
);
794 nsIDOMWindow_Release(dom_window
);
795 if(NS_FAILED(nsres
)) {
796 ERR("MakeWindowEditable failed: %08x\n", nsres
);
800 /* MakeWindowEditable changes WebBrowser's parent URI content listener.
801 * It seams to be a bug in Gecko. To workaround it we set our content
802 * listener again and Gecko's one as its parent.
804 nsIWebBrowser_GetParentURIContentListener(This
->webbrowser
, &listener
);
805 nsIURIContentListener_SetParentContentListener(NSURICL(This
), listener
);
806 nsIURIContentListener_Release(listener
);
807 nsIWebBrowser_SetParentURIContentListener(This
->webbrowser
, NSURICL(This
));
810 void close_gecko(void)
817 nsIComponentManager_Release(pCompMgr
);
820 nsIServiceManager_Release(pServMgr
);
823 nsIMemory_Release(nsmem
);
825 /* Gecko doesn't really support being unloaded */
826 /* if (hXPCOM) FreeLibrary(hXPCOM); */
829 /**********************************************************
830 * nsIWebBrowserChrome interface
833 #define NSWBCHROME_THIS(iface) DEFINE_THIS(NSContainer, WebBrowserChrome, iface)
835 static nsresult NSAPI
nsWebBrowserChrome_QueryInterface(nsIWebBrowserChrome
*iface
,
836 nsIIDRef riid
, nsQIResult result
)
838 NSContainer
*This
= NSWBCHROME_THIS(iface
);
841 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
842 TRACE("(%p)->(IID_nsISupports, %p)\n", This
, result
);
843 *result
= NSWBCHROME(This
);
844 }else if(IsEqualGUID(&IID_nsIWebBrowserChrome
, riid
)) {
845 TRACE("(%p)->(IID_nsIWebBrowserChrome, %p)\n", This
, result
);
846 *result
= NSWBCHROME(This
);
847 }else if(IsEqualGUID(&IID_nsIContextMenuListener
, riid
)) {
848 TRACE("(%p)->(IID_nsIContextMenuListener, %p)\n", This
, result
);
849 *result
= NSCML(This
);
850 }else if(IsEqualGUID(&IID_nsIURIContentListener
, riid
)) {
851 TRACE("(%p)->(IID_nsIURIContentListener %p)\n", This
, result
);
852 *result
= NSURICL(This
);
853 }else if(IsEqualGUID(&IID_nsIEmbeddingSiteWindow
, riid
)) {
854 TRACE("(%p)->(IID_nsIEmbeddingSiteWindow %p)\n", This
, result
);
855 *result
= NSEMBWNDS(This
);
856 }else if(IsEqualGUID(&IID_nsITooltipListener
, riid
)) {
857 TRACE("(%p)->(IID_nsITooltipListener %p)\n", This
, result
);
858 *result
= NSTOOLTIP(This
);
859 }else if(IsEqualGUID(&IID_nsIInterfaceRequestor
, riid
)) {
860 TRACE("(%p)->(IID_nsIInterfaceRequestor %p)\n", This
, result
);
861 *result
= NSIFACEREQ(This
);
862 }else if(IsEqualGUID(&IID_nsIWeakReference
, riid
)) {
863 TRACE("(%p)->(IID_nsIWeakReference %p)\n", This
, result
);
864 *result
= NSWEAKREF(This
);
865 }else if(IsEqualGUID(&IID_nsISupportsWeakReference
, riid
)) {
866 TRACE("(%p)->(IID_nsISupportsWeakReference %p)\n", This
, result
);
867 *result
= NSSUPWEAKREF(This
);
871 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
875 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
876 return NS_NOINTERFACE
;
879 static nsrefcnt NSAPI
nsWebBrowserChrome_AddRef(nsIWebBrowserChrome
*iface
)
881 NSContainer
*This
= NSWBCHROME_THIS(iface
);
882 LONG ref
= InterlockedIncrement(&This
->ref
);
884 TRACE("(%p) ref=%d\n", This
, ref
);
889 static nsrefcnt NSAPI
nsWebBrowserChrome_Release(nsIWebBrowserChrome
*iface
)
891 NSContainer
*This
= NSWBCHROME_THIS(iface
);
892 LONG ref
= InterlockedDecrement(&This
->ref
);
894 TRACE("(%p) ref=%d\n", This
, ref
);
898 nsIWebBrowserChrome_Release(NSWBCHROME(This
->parent
));
905 static nsresult NSAPI
nsWebBrowserChrome_SetStatus(nsIWebBrowserChrome
*iface
,
906 PRUint32 statusType
, const PRUnichar
*status
)
908 NSContainer
*This
= NSWBCHROME_THIS(iface
);
909 TRACE("(%p)->(%d %s)\n", This
, statusType
, debugstr_w(status
));
913 static nsresult NSAPI
nsWebBrowserChrome_GetWebBrowser(nsIWebBrowserChrome
*iface
,
914 nsIWebBrowser
**aWebBrowser
)
916 NSContainer
*This
= NSWBCHROME_THIS(iface
);
918 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
921 return NS_ERROR_INVALID_ARG
;
924 nsIWebBrowser_AddRef(This
->webbrowser
);
925 *aWebBrowser
= This
->webbrowser
;
929 static nsresult NSAPI
nsWebBrowserChrome_SetWebBrowser(nsIWebBrowserChrome
*iface
,
930 nsIWebBrowser
*aWebBrowser
)
932 NSContainer
*This
= NSWBCHROME_THIS(iface
);
934 TRACE("(%p)->(%p)\n", This
, aWebBrowser
);
936 if(aWebBrowser
!= This
->webbrowser
)
937 ERR("Wrong nsWebBrowser!\n");
942 static nsresult NSAPI
nsWebBrowserChrome_GetChromeFlags(nsIWebBrowserChrome
*iface
,
943 PRUint32
*aChromeFlags
)
945 NSContainer
*This
= NSWBCHROME_THIS(iface
);
946 WARN("(%p)->(%p)\n", This
, aChromeFlags
);
947 return NS_ERROR_NOT_IMPLEMENTED
;
950 static nsresult NSAPI
nsWebBrowserChrome_SetChromeFlags(nsIWebBrowserChrome
*iface
,
951 PRUint32 aChromeFlags
)
953 NSContainer
*This
= NSWBCHROME_THIS(iface
);
954 WARN("(%p)->(%08x)\n", This
, aChromeFlags
);
955 return NS_ERROR_NOT_IMPLEMENTED
;
958 static nsresult NSAPI
nsWebBrowserChrome_DestroyBrowserWindow(nsIWebBrowserChrome
*iface
)
960 NSContainer
*This
= NSWBCHROME_THIS(iface
);
961 TRACE("(%p)\n", This
);
962 return NS_ERROR_NOT_IMPLEMENTED
;
965 static nsresult NSAPI
nsWebBrowserChrome_SizeBrowserTo(nsIWebBrowserChrome
*iface
,
966 PRInt32 aCX
, PRInt32 aCY
)
968 NSContainer
*This
= NSWBCHROME_THIS(iface
);
969 WARN("(%p)->(%d %d)\n", This
, aCX
, aCY
);
970 return NS_ERROR_NOT_IMPLEMENTED
;
973 static nsresult NSAPI
nsWebBrowserChrome_ShowAsModal(nsIWebBrowserChrome
*iface
)
975 NSContainer
*This
= NSWBCHROME_THIS(iface
);
976 WARN("(%p)\n", This
);
977 return NS_ERROR_NOT_IMPLEMENTED
;
980 static nsresult NSAPI
nsWebBrowserChrome_IsWindowModal(nsIWebBrowserChrome
*iface
, PRBool
*_retval
)
982 NSContainer
*This
= NSWBCHROME_THIS(iface
);
983 WARN("(%p)->(%p)\n", This
, _retval
);
984 return NS_ERROR_NOT_IMPLEMENTED
;
987 static nsresult NSAPI
nsWebBrowserChrome_ExitModalEventLoop(nsIWebBrowserChrome
*iface
,
990 NSContainer
*This
= NSWBCHROME_THIS(iface
);
991 WARN("(%p)->(%08x)\n", This
, aStatus
);
992 return NS_ERROR_NOT_IMPLEMENTED
;
995 #undef NSWBCHROME_THIS
997 static const nsIWebBrowserChromeVtbl nsWebBrowserChromeVtbl
= {
998 nsWebBrowserChrome_QueryInterface
,
999 nsWebBrowserChrome_AddRef
,
1000 nsWebBrowserChrome_Release
,
1001 nsWebBrowserChrome_SetStatus
,
1002 nsWebBrowserChrome_GetWebBrowser
,
1003 nsWebBrowserChrome_SetWebBrowser
,
1004 nsWebBrowserChrome_GetChromeFlags
,
1005 nsWebBrowserChrome_SetChromeFlags
,
1006 nsWebBrowserChrome_DestroyBrowserWindow
,
1007 nsWebBrowserChrome_SizeBrowserTo
,
1008 nsWebBrowserChrome_ShowAsModal
,
1009 nsWebBrowserChrome_IsWindowModal
,
1010 nsWebBrowserChrome_ExitModalEventLoop
1013 /**********************************************************
1014 * nsIContextMenuListener interface
1017 #define NSCML_THIS(iface) DEFINE_THIS(NSContainer, ContextMenuListener, iface)
1019 static nsresult NSAPI
nsContextMenuListener_QueryInterface(nsIContextMenuListener
*iface
,
1020 nsIIDRef riid
, nsQIResult result
)
1022 NSContainer
*This
= NSCML_THIS(iface
);
1023 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1026 static nsrefcnt NSAPI
nsContextMenuListener_AddRef(nsIContextMenuListener
*iface
)
1028 NSContainer
*This
= NSCML_THIS(iface
);
1029 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1032 static nsrefcnt NSAPI
nsContextMenuListener_Release(nsIContextMenuListener
*iface
)
1034 NSContainer
*This
= NSCML_THIS(iface
);
1035 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1038 static nsresult NSAPI
nsContextMenuListener_OnShowContextMenu(nsIContextMenuListener
*iface
,
1039 PRUint32 aContextFlags
, nsIDOMEvent
*aEvent
, nsIDOMNode
*aNode
)
1041 NSContainer
*This
= NSCML_THIS(iface
);
1042 nsIDOMMouseEvent
*event
;
1044 DWORD dwID
= CONTEXT_MENU_DEFAULT
;
1047 TRACE("(%p)->(%08x %p %p)\n", This
, aContextFlags
, aEvent
, aNode
);
1049 nsres
= nsIDOMEvent_QueryInterface(aEvent
, &IID_nsIDOMMouseEvent
, (void**)&event
);
1050 if(NS_FAILED(nsres
)) {
1051 ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres
);
1055 nsIDOMMouseEvent_GetScreenX(event
, &pt
.x
);
1056 nsIDOMMouseEvent_GetScreenY(event
, &pt
.y
);
1057 nsIDOMMouseEvent_Release(event
);
1059 switch(aContextFlags
) {
1061 case CONTEXT_DOCUMENT
:
1063 dwID
= CONTEXT_MENU_DEFAULT
;
1066 case CONTEXT_IMAGE
|CONTEXT_LINK
:
1067 dwID
= CONTEXT_MENU_IMAGE
;
1070 dwID
= CONTEXT_MENU_ANCHOR
;
1073 dwID
= CONTEXT_MENU_CONTROL
;
1076 FIXME("aContextFlags=%08x\n", aContextFlags
);
1079 show_context_menu(This
->doc
, dwID
, &pt
, (IDispatch
*)HTMLDOMNODE(get_node(This
->doc
->basedoc
.doc_node
, aNode
, TRUE
)));
1086 static const nsIContextMenuListenerVtbl nsContextMenuListenerVtbl
= {
1087 nsContextMenuListener_QueryInterface
,
1088 nsContextMenuListener_AddRef
,
1089 nsContextMenuListener_Release
,
1090 nsContextMenuListener_OnShowContextMenu
1093 /**********************************************************
1094 * nsIURIContentListener interface
1097 #define NSURICL_THIS(iface) DEFINE_THIS(NSContainer, URIContentListener, iface)
1099 static nsresult NSAPI
nsURIContentListener_QueryInterface(nsIURIContentListener
*iface
,
1100 nsIIDRef riid
, nsQIResult result
)
1102 NSContainer
*This
= NSURICL_THIS(iface
);
1103 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1106 static nsrefcnt NSAPI
nsURIContentListener_AddRef(nsIURIContentListener
*iface
)
1108 NSContainer
*This
= NSURICL_THIS(iface
);
1109 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1112 static nsrefcnt NSAPI
nsURIContentListener_Release(nsIURIContentListener
*iface
)
1114 NSContainer
*This
= NSURICL_THIS(iface
);
1115 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1118 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsIWineURI
*nsuri
)
1120 OLECHAR
*new_url
= NULL
, *url
;
1128 nsIWineURI_GetWineURL(nsuri
, &wine_url
);
1130 url
= heap_strdupW(wine_url
);
1131 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
1133 if(hres
!= S_OK
|| !new_url
)
1136 if(strcmpW(url
, new_url
)) {
1137 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
1141 CoTaskMemFree(new_url
);
1145 static nsresult NSAPI
nsURIContentListener_OnStartURIOpen(nsIURIContentListener
*iface
,
1146 nsIURI
*aURI
, PRBool
*_retval
)
1148 NSContainer
*This
= NSURICL_THIS(iface
);
1149 nsIWineURI
*wine_uri
;
1150 nsACString spec_str
;
1155 nsACString_Init(&spec_str
, NULL
);
1156 nsIURI_GetSpec(aURI
, &spec_str
);
1157 nsACString_GetData(&spec_str
, &spec
);
1159 TRACE("(%p)->(%p(%s) %p)\n", This
, aURI
, debugstr_a(spec
), _retval
);
1161 nsACString_Finish(&spec_str
);
1163 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsIWineURI
, (void**)&wine_uri
);
1164 if(NS_FAILED(nsres
)) {
1165 WARN("Could not get nsIWineURI interface: %08x\n", nsres
);
1166 return NS_ERROR_NOT_IMPLEMENTED
;
1169 nsIWineURI_GetIsDocumentURI(wine_uri
, &is_doc_uri
);
1172 nsIWineURI_SetNSContainer(wine_uri
, This
);
1173 nsIWineURI_SetIsDocumentURI(wine_uri
, TRUE
);
1175 *_retval
= translate_url(This
->doc
->basedoc
.doc_obj
, wine_uri
);
1178 nsIWineURI_Release(wine_uri
);
1180 return !*_retval
&& This
->content_listener
1181 ? nsIURIContentListener_OnStartURIOpen(This
->content_listener
, aURI
, _retval
)
1185 static nsresult NSAPI
nsURIContentListener_DoContent(nsIURIContentListener
*iface
,
1186 const char *aContentType
, PRBool aIsContentPreferred
, nsIRequest
*aRequest
,
1187 nsIStreamListener
**aContentHandler
, PRBool
*_retval
)
1189 NSContainer
*This
= NSURICL_THIS(iface
);
1191 TRACE("(%p)->(%s %x %p %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1192 aRequest
, aContentHandler
, _retval
);
1194 return This
->content_listener
1195 ? nsIURIContentListener_DoContent(This
->content_listener
, aContentType
,
1196 aIsContentPreferred
, aRequest
, aContentHandler
, _retval
)
1197 : NS_ERROR_NOT_IMPLEMENTED
;
1200 static nsresult NSAPI
nsURIContentListener_IsPreferred(nsIURIContentListener
*iface
,
1201 const char *aContentType
, char **aDesiredContentType
, PRBool
*_retval
)
1203 NSContainer
*This
= NSURICL_THIS(iface
);
1205 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_a(aContentType
), aDesiredContentType
, _retval
);
1207 /* FIXME: Should we do something here? */
1210 return This
->content_listener
1211 ? nsIURIContentListener_IsPreferred(This
->content_listener
, aContentType
,
1212 aDesiredContentType
, _retval
)
1216 static nsresult NSAPI
nsURIContentListener_CanHandleContent(nsIURIContentListener
*iface
,
1217 const char *aContentType
, PRBool aIsContentPreferred
, char **aDesiredContentType
,
1220 NSContainer
*This
= NSURICL_THIS(iface
);
1222 TRACE("(%p)->(%s %x %p %p)\n", This
, debugstr_a(aContentType
), aIsContentPreferred
,
1223 aDesiredContentType
, _retval
);
1225 return This
->content_listener
1226 ? nsIURIContentListener_CanHandleContent(This
->content_listener
, aContentType
,
1227 aIsContentPreferred
, aDesiredContentType
, _retval
)
1228 : NS_ERROR_NOT_IMPLEMENTED
;
1231 static nsresult NSAPI
nsURIContentListener_GetLoadCookie(nsIURIContentListener
*iface
,
1232 nsISupports
**aLoadCookie
)
1234 NSContainer
*This
= NSURICL_THIS(iface
);
1236 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1238 return This
->content_listener
1239 ? nsIURIContentListener_GetLoadCookie(This
->content_listener
, aLoadCookie
)
1240 : NS_ERROR_NOT_IMPLEMENTED
;
1243 static nsresult NSAPI
nsURIContentListener_SetLoadCookie(nsIURIContentListener
*iface
,
1244 nsISupports
*aLoadCookie
)
1246 NSContainer
*This
= NSURICL_THIS(iface
);
1248 WARN("(%p)->(%p)\n", This
, aLoadCookie
);
1250 return This
->content_listener
1251 ? nsIURIContentListener_SetLoadCookie(This
->content_listener
, aLoadCookie
)
1252 : NS_ERROR_NOT_IMPLEMENTED
;
1255 static nsresult NSAPI
nsURIContentListener_GetParentContentListener(nsIURIContentListener
*iface
,
1256 nsIURIContentListener
**aParentContentListener
)
1258 NSContainer
*This
= NSURICL_THIS(iface
);
1260 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1262 if(This
->content_listener
)
1263 nsIURIContentListener_AddRef(This
->content_listener
);
1265 *aParentContentListener
= This
->content_listener
;
1269 static nsresult NSAPI
nsURIContentListener_SetParentContentListener(nsIURIContentListener
*iface
,
1270 nsIURIContentListener
*aParentContentListener
)
1272 NSContainer
*This
= NSURICL_THIS(iface
);
1274 TRACE("(%p)->(%p)\n", This
, aParentContentListener
);
1276 if(aParentContentListener
== NSURICL(This
))
1279 if(This
->content_listener
)
1280 nsIURIContentListener_Release(This
->content_listener
);
1282 This
->content_listener
= aParentContentListener
;
1283 if(This
->content_listener
)
1284 nsIURIContentListener_AddRef(This
->content_listener
);
1291 static const nsIURIContentListenerVtbl nsURIContentListenerVtbl
= {
1292 nsURIContentListener_QueryInterface
,
1293 nsURIContentListener_AddRef
,
1294 nsURIContentListener_Release
,
1295 nsURIContentListener_OnStartURIOpen
,
1296 nsURIContentListener_DoContent
,
1297 nsURIContentListener_IsPreferred
,
1298 nsURIContentListener_CanHandleContent
,
1299 nsURIContentListener_GetLoadCookie
,
1300 nsURIContentListener_SetLoadCookie
,
1301 nsURIContentListener_GetParentContentListener
,
1302 nsURIContentListener_SetParentContentListener
1305 /**********************************************************
1306 * nsIEmbeddinSiteWindow interface
1309 #define NSEMBWNDS_THIS(iface) DEFINE_THIS(NSContainer, EmbeddingSiteWindow, iface)
1311 static nsresult NSAPI
nsEmbeddingSiteWindow_QueryInterface(nsIEmbeddingSiteWindow
*iface
,
1312 nsIIDRef riid
, nsQIResult result
)
1314 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1315 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1318 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_AddRef(nsIEmbeddingSiteWindow
*iface
)
1320 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1321 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1324 static nsrefcnt NSAPI
nsEmbeddingSiteWindow_Release(nsIEmbeddingSiteWindow
*iface
)
1326 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1327 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1330 static nsresult NSAPI
nsEmbeddingSiteWindow_SetDimensions(nsIEmbeddingSiteWindow
*iface
,
1331 PRUint32 flags
, PRInt32 x
, PRInt32 y
, PRInt32 cx
, PRInt32 cy
)
1333 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1334 WARN("(%p)->(%08x %d %d %d %d)\n", This
, flags
, x
, y
, cx
, cy
);
1335 return NS_ERROR_NOT_IMPLEMENTED
;
1338 static nsresult NSAPI
nsEmbeddingSiteWindow_GetDimensions(nsIEmbeddingSiteWindow
*iface
,
1339 PRUint32 flags
, PRInt32
*x
, PRInt32
*y
, PRInt32
*cx
, PRInt32
*cy
)
1341 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1342 WARN("(%p)->(%08x %p %p %p %p)\n", This
, flags
, x
, y
, cx
, cy
);
1343 return NS_ERROR_NOT_IMPLEMENTED
;
1346 static nsresult NSAPI
nsEmbeddingSiteWindow_SetFocus(nsIEmbeddingSiteWindow
*iface
)
1348 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1350 TRACE("(%p)\n", This
);
1352 if(This
->reset_focus
)
1353 PostMessageW(This
->hwnd
, WM_RESETFOCUS_HACK
, 0, 0);
1355 return nsIBaseWindow_SetFocus(This
->window
);
1358 static nsresult NSAPI
nsEmbeddingSiteWindow_GetVisibility(nsIEmbeddingSiteWindow
*iface
,
1359 PRBool
*aVisibility
)
1361 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1363 TRACE("(%p)->(%p)\n", This
, aVisibility
);
1365 *aVisibility
= This
->doc
&& This
->doc
->hwnd
&& IsWindowVisible(This
->doc
->hwnd
);
1369 static nsresult NSAPI
nsEmbeddingSiteWindow_SetVisibility(nsIEmbeddingSiteWindow
*iface
,
1372 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1374 TRACE("(%p)->(%x)\n", This
, aVisibility
);
1379 static nsresult NSAPI
nsEmbeddingSiteWindow_GetTitle(nsIEmbeddingSiteWindow
*iface
,
1382 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1383 WARN("(%p)->(%p)\n", This
, aTitle
);
1384 return NS_ERROR_NOT_IMPLEMENTED
;
1387 static nsresult NSAPI
nsEmbeddingSiteWindow_SetTitle(nsIEmbeddingSiteWindow
*iface
,
1388 const PRUnichar
*aTitle
)
1390 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1391 WARN("(%p)->(%s)\n", This
, debugstr_w(aTitle
));
1392 return NS_ERROR_NOT_IMPLEMENTED
;
1395 static nsresult NSAPI
nsEmbeddingSiteWindow_GetSiteWindow(nsIEmbeddingSiteWindow
*iface
,
1398 NSContainer
*This
= NSEMBWNDS_THIS(iface
);
1400 TRACE("(%p)->(%p)\n", This
, aSiteWindow
);
1402 *aSiteWindow
= This
->hwnd
;
1406 static const nsIEmbeddingSiteWindowVtbl nsEmbeddingSiteWindowVtbl
= {
1407 nsEmbeddingSiteWindow_QueryInterface
,
1408 nsEmbeddingSiteWindow_AddRef
,
1409 nsEmbeddingSiteWindow_Release
,
1410 nsEmbeddingSiteWindow_SetDimensions
,
1411 nsEmbeddingSiteWindow_GetDimensions
,
1412 nsEmbeddingSiteWindow_SetFocus
,
1413 nsEmbeddingSiteWindow_GetVisibility
,
1414 nsEmbeddingSiteWindow_SetVisibility
,
1415 nsEmbeddingSiteWindow_GetTitle
,
1416 nsEmbeddingSiteWindow_SetTitle
,
1417 nsEmbeddingSiteWindow_GetSiteWindow
1420 #define NSTOOLTIP_THIS(iface) DEFINE_THIS(NSContainer, TooltipListener, iface)
1422 static nsresult NSAPI
nsTooltipListener_QueryInterface(nsITooltipListener
*iface
, nsIIDRef riid
,
1425 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1426 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1429 static nsrefcnt NSAPI
nsTooltipListener_AddRef(nsITooltipListener
*iface
)
1431 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1432 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1435 static nsrefcnt NSAPI
nsTooltipListener_Release(nsITooltipListener
*iface
)
1437 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1438 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1441 static nsresult NSAPI
nsTooltipListener_OnShowTooltip(nsITooltipListener
*iface
,
1442 PRInt32 aXCoord
, PRInt32 aYCoord
, const PRUnichar
*aTipText
)
1444 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1447 show_tooltip(This
->doc
, aXCoord
, aYCoord
, aTipText
);
1452 static nsresult NSAPI
nsTooltipListener_OnHideTooltip(nsITooltipListener
*iface
)
1454 NSContainer
*This
= NSTOOLTIP_THIS(iface
);
1457 hide_tooltip(This
->doc
);
1462 #undef NSTOOLTIM_THIS
1464 static const nsITooltipListenerVtbl nsTooltipListenerVtbl
= {
1465 nsTooltipListener_QueryInterface
,
1466 nsTooltipListener_AddRef
,
1467 nsTooltipListener_Release
,
1468 nsTooltipListener_OnShowTooltip
,
1469 nsTooltipListener_OnHideTooltip
1472 #define NSIFACEREQ_THIS(iface) DEFINE_THIS(NSContainer, InterfaceRequestor, iface)
1474 static nsresult NSAPI
nsInterfaceRequestor_QueryInterface(nsIInterfaceRequestor
*iface
,
1475 nsIIDRef riid
, nsQIResult result
)
1477 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1478 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1481 static nsrefcnt NSAPI
nsInterfaceRequestor_AddRef(nsIInterfaceRequestor
*iface
)
1483 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1484 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1487 static nsrefcnt NSAPI
nsInterfaceRequestor_Release(nsIInterfaceRequestor
*iface
)
1489 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1490 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1493 static nsresult NSAPI
nsInterfaceRequestor_GetInterface(nsIInterfaceRequestor
*iface
,
1494 nsIIDRef riid
, nsQIResult result
)
1496 NSContainer
*This
= NSIFACEREQ_THIS(iface
);
1498 if(IsEqualGUID(&IID_nsIDOMWindow
, riid
)) {
1499 TRACE("(%p)->(IID_nsIDOMWindow %p)\n", This
, result
);
1500 return nsIWebBrowser_GetContentDOMWindow(This
->webbrowser
, (nsIDOMWindow
**)result
);
1503 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1506 #undef NSIFACEREQ_THIS
1508 static const nsIInterfaceRequestorVtbl nsInterfaceRequestorVtbl
= {
1509 nsInterfaceRequestor_QueryInterface
,
1510 nsInterfaceRequestor_AddRef
,
1511 nsInterfaceRequestor_Release
,
1512 nsInterfaceRequestor_GetInterface
1515 #define NSWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, WeakReference, iface)
1517 static nsresult NSAPI
nsWeakReference_QueryInterface(nsIWeakReference
*iface
,
1518 nsIIDRef riid
, nsQIResult result
)
1520 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1521 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1524 static nsrefcnt NSAPI
nsWeakReference_AddRef(nsIWeakReference
*iface
)
1526 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1527 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1530 static nsrefcnt NSAPI
nsWeakReference_Release(nsIWeakReference
*iface
)
1532 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1533 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1536 static nsresult NSAPI
nsWeakReference_QueryReferent(nsIWeakReference
*iface
,
1537 const nsIID
*riid
, void **result
)
1539 NSContainer
*This
= NSWEAKREF_THIS(iface
);
1540 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1543 #undef NSWEAKREF_THIS
1545 static const nsIWeakReferenceVtbl nsWeakReferenceVtbl
= {
1546 nsWeakReference_QueryInterface
,
1547 nsWeakReference_AddRef
,
1548 nsWeakReference_Release
,
1549 nsWeakReference_QueryReferent
1552 #define NSSUPWEAKREF_THIS(iface) DEFINE_THIS(NSContainer, SupportsWeakReference, iface)
1554 static nsresult NSAPI
nsSupportsWeakReference_QueryInterface(nsISupportsWeakReference
*iface
,
1555 nsIIDRef riid
, nsQIResult result
)
1557 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1558 return nsIWebBrowserChrome_QueryInterface(NSWBCHROME(This
), riid
, result
);
1561 static nsrefcnt NSAPI
nsSupportsWeakReference_AddRef(nsISupportsWeakReference
*iface
)
1563 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1564 return nsIWebBrowserChrome_AddRef(NSWBCHROME(This
));
1567 static nsrefcnt NSAPI
nsSupportsWeakReference_Release(nsISupportsWeakReference
*iface
)
1569 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1570 return nsIWebBrowserChrome_Release(NSWBCHROME(This
));
1573 static nsresult NSAPI
nsSupportsWeakReference_GetWeakReference(nsISupportsWeakReference
*iface
,
1574 nsIWeakReference
**_retval
)
1576 NSContainer
*This
= NSSUPWEAKREF_THIS(iface
);
1578 TRACE("(%p)->(%p)\n", This
, _retval
);
1580 nsIWeakReference_AddRef(NSWEAKREF(This
));
1581 *_retval
= NSWEAKREF(This
);
1585 #undef NSWEAKREF_THIS
1587 static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl
= {
1588 nsSupportsWeakReference_QueryInterface
,
1589 nsSupportsWeakReference_AddRef
,
1590 nsSupportsWeakReference_Release
,
1591 nsSupportsWeakReference_GetWeakReference
1595 NSContainer
*NSContainer_Create(HTMLDocumentObj
*doc
, NSContainer
*parent
)
1597 nsIWebBrowserSetup
*wbsetup
;
1598 nsIScrollable
*scrollable
;
1602 if(!load_gecko(TRUE
))
1605 ret
= heap_alloc_zero(sizeof(NSContainer
));
1607 ret
->lpWebBrowserChromeVtbl
= &nsWebBrowserChromeVtbl
;
1608 ret
->lpContextMenuListenerVtbl
= &nsContextMenuListenerVtbl
;
1609 ret
->lpURIContentListenerVtbl
= &nsURIContentListenerVtbl
;
1610 ret
->lpEmbeddingSiteWindowVtbl
= &nsEmbeddingSiteWindowVtbl
;
1611 ret
->lpTooltipListenerVtbl
= &nsTooltipListenerVtbl
;
1612 ret
->lpInterfaceRequestorVtbl
= &nsInterfaceRequestorVtbl
;
1613 ret
->lpWeakReferenceVtbl
= &nsWeakReferenceVtbl
;
1614 ret
->lpSupportsWeakReferenceVtbl
= &nsSupportsWeakReferenceVtbl
;
1619 nsres
= nsIComponentManager_CreateInstanceByContractID(pCompMgr
, NS_WEBBROWSER_CONTRACTID
,
1620 NULL
, &IID_nsIWebBrowser
, (void**)&ret
->webbrowser
);
1621 if(NS_FAILED(nsres
)) {
1622 ERR("Creating WebBrowser failed: %08x\n", nsres
);
1628 nsIWebBrowserChrome_AddRef(NSWBCHROME(parent
));
1629 ret
->parent
= parent
;
1631 nsres
= nsIWebBrowser_SetContainerWindow(ret
->webbrowser
, NSWBCHROME(ret
));
1632 if(NS_FAILED(nsres
))
1633 ERR("SetContainerWindow failed: %08x\n", nsres
);
1635 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIBaseWindow
,
1636 (void**)&ret
->window
);
1637 if(NS_FAILED(nsres
))
1638 ERR("Could not get nsIBaseWindow interface: %08x\n", nsres
);
1640 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserSetup
,
1642 if(NS_SUCCEEDED(nsres
)) {
1643 nsres
= nsIWebBrowserSetup_SetProperty(wbsetup
, SETUP_IS_CHROME_WRAPPER
, FALSE
);
1644 nsIWebBrowserSetup_Release(wbsetup
);
1645 if(NS_FAILED(nsres
))
1646 ERR("SetProperty(SETUP_IS_CHROME_WRAPPER) failed: %08x\n", nsres
);
1648 ERR("Could not get nsIWebBrowserSetup interface\n");
1651 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIWebNavigation
,
1652 (void**)&ret
->navigation
);
1653 if(NS_FAILED(nsres
))
1654 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
1656 nsres
= nsIWebBrowserFocus_QueryInterface(ret
->webbrowser
, &IID_nsIWebBrowserFocus
,
1657 (void**)&ret
->focus
);
1658 if(NS_FAILED(nsres
))
1659 ERR("Could not get nsIWebBrowserFocus interface: %08x\n", nsres
);
1661 if(!nscontainer_class
)
1662 register_nscontainer_class();
1664 ret
->hwnd
= CreateWindowExW(0, wszNsContainer
, NULL
,
1665 WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, 0, 0, 100, 100,
1666 GetDesktopWindow(), NULL
, hInst
, ret
);
1668 nsres
= nsIBaseWindow_InitWindow(ret
->window
, ret
->hwnd
, NULL
, 0, 0, 100, 100);
1669 if(NS_SUCCEEDED(nsres
)) {
1670 nsres
= nsIBaseWindow_Create(ret
->window
);
1671 if(NS_FAILED(nsres
))
1672 WARN("Creating window failed: %08x\n", nsres
);
1674 nsIBaseWindow_SetVisibility(ret
->window
, FALSE
);
1675 nsIBaseWindow_SetEnabled(ret
->window
, FALSE
);
1677 ERR("InitWindow failed: %08x\n", nsres
);
1680 nsres
= nsIWebBrowser_SetParentURIContentListener(ret
->webbrowser
, NSURICL(ret
));
1681 if(NS_FAILED(nsres
))
1682 ERR("SetParentURIContentListener failed: %08x\n", nsres
);
1684 nsres
= nsIWebBrowser_QueryInterface(ret
->webbrowser
, &IID_nsIScrollable
, (void**)&scrollable
);
1685 if(NS_SUCCEEDED(nsres
)) {
1686 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1687 ScrollOrientation_Y
, Scrollbar_Always
);
1688 if(NS_FAILED(nsres
))
1689 ERR("Could not set default Y scrollbar prefs: %08x\n", nsres
);
1691 nsres
= nsIScrollable_SetDefaultScrollbarPreferences(scrollable
,
1692 ScrollOrientation_X
, Scrollbar_Auto
);
1693 if(NS_FAILED(nsres
))
1694 ERR("Could not set default X scrollbar prefs: %08x\n", nsres
);
1696 nsIScrollable_Release(scrollable
);
1698 ERR("Could not get nsIScrollable: %08x\n", nsres
);
1704 void NSContainer_Release(NSContainer
*This
)
1706 TRACE("(%p)\n", This
);
1710 ShowWindow(This
->hwnd
, SW_HIDE
);
1711 SetParent(This
->hwnd
, NULL
);
1713 nsIBaseWindow_SetVisibility(This
->window
, FALSE
);
1714 nsIBaseWindow_Destroy(This
->window
);
1716 nsIWebBrowser_SetContainerWindow(This
->webbrowser
, NULL
);
1718 nsIWebBrowser_Release(This
->webbrowser
);
1719 This
->webbrowser
= NULL
;
1721 nsIWebNavigation_Release(This
->navigation
);
1722 This
->navigation
= NULL
;
1724 nsIBaseWindow_Release(This
->window
);
1725 This
->window
= NULL
;
1727 nsIWebBrowserFocus_Release(This
->focus
);
1730 if(This
->editor_controller
) {
1731 nsIController_Release(This
->editor_controller
);
1732 This
->editor_controller
= NULL
;
1736 nsIEditor_Release(This
->editor
);
1737 This
->editor
= NULL
;
1740 if(This
->content_listener
) {
1741 nsIURIContentListener_Release(This
->content_listener
);
1742 This
->content_listener
= NULL
;
1746 DestroyWindow(This
->hwnd
);
1750 nsIWebBrowserChrome_Release(NSWBCHROME(This
));