1 11 package org.eclipse.swt.browser; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.internal.*; 15 import org.eclipse.swt.internal.mozilla.*; 16 import org.eclipse.swt.layout.*; 17 import org.eclipse.swt.widgets.*; 18 19 class Download_1_8 { 20 XPCOMObject supports; 21 XPCOMObject download; 22 XPCOMObject progressDialog; 23 XPCOMObject webProgressListener; 24 nsICancelable cancelable; 25 int refCount = 0; 26 27 Shell shell; 28 Label status; 29 Button cancel; 30 31 static final boolean is32 = C.PTR_SIZEOF == 4; 32 33 public Download_1_8 () { 34 createCOMInterfaces (); 35 } 36 37 int AddRef () { 38 refCount++; 39 return refCount; 40 } 41 42 void createCOMInterfaces () { 43 44 supports = new XPCOMObject (new int[] {2, 0, 0}) { 45 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 46 public int method1 (int [] args) {return AddRef ();} 47 public int method2 (int [] args) {return Release ();} 48 }; 49 50 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}) { 51 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 52 public int method1 (int [] args) {return AddRef ();} 53 public int method2 (int [] args) {return Release ();} 54 public int method3 (int [] args) {return OnStateChange (args[0], args[1], args[2], args[3]);} 55 public int method4 (int [] args) {return OnProgressChange (args[0], args[1], args[2], args[3], args[4], args[5]);} 56 public int method5 (int [] args) {return OnLocationChange (args[0], args[1], args[2]);} 57 public int method6 (int [] args) {return OnStatusChange (args[0], args[1], args[2], args[3]);} 58 public int method7 (int [] args) {return OnSecurityChange (args[0], args[1], args[2]);} 59 public int method8 (int [] args) { 60 if (args.length == 10) { 61 return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); 62 } else { 63 return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]); 64 } 65 } 66 public int method9 (int [] args) { 67 if (args.length == 8) { 68 return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); 69 } else { 70 return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]); 71 } 72 } 73 public int method10 (int [] args) {return GetTargetFile (args[0]);} 74 public int method11 (int [] args) {return GetPercentComplete (args[0]);} 75 public int method12 (int [] args) {return GetAmountTransferred (args[0]);} 76 public int method13 (int [] args) {return GetSize (args[0]);} 77 public int method14 (int [] args) {return GetSource (args[0]);} 78 public int method15 (int [] args) {return GetTarget (args[0]);} 79 public int method16 (int [] args) {return GetCancelable (args[0]);} 80 public int method17 (int [] args) {return GetDisplayName (args[0]);} 81 public int method18 (int [] args) {return GetStartTime (args[0]);} 82 public int method19 (int [] args) {return GetMIMEInfo (args[0]);} 83 }; 84 85 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}) { 86 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 87 public int method1 (int [] args) {return AddRef ();} 88 public int method2 (int [] args) {return Release ();} 89 public int method3 (int [] args) {return OnStateChange (args[0], args[1], args[2], args[3]);} 90 public int method4 (int [] args) {return OnProgressChange (args[0], args[1], args[2], args[3], args[4], args[5]);} 91 public int method5 (int [] args) {return OnLocationChange (args[0], args[1], args[2]);} 92 public int method6 (int [] args) {return OnStatusChange (args[0], args[1], args[2], args[3]);} 93 public int method7 (int [] args) {return OnSecurityChange (args[0], args[1], args[2]);} 94 public int method8 (int [] args) { 95 if (args.length == 10) { 96 return OnProgressChange64_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); 97 } else { 98 return OnProgressChange64 (args[0], args[1], args[2], args[3], args[4], args[5]); 99 } 100 } 101 public int method9 (int [] args) { 102 if (args.length == 8) { 103 return Init_32 (args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); 104 } else { 105 return Init (args[0], args[1], args[2], args[3], args[4], args[5], args[6]); 106 } 107 } 108 public int method10 (int [] args) {return GetTargetFile (args[0]);} 109 public int method11 (int [] args) {return GetPercentComplete (args[0]);} 110 public int method12 (int [] args) {return GetAmountTransferred (args[0]);} 111 public int method13 (int [] args) {return GetSize (args[0]);} 112 public int method14 (int [] args) {return GetSource (args[0]);} 113 public int method15 (int [] args) {return GetTarget (args[0]);} 114 public int method16 (int [] args) {return GetCancelable (args[0]);} 115 public int method17 (int [] args) {return GetDisplayName (args[0]);} 116 public int method18 (int [] args) {return GetStartTime (args[0]);} 117 public int method19 (int [] args) {return GetMIMEInfo (args[0]);} 118 public int method20 (int [] args) {return Open (args[0]);} 119 public int method21 (int [] args) {return GetCancelDownloadOnClose (args[0]);} 120 public int method22 (int [] args) {return SetCancelDownloadOnClose (args[0]);} 121 public int method23 (int [] args) {return GetObserver (args[0]);} 122 public int method24 (int [] args) {return SetObserver (args[0]);} 123 public int method25 (int [] args) {return GetDialog (args[0]);} 124 public int method26 (int [] args) {return SetDialog (args[0]);} 125 }; 126 127 webProgressListener = new XPCOMObject (new int[] {2, 0, 0, 4, 6, 3, 4, 3}) { 128 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 129 public int method1 (int [] args) {return AddRef ();} 130 public int method2 (int [] args) {return Release ();} 131 public int method3 (int [] args) {return OnStateChange (args[0], args[1], args[2],args[3]);} 132 public int method4 (int [] args) {return OnProgressChange (args[0], args[1], args[2], args[3], args[4], args[5]);} 133 public int method5 (int [] args) {return OnLocationChange (args[0], args[1], args[2]);} 134 public int method6 (int [] args) {return OnStatusChange (args[0], args[1], args[2], args[3]);} 135 public int method7 (int [] args) {return OnSecurityChange (args[0], args[1], args[2]);} 136 }; 137 } 138 139 void disposeCOMInterfaces() { 140 if (supports != null) { 141 supports.dispose (); 142 supports = null; 143 } 144 if (download != null) { 145 download.dispose (); 146 download = null; 147 } 148 if (progressDialog != null) { 149 progressDialog.dispose (); 150 progressDialog = null; 151 } 152 if (webProgressListener != null) { 153 webProgressListener.dispose (); 154 webProgressListener = null; 155 } 156 } 157 158 int getAddress () { 159 return progressDialog.getAddress (); 160 } 161 162 int QueryInterface (int riid, int ppvObject) { 163 if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE; 164 nsID guid = new nsID (); 165 XPCOM.memmove (guid, riid, nsID.sizeof); 166 167 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { 168 XPCOM.memmove (ppvObject, new int [] {supports.getAddress ()}, C.PTR_SIZEOF); 169 AddRef(); 170 return XPCOM.NS_OK; 171 } 172 if (guid.Equals (nsIDownload_1_8.NS_IDOWNLOAD_IID)) { 173 XPCOM.memmove (ppvObject, new int [] {download.getAddress ()}, C.PTR_SIZEOF); 174 AddRef(); 175 return XPCOM.NS_OK; 176 } 177 if (guid.Equals (nsIProgressDialog_1_8.NS_IPROGRESSDIALOG_IID)) { 178 XPCOM.memmove (ppvObject, new int [] {progressDialog.getAddress ()}, C.PTR_SIZEOF); 179 AddRef(); 180 return XPCOM.NS_OK; 181 } 182 if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) { 183 XPCOM.memmove (ppvObject, new int [] {webProgressListener.getAddress ()}, C.PTR_SIZEOF); 184 AddRef(); 185 return XPCOM.NS_OK; 186 } 187 XPCOM.memmove (ppvObject, new int [] {0}, C.PTR_SIZEOF); 188 return XPCOM.NS_ERROR_NO_INTERFACE; 189 } 190 191 int Release () { 192 refCount--; 193 if (refCount == 0) disposeCOMInterfaces (); 194 return refCount; 195 } 196 197 198 199 200 public int Init_32 (int aSource, int aTarget, int aDisplayName, int aMIMEInfo, int startTime1, int startTime2, int aTempFile, int aCancelable) { 201 long startTime = (startTime2 << 32) + startTime1; 202 return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable); 203 } 204 205 public int Init (int aSource, int aTarget, int aDisplayName, int aMIMEInfo, long startTime, int aTempFile, int aCancelable) { 206 cancelable = new nsICancelable (aCancelable); 207 nsIURI source = new nsIURI (aSource); 208 int aSpec = XPCOM.nsEmbedCString_new (); 209 int rc = source.GetHost (aSpec); 210 if (rc != XPCOM.NS_OK) Mozilla.error(rc); 211 int length = XPCOM.nsEmbedCString_Length (aSpec); 212 int buffer = XPCOM.nsEmbedCString_get (aSpec); 213 byte[] dest = new byte[length]; 214 XPCOM.memmove (dest, buffer, length); 215 XPCOM.nsEmbedCString_delete (aSpec); 216 String url = new String (dest); 217 218 nsIURI target = new nsIURI (aTarget); 219 int aPath = XPCOM.nsEmbedCString_new (); 220 rc = target.GetPath (aPath); 221 if (rc != XPCOM.NS_OK) Mozilla.error (rc); 222 length = XPCOM.nsEmbedCString_Length (aPath); 223 buffer = XPCOM.nsEmbedCString_get (aPath); 224 dest = new byte[length]; 225 XPCOM.memmove (dest, buffer, length); 226 XPCOM.nsEmbedCString_delete (aPath); 227 String filename = new String (dest); 228 int separator = filename.lastIndexOf (System.getProperty ("file.separator")); filename = filename.substring (separator + 1); 230 231 Listener listener = new Listener() { 232 public void handleEvent (Event event) { 233 if (event.widget == cancel) { 234 shell.close (); 235 } 236 if (cancelable != null) { 237 int rc = cancelable.Cancel (XPCOM.NS_BINDING_ABORTED); 238 if (rc != XPCOM.NS_OK) Mozilla.error (rc); 239 } 240 shell = null; 241 cancelable = null; 242 } 243 }; 244 shell = new Shell (SWT.DIALOG_TRIM); 245 String msg = Compatibility.getMessage ("SWT_Download_File", new Object [] {filename}); shell.setText (msg); 247 GridLayout gridLayout = new GridLayout (); 248 gridLayout.marginHeight = 15; 249 gridLayout.marginWidth = 15; 250 gridLayout.verticalSpacing = 20; 251 shell.setLayout (gridLayout); 252 msg = Compatibility.getMessage ("SWT_Download_Location", new Object [] {filename, url}); new Label (shell, SWT.SIMPLE).setText (msg); 254 status = new Label (shell, SWT.SIMPLE); 255 msg = Compatibility.getMessage ("SWT_Download_Started"); status.setText (msg); 257 GridData data = new GridData (); 258 data.grabExcessHorizontalSpace = true; 259 data.grabExcessVerticalSpace = true; 260 status.setLayoutData (data); 261 262 cancel = new Button (shell, SWT.PUSH); 263 cancel.setText (SWT.getMessage ("SWT_Cancel")); data = new GridData (); 265 data.horizontalAlignment = GridData.CENTER; 266 cancel.setLayoutData (data); 267 cancel.addListener (SWT.Selection, listener); 268 shell.addListener (SWT.Close, listener); 269 shell.pack (); 270 shell.open (); 271 return XPCOM.NS_OK; 272 } 273 274 int GetAmountTransferred (int arg0) { 275 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 276 } 277 278 int GetCancelable (int arg0) { 279 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 280 } 281 282 public int GetDisplayName (int aDisplayName) { 283 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 284 } 285 286 public int GetMIMEInfo (int aMIMEInfo) { 287 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 288 } 289 290 public int GetPercentComplete (int aPercentComplete) { 291 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 292 } 293 294 int GetSize (int arg0) { 295 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 296 } 297 298 public int GetSource (int aSource) { 299 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 300 } 301 302 public int GetStartTime (int aStartTime) { 303 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 304 } 305 306 public int GetTarget (int aTarget) { 307 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 308 } 309 310 int GetTargetFile (int arg0) { 311 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 312 } 313 314 315 public int GetCancelDownloadOnClose (int aCancelDownloadOnClose) { 316 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 317 } 318 319 public int GetDialog (int aDialog) { 320 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 321 } 322 323 public int GetObserver (int aObserver) { 324 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 325 } 326 327 public int Open (int aParent) { 328 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 329 } 330 331 public int SetCancelDownloadOnClose (int aCancelDownloadOnClose) { 332 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 333 } 334 335 public int SetDialog (int aDialog) { 336 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 337 } 338 339 public int SetObserver (int aObserver) { 340 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 341 } 342 343 344 345 int OnLocationChange (int aWebProgress, int aRequest, int aLocation) { 346 return XPCOM.NS_OK; 347 } 348 349 int OnProgressChange (int aWebProgress, int aRequest, int aCurSelfProgress, int aMaxSelfProgress, int aCurTotalProgress, int aMaxTotalProgress) { 350 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); 351 } 352 353 354 int OnProgressChange64_32 (int aWebProgress, int aRequest, int aCurSelfProgress1, int aCurSelfProgress2, int aMaxSelfProgress1, int aMaxSelfProgress2, int aCurTotalProgress1, int aCurTotalProgress2, int aMaxTotalProgress1, int aMaxTotalProgress2) { 355 long aCurSelfProgress = (aCurSelfProgress2 << 32) + aCurSelfProgress1; 356 long aMaxSelfProgress = (aMaxSelfProgress2 << 32) + aMaxSelfProgress1; 357 long aCurTotalProgress = (aCurTotalProgress2 << 32) + aCurTotalProgress1; 358 long aMaxTotalProgress = (aMaxTotalProgress2 << 32) + aMaxTotalProgress1; 359 return OnProgressChange64 (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); 360 } 361 362 int OnProgressChange64 (int aWebProgress, int aRequest, long aCurSelfProgress, long aMaxSelfProgress, long aCurTotalProgress, long aMaxTotalProgress) { 363 long currentKBytes = aCurTotalProgress / 1024; 364 long totalKBytes = aMaxTotalProgress / 1024; 365 if (shell != null & !shell.isDisposed ()) { 366 Object [] arguments = {new Long (currentKBytes), new Long (totalKBytes)}; 367 String statusMsg = Compatibility.getMessage ("SWT_Download_Status", arguments); status.setText (statusMsg); 369 shell.layout (true); 370 shell.getDisplay ().update (); 371 } 372 return XPCOM.NS_OK; 373 } 374 375 int OnSecurityChange (int aWebProgress, int aRequest, int state) { 376 return XPCOM.NS_OK; 377 } 378 379 int OnStateChange (int aWebProgress, int aRequest, int aStateFlags, int aStatus) { 380 if ((aStateFlags & nsIWebProgressListener.STATE_STOP) != 0) { 381 cancelable = null; 382 if (shell != null && !shell.isDisposed ()) shell.dispose (); 383 shell = null; 384 } 385 return XPCOM.NS_OK; 386 } 387 388 int OnStatusChange (int aWebProgress, int aRequest, int aStatus, int aMessage) { 389 return XPCOM.NS_OK; 390 } 391 } 392 | Popular Tags |