xref: /reactos/dll/win32/mshtml/nsservice.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Copyright 2005 Jacek Caban
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
5*c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
6*c2c66affSColin Finck  * License as published by the Free Software Foundation; either
7*c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
8*c2c66affSColin Finck  *
9*c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
10*c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12*c2c66affSColin Finck  * Lesser General Public License for more details.
13*c2c66affSColin Finck  *
14*c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
15*c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
16*c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17*c2c66affSColin Finck  */
18*c2c66affSColin Finck 
19*c2c66affSColin Finck #include "mshtml_private.h"
20*c2c66affSColin Finck 
21*c2c66affSColin Finck #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
22*c2c66affSColin Finck #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
23*c2c66affSColin Finck 
24*c2c66affSColin Finck #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
25*c2c66affSColin Finck 
26*c2c66affSColin Finck static const nsIID NS_PROMPTSERVICE_CID =
27*c2c66affSColin Finck     {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
28*c2c66affSColin Finck static const nsIID NS_TOOLTIPTEXTPROVIDER_CID =
29*c2c66affSColin Finck     {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
30*c2c66affSColin Finck 
nsPromptService_QueryInterface(nsIPromptService * iface,nsIIDRef riid,void ** result)31*c2c66affSColin Finck static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface,
32*c2c66affSColin Finck         nsIIDRef riid, void **result)
33*c2c66affSColin Finck {
34*c2c66affSColin Finck     *result = NULL;
35*c2c66affSColin Finck 
36*c2c66affSColin Finck     if(IsEqualGUID(&IID_nsISupports, riid)) {
37*c2c66affSColin Finck         TRACE("(IID_nsISupports %p)\n", result);
38*c2c66affSColin Finck         *result = iface;
39*c2c66affSColin Finck     }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
40*c2c66affSColin Finck         TRACE("(IID_nsIPromptService %p)\n", result);
41*c2c66affSColin Finck         *result = iface;
42*c2c66affSColin Finck     }
43*c2c66affSColin Finck 
44*c2c66affSColin Finck     if(*result)
45*c2c66affSColin Finck         return NS_OK;
46*c2c66affSColin Finck 
47*c2c66affSColin Finck     TRACE("(%s %p)\n", debugstr_guid(riid), result);
48*c2c66affSColin Finck     return NS_NOINTERFACE;
49*c2c66affSColin Finck }
50*c2c66affSColin Finck 
nsPromptService_AddRef(nsIPromptService * iface)51*c2c66affSColin Finck static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
52*c2c66affSColin Finck {
53*c2c66affSColin Finck     return 2;
54*c2c66affSColin Finck }
55*c2c66affSColin Finck 
nsPromptService_Release(nsIPromptService * iface)56*c2c66affSColin Finck static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
57*c2c66affSColin Finck {
58*c2c66affSColin Finck     return 1;
59*c2c66affSColin Finck }
60*c2c66affSColin Finck 
nsPromptService_Alert(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText)61*c2c66affSColin Finck static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, nsIDOMWindow *aParent,
62*c2c66affSColin Finck         const PRUnichar *aDialogTitle, const PRUnichar *aText)
63*c2c66affSColin Finck {
64*c2c66affSColin Finck     HTMLOuterWindow *window;
65*c2c66affSColin Finck     BSTR text;
66*c2c66affSColin Finck 
67*c2c66affSColin Finck     TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
68*c2c66affSColin Finck 
69*c2c66affSColin Finck     window = nswindow_to_window(aParent);
70*c2c66affSColin Finck     if(!window) {
71*c2c66affSColin Finck         WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent);
72*c2c66affSColin Finck         return NS_ERROR_UNEXPECTED;
73*c2c66affSColin Finck     }
74*c2c66affSColin Finck 
75*c2c66affSColin Finck     text = SysAllocString(aText);
76*c2c66affSColin Finck     IHTMLWindow2_alert(&window->base.IHTMLWindow2_iface, text);
77*c2c66affSColin Finck     SysFreeString(text);
78*c2c66affSColin Finck 
79*c2c66affSColin Finck     return NS_OK;
80*c2c66affSColin Finck }
81*c2c66affSColin Finck 
nsPromptService_AlertCheck(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,const PRUnichar * aCheckMsg,cpp_bool * aCheckState)82*c2c66affSColin Finck static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
83*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
84*c2c66affSColin Finck         const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState)
85*c2c66affSColin Finck {
86*c2c66affSColin Finck     FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
87*c2c66affSColin Finck           debugstr_w(aCheckMsg), aCheckState);
88*c2c66affSColin Finck     return NS_ERROR_NOT_IMPLEMENTED;
89*c2c66affSColin Finck }
90*c2c66affSColin Finck 
nsPromptService_Confirm(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,cpp_bool * _retval)91*c2c66affSColin Finck static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
92*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
93*c2c66affSColin Finck         cpp_bool *_retval)
94*c2c66affSColin Finck {
95*c2c66affSColin Finck     FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
96*c2c66affSColin Finck     return NS_ERROR_NOT_IMPLEMENTED;
97*c2c66affSColin Finck }
98*c2c66affSColin Finck 
nsPromptService_ConfirmCheck(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,const PRUnichar * aCheckMsg,cpp_bool * aCheckState,cpp_bool * _retval)99*c2c66affSColin Finck static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
100*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
101*c2c66affSColin Finck         const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState,
102*c2c66affSColin Finck         cpp_bool *_retval)
103*c2c66affSColin Finck {
104*c2c66affSColin Finck     FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
105*c2c66affSColin Finck         debugstr_w(aCheckMsg), aCheckState, _retval);
106*c2c66affSColin Finck     return NS_ERROR_NOT_IMPLEMENTED;
107*c2c66affSColin Finck }
108*c2c66affSColin Finck 
nsPromptService_ConfirmEx(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,UINT32 aButtonFlags,const PRUnichar * aButton0Title,const PRUnichar * aButton1Title,const PRUnichar * aButton2Title,const PRUnichar * aCheckMsg,cpp_bool * aCheckState,LONG * _retval)109*c2c66affSColin Finck static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
110*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
111*c2c66affSColin Finck         const PRUnichar *aText, UINT32 aButtonFlags, const PRUnichar *aButton0Title,
112*c2c66affSColin Finck         const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
113*c2c66affSColin Finck         const PRUnichar *aCheckMsg, cpp_bool *aCheckState, LONG *_retval)
114*c2c66affSColin Finck {
115*c2c66affSColin Finck     static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
116*c2c66affSColin Finck 
117*c2c66affSColin Finck     FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
118*c2c66affSColin Finck           debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
119*c2c66affSColin Finck           debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
120*c2c66affSColin Finck           aCheckState, _retval);
121*c2c66affSColin Finck 
122*c2c66affSColin Finck     /*
123*c2c66affSColin Finck      * FIXME:
124*c2c66affSColin Finck      * This is really very very ugly hack!!!
125*c2c66affSColin Finck      */
126*c2c66affSColin Finck 
127*c2c66affSColin Finck     if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
128*c2c66affSColin Finck         *_retval = 0;
129*c2c66affSColin Finck     else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
130*c2c66affSColin Finck         *_retval = 1;
131*c2c66affSColin Finck     else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
132*c2c66affSColin Finck         *_retval = 2;
133*c2c66affSColin Finck     /* else
134*c2c66affSColin Finck      *     let's hope that _retval is set to the default value */
135*c2c66affSColin Finck 
136*c2c66affSColin Finck     return NS_OK;
137*c2c66affSColin Finck }
138*c2c66affSColin Finck 
nsPromptService_Prompt(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,PRUnichar ** aValue,const PRUnichar * aCheckMsg,cpp_bool * aCheckState,cpp_bool * _retval)139*c2c66affSColin Finck static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
140*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
141*c2c66affSColin Finck         const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
142*c2c66affSColin Finck         cpp_bool *aCheckState, cpp_bool *_retval)
143*c2c66affSColin Finck {
144*c2c66affSColin Finck     FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
145*c2c66affSColin Finck           aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
146*c2c66affSColin Finck     return NS_ERROR_NOT_IMPLEMENTED;
147*c2c66affSColin Finck }
148*c2c66affSColin Finck 
nsPromptService_PromptUsernameAndPassword(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,PRUnichar ** aUsername,PRUnichar ** aPassword,const PRUnichar * aCheckMsg,cpp_bool * aCheckState,cpp_bool * _retval)149*c2c66affSColin Finck static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
150*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
151*c2c66affSColin Finck         const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
152*c2c66affSColin Finck         const PRUnichar *aCheckMsg, cpp_bool *aCheckState, cpp_bool *_retval)
153*c2c66affSColin Finck {
154*c2c66affSColin Finck     FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
155*c2c66affSColin Finck         debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
156*c2c66affSColin Finck         _retval);
157*c2c66affSColin Finck     return NS_ERROR_NOT_IMPLEMENTED;
158*c2c66affSColin Finck }
159*c2c66affSColin Finck 
nsPromptService_PromptPassword(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,PRUnichar ** aPassword,const PRUnichar * aCheckMsg,cpp_bool * aCheckState,cpp_bool * _retval)160*c2c66affSColin Finck static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
161*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
162*c2c66affSColin Finck         const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
163*c2c66affSColin Finck         cpp_bool *aCheckState, cpp_bool *_retval)
164*c2c66affSColin Finck {
165*c2c66affSColin Finck     FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
166*c2c66affSColin Finck           debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
167*c2c66affSColin Finck     return NS_ERROR_NOT_IMPLEMENTED;
168*c2c66affSColin Finck }
169*c2c66affSColin Finck 
nsPromptService_Select(nsIPromptService * iface,nsIDOMWindow * aParent,const PRUnichar * aDialogTitle,const PRUnichar * aText,UINT32 aCount,const PRUnichar ** aSelectList,LONG * aOutSelection,cpp_bool * _retval)170*c2c66affSColin Finck static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
171*c2c66affSColin Finck         nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
172*c2c66affSColin Finck         const PRUnichar *aText, UINT32 aCount, const PRUnichar **aSelectList,
173*c2c66affSColin Finck         LONG *aOutSelection, cpp_bool *_retval)
174*c2c66affSColin Finck {
175*c2c66affSColin Finck     FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
176*c2c66affSColin Finck         debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
177*c2c66affSColin Finck     return NS_ERROR_NOT_IMPLEMENTED;
178*c2c66affSColin Finck }
179*c2c66affSColin Finck 
180*c2c66affSColin Finck static const nsIPromptServiceVtbl PromptServiceVtbl = {
181*c2c66affSColin Finck     nsPromptService_QueryInterface,
182*c2c66affSColin Finck     nsPromptService_AddRef,
183*c2c66affSColin Finck     nsPromptService_Release,
184*c2c66affSColin Finck     nsPromptService_Alert,
185*c2c66affSColin Finck     nsPromptService_AlertCheck,
186*c2c66affSColin Finck     nsPromptService_Confirm,
187*c2c66affSColin Finck     nsPromptService_ConfirmCheck,
188*c2c66affSColin Finck     nsPromptService_ConfirmEx,
189*c2c66affSColin Finck     nsPromptService_Prompt,
190*c2c66affSColin Finck     nsPromptService_PromptUsernameAndPassword,
191*c2c66affSColin Finck     nsPromptService_PromptPassword,
192*c2c66affSColin Finck     nsPromptService_Select
193*c2c66affSColin Finck };
194*c2c66affSColin Finck 
195*c2c66affSColin Finck static nsIPromptService nsPromptService = { &PromptServiceVtbl };
196*c2c66affSColin Finck 
nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider * iface,nsIIDRef riid,void ** result)197*c2c66affSColin Finck static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface,
198*c2c66affSColin Finck         nsIIDRef riid, void **result)
199*c2c66affSColin Finck {
200*c2c66affSColin Finck     *result = NULL;
201*c2c66affSColin Finck 
202*c2c66affSColin Finck     if(IsEqualGUID(&IID_nsISupports, riid)) {
203*c2c66affSColin Finck         TRACE("(IID_nsISupports %p)\n", result);
204*c2c66affSColin Finck         *result = iface;
205*c2c66affSColin Finck     }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
206*c2c66affSColin Finck         TRACE("(IID_nsITooltipTextProvider %p)\n", result);
207*c2c66affSColin Finck         *result = iface;
208*c2c66affSColin Finck     }
209*c2c66affSColin Finck 
210*c2c66affSColin Finck     if(*result) {
211*c2c66affSColin Finck         nsITooltipTextProvider_AddRef(iface);
212*c2c66affSColin Finck         return NS_OK;
213*c2c66affSColin Finck     }
214*c2c66affSColin Finck 
215*c2c66affSColin Finck     WARN("(%s %p)\n", debugstr_guid(riid), result);
216*c2c66affSColin Finck     return NS_NOINTERFACE;
217*c2c66affSColin Finck }
218*c2c66affSColin Finck 
nsTooltipTextProvider_AddRef(nsITooltipTextProvider * iface)219*c2c66affSColin Finck static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
220*c2c66affSColin Finck {
221*c2c66affSColin Finck     return 2;
222*c2c66affSColin Finck }
223*c2c66affSColin Finck 
nsTooltipTextProvider_Release(nsITooltipTextProvider * iface)224*c2c66affSColin Finck static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
225*c2c66affSColin Finck {
226*c2c66affSColin Finck     return 1;
227*c2c66affSColin Finck }
228*c2c66affSColin Finck 
nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider * iface,nsIDOMNode * aNode,PRUnichar ** aText,cpp_bool * _retval)229*c2c66affSColin Finck static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface,
230*c2c66affSColin Finck         nsIDOMNode *aNode, PRUnichar **aText, cpp_bool *_retval)
231*c2c66affSColin Finck {
232*c2c66affSColin Finck     nsIDOMHTMLElement *nselem;
233*c2c66affSColin Finck     nsIDOMNode *node = aNode, *parent;
234*c2c66affSColin Finck     nsAString title_str;
235*c2c66affSColin Finck     const PRUnichar *title = NULL;
236*c2c66affSColin Finck     nsresult nsres;
237*c2c66affSColin Finck 
238*c2c66affSColin Finck     TRACE("(%p %p %p)\n", aNode, aText, _retval);
239*c2c66affSColin Finck 
240*c2c66affSColin Finck     *aText = NULL;
241*c2c66affSColin Finck 
242*c2c66affSColin Finck     nsAString_Init(&title_str, NULL);
243*c2c66affSColin Finck 
244*c2c66affSColin Finck     do {
245*c2c66affSColin Finck         nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
246*c2c66affSColin Finck         if(NS_SUCCEEDED(nsres)) {
247*c2c66affSColin Finck             title = NULL;
248*c2c66affSColin Finck 
249*c2c66affSColin Finck             nsIDOMHTMLElement_GetTitle(nselem, &title_str);
250*c2c66affSColin Finck             nsIDOMHTMLElement_Release(nselem);
251*c2c66affSColin Finck 
252*c2c66affSColin Finck             nsAString_GetData(&title_str, &title);
253*c2c66affSColin Finck             if(title && *title) {
254*c2c66affSColin Finck                 if(node != aNode)
255*c2c66affSColin Finck                     nsIDOMNode_Release(node);
256*c2c66affSColin Finck                 break;
257*c2c66affSColin Finck             }
258*c2c66affSColin Finck         }
259*c2c66affSColin Finck 
260*c2c66affSColin Finck         nsres = nsIDOMNode_GetParentNode(node, &parent);
261*c2c66affSColin Finck         if(NS_FAILED(nsres))
262*c2c66affSColin Finck             parent = NULL;
263*c2c66affSColin Finck 
264*c2c66affSColin Finck         if(node != aNode)
265*c2c66affSColin Finck             nsIDOMNode_Release(node);
266*c2c66affSColin Finck         node = parent;
267*c2c66affSColin Finck     } while(node);
268*c2c66affSColin Finck 
269*c2c66affSColin Finck     if(title && *title) {
270*c2c66affSColin Finck         int size = (strlenW(title)+1)*sizeof(PRUnichar);
271*c2c66affSColin Finck 
272*c2c66affSColin Finck         *aText = nsalloc(size);
273*c2c66affSColin Finck         memcpy(*aText, title, size);
274*c2c66affSColin Finck         TRACE("aText = %s\n", debugstr_w(*aText));
275*c2c66affSColin Finck 
276*c2c66affSColin Finck         *_retval = TRUE;
277*c2c66affSColin Finck     }else {
278*c2c66affSColin Finck         *_retval = FALSE;
279*c2c66affSColin Finck     }
280*c2c66affSColin Finck 
281*c2c66affSColin Finck     nsAString_Finish(&title_str);
282*c2c66affSColin Finck 
283*c2c66affSColin Finck     return NS_OK;
284*c2c66affSColin Finck }
285*c2c66affSColin Finck 
286*c2c66affSColin Finck static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
287*c2c66affSColin Finck     nsTooltipTextProvider_QueryInterface,
288*c2c66affSColin Finck     nsTooltipTextProvider_AddRef,
289*c2c66affSColin Finck     nsTooltipTextProvider_Release,
290*c2c66affSColin Finck     nsTooltipTextProvider_GetNodeText
291*c2c66affSColin Finck };
292*c2c66affSColin Finck 
293*c2c66affSColin Finck static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl };
294*c2c66affSColin Finck 
295*c2c66affSColin Finck typedef struct {
296*c2c66affSColin Finck     nsIFactory nsIFactory_iface;
297*c2c66affSColin Finck     nsISupports *service;
298*c2c66affSColin Finck } nsServiceFactory;
299*c2c66affSColin Finck 
impl_from_nsIFactory(nsIFactory * iface)300*c2c66affSColin Finck static inline nsServiceFactory *impl_from_nsIFactory(nsIFactory *iface)
301*c2c66affSColin Finck {
302*c2c66affSColin Finck     return CONTAINING_RECORD(iface, nsServiceFactory, nsIFactory_iface);
303*c2c66affSColin Finck }
304*c2c66affSColin Finck 
nsServiceFactory_QueryInterface(nsIFactory * iface,nsIIDRef riid,void ** result)305*c2c66affSColin Finck static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
306*c2c66affSColin Finck         void **result)
307*c2c66affSColin Finck {
308*c2c66affSColin Finck     nsServiceFactory *This = impl_from_nsIFactory(iface);
309*c2c66affSColin Finck 
310*c2c66affSColin Finck     *result = NULL;
311*c2c66affSColin Finck 
312*c2c66affSColin Finck     if(IsEqualGUID(&IID_nsISupports, riid)) {
313*c2c66affSColin Finck         TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
314*c2c66affSColin Finck         *result = &This->nsIFactory_iface;
315*c2c66affSColin Finck     }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
316*c2c66affSColin Finck         TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
317*c2c66affSColin Finck         *result = &This->nsIFactory_iface;
318*c2c66affSColin Finck     }
319*c2c66affSColin Finck 
320*c2c66affSColin Finck     if(*result)
321*c2c66affSColin Finck         return NS_OK;
322*c2c66affSColin Finck 
323*c2c66affSColin Finck     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
324*c2c66affSColin Finck     return NS_NOINTERFACE;
325*c2c66affSColin Finck }
326*c2c66affSColin Finck 
nsServiceFactory_AddRef(nsIFactory * iface)327*c2c66affSColin Finck static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
328*c2c66affSColin Finck {
329*c2c66affSColin Finck     return 2;
330*c2c66affSColin Finck }
331*c2c66affSColin Finck 
nsServiceFactory_Release(nsIFactory * iface)332*c2c66affSColin Finck static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
333*c2c66affSColin Finck {
334*c2c66affSColin Finck     return 1;
335*c2c66affSColin Finck }
336*c2c66affSColin Finck 
nsServiceFactory_CreateInstance(nsIFactory * iface,nsISupports * aOuter,const nsIID * iid,void ** result)337*c2c66affSColin Finck static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
338*c2c66affSColin Finck         nsISupports *aOuter, const nsIID *iid, void **result)
339*c2c66affSColin Finck {
340*c2c66affSColin Finck     nsServiceFactory *This = impl_from_nsIFactory(iface);
341*c2c66affSColin Finck 
342*c2c66affSColin Finck     TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
343*c2c66affSColin Finck 
344*c2c66affSColin Finck     return nsISupports_QueryInterface(This->service, iid, result);
345*c2c66affSColin Finck }
346*c2c66affSColin Finck 
nsServiceFactory_LockFactory(nsIFactory * iface,cpp_bool lock)347*c2c66affSColin Finck static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
348*c2c66affSColin Finck {
349*c2c66affSColin Finck     nsServiceFactory *This = impl_from_nsIFactory(iface);
350*c2c66affSColin Finck     WARN("(%p)->(%x)\n", This, lock);
351*c2c66affSColin Finck     return NS_OK;
352*c2c66affSColin Finck }
353*c2c66affSColin Finck 
354*c2c66affSColin Finck static const nsIFactoryVtbl nsServiceFactoryVtbl = {
355*c2c66affSColin Finck     nsServiceFactory_QueryInterface,
356*c2c66affSColin Finck     nsServiceFactory_AddRef,
357*c2c66affSColin Finck     nsServiceFactory_Release,
358*c2c66affSColin Finck     nsServiceFactory_CreateInstance,
359*c2c66affSColin Finck     nsServiceFactory_LockFactory
360*c2c66affSColin Finck };
361*c2c66affSColin Finck 
362*c2c66affSColin Finck static nsServiceFactory nsPromptServiceFactory = {
363*c2c66affSColin Finck     { &nsServiceFactoryVtbl },
364*c2c66affSColin Finck     (nsISupports*)&nsPromptService
365*c2c66affSColin Finck };
366*c2c66affSColin Finck 
367*c2c66affSColin Finck static nsServiceFactory nsTooltipTextFactory = {
368*c2c66affSColin Finck     { &nsServiceFactoryVtbl },
369*c2c66affSColin Finck     (nsISupports*)&nsTooltipTextProvider
370*c2c66affSColin Finck };
371*c2c66affSColin Finck 
register_nsservice(nsIComponentRegistrar * registrar,nsIServiceManager * service_manager)372*c2c66affSColin Finck void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
373*c2c66affSColin Finck {
374*c2c66affSColin Finck     nsresult nsres;
375*c2c66affSColin Finck 
376*c2c66affSColin Finck     nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
377*c2c66affSColin Finck             "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, &nsPromptServiceFactory.nsIFactory_iface);
378*c2c66affSColin Finck     if(NS_FAILED(nsres))
379*c2c66affSColin Finck         ERR("RegisterFactory failed: %08x\n", nsres);
380*c2c66affSColin Finck 
381*c2c66affSColin Finck     nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
382*c2c66affSColin Finck             NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID,
383*c2c66affSColin Finck             &nsTooltipTextFactory.nsIFactory_iface);
384*c2c66affSColin Finck     if(NS_FAILED(nsres))
385*c2c66affSColin Finck         ERR("RegisterFactory failed: %08x\n", nsres);
386*c2c66affSColin Finck }
387