diff dwt/browser/Mozilla.d @ 286:44258e0b6687

More fixes for xpcom
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 10:11:58 -0700
parents 93409d9838c5
children eec6ddb07873
line wrap: on
line diff
--- a/dwt/browser/Mozilla.d	Thu Jul 31 21:56:03 2008 -0700
+++ b/dwt/browser/Mozilla.d	Tue Aug 05 10:11:58 2008 -0700
@@ -7,13 +7,19 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
- * Port to the D programming language:
- *     John Reimer <terminal.node@gmail.com>
  *******************************************************************************/
 module dwt.browser.Mozilla;
 
 import dwt.dwthelper.utils;
 
+//import java.io.UnsupportedEncodingException;
+//import java.lang.reflect.Constructor;
+//import java.lang.reflect.InvocationTargetException;
+//import java.lang.reflect.Method;
+//import java.util.Enumeration;
+//import java.util.Locale;
+//import java.util.Vector;
+
 import dwt.DWT;
 import dwt.DWTError;
 import dwt.graphics.Device;
@@ -24,9 +30,10 @@
 import dwt.internal.LONG;
 import dwt.internal.Library;
 
+import dwt.internal.mozilla.XPCOM;
+import dwt.internal.mozilla.XPCOMInit;
+
 import dwt.internal.mozilla.nsEmbedString;
-import dwt.internal.mozilla.nsError;
-
 import dwt.internal.mozilla.nsIAppShell;
 import dwt.internal.mozilla.nsIBaseWindow;
 import dwt.internal.mozilla.nsICategoryManager;
@@ -59,6 +66,7 @@
 import dwt.internal.mozilla.nsIPrefLocalizedString;
 import dwt.internal.mozilla.nsIPrefService;
 import dwt.internal.mozilla.nsIProperties;
+import dwt.internal.mozilla.nsIRequest;
 import dwt.internal.mozilla.nsIServiceManager;
 import dwt.internal.mozilla.nsISimpleEnumerator;
 import dwt.internal.mozilla.nsISupports;
@@ -76,7 +84,6 @@
 import dwt.internal.mozilla.nsIWebProgress;
 import dwt.internal.mozilla.nsIWebProgressListener;
 import dwt.internal.mozilla.nsIWindowWatcher;
-
 import dwt.layout.FillLayout;
 import dwt.widgets.Composite;
 import dwt.widgets.Display;
@@ -86,28 +93,45 @@
 import dwt.widgets.Menu;
 import dwt.widgets.Shell;
 
-class Mozilla : nsIWebBrowser, nsIWeakReference, 
-                nsIWebProgressListener, nsIWebBrowserChrome,
-                nsIWebBrowserChromeFocus, nsIEmbeddingSiteWindow,
-                nsIInterfaceRequestor, nsISupportsWeakReference,
-                nsIContextMenuListener, nsIUriContentListener,
-                nsIToolTipListener, nsIDOMEventListener
-{
-    int /*long*/    embedHandle;
-    nsIWebBrowser   webBrowser;
-    Object          webBrowserObject;
+class Mozilla : WebBrowser, 
+                nsIWeakReference, 
+                nsIWebProgressListener, 
+                nsIWebBrowserChrome,
+                nsIWebBrowserFocus, 
+                nsIEmbeddingSiteWindow, 
+                nsIInterfaceRequestor, 
+                nsISupportsWeakReference, 
+                nsIContextMenuListener, 
+                nsIUriContextListener,
+                nsITooltipListener, 
+                nsIDomEventListener {
+                    
+    GtkWidget* embedHandle;
+    nsIWebBrowser webBrowser;
+    Object webBrowserObject;
     MozillaDelegate mozDelegate;
 
+    /* Interfaces for this Mozilla embedding notification */
+//    XPCOMObject supports;
+//    XPCOMObject weakReference;
+//    XPCOMObject webProgressListener;
+//    XPCOMObject webBrowserChrome;
+//    XPCOMObject webBrowserChromeFocus;
+//    XPCOMObject embeddingSiteWindow;
+//    XPCOMObject interfaceRequestor;
+//    XPCOMObject supportsWeakReference;
+//    XPCOMObject contextMenuListener;    
+//    XPCOMObject uriContentListener;
+//    XPCOMObject tooltipListener;
+//    XPCOMObject domEventListener;
     int chromeFlags = nsIWebBrowserChrome.CHROME_DEFAULT;
     int refCount, lastKeyCode, lastCharCode;
-    int /*long*/ request;
+    nsIRequest request;
     Point location, size;
     bool visible, isChild, ignoreDispose, awaitingNavigate;
     Shell tip = null;
     Listener listener;
-
-    // replace with appropriate D/Tango data structure
-    Vector unhookedDOMWindows = new Vector ();
+    nsIDOMWindow[] unhookedDOMWindows;
 
     static nsIAppShell AppShell;
     static AppFileLocProvider LocationProvider;
@@ -154,7 +178,7 @@
     // TEMPORARY CODE
     static final String GRE_INITIALIZED = "dwt.browser.XULRunnerInitialized"; //$NON-NLS-1$
 
-    static {
+    static this () {
         MozillaClearSessions = new Runnable () {
             public void run () {
                 if (!Initialized) return;
@@ -2045,68 +2069,65 @@
 
 /* nsISupports */
 
-int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) {
-    if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE;
+int QueryInterface (nsID* riid, void** ppvObject) {
+    if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE;
 
-    nsID guid = new nsID ();
-    XPCOM.memmove (guid, riid, nsID.sizeof);
-
-    if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsISupports.IID) {
+        *ppvObject = cast(void*)cast(nsISupports)this;
+        AddRef ();
+        return XPCOM.NS_OK;
+    }
+    if (*riid == nsIWeakReference.IID) {
+        *ppvObject = cast(void*)cast(nsIWeakReference)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsIWeakReference.NS_IWEAKREFERENCE_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {weakReference.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIWebProgressListener.IID) {
+        *ppvObject = cast(void*)cast(nsIWebProgressListener)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {webProgressListener.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIWebBrowserChrome.IID) {
+        *ppvObject = cast(void*)cast(nsIWebBrowserChrome)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsIWebBrowserChrome.NS_IWEBBROWSERCHROME_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {webBrowserChrome.getAddress ()}, C.PTR_SIZEOF);
-        AddRef ();
-        return XPCOM.NS_OK;
-    }
-    if (guid.Equals (nsIWebBrowserChromeFocus.NS_IWEBBROWSERCHROMEFOCUS_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {webBrowserChromeFocus.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIWebBrowserChromeFocus.IID) {
+        *ppvObject = cast(void*)cast(nsIWebBrowserChromeFocus)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsIEmbeddingSiteWindow.NS_IEMBEDDINGSITEWINDOW_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {embeddingSiteWindow.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIEmbeddingSiteWindow.IID) {
+        *ppvObject = cast(void*)cast(nsIEmbeddingSiteWindow)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsIInterfaceRequestor.NS_IINTERFACEREQUESTOR_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {interfaceRequestor.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIInterfaceRequestor.IID) {
+        *ppvObject = cast(void*)cast(nsIInterfaceRequestor)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsISupportsWeakReference.NS_ISUPPORTSWEAKREFERENCE_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {supportsWeakReference.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsISupportsWeakReference.IID) {
+        *ppvObject = cast(void*)cast(nsISupportsWeakReference)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsIContextMenuListener.NS_ICONTEXTMENULISTENER_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {contextMenuListener.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIContextMenuListener.IID) {
+        *ppvObject = cast(void*)cast(nsIContextMenuListener)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsIURIContentListener.NS_IURICONTENTLISTENER_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {uriContentListener.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsIURIContentListener.IID) {
+        *ppvObject = cast(void*)cast(nsIUriContentListener)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    if (guid.Equals (nsITooltipListener.NS_ITOOLTIPLISTENER_IID)) {
-        XPCOM.memmove (ppvObject, new int /*long*/[] {tooltipListener.getAddress ()}, C.PTR_SIZEOF);
+    if (*riid == nsITooltipListener.IID)) {
+        *ppvObject = cast(void*)cast(nsITooltipListener)this;
         AddRef ();
         return XPCOM.NS_OK;
     }
-    XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF);
+    *ppvObject = null;
     return XPCOM.NS_ERROR_NO_INTERFACE;
 }
 
@@ -2117,19 +2138,19 @@
 
 int Release () {
     refCount--;
-    if (refCount is 0) disposeCOMInterfaces ();
+    if (refCount is 0) return 0;
     return refCount;
 }
 
 /* nsIWeakReference */  
     
-int QueryReferent (int /*long*/ riid, int /*long*/ ppvObject) {
+int QueryReferent (nsID* riid, void** ppvObject) {
     return QueryInterface (riid, ppvObject);
 }
 
 /* nsIInterfaceRequestor */
 
-int GetInterface (int /*long*/ riid, int /*long*/ ppvObject) {
+int GetInterface ( nsID* riid, void** ppvObject) {
     if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE;
     nsID guid = new nsID ();
     XPCOM.memmove (guid, riid, nsID.sizeof);