diff dwt/browser/Mozilla.d @ 305:c7c696cdfec2

Mozilla module progress; fixes to other browser modules; update XPCOM interfaces
author John Reimer<terminal.node@gmail.com>
date Sat, 16 Aug 2008 22:53:35 -0700
parents 16ba3d9cb209
children 8235a17d9255
line wrap: on
line diff
--- a/dwt/browser/Mozilla.d	Thu Aug 14 20:25:29 2008 -0700
+++ b/dwt/browser/Mozilla.d	Sat Aug 16 22:53:35 2008 -0700
@@ -166,7 +166,7 @@
     static final String PREFERENCE_PROXYTYPE = "network.proxy.type"; //$NON-NLS-1$
     static final String PROFILE_AFTER_CHANGE = "profile-after-change"; //$NON-NLS-1$
     static final String PROFILE_BEFORE_CHANGE = "profile-before-change"; //$NON-NLS-1$
-    static final String PROFILE_DIR = SEPARATOR_OS + "eclipse" ~ SEPARATOR_OS; //$NON-NLS-1$
+    static final String PROFILE_DIR = SEPARATOR_OS ~ "eclipse" ~ SEPARATOR_OS; //$NON-NLS-1$
     static final String PROFILE_DO_CHANGE = "profile-do-change"; //$NON-NLS-1$
     static final String PROPERTY_PROXYPORT = "network.proxy_port"; //$NON-NLS-1$
     static final String PROPERTY_PROXYHOST = "network.proxy_host"; //$NON-NLS-1$
@@ -257,7 +257,11 @@
             Initialized = true;
         }
         String mozillaPath = System.getProperty (XULRUNNER_PATH);
-        /+ if (mozillaPath is null) {
+        if (mozillaPath is null) {
+            // we don't have to load an initial library in DWT, so set to "true"
+            initLoaded = true;
+/+
+        if (mozillaPath is null) {
             try {
                 String libName = mozDelegate.getSWTInitLibraryName ();
                 Library.loadLibrary (libName);
@@ -269,54 +273,57 @@
                 * points at a GRE. 
                 */
             }
-        } else { +/
++/
+        } else {
             mozillaPath ~= SEPARATOR_OS ~ mozDelegate.getLibraryName ();
             IsXULRunner = true;
-        // }
-
+        }
+         
         if (initLoaded) {
             /* attempt to discover a XULRunner to use as the GRE */
             GREVersionRange range;
             //byte[] bytes = MozillaDelegate.wcsToMbcs (null, GRERANGE_LOWER, true);
-            int /*long*/ lower = C.malloc (bytes.length);
-            C.memmove (lower, bytes, bytes.length);
-            range.lower = lower;
+            //int /*long*/ lower = C.malloc (bytes.length);
+            //C.memmove (lower, bytes, bytes.length);
+            range.lower = GRERANGE_LOWER;
             range.lowerInclusive = LowerRangeInclusive;
 
-            bytes = MozillaDelegate.wcsToMbcs (null, GRERANGE_UPPER, true);
-            int /*long*/ upper = C.malloc (bytes.length);
-            C.memmove (upper, bytes, bytes.length);
-            range.upper = upper;
+            //bytes = MozillaDelegate.wcsToMbcs (null, GRERANGE_UPPER, true);
+            //int /*long*/ upper = C.malloc (bytes.length);
+            //C.memmove (upper, bytes, bytes.length);
+            range.upper = GRERANGE_UPPER;
             range.upperInclusive = UpperRangeInclusive;
 
-            int length = XPCOMInit.PATH_MAX;
-            int /*long*/ greBuffer = C.malloc (length);
-            int /*long*/ propertiesPtr = C.malloc (2 * C.PTR_SIZEOF);
-            int rc = XPCOMInit.GRE_GetGREPathWithProperties (range, 1, propertiesPtr, 0, greBuffer, length);
+            //int length = XPCOMInit.PATH_MAX;
+            //int /*long*/ greBuffer = C.malloc (length);
+            char[] greBuffer = new char[XPCOMInit.PATH_MAX];
+            //int /*long*/ propertiesPtr = C.malloc (2 * C.PTR_SIZEOF);
+            int rc = XPCOMInit.GRE_GetGREPathWithProperties (&range, 1, null, 0, greBuffer.ptr, greBuffer.length);
 
             /*
              * A XULRunner was not found that supports wrapping of XPCOM handles as JavaXPCOM objects.
              * Drop the lower version bound and try to detect an earlier XULRunner installation.
              */
             if (rc !is XPCOM.NS_OK) {
-                C.free (lower);
-                bytes = MozillaDelegate.wcsToMbcs (null, GRERANGE_LOWER_FALLBACK, true);
-                lower = C.malloc (bytes.length);
-                C.memmove (lower, bytes, bytes.length);
-                range.lower = lower;
-                rc = XPCOMInit.GRE_GetGREPathWithProperties (range, 1, propertiesPtr, 0, greBuffer, length);
+                //C.free (lower);
+                //bytes = MozillaDelegate.wcsToMbcs (null, GRERANGE_LOWER_FALLBACK, true);
+                //lower = C.malloc (bytes.length);
+                //C.memmove (lower, bytes, bytes.length);
+                range.lower = GRERANGE_LOWER_FALLBACK;
+                rc = XPCOMInit.GRE_GetGREPathWithProperties (&range, 1, null, 0, greBuffer.ptr, greBuffer.length);
             }
 
-            C.free (lower);
-            C.free (upper);
-            C.free (propertiesPtr);
+            //C.free (lower);
+            //C.free (upper);
+            //C.free (propertiesPtr);
             if (rc is XPCOM.NS_OK) {
                 /* indicates that a XULRunner was found */
-                length = C.strlen (greBuffer);
-                bytes = new byte[length];
-                C.memmove (bytes, greBuffer, length);
-                mozillaPath = new String (MozillaDelegate.mbcsToWcs (null, bytes));
-                IsXULRunner = mozillaPath.length () > 0;
+                //length = C.strlen (greBuffer);
+                //bytes = new byte[length];
+                //C.memmove (bytes, greBuffer, length);
+                //mozillaPath = new String (MozillaDelegate.mbcsToWcs (null, bytes));
+                mozillaPath = greBuffer;
+                IsXULRunner = mozillaPath.length > 0;
 
                 /*
                  * Test whether the detected XULRunner can be used as the GRE before loading swt's
@@ -327,61 +334,67 @@
                  * is running in 32-bit mode, or vice versa.
                  */
                 if (IsXULRunner) {
-                    byte[] path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true);
-                    rc = XPCOMInit.XPCOMGlueStartup (path);
+                    // byte[] path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true);
+                    rc = XPCOMInit.XPCOMGlueStartup (mozillaPath.ptr);
                     if (rc !is XPCOM.NS_OK) {
                         IsXULRunner = false;    /* failed */
-                        mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
-                        if (Device.DEBUG) System.out.println ("cannot use detected XULRunner: " + mozillaPath); //$NON-NLS-1$
+                        mozillaPath = mozillaPath[0 .. locatePrior( mozillaPath, SEPARATOR_OS )];
+                        //mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
+                        if (Device.DEBUG) Stdout ("cannot use detected XULRunner: ") (mozillaPath).newline; //$NON-NLS-1$
                     } else {
                         XPCOMInitWasGlued = true;
                     }
                 }
             }
-            C.free (greBuffer);
+            //C.free (greBuffer);
         }
 
         if (IsXULRunner) {
-            if (Device.DEBUG) System.out.println ("XULRunner path: " + mozillaPath); //$NON-NLS-1$
+            if (Device.DEBUG) Stdout ("XULRunner path: ") (mozillaPath).newline; //$NON-NLS-1$
+/+
             try {
                 Library.loadLibrary ("swt-xulrunner"); //$NON-NLS-1$
             } catch (UnsatisfiedLinkError e) {
                 DWT.error (DWT.ERROR_NO_HANDLES, e);
             }
+            
             byte[] path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true);
-            int rc = XPCOM.XPCOMGlueStartup (path);
+            int rc = XPCOM.XPCOMGlueStartup (path);  
+
             if (rc !is XPCOM.NS_OK) {
                 browser.dispose ();
                 error (rc);
             }
++/          // No need for double layer initialization in DWT; glue is initialized -JJR
             XPCOMWasGlued = true;
 
             /*
              * Remove the trailing xpcom lib name from mozillaPath because the
              * Mozilla.initialize and NS_InitXPCOM2 invocations require a directory name only.
-             */ 
-            mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
+             */
+            mozillaPath = mozillaPath[0 .. locatePrior( mozillaPath, SEPARATOR_OS )];
+            //mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
         } else {
             if ((style & DWT.MOZILLA) !is 0) {
                 browser.dispose ();
-                String errorString = (mozillaPath !is null && mozillaPath.length () > 0) ?
-                    " [Failed to use detected XULRunner: " + mozillaPath + "]" :
+                String errorString = (mozillaPath !is null && mozillaPath.length > 0) ?
+                    " [Failed to use detected XULRunner: " ~ mozillaPath ~ "]" :
                     " [Could not detect registered XULRunner to use]";  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                 DWT.error (DWT.ERROR_NO_HANDLES, null, errorString);
             }
 
             /* attempt to use the GRE pointed at by MOZILLA_FIVE_HOME */
-            int /*long*/ ptr = C.getenv (MozillaDelegate.wcsToMbcs (null, XPCOM.MOZILLA_FIVE_HOME, true));
-            if (ptr !is 0) {
-                int length = C.strlen (ptr);
-                byte[] buffer = new byte[length];
-                C.memmove (buffer, ptr, length);
-                mozillaPath = new String (MozillaDelegate.mbcsToWcs (null, buffer));
+            auto mozFiveHome = tango.sys.Environment.get(XPCOM.MOZILLA_FIVE_HOME);
+            if (mozFiveHome !is null) {
+                //int length = C.strlen (ptr);
+                //byte[] buffer = new byte[length];
+                //C.memmove (buffer, ptr, length);
+                mozillaPath = mozFiveHome;
             } else {
                 browser.dispose ();
                 DWT.error (DWT.ERROR_NO_HANDLES, null, " [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]"); //$NON-NLS-1$
             }
-            if (Device.DEBUG) System.out.println ("Mozilla path: " + mozillaPath); //$NON-NLS-1$
+            if (Device.DEBUG) Stdout ("Mozilla path: ") (mozillaPath).newline; //$NON-NLS-1$
 
             /*
             * Note.  Embedding a Mozilla GTK1.2 causes a crash.  The workaround
@@ -393,7 +406,7 @@
                 browser.dispose ();
                 DWT.error (DWT.ERROR_NO_HANDLES, null, " [Mozilla GTK2 required (GTK1.2 detected)]"); //$NON-NLS-1$                         
             }
-
+/+
             try {
                 Library.loadLibrary ("swt-mozilla"); //$NON-NLS-1$
             } catch (UnsatisfiedLinkError e) {
@@ -412,19 +425,20 @@
                      */
                     DWT.error (DWT.ERROR_NO_HANDLES, e, " [MOZILLA_FIVE_HOME='" + mozillaPath + "']"); //$NON-NLS-1$ //$NON-NLS-2$
                 }
-            }
+            } 
++/
         }
 
         if (!Initialized) {
-            int /*long*/[] retVal = new int /*long*/[1];
-            nsEmbedString pathString = new nsEmbedString (mozillaPath);
-            int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, retVal);
-            pathString.dispose ();
+            nsILocalFile file;
+            scope auto pathString = new nsEmbedString (mozillaPath);
+            nsresult rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile);
+            //pathString.dispose ();
             if (rc !is XPCOM.NS_OK) {
                 browser.dispose ();
                 error (rc);
             }
-            if (retVal[0] is 0) {
+            if (localFile is null) {
                 browser.dispose ();
                 error (XPCOM.NS_ERROR_NULL_POINTER);
             }
@@ -432,19 +446,37 @@
             LocationProvider = new AppFileLocProvider (mozillaPath);
             LocationProvider.AddRef ();
 
-            nsIFile localFile = new nsILocalFile (retVal[0]);
-            rc = XPCOM.NS_InitXPCOM2 (0, localFile.getAddress(), LocationProvider.getAddress ());
+            //nsIFile localFile = new nsILocalFile (retVal[0]);
+            nsIDirectoryServiceProvider directoryServiceProvider;
+            nsIServiceManager serviceManager;
+            rc = LocationProvider.QueryInterface( &nsIDirectoryServiceProvider.IID, cast(void**)&directoryServiceProvider);
+            if (rc !is XPCOM.NS_OK) {
+                browser.dispose();
+                error(rc);
+            }
+            rc = XPCOM.NS_GetServiceManager(&serviceManager);
+            if (rc !is XPCOM.NS_OK) {
+                browser.dispose();
+                error(rc);
+            }
+            if (serviceManager is null || directoryServiceProvider is null) {
+                browser.dispose;
+                error (XPCOM.NS_ERROR_NULL_POINTER);
+            }
+            rc = XPCOM.NS_InitXPCOM2 (&serviceManager, 0, cast(IFile*)&localFile, &directoryServiceProvider);
             localFile.Release ();
+            serviceManager.Release();
+            //LocationProvider.Release();
             if (rc !is XPCOM.NS_OK) {
                 browser.dispose ();
-                DWT.error (DWT.ERROR_NO_HANDLES, null, " [MOZILLA_FIVE_HOME may not point at an embeddable GRE] [NS_InitEmbedding " + mozillaPath + " error " + rc + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                DWT.error (DWT.ERROR_NO_HANDLES, null, Format(" [MOZILLA_FIVE_HOME may not point at an embeddable GRE] [NS_InitEmbedding {0} error {1} ] ", mozillaPath, rc ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
             }
             System.setProperty (GRE_INITIALIZED, "true"); //$NON-NLS-1$
             if (IsXULRunner) {
                 System.setProperty (XULRUNNER_PATH, mozillaPath);
             }
         }
-
+/+
         /* If JavaXPCOM is detected then attempt to initialize it with the XULRunner being used */
         if (IsXULRunner) {
             try {
@@ -472,33 +504,34 @@
             } catch (InstantiationException e) {
             }
         }
-
-        int rc = XPCOM.NS_GetComponentManager (result);
++/
+        nsIComponentManager componentManager;
+        int rc = XPCOM.NS_GetComponentManager (&componentManager);
         if (rc !is XPCOM.NS_OK) {
             browser.dispose ();
             error (rc);
         }
-        if (result[0] is 0) {
+        if (componentManager is null) {
             browser.dispose ();
             error (XPCOM.NS_NOINTERFACE);
         }
         
-        nsIComponentManager componentManager = new nsIComponentManager (result[0]);
-        result[0] = 0;
+        //nsIComponentManager componentManager = new nsIComponentManager (result[0]);
+        //result[0] = 0;
         if (mozDelegate.needsSpinup ()) {
             /* nsIAppShell is discontinued as of xulrunner 1.9, so do not fail if it is not found */
-            rc = componentManager.CreateInstance (XPCOM.NS_APPSHELL_CID, 0, nsIAppShell.NS_IAPPSHELL_IID, result);
+            rc = componentManager.CreateInstance (XPCOM.NS_APPSHELL_CID, 0, nsIAppShell.IID, cast(void**)&AppShell);
             if (rc !is XPCOM.NS_ERROR_NO_INTERFACE) {
                 if (rc !is XPCOM.NS_OK) {
                     browser.dispose ();
                     error (rc);
                 }
-                if (result[0] is 0) {
+                if (AppShell is null) {
                     browser.dispose ();
                     error (XPCOM.NS_NOINTERFACE);
                 }
     
-                AppShell = new nsIAppShell (result[0]);
+                //AppShell = new nsIAppShell (result[0]);
                 rc = AppShell.Create (0, null);
                 if (rc !is XPCOM.NS_OK) {
                     browser.dispose ();
@@ -510,38 +543,40 @@
                     error (rc);
                 }
             }
-            result[0] = 0;
+            //result[0] = 0;
         }
 
-        WindowCreator = new WindowCreator2 ();
+        WindowCreator = new WindowCreator2;
         WindowCreator.AddRef ();
         
-        rc = XPCOM.NS_GetServiceManager (result);
+        nsIServiceManager serviceManager;
+        rc = XPCOM.NS_GetServiceManager (&serviceManager);
         if (rc !is XPCOM.NS_OK) {
             browser.dispose ();
             error (rc);
         }
-        if (result[0] is 0) {
+        if (serviceManager is null) {
             browser.dispose ();
             error (XPCOM.NS_NOINTERFACE);
         }
         
-        nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-        result[0] = 0;      
-        byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WINDOWWATCHER_CONTRACTID, true);
-        rc = serviceManager.GetServiceByContractID (aContractID, nsIWindowWatcher.NS_IWINDOWWATCHER_IID, result);
+        //nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
+        //result[0] = 0;      
+        //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WINDOWWATCHER_CONTRACTID, true);
+        nsIWindowWatcher windowWatcher;
+        rc = serviceManager.GetServiceByContractID (XPCOM.NS_WINDOWWATCHER_CONTRACTID, nsIWindowWatcher.IID, cast(void**)&windowWatcher);
         if (rc !is XPCOM.NS_OK) {
             browser.dispose ();
             error (rc);
         }
-        if (result[0] is 0) {
+        if (windowWatcher is null) {
             browser.dispose ();
             error (XPCOM.NS_NOINTERFACE);       
         }
 
-        nsIWindowWatcher windowWatcher = new nsIWindowWatcher (result[0]);
-        result[0] = 0;
-        rc = windowWatcher.SetWindowCreator (WindowCreator.getAddress());
+        //nsIWindowWatcher windowWatcher = new nsIWindowWatcher (result[0]);
+        //result[0] = 0;
+        rc = windowWatcher.SetWindowCreator (&WindowCreator);
         if (rc !is XPCOM.NS_OK) {
             browser.dispose ();
             error (rc);