diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsISupports.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsISupports.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsISupports.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsISupports.java index a7482f0239..07f6f0b0f5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsISupports.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsISupports.java @@ -50,6 +50,10 @@ public class nsISupports { protected static boolean IsXULRunner31 () { return MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR31, true); } + + protected static boolean IsXULRVersionOrLater (int version) { + return MozillaVersion.CheckVersion (version, false); + } public static final String NS_ISUPPORTS_IID_STR = "00000000-0000-0000-c000-000000000046"; @@ -57,6 +61,55 @@ public class nsISupports { IIDStore.RegisterIID (nsISupports.class, MozillaVersion.VERSION_BASE, new nsID (NS_ISUPPORTS_IID_STR)); } + private static byte[] toByteArray (String str) { + byte[] bytes = new byte[str.length() + 1]; + for (int i = str.length (); i-- > 0; ) + bytes[i] = (byte)str.charAt (i); + return bytes; + } + + protected int callFunction (String methodString, boolean setter, Object[] args) { + int index = getMethodIndex (methodString); + if (setter) index++; + return XPCOM.VtblCall(index, getAddress(), args); + } + + protected int getGetterIndex (String attribute) { + return getMethodIndex (attribute); + } + + protected int getSetterIndex (String attribute) { + return getMethodIndex (attribute) + 1; + } + + protected int getMethodIndex (String methodString) { + long /*int*/[] result = new long /*int*/[1]; + result[0] = 0; + int rc = XPCOM.NS_GetServiceManager (result); + if (rc != XPCOM.NS_OK) return -1; + + nsIServiceManager serviceManager = new nsIServiceManager (result[0]); + result[0] = 0; + rc = serviceManager.GetServiceByContractID (toByteArray (XPCOM.NS_INTERFACEINFOMANAGER_CONTRACTID), IIDStore.GetIID (nsIInterfaceInfoManager.class), result); + serviceManager.Release (); + if (rc != XPCOM.NS_OK) return -1; + + nsIInterfaceInfoManager iim = new nsIInterfaceInfoManager (result[0]); + result[0] = 0; + rc = iim.GetInfoForName (toByteArray (getClass ().getSimpleName ()), result); + iim.Release (); + if (rc != XPCOM.NS_OK) return -1; + + nsIInterfaceInfo info = new nsIInterfaceInfo (result[0]); + int[] index = new int [1]; + long /*int*/[] dummy = new long /*int*/[1]; + rc = info.GetMethodInfoForName (toByteArray (methodString), index, dummy); + info.Release (); + if (rc != XPCOM.NS_OK) return -1; + + return index[0]; + } + long /*int*/ address; public nsISupports(long /*int*/ address) { |