changeset 354:59b54fea05d0

Fixes for XPCOM 1.9 and anonymous classes
author john@andLinux
date Sun, 14 Dec 2008 02:13:20 -0500
parents 7f3013c93a95
children fe52206e0ece
files dwt/browser/Mozilla.d dwt/browser/MozillaDelegate.d dwt/dwthelper/System.d dwt/internal/mozilla/nsIDocShell.d
diffstat 4 files changed, 99 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/browser/Mozilla.d	Tue Nov 04 21:21:43 2008 -0800
+++ b/dwt/browser/Mozilla.d	Sun Dec 14 02:13:20 2008 -0500
@@ -407,8 +407,6 @@
                 error (rc, __FILE__, __LINE__);
             }
 +/          // No need for double layer initialization in DWT; XPCOMInit was glued
-            // At this stage we know that XULRunner is available, but we don't know
-            // TODO: determine if 
             XPCOMWasGlued = true;
 
             /*
@@ -1060,89 +1058,7 @@
 
     if (display.getData (DISPOSE_LISTENER_HOOKED) is null) {
         display.setData (DISPOSE_LISTENER_HOOKED, stringcast(DISPOSE_LISTENER_HOOKED));
-        display.addListener (DWT.Dispose, new class() Listener {
-            public void handleEvent (Event event) {
-                if (BrowserCount > 0) return; /* another display is still active */
-
-                nsIServiceManager serviceManager;
-                //int /*long*/[] result = new int /*long*/[1];
-                int rc = XPCOM.NS_GetServiceManager (&serviceManager);
-                if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
-                if (serviceManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
-
-                //nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-                //result[0] = 0;      
-                //byte[] buffer = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_OBSERVER_CONTRACTID, true);
-                nsIObserverService observerService;
-                rc = serviceManager.GetServiceByContractID (XPCOM.NS_OBSERVER_CONTRACTID.ptr, &nsIObserverService.IID, cast(void**)&observerService);
-                if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
-                if (observerService is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
-
-                //nsIObserverService observerService = new nsIObserverService (result[0]);
-                //result[0] = 0;
-                //buffer = MozillaDelegate.wcsToMbcs (null, PROFILE_BEFORE_CHANGE, true);
-                //int length = SHUTDOWN_PERSIST.length ();
-                //char[] chars = new char [length + 1];
-                //SHUTDOWN_PERSIST.getChars (0, length, chars, 0);
-                rc = observerService.NotifyObservers (null, PROFILE_BEFORE_CHANGE.ptr, SHUTDOWN_PERSIST.toString16().toString16z());
-                if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
-                observerService.Release ();
-
-                if (LocationProvider !is null) {
-                    String prefsLocation = LocationProvider.profilePath ~ AppFileLocProvider.PREFERENCES_FILE;
-                    scope auto pathString = new nsEmbedString (prefsLocation.toString16());
-                    nsILocalFile localFile;
-                    rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile);
-                    if (rc !is XPCOM.NS_OK) Mozilla.error (rc, __FILE__, __LINE__);
-                    if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
-                    //pathString.dispose ();
-
-                    //nsILocalFile localFile = new nsILocalFile (result [0]);
-                    //result[0] = 0;
-                    nsIFile prefFile;
-                    rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&prefFile); 
-                    if (rc !is XPCOM.NS_OK) Mozilla.error (rc, __FILE__, __LINE__);
-                    if (prefFile is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
-                    localFile.Release ();
-
-                    //nsIFile prefFile = new nsIFile (result[0]);
-                    //result[0] = 0;
-                    nsIPrefService prefService;
-                    //buffer = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_PREFSERVICE_CONTRACTID, true);
-                    rc = serviceManager.GetServiceByContractID (XPCOM.NS_PREFSERVICE_CONTRACTID.ptr, &nsIPrefService.IID, cast(void**)&prefService);
-                    if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
-                    if (prefService is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
-
-                    //nsIPrefService prefService = new nsIPrefService (result[0]);
-                    //result[0] = 0;
-                    rc = prefService.SavePrefFile(prefFile);
-                    prefService.Release ();
-                    prefFile.Release ();
-                }
-                serviceManager.Release ();
-
-                if (XPCOMWasGlued) {
-                    // TODO: is there a difference between two startup methhods? Glue functions are same.
-                   /*
-                    * 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) {
-                    XPCOMInit.XPCOMGlueShutdown ();
-                    XPCOMInitWasGlued = false;
-                }
-                Initialized = false;
-            }
-        });
+        display.addListener (DWT.Dispose, dgListener( &handleDisposeEvent, display )  );
     }
 
     BrowserCount++;
@@ -1352,11 +1268,88 @@
     }
 
     mozDelegate.init ();
+        
+    int[] folderEvents = [
+        DWT.Dispose,
+        DWT.Resize,  
+        DWT.FocusIn,
+        DWT.Activate,
+        DWT.Deactivate,
+        DWT.Show,
+        DWT.KeyDown     // needed to make browser traversable
+    ];
+    
+    for (int i = 0; i < folderEvents.length; i++) {
+        browser.addListener (folderEvents[i], dgListener( &handleFolderEvent ));
+    }
+}
 
-    listener = new class () Listener {
-        public void handleEvent (Event event) {
-            Control control = cast(Control)this.outer.browser;
-            Browser browser = this.outer.browser;
+extern(D)
+private void handleDisposeEvent (Event event, Display display) {
+    if (BrowserCount > 0) return; /* another display is still active */
+
+    nsIServiceManager serviceManager;
+
+    int rc = XPCOM.NS_GetServiceManager (&serviceManager);
+    if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
+    if (serviceManager is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
+
+    nsIObserverService observerService;
+    rc = serviceManager.GetServiceByContractID (XPCOM.NS_OBSERVER_CONTRACTID.ptr, &nsIObserverService.IID, cast(void**)&observerService);
+    if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
+    if (observerService is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
+
+    rc = observerService.NotifyObservers (null, PROFILE_BEFORE_CHANGE.ptr, SHUTDOWN_PERSIST.toString16().toString16z());
+    if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
+    observerService.Release ();
+
+    if (LocationProvider !is null) {
+        String prefsLocation = LocationProvider.profilePath ~ AppFileLocProvider.PREFERENCES_FILE;
+        scope auto pathString = new nsEmbedString (prefsLocation.toString16());
+        nsILocalFile localFile;
+        rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile);
+        if (rc !is XPCOM.NS_OK) Mozilla.error (rc, __FILE__, __LINE__);
+        if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
+
+        nsIFile prefFile;
+        rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&prefFile); 
+        if (rc !is XPCOM.NS_OK) Mozilla.error (rc, __FILE__, __LINE__);
+        if (prefFile is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE, __FILE__, __LINE__);
+        localFile.Release ();
+
+        nsIPrefService prefService;
+        rc = serviceManager.GetServiceByContractID (XPCOM.NS_PREFSERVICE_CONTRACTID.ptr, &nsIPrefService.IID, cast(void**)&prefService);
+        if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
+        if (prefService is null) error (XPCOM.NS_NOINTERFACE, __FILE__, __LINE__);
+
+        rc = prefService.SavePrefFile(prefFile);
+        prefService.Release ();
+        prefFile.Release ();
+    }
+    serviceManager.Release ();
+
+    if (XPCOMWasGlued) {
+        /*
+         * 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 = XPCOMInitWasGlued = false;
+    } 
+
+    Initialized = false;
+}
+  
+        
+extern(D)
+private void handleFolderEvent (Event event) {
+            Control control = cast(Control)browser;
             switch (event.type) {
                 case DWT.Dispose: {
                     /* make this handler run after other dispose listeners */
@@ -1394,23 +1387,10 @@
                     });
                     break;
                 }
+                default: break;
             }
         }
-    };
-    int[] folderEvents = [
-        DWT.Dispose,
-        DWT.Resize,  
-        DWT.FocusIn,
-        DWT.Activate,
-        DWT.Deactivate,
-        DWT.Show,
-        DWT.KeyDown     // needed to make browser traversable
-    ];
-    for (int i = 0; i < folderEvents.length; i++) {
-        browser.addListener (folderEvents[i], listener);
-    }
-}
-
+        
 extern(D)
 public bool back () {
     if (awaitingNavigate) return false;
@@ -2779,7 +2759,7 @@
     if (rc !is XPCOM.NS_OK) error (rc, __FILE__, __LINE__);
     domMouseEvent.Release ();
     
-    Event event;
+    auto event = new Event;
     event.x = aScreenX;
     event.y = aScreenY;
     browser.notifyListeners (DWT.MenuDetect, event);
@@ -3118,6 +3098,7 @@
             case DWT.CAPS_LOCK:
             case DWT.NUM_LOCK:
             case DWT.SCROLL_LOCK: return XPCOM.NS_OK;
+            default: break;
         }
 
         //int /*long*/[] result = new int /*long*/[1];
@@ -3150,6 +3131,7 @@
                 case DWT.BS: lastCharCode = DWT.BS; break;
                 case DWT.ESC: lastCharCode = DWT.ESC; break;
                 case DWT.DEL: lastCharCode = DWT.DEL; break;
+                default: break;
             }
         }
         if (aCtrlKey !is 0 && (0 <= lastCharCode && lastCharCode <= 0x7F)) {
@@ -3218,6 +3200,7 @@
             case DWT.COMMAND: {
                 keyEvent.stateMask |= lastKeyCode;
             }
+            default: break;
         }
         browser.notifyListeners (keyEvent.type, keyEvent);
         if (!keyEvent.doit) {
@@ -3317,6 +3300,7 @@
             case 3: mouseEvent.stateMask |= DWT.BUTTON3; break;
             case 4: mouseEvent.stateMask |= DWT.BUTTON4; break;
             case 5: mouseEvent.stateMask |= DWT.BUTTON5; break;
+            default: break;
         }
     }
 
--- a/dwt/browser/MozillaDelegate.d	Tue Nov 04 21:21:43 2008 -0800
+++ b/dwt/browser/MozillaDelegate.d	Sun Dec 14 02:13:20 2008 -0500
@@ -14,10 +14,10 @@
 
 import dwt.dwthelper.utils;
 
+import tango.io.Console;
+
 import dwt.DWT;
-//import dwt.internal.Callback;
 import dwt.internal.Converter;
-//import dwt.internal.gtk.GdkEvent;
 import dwt.internal.gtk.OS;
 import dwt.widgets.Display;
 import dwt.widgets.Event;
@@ -38,12 +38,11 @@
     //static Callback eventCallback;
     // static int /*long*/ eventProc;
     static const gpointer STOP_PROPOGATE = cast(gpointer)1;
-
     static bool IsLinux;
 
 static this () {
-    String osName = System.getProperty ("os.name"); //$NON-NLS-1$
-    IsLinux = tango.text.Util.containsPattern(osName, "linux"); //$NON-NLS-1$
+    String osName = System.getProperty ("os.name").toLowerCase(); //$NON-NLS-1$
+    IsLinux = osName.startsWith("linux"); //$NON-NLS-1$
 }
 
 this (Browser browser) {
--- a/dwt/dwthelper/System.d	Tue Nov 04 21:21:43 2008 -0800
+++ b/dwt/dwthelper/System.d	Sun Dec 14 02:13:20 2008 -0500
@@ -158,7 +158,9 @@
     public static String getProperty( String key ){
         /* get values for global system keys (environment) */
         switch( key ) {
-            case "os.name": return Environment.get("OSTYPE");
+            // Ubuntu Gutsy:Environment.get for OSTYPE is not working
+            // Force default to "linux" for now -JJR
+            case "os.name": return Environment.get("OSTYPE","linux");
             case "user.name": return Environment.get("USER");
             case "user.home": return Environment.get("HOME");
             case "user.dir" : return Environment.get("PWD");
--- a/dwt/internal/mozilla/nsIDocShell.d	Tue Nov 04 21:21:43 2008 -0800
+++ b/dwt/internal/mozilla/nsIDocShell.d	Sun Dec 14 02:13:20 2008 -0500
@@ -150,10 +150,10 @@
 
 ******************************************************************************/
 
-const char[] NS_IDOCSHELL_1_9_IID_STR = "7d1cf6b9-daa3-476d-8f9f-9eb2a971a95c";
+const char[] NS_IDOCSHELL_1_9_IID_STR = "10ed386d-8598-408c-b571-e75ad18edeb0";
 
 const nsIID NS_IDOCSHELL_1_9_IID = 
-  { 0x7d1cf6b9, 0xdaa3, 0x476d, [ 0x8f,0x9f,0x9e,0xb2,0xa9,0x71,0xa9,0x5c ]};
+    {0x10ed386d, 0x8598, 0x408c, [ 0xb5, 0x71, 0xe7, 0x5a, 0xd1, 0x8e, 0xde, 0xb0 ] };
 
 interface nsIDocShell_1_9 : nsIDocShell_1_8 {
 
@@ -164,4 +164,4 @@
   nsresult GetSessionStorageForURI(nsIURI uri, nsIDOMStorage *_retval);
   nsresult AddSessionStorage(nsACString * aDomain, nsIDOMStorage storage);
   nsresult GetCurrentDocumentChannel(nsIChannel  *aCurrentDocumentChannel);
-}
\ No newline at end of file
+}