comparison dwt/browser/Download.d @ 286:44258e0b6687

More fixes for xpcom
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 10:11:58 -0700
parents 93409d9838c5
children eec6ddb07873
comparison
equal deleted inserted replaced
280:e72345914350 286:44258e0b6687
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: 10 * Port to the D programming language:
11 * John Reimer <terminal.node@gmail.com> 11 * John Reimer <terminal.node@gmail.com>
12 *******************************************************************************/ 12 *******************************************************************************/
13 module dwt.browser.Download; 13 module dwt.browser.Download;
14 14
15 import dwt.dwthelper.utils; 15 import dwt.dwthelper.utils;
16 16
17 import dwt.DWT; 17 import dwt.DWT;
18 import dwt.internal.C; 18
19 import dwt.internal.Compatibility; 19 import dwt.internal.Compatibility;
20 import dwt.internal.mozilla.XPCOM; 20 import dwt.internal.mozilla.XPCOM;
21 import dwt.internal.mozilla.XPCOMObject; 21 import dwt.internal.mozilla.XPCOMObject;
22 import dwt.internal.mozilla.nsID; 22 import dwt.internal.mozilla.nsID;
23 import dwt.internal.mozilla.nsIDownload; 23 import dwt.internal.mozilla.nsIDownload;
33 import dwt.widgets.Event; 33 import dwt.widgets.Event;
34 import dwt.widgets.Label; 34 import dwt.widgets.Label;
35 import dwt.widgets.Listener; 35 import dwt.widgets.Listener;
36 import dwt.widgets.Shell; 36 import dwt.widgets.Shell;
37 37
38 class Download { 38 class Download : nsIProgressDialog {
39 XPCOMObject supports;
40 XPCOMObject download;
41 XPCOMObject progressDialog;
42 XPCOMObject webProgressListener;
43 nsIHelperAppLauncher helperAppLauncher; 39 nsIHelperAppLauncher helperAppLauncher;
44 int refCount = 0; 40 int refCount = 0;
45 41
46 Shell shell; 42 Shell shell;
47 Label status; 43 Label status;
48 Button cancel; 44 Button cancel;
49 45
50 Download () { 46 this () {
51 createCOMInterfaces ();
52 } 47 }
53 48
54 int AddRef () { 49 int AddRef () {
55 refCount++; 50 refCount++;
56 return refCount; 51 return refCount;
57 } 52 }
58 53
59 void createCOMInterfaces () { 54 int QueryInterface (nsID* riid, void** ppvObject) {
60 /* Create each of the interfaces that this object implements */ 55 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
61 supports = new XPCOMObject (new int[] {2, 0, 0}) { 56
62 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} 57 if (*riid == nsISupports.IID)) {
63 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} 58 *ppvObject = cast(void*)cast(nsISupports)this;
64 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} 59 AddRef();
65 }; 60 return XPCOM.NS_OK;
66 61 }
67 download = new XPCOMObject (new int[] {2, 0, 0, 7, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1}) { 62 if (*riid == nsIDownload.IID) {
68 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} 63 *ppvObject = cast(void*)cast(nsIDownload)this;
69 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} 64 AddRef();
70 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} 65 return XPCOM.NS_OK;
71 public int /*long*/ method3 (int /*long*/[] args) {return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} 66 }
72 public int /*long*/ method4 (int /*long*/[] args) {return GetSource (args[0]);} 67 if (*riid == nsIProgressDialog.IID) {
73 public int /*long*/ method5 (int /*long*/[] args) {return GetTarget (args[0]);} 68 *ppvObject = cast(void*)cast(nsIProgressDialog)this;
74 public int /*long*/ method6 (int /*long*/[] args) {return GetPersist (args[0]);} 69 AddRef();
75 public int /*long*/ method7 (int /*long*/[] args) {return GetPercentComplete (args[0]);} 70 return XPCOM.NS_OK;
76 public int /*long*/ method8 (int /*long*/[] args) {return GetDisplayName (args[0]);} 71 }
77 public int /*long*/ method9 (int /*long*/[] args) {return SetDisplayName (args[0]);} 72 if (*riid == nsIWebProgressListener.IID) {
78 public int /*long*/ method10 (int /*long*/[] args) {return GetStartTime (args[0]);} 73 *ppvObject = cast(void*)cast(nsIWebProgressListener)this;
79 public int /*long*/ method11 (int /*long*/[] args) {return GetMIMEInfo (args[0]);} 74 AddRef();
80 public int /*long*/ method12 (int /*long*/[] args) {return GetListener (args[0]);} 75 return XPCOM.NS_OK;
81 public int /*long*/ method13 (int /*long*/[] args) {return SetListener (args[0]);} 76 }
82 public int /*long*/ method14 (int /*long*/[] args) {return GetObserver (args[0]);} 77 *ppvObject = null;
83 public int /*long*/ method15 (int /*long*/[] args) {return SetObserver (args[0]);}
84 };
85
86 progressDialog = new XPCOMObject (new int[] {2, 0, 0, 7, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) {
87 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
88 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
89 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
90 public int /*long*/ method3 (int /*long*/[] args) {return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);}
91 public int /*long*/ method4 (int /*long*/[] args) {return GetSource (args[0]);}
92 public int /*long*/ method5 (int /*long*/[] args) {return GetTarget (args[0]);}
93 public int /*long*/ method6 (int /*long*/[] args) {return GetPersist (args[0]);}
94 public int /*long*/ method7 (int /*long*/[] args) {return GetPercentComplete (args[0]);}
95 public int /*long*/ method8 (int /*long*/[] args) {return GetDisplayName (args[0]);}
96 public int /*long*/ method9 (int /*long*/[] args) {return SetDisplayName (args[0]);}
97 public int /*long*/ method10 (int /*long*/[] args) {return GetStartTime (args[0]);}
98 public int /*long*/ method11 (int /*long*/[] args) {return GetMIMEInfo (args[0]);}
99 public int /*long*/ method12 (int /*long*/[] args) {return GetListener (args[0]);}
100 public int /*long*/ method13 (int /*long*/[] args) {return SetListener (args[0]);}
101 public int /*long*/ method14 (int /*long*/[] args) {return GetObserver (args[0]);}
102 public int /*long*/ method15 (int /*long*/[] args) {return SetObserver (args[0]);}
103 public int /*long*/ method16 (int /*long*/[] args) {return Open (args[0]);}
104 public int /*long*/ method17 (int /*long*/[] args) {return GetCancelDownloadOnClose (args[0]);}
105 public int /*long*/ method18 (int /*long*/[] args) {return SetCancelDownloadOnClose ((int)/*64*/args[0]);}
106 public int /*long*/ method19 (int /*long*/[] args) {return GetDialog (args[0]);}
107 public int /*long*/ method20 (int /*long*/[] args) {return SetDialog (args[0]);}
108 };
109
110 webProgressListener = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3}) {
111 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
112 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
113 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
114 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);}
115 public int /*long*/ method4 (int /*long*/[] args) {return OnProgressChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3], (int)/*64*/args[4], (int)/*64*/args[5]);}
116 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);}
117 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);}
118 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);}
119 };
120 }
121
122 void disposeCOMInterfaces () {
123 if (supports !is null) {
124 supports.dispose ();
125 supports = null;
126 }
127 if (download !is null) {
128 download.dispose ();
129 download = null;
130 }
131 if (progressDialog !is null) {
132 progressDialog.dispose ();
133 progressDialog = null;
134 }
135 if (webProgressListener !is null) {
136 webProgressListener.dispose ();
137 webProgressListener = null;
138 }
139 }
140
141 int /*long*/ getAddress () {
142 return progressDialog.getAddress ();
143 }
144
145 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) {
146 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE;
147 nsID guid = new nsID ();
148 XPCOM.memmove (guid, riid, nsID.sizeof);
149
150 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) {
151 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF);
152 AddRef();
153 return XPCOM.NS_OK;
154 }
155 if (guid.Equals (nsIDownload.NS_IDOWNLOAD_IID)) {
156 XPCOM.memmove (ppvObject, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF);
157 AddRef();
158 return XPCOM.NS_OK;
159 }
160 if (guid.Equals (nsIProgressDialog.NS_IPROGRESSDIALOG_IID)) {
161 XPCOM.memmove (ppvObject, new int /*long*/[] {progressDialog.getAddress ()}, C.PTR_SIZEOF);
162 AddRef();
163 return XPCOM.NS_OK;
164 }
165 if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) {
166 XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF);
167 AddRef();
168 return XPCOM.NS_OK;
169 }
170 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF);
171 return XPCOM.NS_ERROR_NO_INTERFACE; 78 return XPCOM.NS_ERROR_NO_INTERFACE;
172 } 79 }
173 80
174 int Release () { 81 int Release () {
175 refCount--; 82 refCount--;
176 if (refCount is 0) disposeCOMInterfaces (); 83 if (refCount is 0) return 0;
177 return refCount; 84 return refCount;
178 } 85 }
179 86
180 /* nsIDownload */ 87 /* nsIDownload */
181 88
182 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */ 89 /* Note. The argument startTime is defined as a PRInt64. This translates into two java ints. */
183 int Init (int /*long*/ aSource, int /*long*/ aTarget, int /*long*/ aDisplayName, int /*long*/ aMIMEInfo, int /*long*/ startTime1, int /*long*/ startTime2, int /*long*/ aPersist) { 90 int Init (nsIURI aSource, nsIURI aTarget, nsAString* aDisplayName, nsIMIMEInfo aMIMEInfo, PRTime startTime, PRBool aPersist) {
184 nsIURI source = new nsIURI (aSource); 91 nsIURI source = new nsIURI (aSource);
185 int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); 92 scope auto aSpec = new nsEmbedString;
186 int rc = source.GetHost (aSpec); 93 int rc = source.GetHost (cast(nsAString*)aSpec);
187 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 94 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
188 int length = XPCOM.nsEmbedCString_Length (aSpec); 95 int length = XPCOM.nsEmbedCString_Length (aSpec);
189 int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); 96 int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec);
190 byte[] dest = new byte[length]; 97 byte[] dest = new byte[length];
191 XPCOM.memmove (dest, buffer, length); 98 XPCOM.memmove (dest, buffer, length);
278 185
279 int GetTarget (int /*long*/ aTarget) { 186 int GetTarget (int /*long*/ aTarget) {
280 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 187 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
281 } 188 }
282 189
283 int GetPersist (int /*long*/ aPersist) { 190 int GetPersist (PRBool* aPersist) {
284 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 191 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
285 } 192 }
286 193
287 int GetPercentComplete (int /*long*/ aPercentComplete) { 194 int GetPercentComplete (int /*long*/ aPercentComplete) {
288 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 195 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
310 217
311 int SetListener (int /*long*/ aListener) { 218 int SetListener (int /*long*/ aListener) {
312 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 219 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
313 } 220 }
314 221
315 int GetObserver (int /*long*/ aObserver) { 222 nsresult GetObserver (nsIObserver* aObserver) {
316 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 223 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
317 } 224 }
318 225
319 int SetObserver (int /*long*/ aObserver) { 226 nsresult SetObserver (nsIOBserver aObserver) {
320 if (aObserver !is 0) { 227 if (aObserver !is 0) {
321 nsISupports supports = new nsISupports (aObserver); 228 nsISupports supports = new nsISupports (aObserver);
322 int /*long*/[] result = new int /*long*/[1]; 229 int /*long*/[] result = new int /*long*/[1];
323 int rc = supports.QueryInterface (nsIHelperAppLauncher.NS_IHELPERAPPLAUNCHER_IID, result); 230 int rc = supports.QueryInterface (nsIHelperAppLauncher.NS_IHELPERAPPLAUNCHER_IID, result);
324 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 231 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
327 } 234 }
328 return XPCOM.NS_OK; 235 return XPCOM.NS_OK;
329 } 236 }
330 237
331 /* nsIProgressDialog */ 238 /* nsIProgressDialog */
332 int Open (int /*long*/ aParent) { 239 nsresult Open (int /*long*/ aParent) {
333 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 240 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;
334 } 241 }
335 242
336 int GetCancelDownloadOnClose (int /*long*/ aCancelDownloadOnClose) { 243 int GetCancelDownloadOnClose (int /*long*/ aCancelDownloadOnClose) {
337 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 244 return XPCOM.NS_ERROR_NOT_IMPLEMENTED;