diff dwt/browser/HelperAppLauncherDialog.d @ 352:a3c5f744d03f

Update Browser/Mozilla package to SWT 3.4.1 and bug fixes
author John Reimer <terminal.node@gmail.com>
date Tue, 04 Nov 2008 21:20:45 -0800
parents 9a4d7706df52
children
line wrap: on
line diff
--- a/dwt/browser/HelperAppLauncherDialog.d	Mon Nov 03 23:35:30 2008 +0100
+++ b/dwt/browser/HelperAppLauncherDialog.d	Tue Nov 04 21:20:45 2008 -0800
@@ -26,7 +26,6 @@
 import dwt.internal.mozilla.nsIHelperAppLauncher;
 import dwt.internal.mozilla.nsIHelperAppLauncherDialog;
 import dwt.internal.mozilla.nsIHelperAppLauncher_1_8;
-import dwt.internal.mozilla.nsIHelperAppLauncher_1_9;
 import dwt.internal.mozilla.nsISupports;
 import dwt.internal.mozilla.nsILocalFile;
 import dwt.internal.mozilla.nsStringAPI;
@@ -36,6 +35,13 @@
 import dwt.widgets.FileDialog;
 import dwt.widgets.Shell;
 
+/**
+ * This class implements the HelperAppLauncherDialog interface for mozilla
+ * versions 1.4 - 1.8.x.  For mozilla versions >= 1.9 this interface is
+ * implemented by class HelperAppLauncherDialog_1_9.  HelperAppLauncherDialogFactory
+ * determines at runtime which of these classes to instantiate. 
+ */
+
 class HelperAppLauncherDialog : nsIHelperAppLauncherDialog {
     int refCount = 0;
 
@@ -77,7 +83,7 @@
     * cancels the File Dialog, cancels or closes the Download Dialog
     * and when the Download Dialog goes away after the download is completed.
     */
-    //if (refCount is 0) disposeCOMInterfaces ();
+    if (refCount is 0) return 0;
     return refCount;
 }
 
@@ -85,33 +91,24 @@
 
 extern(System)
 nsresult Show(nsIHelperAppLauncher aLauncher, nsISupports aContext, PRUint32 aReason) {
-    /*
-    * The interface for nsIHelperAppLauncher changed in GRE versions 1.8 and 1.9.  Query for
-    * each of these interfaces in turn until one is found.
-    */
-    // FIXME: Not sure if this will work because of different versions of 
-    // nsIHelperAppLauncher.  Remember to check. -JJR
-    nsIHelperAppLauncher_1_9 helperAppLauncher1;
-    int rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_9.IID, cast(void**)&helperAppLauncher1);
+     /*
+     * The interface for nsIHelperAppLauncher changed as of mozilla 1.8.  Query the received
+     * nsIHelperAppLauncher for the new interface, and if it is not found then fall back to
+     * the old interface. 
+     */
+
+    nsISupports supports = cast(nsISupports)aLauncher;
+    nsIHelperAppLauncher_1_8 helperAppLauncher;
+    nsresult rc = supports.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher);
     if (rc is 0) {
-       // nsIHelperAppLauncher_1_9 helperAppLauncher = new nsIHelperAppLauncher_1_9 (aLauncher);
-        rc = helperAppLauncher1.SaveToDisk (null, 0);
-        helperAppLauncher1.Release ();
+        rc = helperAppLauncher.SaveToDisk (null, 0);
+        helperAppLauncher.Release ();
         return rc;
     }
 
-    //result[0] = 0;
-    nsIHelperAppLauncher_1_8 helperAppLauncher2;
-    rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher2);
-    if (rc is 0) {
-        //nsIHelperAppLauncher_1_8 helperAppLauncher = new nsIHelperAppLauncher_1_8 (aLauncher);
-        rc = helperAppLauncher2.SaveToDisk (null, 0);
-        helperAppLauncher2.Release ();
-        return rc;
-    }
-
-    //nsIHelperAppLauncher helperAppLauncher = new nsIHelperAppLauncher (aLauncher);  /* < 1.8 */
+    /* < 1.8 */
     return aLauncher.SaveToDisk (null, 0);
+    // no Release for this? -JJR
 }
 
 extern(System)
@@ -131,47 +128,29 @@
      * The interface for nsIHelperAppLauncher changed as of mozilla 1.8, so the first
      * argument must be queried for both the old and new nsIHelperAppLauncher interfaces. 
      */
-    bool using_1_8 = false, using_1_9 = false;
-    // technically this should have an AddRef? -JJR
-    //nsISupports support = cast(nsISupports)arg0; 
-    //int /*long*/[] result = new int /*long*/[1];
+    bool using_1_8 = false;
+    nsISupports support = cast(nsISupports)aLauncher; 
+    
     if (aLauncher is null)
         assert(0);
-        
-    // TODO: D Bindings are locked to the XPCOM interface version provided in
-    // dwt/internal/mozilla package; therefore the following version checks 
-    // are redundant for now. In this case, 1.8 and 1.9
-    // will be bypassed.  To get 1.8 and 1.9 working for D, we will 
-    // have to customize this section a bit or simply remove the references
-    // until the default aligns with these versions in later swt updates. 
-    // For now this should work as is.
 
     nsIHelperAppLauncher_1_8 helperAppLauncher1;
-
-    int rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher1);
-    if (rc is 0) {
+    int rc = support.QueryInterface (&nsIHelperAppLauncher_1_8.IID, cast(void**)&helperAppLauncher1);
+    if (rc is XPCOM.NS_OK) {
         using_1_8 = true;
         hasLauncher = true;
         helperAppLauncher1.Release ();
     } else {
-        nsIHelperAppLauncher_1_9 helperAppLauncher2;
-        rc = aLauncher.QueryInterface (&nsIHelperAppLauncher_1_9.IID, cast(void**)&helperAppLauncher2);
-        if (rc is 0) {
-            using_1_9 = true;
+        nsIHelperAppLauncher helperAppLauncher;
+        rc = support.QueryInterface (&nsIHelperAppLauncher.IID, cast(void**)&helperAppLauncher);
+        if (rc is XPCOM.NS_OK) {
             hasLauncher = true;
-            helperAppLauncher2.Release;
-        } else {
-            nsIHelperAppLauncher helperAppLauncher;
-            rc = aLauncher.QueryInterface (&nsIHelperAppLauncher.IID, cast(void**)&helperAppLauncher);
-            if (rc is 0) {
-                hasLauncher = true;
-                helperAppLauncher.Release;
-            }
+            helperAppLauncher.Release;
         }
     }
 
 /+
-    // In D port, Mozilla version is determined by the bindings used
+    // In D port, no suppport for version >1.4 yet
     if (hasLauncher) {  /* >= 1.5 */
         aDefaultFile = arg2;
         aSuggestedFileExtension = arg3;
@@ -203,15 +182,12 @@
     shell.close ();
     if (name is null) {
         if (hasLauncher) {
-            // not sure if these produce correct interface alignment. Check. -JJR
-            if (using_1_8 || using_1_9) {
-                //rc = aLauncher.Cancel (XPCOM.NS_BINDING_ABORTED);
-                implMissing(__FILE__,__LINE__);
+            if (using_1_8) {
+                rc = (cast(nsIHelperAppLauncher_1_8)aLauncher).Cancel (XPCOM.NS_BINDING_ABORTED);
             } else {
-                //nsIHelperAppLauncher launcher = new nsIHelperAppLauncher (arg0);
                 rc = aLauncher.Cancel ();
             }
-            if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 
+            if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__); 
             return XPCOM.NS_OK;
         }
         return XPCOM.NS_ERROR_FAILURE;
@@ -220,8 +196,8 @@
     nsILocalFile localFile;
     rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, &localFile);
     //path.dispose ();
-    if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
-    if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
+    if (rc !is XPCOM.NS_OK) Mozilla.error (rc,__FILE__,__LINE__);
+    if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER,__FILE__,__LINE__);
     /* Our own nsIDownload has been registered during the Browser initialization. It will be invoked by Mozilla. */
     *_retval = localFile; 
     //XPCOM.memmove (_retval, result, C.PTR_SIZEOF);