ReactOS  0.4.13-dev-39-g8b6696f
nsservice.c
Go to the documentation of this file.
1 /*
2  * Copyright 2005 Jacek Caban
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include "mshtml_private.h"
20 
21 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
22 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
23 
24 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
25 
27  {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
29  {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
30 
32  nsIIDRef riid, void **result)
33 {
34  *result = NULL;
35 
36  if(IsEqualGUID(&IID_nsISupports, riid)) {
37  TRACE("(IID_nsISupports %p)\n", result);
38  *result = iface;
39  }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
40  TRACE("(IID_nsIPromptService %p)\n", result);
41  *result = iface;
42  }
43 
44  if(*result)
45  return NS_OK;
46 
47  TRACE("(%s %p)\n", debugstr_guid(riid), result);
48  return NS_NOINTERFACE;
49 }
50 
52 {
53  return 2;
54 }
55 
57 {
58  return 1;
59 }
60 
62  const PRUnichar *aDialogTitle, const PRUnichar *aText)
63 {
65  BSTR text;
66 
67  TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
68 
69  window = nswindow_to_window(aParent);
70  if(!window) {
71  WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent);
72  return NS_ERROR_UNEXPECTED;
73  }
74 
75  text = SysAllocString(aText);
76  IHTMLWindow2_alert(&window->base.IHTMLWindow2_iface, text);
78 
79  return NS_OK;
80 }
81 
83  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
84  const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState)
85 {
86  FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
87  debugstr_w(aCheckMsg), aCheckState);
89 }
90 
92  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
93  cpp_bool *_retval)
94 {
95  FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
97 }
98 
100  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
101  const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState,
102  cpp_bool *_retval)
103 {
104  FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
105  debugstr_w(aCheckMsg), aCheckState, _retval);
107 }
108 
110  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
111  const PRUnichar *aText, UINT32 aButtonFlags, const PRUnichar *aButton0Title,
112  const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
113  const PRUnichar *aCheckMsg, cpp_bool *aCheckState, LONG *_retval)
114 {
115  static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
116 
117  FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
118  debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
119  debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
120  aCheckState, _retval);
121 
122  /*
123  * FIXME:
124  * This is really very very ugly hack!!!
125  */
126 
127  if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
128  *_retval = 0;
129  else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
130  *_retval = 1;
131  else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
132  *_retval = 2;
133  /* else
134  * let's hope that _retval is set to the default value */
135 
136  return NS_OK;
137 }
138 
140  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
141  const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
142  cpp_bool *aCheckState, cpp_bool *_retval)
143 {
144  FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
145  aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
147 }
148 
150  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
151  const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
152  const PRUnichar *aCheckMsg, cpp_bool *aCheckState, cpp_bool *_retval)
153 {
154  FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
155  debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
156  _retval);
158 }
159 
161  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
162  const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
163  cpp_bool *aCheckState, cpp_bool *_retval)
164 {
165  FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
166  debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
168 }
169 
171  nsIDOMWindow *aParent, const PRUnichar *aDialogTitle,
172  const PRUnichar *aText, UINT32 aCount, const PRUnichar **aSelectList,
173  LONG *aOutSelection, cpp_bool *_retval)
174 {
175  FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
176  debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
178 }
179 
180 static const nsIPromptServiceVtbl PromptServiceVtbl = {
193 };
194 
196 
198  nsIIDRef riid, void **result)
199 {
200  *result = NULL;
201 
202  if(IsEqualGUID(&IID_nsISupports, riid)) {
203  TRACE("(IID_nsISupports %p)\n", result);
204  *result = iface;
205  }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
206  TRACE("(IID_nsITooltipTextProvider %p)\n", result);
207  *result = iface;
208  }
209 
210  if(*result) {
211  nsITooltipTextProvider_AddRef(iface);
212  return NS_OK;
213  }
214 
215  WARN("(%s %p)\n", debugstr_guid(riid), result);
216  return NS_NOINTERFACE;
217 }
218 
220 {
221  return 2;
222 }
223 
225 {
226  return 1;
227 }
228 
230  nsIDOMNode *aNode, PRUnichar **aText, cpp_bool *_retval)
231 {
232  nsIDOMHTMLElement *nselem;
233  nsIDOMNode *node = aNode, *parent;
234  nsAString title_str;
235  const PRUnichar *title = NULL;
236  nsresult nsres;
237 
238  TRACE("(%p %p %p)\n", aNode, aText, _retval);
239 
240  *aText = NULL;
241 
242  nsAString_Init(&title_str, NULL);
243 
244  do {
245  nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
246  if(NS_SUCCEEDED(nsres)) {
247  title = NULL;
248 
249  nsIDOMHTMLElement_GetTitle(nselem, &title_str);
250  nsIDOMHTMLElement_Release(nselem);
251 
252  nsAString_GetData(&title_str, &title);
253  if(title && *title) {
254  if(node != aNode)
255  nsIDOMNode_Release(node);
256  break;
257  }
258  }
259 
260  nsres = nsIDOMNode_GetParentNode(node, &parent);
261  if(NS_FAILED(nsres))
262  parent = NULL;
263 
264  if(node != aNode)
265  nsIDOMNode_Release(node);
266  node = parent;
267  } while(node);
268 
269  if(title && *title) {
270  int size = (strlenW(title)+1)*sizeof(PRUnichar);
271 
272  *aText = nsalloc(size);
273  memcpy(*aText, title, size);
274  TRACE("aText = %s\n", debugstr_w(*aText));
275 
276  *_retval = TRUE;
277  }else {
278  *_retval = FALSE;
279  }
280 
281  nsAString_Finish(&title_str);
282 
283  return NS_OK;
284 }
285 
286 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
291 };
292 
294 
295 typedef struct {
299 
301 {
302  return CONTAINING_RECORD(iface, nsServiceFactory, nsIFactory_iface);
303 }
304 
306  void **result)
307 {
309 
310  *result = NULL;
311 
312  if(IsEqualGUID(&IID_nsISupports, riid)) {
313  TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
314  *result = &This->nsIFactory_iface;
315  }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
316  TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
317  *result = &This->nsIFactory_iface;
318  }
319 
320  if(*result)
321  return NS_OK;
322 
323  WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
324  return NS_NOINTERFACE;
325 }
326 
328 {
329  return 2;
330 }
331 
333 {
334  return 1;
335 }
336 
338  nsISupports *aOuter, const nsIID *iid, void **result)
339 {
341 
342  TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
343 
344  return nsISupports_QueryInterface(This->service, iid, result);
345 }
346 
348 {
350  WARN("(%p)->(%x)\n", This, lock);
351  return NS_OK;
352 }
353 
354 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
360 };
361 
365 };
366 
370 };
371 
373 {
374  nsresult nsres;
375 
376  nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
378  if(NS_FAILED(nsres))
379  ERR("RegisterFactory failed: %08x\n", nsres);
380 
381  nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
384  if(NS_FAILED(nsres))
385  ERR("RegisterFactory failed: %08x\n", nsres);
386 }
static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface, nsIIDRef riid, void **result)
Definition: nsservice.c:31
nsIFactory nsIFactory_iface
Definition: nsservice.c:296
#define TRUE
Definition: types.h:120
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
rwlock_t lock
Definition: tcpcore.h:1163
#define NS_PROMPTSERVICE_CONTRACTID
Definition: nsservice.c:21
#define NSAPI
#define NS_TOOLTIPTEXTPROVIDER_CONTRACTID
Definition: nsservice.c:22
REFIID riid
Definition: precomp.h:44
static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface, nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText, cpp_bool *_retval)
Definition: nsservice.c:91
#define NS_TOOLTIPTEXTPROVIDER_CLASSNAME
Definition: nsservice.c:24
const WCHAR * text
Definition: package.c:1827
void * nsalloc(size_t) __WINE_ALLOC_SIZE(1) DECLSPEC_HIDDEN
Definition: nsembed.c:778
#define WARN(fmt,...)
Definition: debug.h:111
REFIID nsIIDRef
Definition: nsiface.idl:45
static const nsIID NS_TOOLTIPTEXTPROVIDER_CID
Definition: nsservice.c:28
static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
Definition: nsservice.c:56
OLECHAR * BSTR
Definition: compat.h:1927
static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
Definition: nsservice.c:51
static const nsIPromptServiceVtbl PromptServiceVtbl
Definition: nsservice.c:180
#define NS_OK
static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl
Definition: nsservice.c:286
unsigned int UINT32
long LONG
Definition: pedump.c:60
static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
Definition: nsservice.c:219
static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
Definition: nsservice.c:327
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:241
HTMLOuterWindow * nswindow_to_window(const nsIDOMWindow *nswindow)
Definition: htmlwindow.c:3099
#define debugstr_guid
Definition: kernel32.h:35
static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
Definition: nsservice.c:332
static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface, nsIIDRef riid, void **result)
Definition: nsservice.c:197
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static nsresult NSAPI 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)
Definition: nsservice.c:109
#define NS_FAILED(res)
static nsresult NSAPI 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)
Definition: nsservice.c:149
static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface, nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState)
Definition: nsservice.c:82
unsigned char cpp_bool
Definition: atl.c:39
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
static nsIPromptService nsPromptService
Definition: nsservice.c:195
r parent
Definition: btrfs.c:2659
static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
Definition: nsservice.c:347
#define NS_ERROR_NOT_IMPLEMENTED
nsISupports * service
Definition: nsservice.c:297
static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
Definition: nsservice.c:224
#define NS_SUCCEEDED(res)
static const nsIID NS_PROMPTSERVICE_CID
Definition: nsservice.c:26
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
UINT32 nsAString_GetData(const nsAString *, const PRUnichar **) DECLSPEC_HIDDEN
Definition: nsembed.c:831
static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface, nsIDOMNode *aNode, PRUnichar **aText, cpp_bool *_retval)
Definition: nsservice.c:229
static IHTMLWindow2 * window
Definition: events.c:77
static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface, nsISupports *aOuter, const nsIID *iid, void **result)
Definition: nsservice.c:337
#define ERR(fmt,...)
Definition: debug.h:109
static nsServiceFactory nsPromptServiceFactory
Definition: nsservice.c:362
static nsITooltipTextProvider nsTooltipTextProvider
Definition: nsservice.c:293
static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface, nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg, cpp_bool *aCheckState, cpp_bool *_retval)
Definition: nsservice.c:139
#define NS_NOINTERFACE
static nsServiceFactory nsTooltipTextFactory
Definition: nsservice.c:367
static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface, nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg, cpp_bool *aCheckState, cpp_bool *_retval)
Definition: nsservice.c:160
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
Definition: nsservice.c:372
static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface, nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState, cpp_bool *_retval)
Definition: nsservice.c:99
BOOL nsAString_Init(nsAString *, const PRUnichar *) DECLSPEC_HIDDEN
Definition: nsembed.c:817
void nsAString_Finish(nsAString *) DECLSPEC_HIDDEN
Definition: nsembed.c:836
HRESULT nsresult
Definition: nsiface.idl:39
WCHAR PRUnichar
Definition: nsiface.idl:48
static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid, void **result)
Definition: nsservice.c:305
static const nsIFactoryVtbl nsServiceFactoryVtbl
Definition: nsservice.c:354
GLuint64EXT * result
Definition: glext.h:11304
static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText)
Definition: nsservice.c:61
static nsServiceFactory * impl_from_nsIFactory(nsIFactory *iface)
Definition: nsservice.c:300
static char title[]
Definition: ps.c:92
static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface, nsIDOMWindow *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText, UINT32 aCount, const PRUnichar **aSelectList, LONG *aOutSelection, cpp_bool *_retval)
Definition: nsservice.c:170
#define NS_ERROR_UNEXPECTED
ULONG nsrefcnt
Definition: nsiface.idl:40
Definition: dlist.c:348