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