comparison dwt/browser.old/PromptService2.d @ 288:4ee8c4237614

old branches... commit by mistake
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 18:00:50 -0700
parents
children
comparison
equal deleted inserted replaced
287:9cbe6285f746 288:4ee8c4237614
1 /*******************************************************************************
2 * Copyright (c) 2003, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 module dwt.browser.PromptService2;
12
13
14 import Utf = tango.text.convert.Utf;
15
16 import dwt.dwthelper.utils;
17
18 import dwt.DWT;
19
20 import dwt.internal.Compatibility;
21
22 import dwt.internal.mozilla.nsEmbedString;
23 import dwt.internal.mozilla.nsIAuthInformation;
24 import dwt.internal.mozilla.nsIChannel;
25 import dwt.internal.mozilla.nsID;
26 import dwt.internal.mozilla.nsIDOMWindow;
27 import dwt.internal.mozilla.nsIEmbeddingSiteWindow;
28 import dwt.internal.mozilla.nsIMemory;
29 import dwt.internal.mozilla.nsIPromptService;
30 import dwt.internal.mozilla.nsIPromptService2;
31 import dwt.internal.mozilla.nsIServiceManager;
32 import dwt.internal.mozilla.nsISupports;
33 import dwt.internal.mozilla.nsIURI;
34 import dwt.internal.mozilla.nsIWebBrowserChrome;
35 import dwt.internal.mozilla.nsIWindowWatcher;
36
37 import nsStringAPI = dwt.internal.mozilla.nsStringAPI;
38
39 import dwt.widgets.MessageBox;
40 import dwt.widgets.Shell;
41
42 class PromptService2
43 {
44 private nsrefcnt _refCount = 0;
45
46 /**************************************************************************
47
48 **************************************************************************/
49
50 this ()
51 {
52 }
53
54 /**************************************************************************
55
56 **************************************************************************/
57
58 nsrefcnt AddRef ()
59 {
60 _refCount++;
61 return _refCount;
62 }
63
64 /**************************************************************************
65
66 **************************************************************************/
67
68 nsresult QueryInterface ( ref nsIID riid, void** ppvObject )
69 {
70 if (riid is null || ppvObject is null)
71 return NS_ERROR_NO_INTERFACE;
72
73 if (riid == nsISupports.IID))
74 {
75 *ppvObject = cast(void*)cast(nsISupports)this;
76 AddRef ();
77 return NS_OK;
78 }
79
80 if ( riid == nsIPromptService.IID )
81 {
82 *ppvObject = cast(void*)cast(nsIPromptService)this;
83 AddRef ();
84 return NS_OK;
85 }
86
87 if ( riid == nsIPromptService2.IID)
88 {
89 *ppvObject = cast(void*)cast(nsIPromptService2)this;
90 AddRef ();
91 return NS_OK;
92 }
93
94 *ppvObject = null;
95 return NS_ERROR_NO_INTERFACE;
96 }
97
98 /**************************************************************************
99
100 **************************************************************************/
101
102 nsrefcnt Release ()
103 {
104 _refCount--;
105 if (_refCount is 0)
106 return 0;
107 return refCount;
108 }
109
110 /**************************************************************************
111
112 **************************************************************************/
113
114 Browser getBrowser (nsIDOMWindow aDOMWindow)
115 {
116 if (aDOMWindow is null)
117 return null;
118
119 nsIServiceManager serviceManager;
120 void* result;
121
122 nsresult rc = XPCOM.NS_GetServiceManager (&serviceManager);
123
124 if (rc !is NS_OK)
125 Mozilla.error (rc);
126 if (serviceManager is null)
127 Mozilla.error (NS_NOINTERFACE);
128
129 nsIWindowWatcher windowWatcher;
130 rc = serviceManager.GetServiceByContractID (aContractID, nsIWindowWatcher.IID, &windowWatcher);
131
132 if (rc !is NS_OK)
133 Mozilla.error(rc);
134 if (windowWatcher is null)
135 Mozilla.error (NS_NOINTERFACE);
136
137 serviceManager.Release ();
138
139 /* the chrome will only be answered for the top-level nsIDOMWindow */
140 auto window = aDOMWindow;
141
142 rc = window.GetTop (&result);
143
144 if (rc !is NS_OK)
145 Mozilla.error (rc);
146 if (result is null)
147 Mozilla.error (NS_NOINTERFACE);
148
149 aDOMWindow = result;
150
151 rc = windowWatcher.GetChromeForWindow (aDOMWindow, &result);
152
153 if (rc !is NS_OK)
154 Mozilla.error (rc);
155 if (result is null)
156 Mozilla.error (NS_NOINTERFACE);
157
158 windowWatcher.Release ();
159
160 // This assignment should work if "result" tested valid in prior tests
161 auto webBrowserChrome = cast(nsIWebBrowserChrome) result;
162
163 rc = webBrowserChrome.QueryInterface (nsIEmbeddingSiteWindow.IID, &result);
164
165 if (rc !is NS_OK)
166 Mozilla.error (rc);
167 if (result is null)
168 Mozilla.error (NS_NOINTERFACE);
169
170 webBrowserChrome.Release ();
171
172 auto embeddingSiteWindow = cast(nsIEmbeddingSiteWindow) result;
173
174 rc = embeddingSiteWindow.GetSiteWindow (&result);
175
176 if (rc !is NS_OK)
177 Mozilla.error (rc);
178 if (result is null)
179 Mozilla.error (NS_NOINTERFACE);
180
181 embeddingSiteWindow.Release ();
182
183 return Mozilla.findBrowser (result);
184 }
185
186 /**************************************************************************
187
188 **************************************************************************/
189
190 String getLabel (int buttonFlag, int index, PRUnichar* buttonTitle)
191 {
192 String label = null;
193 int flag = (buttonFlag & (0xff * index)) / index;
194
195 switch (flag)
196 {
197 case nsIPromptService.BUTTON_TITLE_CANCEL :
198 label = DWT.getMessage ("SWT_Cancel");
199 break;
200 case nsIPromptService.BUTTON_TITLE_NO :
201 label = DWT.getMessage ("SWT_No");
202 break;
203 case nsIPromptService.BUTTON_TITLE_OK :
204 label = DWT.getMessage ("SWT_OK");
205 break;
206 case nsIPromptService.BUTTON_TITLE_SAVE :
207 label = DWT.getMessage ("SWT_Save");
208 break;
209 case nsIPromptService.BUTTON_TITLE_YES :
210 label = DWT.getMessage ("SWT_Yes");
211 break;
212 case nsIPromptService.BUTTON_TITLE_IS_STRING :
213 {
214 int span = nsStringAPI.strlen_PRUnichar (buttonTitle);
215 label = Utf.toString( buttonTitle[0..span] );
216 }
217 }
218 return label;
219 }
220
221 /**************************************************************************
222
223 nsIPromptService
224
225 **************************************************************************/
226
227 nsresult Alert (nsIDOMWindow aParent, PRUnichar* aDialogTitle, PRUnichar* aText)
228 {
229 Browser browser = getBrowser (aParent);
230
231 int span = nsStringAPI.strlen_PRUnichar( aDialogTitle );
232 String titleLabel = Utf.toString (aDialogTitle[0..span]);
233
234 span = nsStringAPI.strlen_PRUnichar( aText );
235 String textLabel = Utf.toString( aText[0..span] );
236
237 Shell shell = browser is null ? new Shell () : browser.getShell ();
238
239 auto messageBox = new MessageBox (shell, DWT.OK | DWT.ICON_WARNING);
240 messageBox.setText (titleLabel);
241 messageBox.setMessage (textLabel);
242 messageBox.open ();
243
244 return NS_OK;
245 }
246
247 /**************************************************************************
248
249 **************************************************************************/
250
251 nsresult AlertCheck ( nsIDOMWindow aParent, PRUnichar* aDialogTitle,
252 PRUnichar* aText, PRUnichar* aCheckMsg, PRBool* aCheckState )
253 {
254 auto browser = getBrowser (aParent);
255
256 int span = nsStringAPI.strlen_PRUnichar( aDialogTitle );
257 String titleLabel = Utf.toString( aDialogTitle[0..span] );
258
259 span = nsStringAPI.strlen_PRUnichar( aText );
260 String textLabel = Utf.toString( aText[0..span] );
261
262 span = nsStringAPI.strlen_PRUnichar( aCheckMsg );
263 String checkLabel = Utf.toString( aCheckMsg[0..span] );
264
265 auto shell = browser is null ? new Shell () : browser.getShell ();
266 auto dialog = new PromptDialog( shell );
267 PRBool check = *aCheckState;
268 dialog.alertCheck( titleLabel, textLabel, checkLabel, check );
269 return NS_OK;
270 }
271
272 /**************************************************************************
273
274 **************************************************************************/
275
276 int AsyncPromptAuth(int /*long*/ aParent, int /*long*/ aChannel, int /*long*/ aCallback, int /*long*/ aContext, int level, int /*long*/ authInfo, int /*long*/ checkboxLabel, int /*long*/ checkValue, int /*long*/ _retval)
277 {
278 return NS_ERROR_NOT_IMPLEMENTED;
279 }
280
281 /**************************************************************************
282
283 **************************************************************************/
284
285 int Confirm (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int /*long*/ _retval) {
286 Browser browser = getBrowser (aParent);
287
288 int length = XPCOM.strlen_PRUnichar (aDialogTitle);
289 char[] dest = new char[length];
290 XPCOM.memmove (dest, aDialogTitle, length * 2);
291 String titleLabel = new String (dest);
292
293 length = XPCOM.strlen_PRUnichar (aText);
294 dest = new char[length];
295 XPCOM.memmove (dest, aText, length * 2);
296 String textLabel = new String (dest);
297
298 Shell shell = browser is null ? new Shell () : browser.getShell ();
299 MessageBox messageBox = new MessageBox (shell, DWT.OK | DWT.CANCEL | DWT.ICON_QUESTION);
300 messageBox.setText (titleLabel);
301 messageBox.setMessage (textLabel);
302 int id = messageBox.open ();
303 int[] result = {id is DWT.OK ? 1 : 0};
304 XPCOM.memmove (_retval, result, 4);
305 return XPCOM.NS_OK;
306 }
307
308 /**************************************************************************
309
310 **************************************************************************/
311
312 int ConfirmCheck (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int /*long*/ aCheckMsg, int /*long*/ aCheckState, int /*long*/ _retval) {
313 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
314 }
315
316 /**************************************************************************
317
318 **************************************************************************/
319
320 int ConfirmEx (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int aButtonFlags, int /*long*/ aButton0Title, int /*long*/ aButton1Title, int /*long*/ aButton2Title, int /*long*/ aCheckMsg, int /*long*/ aCheckState, int /*long*/ _retval) {
321 Browser browser = getBrowser (aParent);
322
323 int length = XPCOM.strlen_PRUnichar (aDialogTitle);
324 char[] dest = new char[length];
325 XPCOM.memmove (dest, aDialogTitle, length * 2);
326 String titleLabel = new String (dest);
327
328 length = XPCOM.strlen_PRUnichar (aText);
329 dest = new char[length];
330 XPCOM.memmove (dest, aText, length * 2);
331 String textLabel = new String (dest);
332
333 String checkLabel = null;
334 if (aCheckMsg !is 0) {
335 length = XPCOM.strlen_PRUnichar (aCheckMsg);
336 dest = new char[length];
337 XPCOM.memmove (dest, aCheckMsg, length * 2);
338 checkLabel = new String (dest);
339 }
340
341 String button0Label = getLabel (aButtonFlags, nsIPromptService.BUTTON_POS_0, aButton0Title);
342 String button1Label = getLabel (aButtonFlags, nsIPromptService.BUTTON_POS_1, aButton1Title);
343 String button2Label = getLabel (aButtonFlags, nsIPromptService.BUTTON_POS_2, aButton2Title);
344
345 int defaultIndex = 0;
346 if ((aButtonFlags & nsIPromptService.BUTTON_POS_1_DEFAULT) !is 0) {
347 defaultIndex = 1;
348 } else if ((aButtonFlags & nsIPromptService.BUTTON_POS_2_DEFAULT) !is 0) {
349 defaultIndex = 2;
350 }
351
352 Shell shell = browser is null ? new Shell () : browser.getShell ();
353 PromptDialog dialog = new PromptDialog (shell);
354 int[] check = new int[1], result = new int[1];
355 if (aCheckState !is 0) XPCOM.memmove (check, aCheckState, 4);
356 dialog.confirmEx (titleLabel, textLabel, checkLabel, button0Label, button1Label, button2Label, defaultIndex, check, result);
357 if (aCheckState !is 0) XPCOM.memmove (aCheckState, check, 4);
358 XPCOM.memmove (_retval, result, 4);
359 return XPCOM.NS_OK;
360 }
361
362 /**************************************************************************
363
364 **************************************************************************/
365
366 int Prompt (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int /*long*/ aValue, int /*long*/ aCheckMsg, int /*long*/ aCheckState, int /*long*/ _retval) {
367 Browser browser = getBrowser (aParent);
368 String titleLabel = null, textLabel, checkLabel = null;
369 String[] valueLabel = new String[1];
370 char[] dest;
371 int length;
372 if (aDialogTitle !is 0) {
373 length = XPCOM.strlen_PRUnichar (aDialogTitle);
374 dest = new char[length];
375 XPCOM.memmove (dest, aDialogTitle, length * 2);
376 titleLabel = new String (dest);
377 }
378
379 length = XPCOM.strlen_PRUnichar (aText);
380 dest = new char[length];
381 XPCOM.memmove (dest, aText, length * 2);
382 textLabel = new String (dest);
383
384 int /*long*/[] valueAddr = new int /*long*/[1];
385 XPCOM.memmove (valueAddr, aValue, C.PTR_SIZEOF);
386 if (valueAddr[0] !is 0) {
387 length = XPCOM.strlen_PRUnichar (valueAddr[0]);
388 dest = new char[length];
389 XPCOM.memmove (dest, valueAddr[0], length * 2);
390 valueLabel[0] = new String (dest);
391 }
392
393 if (aCheckMsg !is 0) {
394 length = XPCOM.strlen_PRUnichar (aCheckMsg);
395 if (length > 0) {
396 dest = new char[length];
397 XPCOM.memmove (dest, aCheckMsg, length * 2);
398 checkLabel = new String (dest);
399 }
400 }
401
402 Shell shell = browser is null ? new Shell () : browser.getShell ();
403 PromptDialog dialog = new PromptDialog (shell);
404 int[] check = new int[1], result = new int[1];
405 if (aCheckState !is 0) XPCOM.memmove (check, aCheckState, 4);
406 dialog.prompt (titleLabel, textLabel, checkLabel, valueLabel, check, result);
407
408 XPCOM.memmove (_retval, result, 4);
409 if (result[0] is 1) {
410 /*
411 * User selected OK. User name and password are returned as PRUnichar values. Any default
412 * value that we override must be freed using the nsIMemory service.
413 */
414 int cnt, size;
415 int /*long*/ ptr;
416 char[] buffer;
417 int /*long*/[] result2 = new int /*long*/[1];
418 if (valueLabel[0] !is null) {
419 cnt = valueLabel[0].length ();
420 buffer = new char[cnt + 1];
421 valueLabel[0].getChars (0, cnt, buffer, 0);
422 size = buffer.length * 2;
423 ptr = C.malloc (size);
424 XPCOM.memmove (ptr, buffer, size);
425 XPCOM.memmove (aValue, new int /*long*/[] {ptr}, C.PTR_SIZEOF);
426
427 if (valueAddr[0] !is 0) {
428 int rc = XPCOM.NS_GetServiceManager (result2);
429 if (rc !is XPCOM.NS_OK) DWT.error (rc);
430 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE);
431
432 nsIServiceManager serviceManager = new nsIServiceManager (result2[0]);
433 result2[0] = 0;
434 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
435 rc = serviceManager.GetServiceByContractID (aContractID, nsIMemory.NS_IMEMORY_IID, result2);
436 if (rc !is XPCOM.NS_OK) DWT.error (rc);
437 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE);
438 serviceManager.Release ();
439
440 nsIMemory memory = new nsIMemory (result2[0]);
441 result2[0] = 0;
442 memory.Free (valueAddr[0]);
443 memory.Release ();
444 }
445 }
446 }
447 if (aCheckState !is 0) XPCOM.memmove (aCheckState, check, 4);
448 return XPCOM.NS_OK;
449 }
450
451 /**************************************************************************
452
453 **************************************************************************/
454
455 int PromptAuth(int /*long*/ aParent, int /*long*/ aChannel, int level, int /*long*/ authInfo, int /*long*/ checkboxLabel, int /*long*/ checkboxValue, int /*long*/ _retval) {
456 Browser browser = getBrowser (aParent);
457 String checkLabel = null;
458 int[] checkValue = new int[1];
459 String[] userLabel = new String[1], passLabel = new String[1];
460
461 String title = DWT.getMessage ("SWT_Authentication_Required"); //$NON-NLS-1$
462
463 if (checkboxLabel !is 0 && checkboxValue !is 0) {
464 int length = XPCOM.strlen_PRUnichar (checkboxLabel);
465 char[] dest = new char[length];
466 XPCOM.memmove (dest, checkboxLabel, length * 2);
467 checkLabel = new String (dest);
468 XPCOM.memmove (checkValue, checkboxValue, 4); /* PRBool */
469 }
470
471 /* get initial username and password values */
472
473 nsIAuthInformation auth = new nsIAuthInformation (authInfo);
474
475 int /*long*/ ptr = XPCOM.nsEmbedString_new ();
476 int rc = auth.GetUsername (ptr);
477 if (rc !is XPCOM.NS_OK) DWT.error (rc);
478 int length = XPCOM.nsEmbedString_Length (ptr);
479 int /*long*/ buffer = XPCOM.nsEmbedString_get (ptr);
480 char[] chars = new char[length];
481 XPCOM.memmove (chars, buffer, length * 2);
482 userLabel[0] = new String (chars);
483 XPCOM.nsEmbedString_delete (ptr);
484
485 ptr = XPCOM.nsEmbedString_new ();
486 rc = auth.GetPassword (ptr);
487 if (rc !is XPCOM.NS_OK) DWT.error (rc);
488 length = XPCOM.nsEmbedString_Length (ptr);
489 buffer = XPCOM.nsEmbedString_get (ptr);
490 chars = new char[length];
491 XPCOM.memmove (chars, buffer, length * 2);
492 passLabel[0] = new String (chars);
493 XPCOM.nsEmbedString_delete (ptr);
494
495 /* compute the message text */
496
497 ptr = XPCOM.nsEmbedString_new ();
498 rc = auth.GetRealm (ptr);
499 if (rc !is XPCOM.NS_OK) DWT.error (rc);
500 length = XPCOM.nsEmbedString_Length (ptr);
501 buffer = XPCOM.nsEmbedString_get (ptr);
502 chars = new char[length];
503 XPCOM.memmove (chars, buffer, length * 2);
504 String realm = new String (chars);
505 XPCOM.nsEmbedString_delete (ptr);
506
507 nsIChannel channel = new nsIChannel (aChannel);
508 int /*long*/[] uri = new int /*long*/[1];
509 rc = channel.GetURI (uri);
510 if (rc !is XPCOM.NS_OK) DWT.error (rc);
511 if (uri[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
512
513 nsIURI nsURI = new nsIURI (uri[0]);
514 int /*long*/ aSpec = XPCOM.nsEmbedCString_new ();
515 rc = nsURI.GetHost (aSpec);
516 if (rc !is XPCOM.NS_OK) DWT.error (rc);
517 length = XPCOM.nsEmbedCString_Length (aSpec);
518 buffer = XPCOM.nsEmbedCString_get (aSpec);
519 byte[] bytes = new byte[length];
520 XPCOM.memmove (bytes, buffer, length);
521 XPCOM.nsEmbedCString_delete (aSpec);
522 String host = new String (bytes);
523 nsURI.Release ();
524
525 String message;
526 if (realm.length () > 0 && host.length () > 0) {
527 message = Compatibility.getMessage ("SWT_Enter_Username_and_Password", new String[] {realm, host}); //$NON-NLS-1$
528 } else {
529 message = ""; //$NON-NLS-1$
530 }
531
532 /* open the prompter */
533 Shell shell = browser is null ? new Shell () : browser.getShell ();
534 PromptDialog dialog = new PromptDialog (shell);
535 int[] result = new int[1];
536 dialog.promptUsernameAndPassword (title, message, checkLabel, userLabel, passLabel, checkValue, result);
537
538 XPCOM.memmove (_retval, result, 4); /* PRBool */
539 if (result[0] is 1) { /* User selected OK */
540 nsEmbedString string = new nsEmbedString (userLabel[0]);
541 rc = auth.SetUsername(string.getAddress ());
542 if (rc !is XPCOM.NS_OK) DWT.error (rc);
543 string.dispose ();
544
545 string = new nsEmbedString (passLabel[0]);
546 rc = auth.SetPassword(string.getAddress ());
547 if (rc !is XPCOM.NS_OK) DWT.error (rc);
548 string.dispose ();
549 }
550
551 if (checkboxValue !is 0) XPCOM.memmove (checkboxValue, checkValue, 4); /* PRBool */
552 return XPCOM.NS_OK;
553 }
554
555 /**************************************************************************
556
557 **************************************************************************/
558
559 int PromptUsernameAndPassword (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int /*long*/ aUsername, int /*long*/ aPassword, int /*long*/ aCheckMsg, int /*long*/ aCheckState, int /*long*/ _retval) {
560 Browser browser = getBrowser (aParent);
561 String titleLabel, textLabel, checkLabel = null;
562 String[] userLabel = new String[1], passLabel = new String[1];
563 char[] dest;
564 int length;
565 if (aDialogTitle !is 0) {
566 length = XPCOM.strlen_PRUnichar (aDialogTitle);
567 dest = new char[length];
568 XPCOM.memmove (dest, aDialogTitle, length * 2);
569 titleLabel = new String (dest);
570 } else {
571 titleLabel = DWT.getMessage ("SWT_Authentication_Required"); //$NON-NLS-1$
572 }
573
574 length = XPCOM.strlen_PRUnichar (aText);
575 dest = new char[length];
576 XPCOM.memmove (dest, aText, length * 2);
577 textLabel = new String (dest);
578
579 int /*long*/[] userAddr = new int /*long*/[1];
580 XPCOM.memmove (userAddr, aUsername, C.PTR_SIZEOF);
581 if (userAddr[0] !is 0) {
582 length = XPCOM.strlen_PRUnichar (userAddr[0]);
583 dest = new char[length];
584 XPCOM.memmove (dest, userAddr[0], length * 2);
585 userLabel[0] = new String (dest);
586 }
587
588 int /*long*/[] passAddr = new int /*long*/[1];
589 XPCOM.memmove (passAddr, aPassword, C.PTR_SIZEOF);
590 if (passAddr[0] !is 0) {
591 length = XPCOM.strlen_PRUnichar (passAddr[0]);
592 dest = new char[length];
593 XPCOM.memmove (dest, passAddr[0], length * 2);
594 passLabel[0] = new String (dest);
595 }
596
597 if (aCheckMsg !is 0) {
598 length = XPCOM.strlen_PRUnichar (aCheckMsg);
599 if (length > 0) {
600 dest = new char[length];
601 XPCOM.memmove (dest, aCheckMsg, length * 2);
602 checkLabel = new String (dest);
603 }
604 }
605
606 Shell shell = browser is null ? new Shell () : browser.getShell ();
607 PromptDialog dialog = new PromptDialog (shell);
608 int[] check = new int[1], result = new int[1];
609 if (aCheckState !is 0) XPCOM.memmove (check, aCheckState, 4); /* PRBool */
610 dialog.promptUsernameAndPassword (titleLabel, textLabel, checkLabel, userLabel, passLabel, check, result);
611
612 XPCOM.memmove (_retval, result, 4); /* PRBool */
613 if (result[0] is 1) {
614 /*
615 * User selected OK. User name and password are returned as PRUnichar values. Any default
616 * value that we override must be freed using the nsIMemory service.
617 */
618 int cnt, size;
619 int /*long*/ ptr;
620 char[] buffer;
621 int /*long*/[] result2 = new int /*long*/[1];
622 if (userLabel[0] !is null) {
623 cnt = userLabel[0].length ();
624 buffer = new char[cnt + 1];
625 userLabel[0].getChars (0, cnt, buffer, 0);
626 size = buffer.length * 2;
627 ptr = C.malloc (size);
628 XPCOM.memmove (ptr, buffer, size);
629 XPCOM.memmove (aUsername, new int /*long*/[] {ptr}, C.PTR_SIZEOF);
630
631 if (userAddr[0] !is 0) {
632 int rc = XPCOM.NS_GetServiceManager (result2);
633 if (rc !is XPCOM.NS_OK) DWT.error (rc);
634 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE);
635
636 nsIServiceManager serviceManager = new nsIServiceManager (result2[0]);
637 result2[0] = 0;
638 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
639 rc = serviceManager.GetServiceByContractID (aContractID, nsIMemory.NS_IMEMORY_IID, result2);
640 if (rc !is XPCOM.NS_OK) DWT.error (rc);
641 if (result[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE);
642 serviceManager.Release ();
643
644 nsIMemory memory = new nsIMemory (result2[0]);
645 result2[0] = 0;
646 memory.Free (userAddr[0]);
647 memory.Release ();
648 }
649 }
650 if (passLabel[0] !is null) {
651 cnt = passLabel[0].length ();
652 buffer = new char[cnt + 1];
653 passLabel[0].getChars (0, cnt, buffer, 0);
654 size = buffer.length * 2;
655 ptr = C.malloc (size);
656 XPCOM.memmove (ptr, buffer, size);
657 XPCOM.memmove (aPassword, new int /*long*/[] {ptr}, C.PTR_SIZEOF);
658
659 if (passAddr[0] !is 0) {
660 int rc = XPCOM.NS_GetServiceManager (result2);
661 if (rc !is XPCOM.NS_OK) DWT.error (rc);
662 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE);
663
664 nsIServiceManager serviceManager = new nsIServiceManager (result2[0]);
665 result2[0] = 0;
666 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
667 rc = serviceManager.GetServiceByContractID (aContractID, nsIMemory.NS_IMEMORY_IID, result2);
668 if (rc !is XPCOM.NS_OK) DWT.error (rc);
669 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE);
670 serviceManager.Release ();
671
672 nsIMemory memory = new nsIMemory (result2[0]);
673 result2[0] = 0;
674 memory.Free (passAddr[0]);
675 memory.Release ();
676 }
677 }
678 }
679 if (aCheckState !is 0) XPCOM.memmove (aCheckState, check, 4); /* PRBool */
680 return XPCOM.NS_OK;
681 }
682
683 /**************************************************************************
684
685 **************************************************************************/
686
687 int PromptPassword (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int /*long*/ aPassword, int /*long*/ aCheckMsg, int /*long*/ aCheckState, int /*long*/ _retval)
688 {
689 return NS_ERROR_NOT_IMPLEMENTED;
690 }
691
692 /**************************************************************************
693
694 **************************************************************************/
695
696 int Select (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int aCount, int /*long*/ aSelectList, int /*long*/ aOutSelection, int /*long*/ _retval)
697 {
698 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
699 }
700
701 }