diff dwt/browser/Mozilla.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 373b48b9eaf0
children 59b54fea05d0
line wrap: on
line diff
--- a/dwt/browser/Mozilla.d	Mon Nov 03 23:35:30 2008 +0100
+++ b/dwt/browser/Mozilla.d	Tue Nov 04 21:20:45 2008 -0800
@@ -352,11 +352,37 @@
                     // byte[] path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true);
                     rc = XPCOMInit.XPCOMGlueStartup (mozillaPath.ptr);
                     if (rc !is XPCOM.NS_OK) {
-                        IsXULRunner = false;    /* failed */
-                        //mozillaPath = mozillaPath[0 .. locatePrior( mozillaPath, SEPARATOR_OS )];
                         mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
                         if (Device.DEBUG) Cerr ("cannot use detected XULRunner: ") (mozillaPath).newline; //$NON-NLS-1$
-                    } else {
+                        
+                        /* attempt to XPCOMGlueStartup the GRE pointed at by MOZILLA_FIVE_HOME */
+                        auto ptr = Environment.get(XPCOM.MOZILLA_FIVE_HOME);
+                        if (ptr is null) {
+                            IsXULRunner = false;
+                        } else {
+                            //length = C.strlen (ptr);
+                            //byte[] buffer = new byte[length];
+                            //C.memmove (buffer, ptr, length);
+                            mozillaPath = ptr;
+                            /*
+                             * Attempting to XPCOMGlueStartup a mozilla-based GRE !is xulrunner can
+                             * crash, so don't attempt unless the GRE appears to be xulrunner.
+                             */
+                            if (mozillaPath.indexOf("xulrunner") is -1) { //$NON-NLS-1$
+                                IsXULRunner = false;    
+
+                            } else {
+                                mozillaPath ~= SEPARATOR_OS ~ mozDelegate.getLibraryName ();
+                                rc = XPCOMInit.XPCOMGlueStartup (toStringz(mozillaPath));
+                                if (rc !is XPCOM.NS_OK) {
+                                    IsXULRunner = false;
+                                    mozillaPath = mozillaPath.substring (0, mozillaPath.lastIndexOf (SEPARATOR_OS));
+                                    if (Device.DEBUG) Cerr ("failed to start as XULRunner: " )(mozillaPath).newline; //$NON-NLS-1$
+                                }
+                            }
+                        } 
+                    }
+                    if (IsXULRunner) {
                         XPCOMInitWasGlued = true;
                     }
                 }
@@ -994,18 +1020,6 @@
             error (rc, __FILE__, __LINE__);
         }
         factory.Release ();
-        
-        HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory ();
-        dialogFactory.AddRef ();
-        //aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID, true);
-        aClassName = "Helper App Launcher Dialog";
-        //aClassName = MozillaDelegate.wcsToMbcs (null, "Helper App Launcher Dialog", true); //$NON-NLS-1$
-        rc = componentRegistrar.RegisterFactory (&XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CID, aClassName.ptr, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID.ptr, cast(nsIFactory)dialogFactory);
-        if (rc !is XPCOM.NS_OK) {
-            browser.dispose ();
-            error (rc, __FILE__, __LINE__);
-        }
-        dialogFactory.Release ();
 
         /*
         * This Download factory will be used if the GRE version is < 1.8.
@@ -1109,7 +1123,17 @@
 
                 if (XPCOMWasGlued) {
                     // TODO: is there a difference between two startup methhods? Glue functions are same.
-                    XPCOMInit.XPCOMGlueShutdown ();
+                   /*
+                    * XULRunner 1.9 can crash on Windows if XPCOMGlueShutdown is invoked here,
+                    * presumably because one or more of its unloaded symbols are referenced when
+                    * this callback returns.  The workaround is to delay invoking XPCOMGlueShutdown
+                    * so that its symbols are still available once this callback returns.
+                    */
+                    display.asyncExec (new class() Runnable {
+                        public void run () {
+                            XPCOMInit.XPCOMGlueShutdown ();
+                        }
+                    });
                     XPCOMWasGlued = false;
                 }
                 if (XPCOMInitWasGlued) {
@@ -1195,6 +1219,28 @@
 
     if (!PerformedVersionCheck) {
         PerformedVersionCheck = true;
+        
+        nsIComponentRegistrar componentRegistrar;
+        rc = componentManager.QueryInterface (&nsIComponentRegistrar.IID, cast(void**)&componentRegistrar);
+        if (rc !is XPCOM.NS_OK) {
+            browser.dispose ();
+            error (rc, __FILE__,__LINE__);
+        }
+        if (componentRegistrar is null) {
+            browser.dispose ();
+            error (XPCOM.NS_NOINTERFACE,__FILE__,__LINE__);
+        }
+
+        HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory ();
+        dialogFactory.AddRef ();
+        //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID, true);
+        String aClassName = "Helper App Launcher Dialog"; //$NON-NLS-1$
+        rc = componentRegistrar.RegisterFactory (&XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CID, aClassName.ptr, XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID.ptr, cast(nsIFactory)dialogFactory);
+        if (rc !is XPCOM.NS_OK) {
+            browser.dispose ();
+            error (rc,__FILE__,__LINE__);
+        }
+        dialogFactory.Release ();
 
         /*
         * Check for the availability of the pre-1.8 implementation of nsIDocShell
@@ -1235,31 +1281,18 @@
             rc = interfaceRequestor.GetInterface (&nsIDocShell_1_8.IID, cast(void**)&docShell_1_8);
             if (rc is XPCOM.NS_OK && docShell_1_8 !is null) { /* 1.8 */
                 docShell_1_8.Release ();
-                //result[0] = 0;
-                nsIComponentRegistrar componentRegistrar;
-                rc = componentManager.QueryInterface (&nsIComponentRegistrar.IID, cast(void**)&componentRegistrar);
-                if (rc !is XPCOM.NS_OK) {
-                    browser.dispose ();
-                    error (rc, __FILE__, __LINE__);
-                }
-                if (componentRegistrar is null) {
-                    browser.dispose ();
-                    error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
-                }
-
-                // nsIComponentRegistrar componentRegistrar = new nsIComponentRegistrar (result[0]);
+ 
                 DownloadFactory_1_8 downloadFactory_1_8 = new DownloadFactory_1_8 ();
                 downloadFactory_1_8.AddRef ();
                 // byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_TRANSFER_CONTRACTID, true);
                 
-                String aClassName = "Transfer"; //$NON-NLS-1$
+                aClassName = "Transfer"; //$NON-NLS-1$
                 rc = componentRegistrar.RegisterFactory (&XPCOM.NS_DOWNLOAD_CID, aClassName.ptr, XPCOM.NS_TRANSFER_CONTRACTID.ptr, cast(nsIFactory)downloadFactory_1_8);
                 if (rc !is XPCOM.NS_OK) {
                     browser.dispose ();
                     error (rc, __FILE__, __LINE__);
                 }
                 downloadFactory_1_8.Release ();
-                componentRegistrar.Release ();
                 } else { /* >= 1.9 */
                 /*
                  * Bug in XULRunner 1.9.  Mozilla no longer clears its background before initial content has
@@ -1285,10 +1318,12 @@
                 //ABOUT_BLANK.getChars (0, ABOUT_BLANK.length (), uri, 0);
                 rc = webNavigation.LoadURI (ABOUT_BLANK.toString16().toString16z(), nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
                 webNavigation.Release ();
+                dialogFactory.isPre_1_9 = false;
             }
         }
         //result[0] = 0;
         interfaceRequestor.Release ();
+        componentRegistrar.Release ();
     }
     componentManager.Release ();
 
@@ -2835,7 +2870,7 @@
             //byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_WEBNAVIGATIONINFO_CONTRACTID, true);
             nsIWebNavigationInfo info;
             rc = serviceManager.GetServiceByContractID (XPCOM.NS_WEBNAVIGATIONINFO_CONTRACTID.ptr, &nsIWebNavigationInfo.IID, cast(void**)&info);
-            if (rc is 0) {
+            if (rc is XPCOM.NS_OK) {
                 //byte[] bytes = MozillaDelegate.wcsToMbcs (null, contentType, true);
                 scope auto typePtr = new nsEmbedCString(contentType);
                 //nsIWebNavigationInfo info = new nsIWebNavigationInfo (result[0]);