Mercurial > projects > dwt-linux
changeset 337:2e04c08f5e32
More Mozilla
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 21:31:37 -0700 |
parents | 7d6e1394b849 |
children | d47095c2d585 |
files | dwt/browser/Mozilla.d |
diffstat | 1 files changed, 134 insertions(+), 116 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/browser/Mozilla.d Mon Oct 20 21:13:53 2008 -0700 +++ b/dwt/browser/Mozilla.d Thu Oct 23 21:31:37 2008 -0700 @@ -1301,14 +1301,14 @@ error(XPCOM.NS_ERROR_NO_INTERFACE); } - // TODO: Find appropriate place to "Release" weakReference + // TODO: Find appropriate place to "Release" weakReference -JJR rc = webBrowser.AddWebBrowserListener (weakReference, &nsIWebProgressListener.IID); if (rc !is XPCOM.NS_OK) { browser.dispose (); error (rc); } - // TODO: Find appropriate place to "Release" uriContentListener + // TODO: Find appropriate place to "Release" uriContentListener -JJR nsIUriContentListener uriContentListener; this.QueryInterface(&nsIUriContentListener.IID, cast(void**)&uriContentListener); if (rc !is XPCOM.NS_OK) { @@ -1509,33 +1509,33 @@ public String getUrl () { if (awaitingNavigate) return ""; //$NON-NLS-1$ - int /*long*/[] result = new int /*long*/[1]; - int rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIWebNavigation webNavigation; + int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); - int /*long*/[] aCurrentURI = new int /*long*/[1]; - rc = webNavigation.GetCurrentURI (aCurrentURI); + //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); + nsIURI aCurrentURI; + rc = webNavigation.GetCurrentURI (&aCurrentURI); if (rc !is XPCOM.NS_OK) error (rc); webNavigation.Release (); - byte[] dest = null; - if (aCurrentURI[0] !is 0) { - nsIURI uri = new nsIURI (aCurrentURI[0]); - int /*long*/ aSpec = XPCOM.nsEmbedCString_new (); - rc = uri.GetSpec (aSpec); + String location = null; + if (aCurrentURI !is null) { + //nsIURI uri = new nsIURI (aCurrentURI[0]); + scope auto aSpec = new nsEmbedCString; + rc = aCurrentURI.GetSpec (cast(nsACString*)aSpec); if (rc !is XPCOM.NS_OK) error (rc); - int length = XPCOM.nsEmbedCString_Length (aSpec); - int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); - dest = new byte[length]; - XPCOM.memmove (dest, buffer, length); - XPCOM.nsEmbedCString_delete (aSpec); + //int length = XPCOM.nsEmbedCString_Length (aSpec); + //int /*long*/ buffer = XPCOM.nsEmbedCString_get (aSpec); + location = aSpec.toString; + //XPCOM.memmove (dest, buffer, length); + //XPCOM.nsEmbedCString_delete (aSpec); uri.Release (); } - if (dest is null) return ""; //$NON-NLS-1$ + if (location is null) return ""; //$NON-NLS-1$ - String location = new String (dest); /* * If the URI indicates that the page is being rendered from memory * (via setText()) then set it to about:blank to be consistent with IE. @@ -1547,64 +1547,70 @@ public Object getWebBrowser () { if ((browser.getStyle () & DWT.MOZILLA) is 0) return null; if (webBrowserObject !is null) return webBrowserObject; - + implMissing(__FILE__,__LINE__); +/+ try { + // TODO: this references the JavaXPCOM browser... not sure what needs to be done here, + // but I don't think this method is necessary. Class clazz = Class.forName ("org.mozilla.xpcom.Mozilla"); //$NON-NLS-1$ Method method = clazz.getMethod ("getInstance", new Class[0]); //$NON-NLS-1$ Object mozilla = method.invoke (null, new Object[0]); method = clazz.getMethod ("wrapXPCOMObject", new Class[] {Long.TYPE, String.class}); //$NON-NLS-1$ - webBrowserObject = method.invoke (mozilla, new Object[] {new Long (webBrowser.getAddress ()), nsIWebBrowser.NS_IWEBBROWSER_IID_STR}); + webBrowserObject = webBrowser.getAddress ()), nsIWebBrowser.NS_IWEBBROWSER_IID_STR}); /* * The following AddRef() is needed to offset the automatic Release() that * will be performed by JavaXPCOM when webBrowserObject is finalized. */ webBrowser.AddRef (); return webBrowserObject; - } catch (ClassNotFoundException e) { - } catch (NoSuchMethodException e) { - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } - return null; + } catch (ClassNotFoundException e) { + } catch (NoSuchMethodException e) { + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } ++/ + return null; } public bool isBackEnabled () { if (awaitingNavigate) return false; - int /*long*/[] result = new int /*long*/[1]; - int rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIWebNavigation webNavigation; + int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); - int[] aCanGoBack = new int[1]; /* PRBool */ - rc = webNavigation.GetCanGoBack (aCanGoBack); + //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); + PRBool aCanGoBack; /* PRBool */ + rc = webNavigation.GetCanGoBack (&aCanGoBack); webNavigation.Release (); - return aCanGoBack[0] !is 0; + return aCanGoBack !is 0; } public bool isForwardEnabled () { if (awaitingNavigate) return false; - int /*long*/[] result = new int /*long*/[1]; - int rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIWebNavigation webNavigation; + int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); - int[] aCanGoForward = new int[1]; /* PRBool */ - rc = webNavigation.GetCanGoForward (aCanGoForward); + //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); + PRBool aCanGoForward; /* PRBool */ + rc = webNavigation.GetCanGoForward (&aCanGoForward); webNavigation.Release (); - return aCanGoForward[0] !is 0; + return aCanGoForward !is 0; } static String error (int code) { - throw new DWTError ("XPCOM error " + code); //$NON-NLS-1$ + throw new DWTError ("XPCOM error " ~ code); //$NON-NLS-1$ } void onDispose (Display display) { - int rc = webBrowser.RemoveWebBrowserListener (weakReference.getAddress (), nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID); + int rc = webBrowser.RemoveWebBrowserListener (weakReference, &nsIWebProgressListener.IID); if (rc !is XPCOM.NS_OK) error (rc); rc = webBrowser.SetParentURIContentListener (0); @@ -1612,7 +1618,7 @@ unhookDOMListeners (); if (listener !is null) { - int[] folderEvents = new int[] { + int[] folderEvents = [ DWT.Dispose, DWT.Resize, DWT.FocusIn, @@ -1620,19 +1626,20 @@ DWT.Deactivate, DWT.Show, DWT.KeyDown, - }; + ]; for (int i = 0; i < folderEvents.length; i++) { browser.removeListener (folderEvents[i], listener); } listener = null; } - int /*long*/[] result = new int /*long*/[1]; - rc = webBrowser.QueryInterface (nsIBaseWindow.NS_IBASEWINDOW_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIBaseWindow baseWindow; + rc = webBrowser.QueryInterface (&nsIBaseWindow.IID, cast(void**)&baseWindow); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (baseWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); + //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); rc = baseWindow.Destroy (); if (rc !is XPCOM.NS_OK) error (rc); baseWindow.Release (); @@ -1646,10 +1653,10 @@ tip = null; location = size = null; - Enumeration elements = unhookedDOMWindows.elements (); - while (elements.hasMoreElements ()) { - LONG ptrObject = (LONG)elements.nextElement (); - new nsISupports (ptrObject.value).Release (); + //Enumeration elements = unhookedDOMWindows.elements (); + foreach (win ; unhookedDOMWindows) { + //LONG ptrObject = (LONG)elements.nextElement (); + win.Release (); } unhookedDOMWindows = null; @@ -1661,24 +1668,26 @@ } void Activate () { - int /*long*/[] result = new int /*long*/[1]; - int rc = webBrowser.QueryInterface (nsIWebBrowserFocus.NS_IWEBBROWSERFOCUS_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIWebBrowserFocus webBrowserFocus; + int rc = webBrowser.QueryInterface (&nsIWebBrowserFocus.IID, cast(void**)&webBrowserFocus); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (webBrowserFocus is null) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIWebBrowserFocus webBrowserFocus = new nsIWebBrowserFocus (result[0]); + //nsIWebBrowserFocus webBrowserFocus = new nsIWebBrowserFocus (result[0]); rc = webBrowserFocus.Activate (); if (rc !is XPCOM.NS_OK) error (rc); webBrowserFocus.Release (); } void Deactivate () { - int /*long*/[] result = new int /*long*/[1]; - int rc = webBrowser.QueryInterface (nsIWebBrowserFocus.NS_IWEBBROWSERFOCUS_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIWebBrowserFocus webBrowserFocus; + int rc = webBrowser.QueryInterface (&nsIWebBrowserFocus.IID, cast(void**)&webBrowserFocus); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (webBrowserFocus is null) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIWebBrowserFocus webBrowserFocus = new nsIWebBrowserFocus (result[0]); + //nsIWebBrowserFocus webBrowserFocus = new nsIWebBrowserFocus (result[0]); rc = webBrowserFocus.Deactivate (); if (rc !is XPCOM.NS_OK) error (rc); webBrowserFocus.Release (); @@ -1689,13 +1698,14 @@ int width = Math.max (1, rect.width); int height = Math.max (1, rect.height); - int /*long*/[] result = new int /*long*/[1]; - int rc = webBrowser.QueryInterface (nsIBaseWindow.NS_IBASEWINDOW_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIBaseWindow baseWindow; + int rc = webBrowser.QueryInterface (&nsIBaseWindow.IID, cast(void**)&baseWindow); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (baseWindow is null) error (XPCOM.NS_ERROR_NO_INTERFACE); mozDelegate.setSize (embedHandle, width, height); - nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); + //nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); rc = baseWindow.SetPositionAndSize (0, 0, width, height, 1); if (rc !is XPCOM.NS_OK) error (rc); baseWindow.Release (); @@ -1704,12 +1714,13 @@ public void refresh () { if (awaitingNavigate) return; - int /*long*/[] result = new int /*long*/[1]; - int rc = webBrowser.QueryInterface (nsIWebNavigation.NS_IWEBNAVIGATION_IID, result); + //int /*long*/[] result = new int /*long*/[1]; + nsIWebNavigation webNavigation; + int rc = webBrowser.QueryInterface (&nsIWebNavigation.IID, cast(void**)&webNavigation); if (rc !is XPCOM.NS_OK) error(rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); + if (webNavigation is null) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); + //nsIWebNavigation webNavigation = new nsIWebNavigation (result[0]); rc = webNavigation.Reload (nsIWebNavigation.LOAD_FLAGS_NONE); webNavigation.Release (); if (rc is XPCOM.NS_OK) return; @@ -1747,55 +1758,59 @@ if (browser !is browser.getDisplay ().getFocusControl ()) Deactivate (); /* convert the String containing HTML to an array of bytes with UTF-8 data */ + /+ byte[] data = null; try { data = html.getBytes ("UTF-8"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { return false; } - + +/ awaitingNavigate = false; - byte[] contentTypeBuffer = MozillaDelegate.wcsToMbcs (null, "text/html", true); // $NON-NLS-1$ - int /*long*/ aContentType = XPCOM.nsEmbedCString_new (contentTypeBuffer, contentTypeBuffer.length); - byte[] contentCharsetBuffer = MozillaDelegate.wcsToMbcs (null, "UTF-8", true); //$NON-NLS-1$ - int /*long*/ aContentCharset = XPCOM.nsEmbedCString_new (contentCharsetBuffer, contentCharsetBuffer.length); + //byte[] contentTypeBuffer = MozillaDelegate.wcsToMbcs (null, "text/html", true); // $NON-NLS-1$ + scope auto aContentType = new nsEmbedCString ("text/html"); + //byte[] contentCharsetBuffer = MozillaDelegate.wcsToMbcs (null, "UTF-8", true); //$NON-NLS-1$ + scope auto aContentCharset = new nsEmbedCString ("UTF-8"); - int /*long*/[] result = new int /*long*/[1]; - int rc = XPCOM.NS_GetServiceManager (result); + //int /*long*/[] result = new int /*long*/[1]; + nsIServiceManager serviceManager; + int rc = XPCOM.NS_GetServiceManager (&serviceManager); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_NOINTERFACE); + if (serviceManager is null) error (XPCOM.NS_NOINTERFACE); - nsIServiceManager serviceManager = new nsIServiceManager (result[0]); - result[0] = 0; - rc = serviceManager.GetService (XPCOM.NS_IOSERVICE_CID, nsIIOService.NS_IIOSERVICE_IID, result); + //nsIServiceManager serviceManager = new nsIServiceManager (result[0]); + //result[0] = 0; + nsIIOService ioService; + rc = serviceManager.GetService (XPCOM.NS_IOSERVICE_CID, &nsIIOService.IID, cast(void**)&ioService); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_NOINTERFACE); + if (ioService is null) error (XPCOM.NS_NOINTERFACE); serviceManager.Release (); - nsIIOService ioService = new nsIIOService (result[0]); - result[0] = 0; + //nsIIOService ioService = new nsIIOService (result[0]); + //result[0] = 0; /* * Note. Mozilla ignores LINK tags used to load CSS stylesheets * when the URI protocol for the nsInputStreamChannel * is about:blank. The fix is to specify the file protocol. */ - byte[] aString = MozillaDelegate.wcsToMbcs (null, URI_FROMMEMORY, false); - int /*long*/ aSpec = XPCOM.nsEmbedCString_new (aString, aString.length); - rc = ioService.NewURI (aSpec, null, 0, result); + //byte[] aString = MozillaDelegate.wcsToMbcs (null, URI_FROMMEMORY, false); + scope auto aSpec = new nsEmbedCString(URI_FROMMEMORY); + nsIURI uri; + rc = ioService.NewURI (cast(nsACString*)aSpec, null, null, &uri); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_NOINTERFACE); - XPCOM.nsEmbedCString_delete (aSpec); + if (uri is null) error (XPCOM.NS_NOINTERFACE); + //XPCOM.nsEmbedCString_delete (aSpec); ioService.Release (); - nsIURI uri = new nsIURI (result[0]); - result[0] = 0; - - rc = webBrowser.QueryInterface (nsIInterfaceRequestor.NS_IINTERFACEREQUESTOR_IID, result); + //nsIURI uri = new nsIURI (result[0]); + //result[0] = 0; + nsIInterfaceRequestor interfaceRequestor; + rc = webBrowser.QueryInterface (&nsIInterfaceRequestor.IID, cast(void**)&interfaceRequestor); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor (result[0]); - result[0] = 0; + if (interfaceRequestor is null) error (XPCOM.NS_ERROR_NO_INTERFACE); + //nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor (result[0]); + //result[0] = 0; /* * Feature in Mozilla. LoadStream invokes the nsIInputStream argument @@ -1806,38 +1821,41 @@ InputStream inputStream = new InputStream (data); inputStream.AddRef (); - rc = interfaceRequestor.GetInterface (nsIDocShell_1_9.NS_IDOCSHELL_IID, result); + nsIDocShell_1_9 docShell_1_9; + rc = interfaceRequestor.GetInterface (&nsIDocShell_1_9.IID, cast(void**)&docShell_1_9); if (rc is XPCOM.NS_OK) { - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIDocShell_1_9 docShell = new nsIDocShell_1_9 (result[0]); - rc = docShell.LoadStream (inputStream.getAddress (), uri.getAddress (), aContentType, aContentCharset, 0); - docShell.Release (); + if (docShell_1_9 is null) error (XPCOM.NS_ERROR_NO_INTERFACE); + //nsIDocShell_1_9 docShell = new nsIDocShell_1_9 (result[0]); + rc = docShell_1_9.LoadStream (inputStream, uri, cast(nsACString*)aContentType, cast(nsACString*)aContentCharset, null); + docShell_1_9.Release (); } else { - result[0] = 0; - rc = interfaceRequestor.GetInterface (nsIDocShell_1_8.NS_IDOCSHELL_IID, result); + //result[0] = 0; + nsDocShell_1_8 docShell_1_8; + rc = interfaceRequestor.GetInterface (&nsIDocShell_1_8.IID, cast(void**)&docShell_1_8); if (rc is XPCOM.NS_OK) { - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIDocShell_1_8 docShell = new nsIDocShell_1_8 (result[0]); - rc = docShell.LoadStream (inputStream.getAddress (), uri.getAddress (), aContentType, aContentCharset, 0); - docShell.Release (); + if (docShell_1_8 is null) error (XPCOM.NS_ERROR_NO_INTERFACE); + //nsIDocShell_1_8 docShell = new nsIDocShell_1_8 (result[0]); + rc = docShell_1_8.LoadStream (inputStream, uri, cast(nsACString*)aContentType, cast(nsACString*)aContentCharset, null); + docShell_1_8.Release (); } else { - result[0] = 0; - rc = interfaceRequestor.GetInterface (nsIDocShell.NS_IDOCSHELL_IID, result); + //result[0] = 0; + nsIDocShell docShell; + rc = interfaceRequestor.GetInterface (&nsIDocShell.IID, cast(void**)&docShell); if (rc !is XPCOM.NS_OK) error (rc); - if (result[0] is 0) error (XPCOM.NS_ERROR_NO_INTERFACE); - nsIDocShell docShell = new nsIDocShell (result[0]); - rc = docShell.LoadStream (inputStream.getAddress (), uri.getAddress (), aContentType, aContentCharset, 0); + if (docShell is null) error (XPCOM.NS_ERROR_NO_INTERFACE); + //nsIDocShell docShell = new nsIDocShell (result[0]); + rc = docShell.LoadStream (inputStream, uri, cast(nsACString*) aContentType, cast(nsACString*)aContentCharset, null); docShell.Release (); } } if (rc !is XPCOM.NS_OK) error (rc); - result[0] = 0; + //result[0] = 0; inputStream.Release (); interfaceRequestor.Release (); uri.Release (); - XPCOM.nsEmbedCString_delete (aContentCharset); - XPCOM.nsEmbedCString_delete (aContentType); + //XPCOM.nsEmbedCString_delete (aContentCharset); + //XPCOM.nsEmbedCString_delete (aContentType); return true; }