comparison dwt/browser/Download_1_8.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 b0bd1789106b
comparison
equal deleted inserted replaced
280:e72345914350 286:44258e0b6687
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.Download_1_8; 13 module dwt.browser.Download_1_8;
12 14
13 import dwt.dwthelper.utils; 15 import dwt.dwthelper.utils;
14 16
15 import dwt.DWT; 17 import dwt.DWT;
16 import dwt.internal.C; 18
17 import dwt.internal.Compatibility; 19 import dwt.internal.Compatibility;
18 import dwt.internal.mozilla.XPCOM; 20 import dwt.internal.mozilla.XPCOM;
19 import dwt.internal.mozilla.XPCOMObject;
20 import dwt.internal.mozilla.nsICancelable; 21 import dwt.internal.mozilla.nsICancelable;
21 import dwt.internal.mozilla.nsID; 22 import dwt.internal.mozilla.nsID;
22 import dwt.internal.mozilla.nsIDownload_1_8; 23 import dwt.internal.mozilla.nsIDownload_1_8;
23 import dwt.internal.mozilla.nsIProgressDialog_1_8; 24 import dwt.internal.mozilla.nsIProgressDialog_1_8;
24 import dwt.internal.mozilla.nsISupports; 25 import dwt.internal.mozilla.nsISupports;
30 import dwt.widgets.Event; 31 import dwt.widgets.Event;
31 import dwt.widgets.Label; 32 import dwt.widgets.Label;
32 import dwt.widgets.Listener; 33 import dwt.widgets.Listener;
33 import dwt.widgets.Shell; 34 import dwt.widgets.Shell;
34 35
35 class Download_1_8 { 36 class Download_1_8 : nsIProgressDialog_1_8 {
36 XPCOMObject supports;
37 XPCOMObject download;
38 XPCOMObject progressDialog;
39 XPCOMObject webProgressListener;
40 nsICancelable cancelable; 37 nsICancelable cancelable;
41 int refCount = 0; 38 int refCount = 0;
42 39
43 Shell shell; 40 Shell shell;
44 Label status; 41 Label status;
45 Button cancel; 42 Button cancel;
46 43
47 static final bool is32 = C.PTR_SIZEOF is 4; 44 //static final bool is32 = C.PTR_SIZEOF is 4; //determine if 32 or 64 bit platform?
48 45
49 Download_1_8 () { 46 this () {
50 createCOMInterfaces ();
51 } 47 }
52 48
53 int AddRef () { 49 int AddRef () {
54 refCount++; 50 refCount++;
55 return refCount; 51 return refCount;
56 } 52 }
57 53
58 void createCOMInterfaces () { 54 int QueryInterface ( nsID* riid, void** ppvObject) {
59 /* Create each of the interfaces that this object implements */ 55 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
60 supports = new XPCOMObject (new int[] {2, 0, 0}) { 56
61 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} 57 if (*riid == nsISupports.IID)) {
62 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} 58 *ppvObject = cast(void*)cast(nsISupports)this;
63 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} 59 AddRef();
64 }; 60 return XPCOM.NS_OK;
65 61 }
66 download = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3, is32 ? 10 : 6, is32 ? 8 : 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { 62 if (*riid == nsIDownload_1_8.IID)) {
67 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} 63 *ppvObject = cast(void*)cast(nsIDownload_1_8)this;
68 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} 64 AddRef();
69 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} 65 return XPCOM.NS_OK;
70 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);} 66 }
71 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]);} 67 if (*riid == nsIProgressDialog_1_8.IID) {
72 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);} 68 *ppvObject = cast(void*)cast(nsIProgressDialog_1_8)this;
73 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);} 69 AddRef();
74 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);} 70 return XPCOM.NS_OK;
75 public int /*long*/ method8 (int /*long*/[] args) { 71 }
76 if (args.length is 10) { 72 if (*riid == nsIWebProgressListener.IID) {
77 return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); 73 *ppvObject = cast(void*)cast(nsIWebProgressListener)this;
78 } else { 74 AddRef();
79 return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]); 75 return XPCOM.NS_OK;
80 } 76 }
81 } 77 *ppvObject = null;
82 public int /*long*/ method9 (int /*long*/[] args) {
83 if (args.length is 8) {
84 return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
85 } else {
86 return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
87 }
88 }
89 public int /*long*/ method10 (int /*long*/[] args) {return GetTargetFile (args[0]);}
90 public int /*long*/ method11 (int /*long*/[] args) {return GetPercentComplete (args[0]);}
91 public int /*long*/ method12 (int /*long*/[] args) {return GetAmountTransferred (args[0]);}
92 public int /*long*/ method13 (int /*long*/[] args) {return GetSize (args[0]);}
93 public int /*long*/ method14 (int /*long*/[] args) {return GetSource (args[0]);}
94 public int /*long*/ method15 (int /*long*/[] args) {return GetTarget (args[0]);}
95 public int /*long*/ method16 (int /*long*/[] args) {return GetCancelable (args[0]);}
96 public int /*long*/ method17 (int /*long*/[] args) {return GetDisplayName (args[0]);}
97 public int /*long*/ method18 (int /*long*/[] args) {return GetStartTime (args[0]);}
98 public int /*long*/ method19 (int /*long*/[] args) {return GetMIMEInfo (args[0]);}
99 };
100
101 progressDialog = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3, is32 ? 10 : 6, is32 ? 8 : 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) {
102 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
103 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
104 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
105 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);}
106 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]);}
107 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);}
108 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);}
109 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);}
110 public int /*long*/ method8 (int /*long*/[] args) {
111 if (args.length is 10) {
112 return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]);
113 } else {
114 return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]);
115 }
116 }
117 public int /*long*/ method9 (int /*long*/[] args) {
118 if (args.length is 8) {
119 return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
120 } else {
121 return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
122 }
123 }
124 public int /*long*/ method10 (int /*long*/[] args) {return GetTargetFile (args[0]);}
125 public int /*long*/ method11 (int /*long*/[] args) {return GetPercentComplete (args[0]);}
126 public int /*long*/ method12 (int /*long*/[] args) {return GetAmountTransferred (args[0]);}
127 public int /*long*/ method13 (int /*long*/[] args) {return GetSize (args[0]);}
128 public int /*long*/ method14 (int /*long*/[] args) {return GetSource (args[0]);}
129 public int /*long*/ method15 (int /*long*/[] args) {return GetTarget (args[0]);}
130 public int /*long*/ method16 (int /*long*/[] args) {return GetCancelable (args[0]);}
131 public int /*long*/ method17 (int /*long*/[] args) {return GetDisplayName (args[0]);}
132 public int /*long*/ method18 (int /*long*/[] args) {return GetStartTime (args[0]);}
133 public int /*long*/ method19 (int /*long*/[] args) {return GetMIMEInfo (args[0]);}
134 public int /*long*/ method20 (int /*long*/[] args) {return Open (args[0]);}
135 public int /*long*/ method21 (int /*long*/[] args) {return GetCancelDownloadOnClose (args[0]);}
136 public int /*long*/ method22 (int /*long*/[] args) {return SetCancelDownloadOnClose ((int)/*64*/args[0]);}
137 public int /*long*/ method23 (int /*long*/[] args) {return GetObserver (args[0]);}
138 public int /*long*/ method24 (int /*long*/[] args) {return SetObserver (args[0]);}
139 public int /*long*/ method25 (int /*long*/[] args) {return GetDialog (args[0]);}
140 public int /*long*/ method26 (int /*long*/[] args) {return SetDialog (args[0]);}
141 };
142
143 webProgressListener = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3}) {
144 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
145 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
146 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
147 public int /*long*/ method3 (int /*long*/[] args) {return OnStateChange (args[0], args[1], (int)/*64*/args[2], (int)/*64*/args[3]);}
148 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]);}
149 public int /*long*/ method5 (int /*long*/[] args) {return OnLocationChange (args[0], args[1], args[2]);}
150 public int /*long*/ method6 (int /*long*/[] args) {return OnStatusChange (args[0], args[1], (int)/*64*/args[2], args[3]);}
151 public int /*long*/ method7 (int /*long*/[] args) {return OnSecurityChange (args[0], args[1], (int)/*64*/args[2]);}
152 };
153 }
154
155 void disposeCOMInterfaces() {
156 if (supports !is null) {
157 supports.dispose ();
158 supports = null;
159 }
160 if (download !is null) {
161 download.dispose ();
162 download = null;
163 }
164 if (progressDialog !is null) {
165 progressDialog.dispose ();
166 progressDialog = null;
167 }
168 if (webProgressListener !is null) {
169 webProgressListener.dispose ();
170 webProgressListener = null;
171 }
172 }
173
174 int /*long*/ getAddress () {
175 return progressDialog.getAddress ();
176 }
177
178 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) {
179 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE;
180 nsID guid = new nsID ();
181 XPCOM.memmove (guid, riid, nsID.sizeof);
182
183 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) {
184 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF);
185 AddRef();
186 return XPCOM.NS_OK;
187 }
188 if (guid.Equals (nsIDownload_1_8.NS_IDOWNLOAD_IID)) {
189 XPCOM.memmove (ppvObject, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF);
190 AddRef();
191 return XPCOM.NS_OK;
192 }
193 if (guid.Equals (nsIProgressDialog_1_8.NS_IPROGRESSDIALOG_IID)) {
194 XPCOM.memmove (ppvObject, new int /*long*/[] {progressDialog.getAddress ()}, C.PTR_SIZEOF);
195 AddRef();
196 return XPCOM.NS_OK;
197 }
198 if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) {
199 XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF);
200 AddRef();
201 return XPCOM.NS_OK;
202 }
203 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF);
204 return XPCOM.NS_ERROR_NO_INTERFACE; 78 return XPCOM.NS_ERROR_NO_INTERFACE;
205 } 79 }
206 80
207 int Release () { 81 int Release () {
208 refCount--; 82 refCount--;
209 if (refCount is 0) disposeCOMInterfaces (); 83 if (refCount is 0) return 0;
210 return refCount; 84 return refCount;
211 } 85 }
212 86
213 /* nsIDownload */ 87 /* nsIDownload */
214 88