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