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