Mercurial > projects > dwt-linux
comparison dwt/browser/PromptService2.d @ 302:bfe1c57259e3
More browser code ported
author | John Reimer<terminal.node@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 21:11:17 -0700 |
parents | eec6ddb07873 |
children | b72d84d1ba95 |
comparison
equal
deleted
inserted
replaced
301:d1474e6bb509 | 302:bfe1c57259e3 |
---|---|
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * John Reimer <terminal.node@gmail.com> | 11 * John Reimer <terminal.node@gmail.com> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module dwt.browser.PromptService2; | 13 module dwt.browser.PromptService2; |
14 | 14 |
15 import dwt.dwthelper.utils; | 15 import tango.stdc.stdlib; |
16 | |
17 //import dwt.dwthelper.utils; | |
16 | 18 |
17 import dwt.DWT; | 19 import dwt.DWT; |
18 //import dwt.internal.C; | 20 //import dwt.internal.C; |
19 import dwt.internal.Compatibility; | 21 import dwt.internal.Compatibility; |
20 import dwt.internal.mozilla.XPCOM; | 22 import dwt.internal.mozilla.XPCOM; |
35 import dwt.internal.mozilla.nsIWindowWatcher; | 37 import dwt.internal.mozilla.nsIWindowWatcher; |
36 import dwt.widgets.MessageBox; | 38 import dwt.widgets.MessageBox; |
37 import dwt.widgets.Shell; | 39 import dwt.widgets.Shell; |
38 | 40 |
39 class PromptService2 : nsIPromptService2 { | 41 class PromptService2 : nsIPromptService2 { |
40 //XPCOMObject supports; | |
41 //XPCOMObject promptService; | |
42 //XPCOMObject promptService2; | |
43 int refCount = 0; | 42 int refCount = 0; |
44 | 43 |
45 this () { | 44 this () { |
46 // createCOMInterfaces (); | |
47 } | 45 } |
48 | 46 |
49 nsrefcnt AddRef () { | 47 nsrefcnt AddRef () { |
50 refCount++; | 48 refCount++; |
51 return refCount; | 49 return refCount; |
52 } | 50 } |
53 /+ | 51 |
54 void createCOMInterfaces () { | |
55 /* Create each of the interfaces that this object implements */ | |
56 supports = new XPCOMObject (new int[] {2, 0, 0}) { | |
57 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
58 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
59 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
60 }; | |
61 | |
62 promptService = new XPCOMObject (new int[] {2, 0, 0, 3, 5, 4, 6, 10, 7, 8, 7, 7}) { | |
63 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
64 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
65 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
66 public int /*long*/ method3 (int /*long*/[] args) {return Alert (args[0], args[1], args[2]);} | |
67 public int /*long*/ method4 (int /*long*/[] args) {return AlertCheck (args[0], args[1], args[2], args[3], args[4]);} | |
68 public int /*long*/ method5 (int /*long*/[] args) {return Confirm (args[0], args[1], args[2], args[3]);} | |
69 public int /*long*/ method6 (int /*long*/[] args) {return ConfirmCheck (args[0], args[1], args[2], args[3], args[4], args[5]);} | |
70 public int /*long*/ method7 (int /*long*/[] args) {return ConfirmEx (args[0], args[1], args[2], (int)/*64*/args[3], args[4], args[5], args[6], args[7], args[8], args[9]);} | |
71 public int /*long*/ method8 (int /*long*/[] args) {return Prompt (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} | |
72 public int /*long*/ method9 (int /*long*/[] args) {return PromptUsernameAndPassword (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);} | |
73 public int /*long*/ method10 (int /*long*/[] args) {return PromptPassword (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} | |
74 public int /*long*/ method11 (int /*long*/[] args) {return Select (args[0], args[1], args[2], (int)/*64*/args[3], args[4], args[5], args[6]);} | |
75 }; | |
76 | |
77 promptService2 = new XPCOMObject (new int[] {2, 0, 0, 3, 5, 4, 6, 10, 7, 8, 7, 7, 7, 9}) { | |
78 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
79 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
80 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
81 public int /*long*/ method3 (int /*long*/[] args) {return Alert (args[0], args[1], args[2]);} | |
82 public int /*long*/ method4 (int /*long*/[] args) {return AlertCheck (args[0], args[1], args[2], args[3], args[4]);} | |
83 public int /*long*/ method5 (int /*long*/[] args) {return Confirm (args[0], args[1], args[2], args[3]);} | |
84 public int /*long*/ method6 (int /*long*/[] args) {return ConfirmCheck (args[0], args[1], args[2], args[3], args[4], args[5]);} | |
85 public int /*long*/ method7 (int /*long*/[] args) {return ConfirmEx (args[0], args[1], args[2], (int)/*64*/args[3], args[4], args[5], args[6], args[7], args[8], args[9]);} | |
86 public int /*long*/ method8 (int /*long*/[] args) {return Prompt (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} | |
87 public int /*long*/ method9 (int /*long*/[] args) {return PromptUsernameAndPassword (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);} | |
88 public int /*long*/ method10 (int /*long*/[] args) {return PromptPassword (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} | |
89 public int /*long*/ method11 (int /*long*/[] args) {return Select (args[0], args[1], args[2], (int)/*64*/args[3], args[4], args[5], args[6]);} | |
90 public int /*long*/ method12 (int /*long*/[] args) {return PromptAuth (args[0], args[1], (int)/*64*/args[2], args[3], args[4], args[5], args[6]);} | |
91 public int /*long*/ method13 (int /*long*/[] args) {return AsyncPromptAuth (args[0], args[1], args[2], args[3], (int)/*64*/args[4], args[5], args[6], args[7], args[8]);} | |
92 }; | |
93 } | |
94 | |
95 void disposeCOMInterfaces () { | |
96 if (supports !is null) { | |
97 supports.dispose (); | |
98 supports = null; | |
99 } | |
100 if (promptService !is null) { | |
101 promptService.dispose (); | |
102 promptService = null; | |
103 } | |
104 if (promptService2 !is null) { | |
105 promptService2.dispose (); | |
106 promptService2 = null; | |
107 } | |
108 } | |
109 | |
110 int /*long*/ getAddress () { | |
111 return promptService2.getAddress (); | |
112 } | |
113 +/ | |
114 nsresult QueryInterface (nsID* riid, void** ppvObject) { | 52 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
115 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; | 53 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
116 //nsID guid = new nsID (); | 54 |
117 //XPCOM.memmove (guid, riid, nsID.sizeof); | |
118 | |
119 if (*riid == nsISupports.IID) { | 55 if (*riid == nsISupports.IID) { |
120 *ppvObject = cast(void*)cast(nsISupports)this; | 56 *ppvObject = cast(void*)cast(nsISupports)this; |
121 AddRef (); | 57 AddRef (); |
122 return XPCOM.NS_OK; | 58 return XPCOM.NS_OK; |
123 } | 59 } |
153 | 89 |
154 //nsIServiceManager serviceManager = new nsIServiceManager (result[0]); | 90 //nsIServiceManager serviceManager = new nsIServiceManager (result[0]); |
155 //result[0] = 0; | 91 //result[0] = 0; |
156 //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WINDOWWATCHER_CONTRACTID, true); | 92 //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WINDOWWATCHER_CONTRACTID, true); |
157 nsIWindowWatcher windowWatcher; | 93 nsIWindowWatcher windowWatcher; |
158 rc = serviceManager.GetServiceByContractID (XPCOM.NS_WINDOWWATCHER_CONTRACTID, nsIWindowWatcher.IID, cast(void*)&windowWatcher); | 94 rc = serviceManager.GetServiceByContractID (XPCOM.NS_WINDOWWATCHER_CONTRACTID, &nsIWindowWatcher.IID, cast(void**)&windowWatcher); |
159 if (rc !is XPCOM.NS_OK) Mozilla.error(rc); | 95 if (rc !is XPCOM.NS_OK) Mozilla.error(rc); |
160 if (windowWatcher is null) Mozilla.error (XPCOM.NS_NOINTERFACE); | 96 if (windowWatcher is null) Mozilla.error (XPCOM.NS_NOINTERFACE); |
161 serviceManager.Release (); | 97 serviceManager.Release (); |
162 | 98 |
163 //nsIWindowWatcher windowWatcher = new nsIWindowWatcher (result[0]); | 99 //nsIWindowWatcher windowWatcher = new nsIWindowWatcher (result[0]); |
177 windowWatcher.Release (); | 113 windowWatcher.Release (); |
178 | 114 |
179 //nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (result[0]); | 115 //nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (result[0]); |
180 //result[0] = 0; | 116 //result[0] = 0; |
181 nsIEmbeddingSiteWindow embeddingSiteWindow; | 117 nsIEmbeddingSiteWindow embeddingSiteWindow; |
182 rc = webBrowserChrome.QueryInterface (nsIEmbeddingSiteWindow.IID, cast(void*)&embeddingSiteWindow); | 118 rc = webBrowserChrome.QueryInterface (nsIEmbeddingSiteWindow.IID, cast(void**)&embeddingSiteWindow); |
183 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 119 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
184 if (embeddingSiteWindow is null) Mozilla.error (XPCOM.NS_NOINTERFACE); | 120 if (embeddingSiteWindow is null) Mozilla.error (XPCOM.NS_NOINTERFACE); |
185 webBrowserChrome.Release (); | 121 webBrowserChrome.Release (); |
186 | 122 |
187 //nsIEmbeddingSiteWindow embeddingSiteWindow = new nsIEmbeddingSiteWindow (result[0]); | 123 //nsIEmbeddingSiteWindow embeddingSiteWindow = new nsIEmbeddingSiteWindow (result[0]); |
358 //XPCOM.memmove (dest, aText, length * 2); | 294 //XPCOM.memmove (dest, aText, length * 2); |
359 textLabel = Utf.toString (aText[0 .. span]); | 295 textLabel = Utf.toString (aText[0 .. span]); |
360 | 296 |
361 //int /*long*/[] valueAddr = new int /*long*/[1]; | 297 //int /*long*/[] valueAddr = new int /*long*/[1]; |
362 //XPCOM.memmove (valueAddr, aValue, C.PTR_SIZEOF); | 298 //XPCOM.memmove (valueAddr, aValue, C.PTR_SIZEOF); |
363 if (aValue !is null) { | 299 auto valueAddr = aValue; |
364 if(*aValue !is null) { | 300 if (valueAddr[0] !is null) { |
365 span = XPCOM.strlen_PRUnichar (*aValue); | 301 span = XPCOM.strlen_PRUnichar (valueAddr[0]); |
366 //dest = new char[length]; | 302 //dest = new char[length]; |
367 //XPCOM.memmove (dest, valueAddr[0], length * 2); | 303 //XPCOM.memmove (dest, valueAddr[0], length * 2); |
368 valueLabel = Utf.toString ((*aValue)[0 .. span]); | 304 valueLabel = Utf.toString ((valueAddr[0])[0 .. span]); |
369 } | |
370 } | 305 } |
371 | 306 |
372 if (aCheckMsg !is null) { | 307 if (aCheckMsg !is null) { |
373 span = XPCOM.strlen_PRUnichar (aCheckMsg); | 308 span = XPCOM.strlen_PRUnichar (aCheckMsg); |
374 if (span > 0) { | 309 if (span > 0) { |
387 if (result is 1) { | 322 if (result is 1) { |
388 /* | 323 /* |
389 * User selected OK. User name and password are returned as PRUnichar values. Any default | 324 * User selected OK. User name and password are returned as PRUnichar values. Any default |
390 * value that we override must be freed using the nsIMemory service. | 325 * value that we override must be freed using the nsIMemory service. |
391 */ | 326 */ |
392 int cnt, size; | 327 int size; |
393 int /*long*/ ptr; | 328 void* ptr; |
394 char[] buffer; | 329 wchar[] buffer; |
395 int /*long*/[] result2 = new int /*long*/[1]; | 330 nsIServiceManager serviceManager; |
396 if (valueLabel !is null) { | 331 if (valueLabel !is null) { |
397 cnt = valueLabel.length; | 332 //cnt = valueLabel.length; |
398 buffer = new char[cnt + 1]; | 333 //buffer = new wchar[cnt + 1]; |
399 valueLabel.getChars (0, cnt, buffer, 0); | 334 //valueLabel.getChars (0, cnt, buffer, 0); |
335 buffer = Utf.toString16(valueLabel); | |
400 size = buffer.length * 2; | 336 size = buffer.length * 2; |
401 ptr = C.malloc (size); | 337 ptr = tango.stdc.stdlib.malloc (size); |
402 XPCOM.memmove (ptr, buffer, size); | 338 (cast(wchar*)ptr)[0 .. buffer.length] = buffer[0 .. $]; |
403 XPCOM.memmove (aValue, new int /*long*/[] {ptr}, C.PTR_SIZEOF); | 339 //XPCOM.memmove (ptr, buffer, size); |
404 | 340 //XPCOM.memmove (aValue, new int /*long*/[] {ptr}, C.PTR_SIZEOF); |
405 if (valueAddr[0] !is 0) { | 341 *aValue = cast(PRUnichar*)ptr; |
406 int rc = XPCOM.NS_GetServiceManager (result2); | 342 |
343 if (valueAddr[0] !is null) { | |
344 int rc = XPCOM.NS_GetServiceManager (&serviceManager); | |
407 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 345 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
408 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE); | 346 if (serviceManager is null) DWT.error (XPCOM.NS_NOINTERFACE); |
409 | 347 |
410 nsIServiceManager serviceManager = new nsIServiceManager (result2[0]); | 348 //nsIServiceManager serviceManager = new nsIServiceManager (result2[0]); |
411 result2[0] = 0; | 349 //result2[0] = 0; |
412 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); | 350 nsIMemory memory; |
413 rc = serviceManager.GetServiceByContractID (aContractID, nsIMemory.NS_IMEMORY_IID, result2); | 351 //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); |
352 rc = serviceManager.GetServiceByContractID (XPCOM.NS_MEMORY_CONTRACTID, &nsIMemory.IID, cast(void**)&memory); | |
414 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 353 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
415 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE); | 354 if (memory is null) DWT.error (XPCOM.NS_NOINTERFACE); |
416 serviceManager.Release (); | 355 serviceManager.Release (); |
417 | 356 |
418 nsIMemory memory = new nsIMemory (result2[0]); | 357 //nsIMemory memory = new nsIMemory (result2[0]); |
419 result2[0] = 0; | 358 //result2[0] = 0; |
420 memory.Free (valueAddr[0]); | 359 memory.Free (valueAddr[0]); |
421 memory.Release (); | 360 memory.Release (); |
422 } | 361 } |
423 } | 362 } |
424 } | 363 } |
425 if (aCheckState !is 0) XPCOM.memmove (aCheckState, check, 4); | 364 if (aCheckState !is null) *aCheckState = check; |
426 return XPCOM.NS_OK; | 365 return XPCOM.NS_OK; |
427 } | 366 } |
428 | 367 |
429 nsresult PromptAuth(int /*long*/ aParent, int /*long*/ aChannel, int level, int /*long*/ authInfo, int /*long*/ checkboxLabel, int /*long*/ checkboxValue, int /*long*/ _retval) { | 368 nsresult PromptAuth(nsIDOMWindow aParent, nsIChannel aChannel, PRUint32 level, nsIAuthInformation authInfo, PRUnichar* checkboxLabel, PRBool* checkboxValue, PRBool* _retval) { |
430 Browser browser = getBrowser (aParent); | 369 Browser browser = getBrowser (aParent); |
431 String checkLabel = null; | 370 String checkLabel = null; |
432 int[] checkValue = new int[1]; | 371 //int[] checkValue = new int[1]; |
433 String[] userLabel = new String[1], passLabel = new String[1]; | 372 //String[] userLabel = new String[1], passLabel = new String[1]; |
434 | 373 int checkValue; |
435 String title = DWT.getMessage ("SWT_Authentication_Required"); //$NON-NLS-1$ | 374 String userLabel, passLabel; |
436 | 375 //String title = DWT.getMessage ("SWT_Authentication_Required"); //$NON-NLS-1$ |
437 if (checkboxLabel !is 0 && checkboxValue !is 0) { | 376 String title = "Authentication Required"; |
438 int length = XPCOM.strlen_PRUnichar (checkboxLabel); | 377 |
439 char[] dest = new char[length]; | 378 if (checkboxLabel !is null && checkboxValue !is null) { |
440 XPCOM.memmove (dest, checkboxLabel, length * 2); | 379 int span = XPCOM.strlen_PRUnichar (checkboxLabel); |
441 checkLabel = new String (dest); | 380 //char[] dest = new char[length]; |
442 XPCOM.memmove (checkValue, checkboxValue, 4); /* PRBool */ | 381 //XPCOM.memmove (dest, checkboxLabel, length * 2); |
382 checkLabel = Utf.toString (checkboxLabel[0 .. span]); | |
383 checkValue = *checkboxValue; /* PRBool */ | |
443 } | 384 } |
444 | 385 |
445 /* get initial username and password values */ | 386 /* get initial username and password values */ |
446 | 387 |
447 nsIAuthInformation auth = new nsIAuthInformation (authInfo); | 388 //nsIAuthInformation auth = new nsIAuthInformation (authInfo); |
448 | 389 |
449 int /*long*/ ptr = XPCOM.nsEmbedString_new (); | 390 scope auto ptr1 = new nsEmbedString; |
450 int rc = auth.GetUsername (ptr); | 391 int rc = authInfo.GetUsername (cast(nsAString*)ptr1); |
451 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 392 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
452 int length = XPCOM.nsEmbedString_Length (ptr); | 393 //int length = XPCOM.nsEmbedString_Length (ptr); |
453 int /*long*/ buffer = XPCOM.nsEmbedString_get (ptr); | 394 //int /*long*/ buffer = XPCOM.nsEmbedString_get (ptr); |
454 char[] chars = new char[length]; | 395 //char[] chars = new char[length]; |
455 XPCOM.memmove (chars, buffer, length * 2); | 396 //XPCOM.memmove (chars, buffer, length * 2); |
456 userLabel[0] = new String (chars); | 397 userLabel = ptr1.toString; |
457 XPCOM.nsEmbedString_delete (ptr); | 398 //XPCOM.nsEmbedString_delete (ptr); |
458 | 399 |
459 ptr = XPCOM.nsEmbedString_new (); | 400 scope auto ptr2 = new nsEmbedString; |
460 rc = auth.GetPassword (ptr); | 401 rc = authInfo.GetPassword (ptr2); |
461 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 402 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
462 length = XPCOM.nsEmbedString_Length (ptr); | 403 //length = XPCOM.nsEmbedString_Length (ptr); |
463 buffer = XPCOM.nsEmbedString_get (ptr); | 404 //buffer = XPCOM.nsEmbedString_get (ptr); |
464 chars = new char[length]; | 405 //chars = new char[length]; |
465 XPCOM.memmove (chars, buffer, length * 2); | 406 //XPCOM.memmove (chars, buffer, length * 2); |
466 passLabel[0] = new String (chars); | 407 passLabel = ptr2.toString; |
467 XPCOM.nsEmbedString_delete (ptr); | 408 //XPCOM.nsEmbedString_delete (ptr); |
468 | 409 |
469 /* compute the message text */ | 410 /* compute the message text */ |
470 | 411 |
471 ptr = XPCOM.nsEmbedString_new (); | 412 scope auto ptr3 = new nsEmbedString; |
472 rc = auth.GetRealm (ptr); | 413 rc = authInfo.GetRealm (cast(nsAString*)ptr3); |
473 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 414 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
474 length = XPCOM.nsEmbedString_Length (ptr); | 415 //length = XPCOM.nsEmbedString_Length (ptr); |
475 buffer = XPCOM.nsEmbedString_get (ptr); | 416 //buffer = XPCOM.nsEmbedString_get (ptr); |
476 chars = new char[length]; | 417 //chars = new char[length]; |
477 XPCOM.memmove (chars, buffer, length * 2); | 418 //XPCOM.memmove (chars, buffer, length * 2); |
478 String realm = new String (chars); | 419 String realm = ptr3.toString; |
479 XPCOM.nsEmbedString_delete (ptr); | 420 //XPCOM.nsEmbedString_delete (ptr); |
480 | 421 |
481 nsIChannel channel = new nsIChannel (aChannel); | 422 n///sIChannel channel = new nsIChannel (aChannel); |
482 int /*long*/[] uri = new int /*long*/[1]; | 423 nsIURI uri; |
483 rc = channel.GetURI (uri); | 424 rc = channel.GetURI (&uri); |
484 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 425 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
485 if (uri[0] is 0) Mozilla.error (XPCOM.NS_NOINTERFACE); | 426 if (uri is null) Mozilla.error (XPCOM.NS_NOINTERFACE); |
486 | 427 |
487 nsIURI nsURI = new nsIURI (uri[0]); | 428 //nsIURI nsURI = new nsIURI (uri[0]); |
488 int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); | 429 scope auto aSpec = new nsEmbedCString; |
489 rc = nsURI.GetHost (aSpec); | 430 rc = uri.GetHost (cast(nsACString*)aSpec); |
490 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 431 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
491 length = XPCOM.nsEmbedCString_Length (aSpec); | 432 //length = XPCOM.nsEmbedCString_Length (aSpec); |
492 buffer = XPCOM.nsEmbedCString_get (aSpec); | 433 //buffer = XPCOM.nsEmbedCString_get (aSpec); |
493 byte[] bytes = new byte[length]; | 434 //byte[] bytes = new byte[length]; |
494 XPCOM.memmove (bytes, buffer, length); | 435 //XPCOM.memmove (bytes, buffer, length); |
495 XPCOM.nsEmbedCString_delete (aSpec); | 436 //XPCOM.nsEmbedCString_delete (aSpec); |
496 String host = new String (bytes); | 437 String host = aSpec.toString; |
497 nsURI.Release (); | 438 uri.Release (); |
498 | 439 |
499 String message; | 440 String message; |
500 if (realm.length () > 0 && host.length () > 0) { | 441 if (realm.length () > 0 && host.length () > 0) { |
501 message = Compatibility.getMessage ("SWT_Enter_Username_and_Password", new String[] {realm, host}); //$NON-NLS-1$ | 442 //message = Compatibility.getMessage ("SWT_Enter_Username_and_Password", new String[] {realm, host}); //$NON-NLS-1$ |
443 message = Format("Enter user name and password for {0} at {1}",realm, host); | |
502 } else { | 444 } else { |
503 message = ""; //$NON-NLS-1$ | 445 message = ""; //$NON-NLS-1$ |
504 } | 446 } |
505 | 447 |
506 /* open the prompter */ | 448 /* open the prompter */ |
507 Shell shell = browser is null ? new Shell () : browser.getShell (); | 449 Shell shell = browser is null ? new Shell () : browser.getShell (); |
508 PromptDialog dialog = new PromptDialog (shell); | 450 PromptDialog dialog = new PromptDialog (shell); |
509 int[] result = new int[1]; | 451 int result; |
510 dialog.promptUsernameAndPassword (title, message, checkLabel, userLabel, passLabel, checkValue, result); | 452 dialog.promptUsernameAndPassword (title, message, checkLabel, userLabel, passLabel, checkValue, result); |
511 | 453 |
512 XPCOM.memmove (_retval, result, 4); /* PRBool */ | 454 //XPCOM.memmove (_retval, result, 4); /* PRBool */ |
513 if (result[0] is 1) { /* User selected OK */ | 455 *_retval = result; |
514 nsEmbedString string = new nsEmbedString (userLabel[0]); | 456 if (result is 1) { /* User selected OK */ |
515 rc = auth.SetUsername(string.getAddress ()); | 457 scope auto string1 = new nsEmbedString (userLabel); |
458 rc = authInfo.SetUsername(cast(nsAString*)string1); | |
516 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 459 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
517 string.dispose (); | 460 //string.dispose (); |
518 | 461 |
519 string = new nsEmbedString (passLabel[0]); | 462 scope auto string2 = new nsEmbedString (passLabel); |
520 rc = auth.SetPassword(string.getAddress ()); | 463 rc = authInfo.SetPassword(cast(nsAString*)string2); |
521 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 464 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
522 string.dispose (); | 465 //string.dispose (); |
523 } | 466 } |
524 | 467 |
525 if (checkboxValue !is 0) XPCOM.memmove (checkboxValue, checkValue, 4); /* PRBool */ | 468 if (checkboxValue !is null) *checkboxValue = checkValue; /* PRBool */ |
526 return XPCOM.NS_OK; | 469 return XPCOM.NS_OK; |
527 } | 470 } |
528 | 471 |
529 nsresult 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) { | 472 nsresult PromptUsernameAndPassword (nsIDOMWindow aParent, PRUnichar* aDialogTitle, PRUnichar* aText, PRUnichar** aUsername, PRUnichar** aPassword, PRUnichar* aCheckMsg, PRBool* aCheckState, PRBool* _retval) { |
530 Browser browser = getBrowser (aParent); | 473 Browser browser = getBrowser (aParent); |
531 String titleLabel, textLabel, checkLabel = null; | 474 String titleLabel, textLabel, checkLabel = null; |
532 String[] userLabel = new String[1], passLabel = new String[1]; | 475 String userLabel, passLabel; |
533 char[] dest; | 476 char[] dest; |
534 int length; | 477 int span; |
535 if (aDialogTitle !is 0) { | 478 if (aDialogTitle !is null) { |
536 length = XPCOM.strlen_PRUnichar (aDialogTitle); | 479 span = XPCOM.strlen_PRUnichar (aDialogTitle); |
537 dest = new char[length]; | 480 //dest = new char[length]; |
538 XPCOM.memmove (dest, aDialogTitle, length * 2); | 481 //XPCOM.memmove (dest, aDialogTitle, length * 2); |
539 titleLabel = new String (dest); | 482 titleLabel = Utf.toString (aDialogTitle[0 .. span]); |
540 } else { | 483 } else { |
541 titleLabel = DWT.getMessage ("SWT_Authentication_Required"); //$NON-NLS-1$ | 484 //titleLabel = DWT.getMessage ("SWT_Authentication_Required"); //$NON-NLS-1$ |
542 } | 485 titleLable = "Authentication Required" |
543 | 486 } |
544 length = XPCOM.strlen_PRUnichar (aText); | 487 |
545 dest = new char[length]; | 488 span = XPCOM.strlen_PRUnichar (aText); |
546 XPCOM.memmove (dest, aText, length * 2); | 489 //dest = new char[length]; |
547 textLabel = new String (dest); | 490 //XPCOM.memmove (dest, aText, length * 2); |
548 | 491 textLabel = Utf.toString (aText[0 .. span]); |
549 int /*long*/[] userAddr = new int /*long*/[1]; | 492 |
550 XPCOM.memmove (userAddr, aUsername, C.PTR_SIZEOF); | 493 //int /*long*/[] userAddr = new int /*long*/[1]; |
551 if (userAddr[0] !is 0) { | 494 //XPCOM.memmove (userAddr, aUsername, C.PTR_SIZEOF); |
552 length = XPCOM.strlen_PRUnichar (userAddr[0]); | 495 auto userAddr = aUsername; |
553 dest = new char[length]; | 496 if (userAddr[0] !is null) { |
554 XPCOM.memmove (dest, userAddr[0], length * 2); | 497 span = XPCOM.strlen_PRUnichar (userAddr[0]); |
555 userLabel[0] = new String (dest); | 498 //dest = new char[length]; |
556 } | 499 //XPCOM.memmove (dest, userAddr[0], length * 2); |
557 | 500 userLabel = Utf.toString((userAddr[0])[0 .. span]); |
558 int /*long*/[] passAddr = new int /*long*/[1]; | 501 } |
559 XPCOM.memmove (passAddr, aPassword, C.PTR_SIZEOF); | 502 |
560 if (passAddr[0] !is 0) { | 503 //int /*long*/[] passAddr = new int /*long*/[1]; |
561 length = XPCOM.strlen_PRUnichar (passAddr[0]); | 504 //XPCOM.memmove (passAddr, aPassword, C.PTR_SIZEOF); |
562 dest = new char[length]; | 505 auto passAddr = aPassword; |
563 XPCOM.memmove (dest, passAddr[0], length * 2); | 506 if (passAddr[0] !is null) { |
564 passLabel[0] = new String (dest); | 507 span = XPCOM.strlen_PRUnichar (passAddr[0]); |
565 } | 508 //dest = new char[length]; |
566 | 509 //XPCOM.memmove (dest, passAddr[0], length * 2); |
567 if (aCheckMsg !is 0) { | 510 passLabel = Utf.toString((passAddr[0])[0 .. span]); |
568 length = XPCOM.strlen_PRUnichar (aCheckMsg); | 511 } |
569 if (length > 0) { | 512 |
570 dest = new char[length]; | 513 if (aCheckMsg !is null) { |
571 XPCOM.memmove (dest, aCheckMsg, length * 2); | 514 span = XPCOM.strlen_PRUnichar (aCheckMsg); |
572 checkLabel = new String (dest); | 515 if (span > 0) { |
516 //dest = new char[length]; | |
517 //XPCOM.memmove (dest, aCheckMsg, length * 2); | |
518 checkLabel = Utf.toString (aCheckMsg[0 .. span]); | |
573 } | 519 } |
574 } | 520 } |
575 | 521 |
576 Shell shell = browser is null ? new Shell () : browser.getShell (); | 522 Shell shell = browser is null ? new Shell () : browser.getShell (); |
577 PromptDialog dialog = new PromptDialog (shell); | 523 PromptDialog dialog = new PromptDialog (shell); |
578 int[] check = new int[1], result = new int[1]; | 524 int check, result; |
579 if (aCheckState !is 0) XPCOM.memmove (check, aCheckState, 4); /* PRBool */ | 525 if (aCheckState !is null) check = *aCheckState; /* PRBool */ |
580 dialog.promptUsernameAndPassword (titleLabel, textLabel, checkLabel, userLabel, passLabel, check, result); | 526 dialog.promptUsernameAndPassword (titleLabel, textLabel, checkLabel, userLabel, passLabel, check, result); |
581 | 527 |
582 XPCOM.memmove (_retval, result, 4); /* PRBool */ | 528 *_retval = result; /* PRBool */ |
583 if (result[0] is 1) { | 529 if (result is 1) { |
584 /* | 530 /* |
585 * User selected OK. User name and password are returned as PRUnichar values. Any default | 531 * User selected OK. User name and password are returned as PRUnichar values. Any default |
586 * value that we override must be freed using the nsIMemory service. | 532 * value that we override must be freed using the nsIMemory service. |
587 */ | 533 */ |
588 int cnt, size; | 534 int cnt, size; |
589 int /*long*/ ptr; | 535 void* ptr; |
590 char[] buffer; | 536 wchar[] buffer; |
591 int /*long*/[] result2 = new int /*long*/[1]; | 537 int /*long*/[] result2 = new int /*long*/[1]; |
592 if (userLabel[0] !is null) { | 538 if (userLabel !is null) { |
593 cnt = userLabel[0].length (); | 539 //cnt = userLabel[0].length (); |
594 buffer = new char[cnt + 1]; | 540 //buffer = new char[cnt + 1]; |
595 userLabel[0].getChars (0, cnt, buffer, 0); | 541 buffer = Utf.toString16(userLabel); |
542 //userLabel[0].getChars (0, cnt, buffer, 0); | |
596 size = buffer.length * 2; | 543 size = buffer.length * 2; |
597 ptr = C.malloc (size); | 544 ptr = tango.stdc.stdlib.malloc (size); |
598 XPCOM.memmove (ptr, buffer, size); | 545 (cast(wchar*)ptr)[0 .. buffer.length] = buffer[0 .. $]; |
599 XPCOM.memmove (aUsername, new int /*long*/[] {ptr}, C.PTR_SIZEOF); | 546 //XPCOM.memmove (ptr, buffer, size); |
600 | 547 *aUsername = cast(PRUnichar*)ptr; |
601 if (userAddr[0] !is 0) { | 548 //XPCOM.memmove (aUsername, new int /*long*/[] {ptr}, C.PTR_SIZEOF); |
602 int rc = XPCOM.NS_GetServiceManager (result2); | 549 nsIServiceManager serviceManager; |
550 | |
551 if (userAddr[0] !is null) { | |
552 int rc = XPCOM.NS_GetServiceManager (&serviceManager); | |
603 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 553 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
604 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE); | 554 if (serviceManager is null) DWT.error (XPCOM.NS_NOINTERFACE); |
605 | 555 |
606 nsIServiceManager serviceManager = new nsIServiceManager (result2[0]); | 556 //nsIServiceManager serviceManager = new nsIServiceManager (result2[0]); |
607 result2[0] = 0; | 557 //result2[0] = 0; |
608 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); | 558 //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); |
609 rc = serviceManager.GetServiceByContractID (aContractID, nsIMemory.NS_IMEMORY_IID, result2); | 559 nsIMemory memory; |
560 rc = serviceManager.GetServiceByContractID (XPCOM.NS_MEMORY_CONTRACTID, nsIMemory.NS_IMEMORY_IID, cast(void**)&memory); | |
610 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 561 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
611 if (result[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE); | 562 if (memory is null) DWT.error (XPCOM.NS_NOINTERFACE); |
612 serviceManager.Release (); | 563 serviceManager.Release (); |
613 | 564 |
614 nsIMemory memory = new nsIMemory (result2[0]); | 565 //nsIMemory memory = new nsIMemory (result2[0]); |
615 result2[0] = 0; | 566 //result2[0] = 0; |
616 memory.Free (userAddr[0]); | 567 memory.Free (userAddr[0]); |
617 memory.Release (); | 568 memory.Release (); |
618 } | 569 } |
619 } | 570 } |
620 if (passLabel[0] !is null) { | 571 if (passLabel !is null) { |
621 cnt = passLabel[0].length (); | 572 //cnt = passLabel[0].length (); |
622 buffer = new char[cnt + 1]; | 573 //buffer = new char[cnt + 1]; |
623 passLabel[0].getChars (0, cnt, buffer, 0); | 574 buffer = Utf.toString16( passLabel ); |
575 //passLabel[0].getChars (0, cnt, buffer, 0); | |
624 size = buffer.length * 2; | 576 size = buffer.length * 2; |
625 ptr = C.malloc (size); | 577 ptr = tango.stdc.stdlib.malloc (size); |
626 XPCOM.memmove (ptr, buffer, size); | 578 (cast(wchar*)ptr)[0 .. buffer.length] = buffer[0 .. $]; |
627 XPCOM.memmove (aPassword, new int /*long*/[] {ptr}, C.PTR_SIZEOF); | 579 //XPCOM.memmove (ptr, buffer, size); |
580 *aPassword = cast(PRUnichar*)ptr; | |
581 //XPCOM.memmove (aPassword, new int /*long*/[] {ptr}, C.PTR_SIZEOF); | |
628 | 582 |
629 if (passAddr[0] !is 0) { | 583 if (passAddr[0] !is null) { |
630 int rc = XPCOM.NS_GetServiceManager (result2); | 584 int rc = XPCOM.NS_GetServiceManager (&serviceManager); |
631 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 585 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
632 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE); | 586 if (serviceManager is null) DWT.error (XPCOM.NS_NOINTERFACE); |
633 | 587 |
634 nsIServiceManager serviceManager = new nsIServiceManager (result2[0]); | 588 //nsIServiceManager serviceManager = new nsIServiceManager (result2[0]); |
635 result2[0] = 0; | 589 //result2[0] = 0; |
636 byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); | 590 //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true); |
637 rc = serviceManager.GetServiceByContractID (aContractID, nsIMemory.NS_IMEMORY_IID, result2); | 591 nsIMemory memory; |
592 rc = serviceManager.GetServiceByContractID (XPCOM.NS_MEMORY_CONTRACTID, nsIMemory.NS_IMEMORY_IID, cast(void**)&memory); | |
638 if (rc !is XPCOM.NS_OK) DWT.error (rc); | 593 if (rc !is XPCOM.NS_OK) DWT.error (rc); |
639 if (result2[0] is 0) DWT.error (XPCOM.NS_NOINTERFACE); | 594 if (memory is null) DWT.error (XPCOM.NS_NOINTERFACE); |
640 serviceManager.Release (); | 595 serviceManager.Release (); |
641 | 596 |
642 nsIMemory memory = new nsIMemory (result2[0]); | 597 //nsIMemory memory = new nsIMemory (result2[0]); |
643 result2[0] = 0; | 598 //result2[0] = 0; |
644 memory.Free (passAddr[0]); | 599 memory.Free (passAddr[0]); |
645 memory.Release (); | 600 memory.Release (); |
646 } | 601 } |
647 } | 602 } |
648 } | 603 } |
649 if (aCheckState !is 0) XPCOM.memmove (aCheckState, check, 4); /* PRBool */ | 604 if (aCheckState !is null) *aCheckState = check; /* PRBool */ |
650 return XPCOM.NS_OK; | 605 return XPCOM.NS_OK; |
651 } | 606 } |
652 | 607 |
653 nsresult PromptPassword (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int /*long*/ aPassword, int /*long*/ aCheckMsg, int /*long*/ aCheckState, int /*long*/ _retval) { | 608 nsresult PromptPassword (nsIDOMWindow aParent, PRUnichar* aDialogTitle, PRUnichar* aText, PRUnichar** aPassword, PRUnichar* aCheckMsg, PRBool* aCheckState, PRBool* _retval) { |
654 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 609 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
655 } | 610 } |
656 | 611 |
657 nsresult Select (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText, int aCount, int /*long*/ aSelectList, int /*long*/ aOutSelection, int /*long*/ _retval) { | 612 nsresult Select (nsIDOMWindow aParent, PRUnichar* aDialogTitle, PRUnichar* aText, PRUint32 aCount, PRUnichar** aSelectList, PRInt32* aOutSelection, PRBool* _retval) { |
658 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | 613 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
659 } | 614 } |
660 | 615 |
661 } | 616 } |