Bug 429739 - Permission denied to access property ''

Rather than directly accessing the JavaScript engine this seeks to use
XPConnect to communicate with JavaScript. The idea was actually based on
an earlier version of SWT but the relevant component was never used.

* Revert to using the previous mozilla / profile paths for XUL < 24
* Remove with() from evalAsChrome as alters security context

Change-Id: I63a2b085a96193904c0d67d960e158233464ca56
Signed-off-by: mjgp2 <matthew.painter@import.io>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp
index fb544ad..520826c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -37,14 +37,9 @@
 #else
 	"_1Call__JJJ_3BII_3I",
 #endif
-	"_1JS_1DefineFunction",
-	"_1JS_1DefineFunction24",
 	"_1JS_1EvaluateUCScriptForPrincipals",
 	"_1JS_1EvaluateUCScriptForPrincipals191",
-	"_1JS_1EvaluateUCScriptForPrincipals24",
-	"_1JS_1GetGlobalForScopeChain24",
 	"_1JS_1GetGlobalObject",
-	"_1JS_1NewObject",
 	"_1NS_1Free",
 	"_1NS_1GetComponentManager",
 	"_1NS_1GetServiceManager",
@@ -1128,11 +1123,7 @@
 	"_1nsID_1new",
 	"_1nsIMemory_1Alloc",
 	"_1nsIMemory_1Realloc",
-	"_1nsIScriptContext24_1GetNativeContext",
 	"_1nsIScriptContext_1GetNativeContext",
-	"_1nsIScriptGlobalObject24_1EnsureScriptEnvironment",
-	"_1nsIScriptGlobalObject24_1GetGlobalJSObject",
-	"_1nsIScriptGlobalObject24_1GetScriptContext",
 	"_1nsIScriptGlobalObject_1EnsureScriptEnvironment",
 	"_1nsIScriptGlobalObject_1GetScriptContext",
 #ifndef JNI64
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h
index 8de90ab..07690ab 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -47,14 +47,9 @@
 #else
 	_1Call__JJJ_3BII_3I_FUNC,
 #endif
-	_1JS_1DefineFunction_FUNC,
-	_1JS_1DefineFunction24_FUNC,
 	_1JS_1EvaluateUCScriptForPrincipals_FUNC,
 	_1JS_1EvaluateUCScriptForPrincipals191_FUNC,
-	_1JS_1EvaluateUCScriptForPrincipals24_FUNC,
-	_1JS_1GetGlobalForScopeChain24_FUNC,
 	_1JS_1GetGlobalObject_FUNC,
-	_1JS_1NewObject_FUNC,
 	_1NS_1Free_FUNC,
 	_1NS_1GetComponentManager_FUNC,
 	_1NS_1GetServiceManager_FUNC,
@@ -1138,11 +1133,7 @@
 	_1nsID_1new_FUNC,
 	_1nsIMemory_1Alloc_FUNC,
 	_1nsIMemory_1Realloc_FUNC,
-	_1nsIScriptContext24_1GetNativeContext_FUNC,
 	_1nsIScriptContext_1GetNativeContext_FUNC,
-	_1nsIScriptGlobalObject24_1EnsureScriptEnvironment_FUNC,
-	_1nsIScriptGlobalObject24_1GetGlobalJSObject_FUNC,
-	_1nsIScriptGlobalObject24_1GetScriptContext_FUNC,
 	_1nsIScriptGlobalObject_1EnsureScriptEnvironment_FUNC,
 	_1nsIScriptGlobalObject_1GetScriptContext_FUNC,
 #ifndef JNI64
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/AppFileLocProvider.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/AppFileLocProvider.java
index c40c531..1d00619 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/AppFileLocProvider.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/AppFileLocProvider.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -294,15 +294,27 @@
 	} else if (propertyName.equals (XPCOM.NS_GRE_DIR)) {
 		propertyValue = mozillaPath;
 	} else if (propertyName.equals (XPCOM.NS_GRE_COMPONENT_DIR)) {
-		propertyValue = profilePath + COMPONENTS_DIR;
+		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24, false)) {
+			propertyValue = mozillaPath + COMPONENTS_DIR;
+		} else {
+			propertyValue = profilePath + COMPONENTS_DIR;
+		}
 	} else if (propertyName.equals (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) {
 		propertyValue = mozillaPath;
 	} else if (propertyName.equals (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) {
 		propertyValue = mozillaPath;
 	} else if (propertyName.equals (XPCOM.NS_XPCOM_COMPONENT_DIR)) {
-		propertyValue = mozillaPath + COMPONENTS_DIR;
+		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24, false)) {
+			propertyValue = profilePath + COMPONENTS_DIR;
+		} else {
+			propertyValue = mozillaPath + COMPONENTS_DIR;
+		}
 	} else if (propertyName.equals (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) {
-		propertyValue = mozillaPath;
+		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24, false)) {
+			propertyValue = profilePath;
+		} else {
+			propertyValue = mozillaPath;
+		}
 	} else if (propertyName.equals (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) {
 		/*
 		* Answering a value for this property causes problems in Mozilla versions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java
index 8bb636b..ce015df 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2015 IBM Corporation and others.
+ * Copyright (c) 2008, 2013 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Neil Rashbrook <neil@parkwaycc.co.uk> - Bug 429739
+ *     Matthew Painter <matthew.painter@import.io>
  *     Red Hat Inc. - generification
  *******************************************************************************/
 package org.eclipse.swt.browser;
@@ -26,27 +28,7 @@
 	XPCOMObject supports;
 	XPCOMObject external;
 	XPCOMObject classInfo;
-	XPCOMObject securityCheckedComponent;
-	XPCOMObject scriptObjectOwner;
-	XPCOMObject xpcScriptable;
 	int refCount = 0;
-	
-	static final String CALLJAVA = "callJava"; //$NON-NLS-1$
-
-	static Callback CallJavaProc, GetScriptableFlags24Proc = null;
-	static {
-		CallJavaProc = new Callback (External.class, CALLJAVA, 3);
-		if (CallJavaProc.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
-		/*
-		 * On win32 a substitute callback is provided for nsIXPCScriptable.getScriptableFlags()
-		 * because it does not use the standard XPCOM calling convention.
-		 */
-		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24) && SWT.getPlatform ().equals ("win32")) { //$NON-NLS-1$
-			GetScriptableFlags24Proc = new Callback (External.class, "getScriptableFlags", 0); //$NON-NLS-1$
-			if (GetScriptableFlags24Proc.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-		}
-	}
 
 External () {
 	createCOMInterfaces ();
@@ -54,121 +36,17 @@
 
 /* external */
 
-/*
- * This is the BrowserFunction entry point for XULRunner releases >= 4 because
- * QueryInterface answers an nsIScriptObjectOwner implementation (which points
- * at this function) iff the detected XULRunner version is >= 4.
- */
-static long /*int*/ callJava (long /*int*/ cx, long /*int*/ argc, long /*int*/ vp) {
-	int jsval_sizeof = 8;
-	long /*int*/ argsPtr = vp + 2 * jsval_sizeof;
-	nsIVariant resultVariant = null;
-
-	long /*int*/[] result = new long /*int*/[1];
-	int rc = XPCOM.NS_GetServiceManager (result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-
-	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-	result[0] = 0;
-	rc = serviceManager.GetService (XPCOM.NS_IXPCONNECT_CID, IIDStore.GetIID (nsIXPConnect.class), result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-
-	nsIXPConnect connect = new nsIXPConnect (result[0]);
-	result[0] = 0;
-
-	/* extract the first argument value (the function id) */
-	rc = connect.JSValToVariant (cx, argsPtr, result);
-	if (rc == XPCOM.NS_OK && result[0] != 0) {
-		nsIVariant idVariant = new nsIVariant (result[0]);
-		result[0] = 0;
-		short[] dataType = new short[1];
-		rc = idVariant.GetDataType (dataType);
-		if (rc == XPCOM.NS_OK && dataType[0] == nsIDataType.VTYPE_INT32) {
-			int[] intResult = new int[1];
-			rc = idVariant.GetAsInt32 (intResult); /* PRInt32 */
-			if (rc == XPCOM.NS_OK) {
-				int functionId = intResult[0];
-
-				/* get the second argument variant (the token string) */
-				argsPtr += jsval_sizeof;
-				rc = connect.JSValToVariant (cx, argsPtr, result);
-				if (rc == XPCOM.NS_OK && result[0] != 0) {
-					long /*int*/ tokenVariant = result[0];
-					result[0] = 0;
-
-					/* get the third argument variant (the invocation args) */
-					argsPtr += jsval_sizeof;
-					rc = connect.JSValToVariant (cx, argsPtr, result);
-					if (rc == XPCOM.NS_OK && result[0] != 0) {
-						long /*int*/ argsVariant = result[0];
-						result[0] = 0;
-
-						/* invoke the BrowserFunction */
-						resultVariant = new nsIVariant (invokeFunction (functionId, tokenVariant, argsVariant));
-						new nsISupports (argsVariant).Release ();
-					}
-					new nsISupports (tokenVariant).Release ();
-				}
-			}
-		}
-		idVariant.Release ();
-	}
-	result[0] = 0;
-
-	/* if the BrowserFunction could not be invoked for some reason then return null to JS */
-	if (resultVariant == null) {
-		rc = XPCOM.NS_GetComponentManager (result);
-		if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-		if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-		nsIComponentManager componentManager = new nsIComponentManager (result[0]);
-		result[0] = 0;
-		resultVariant = convertToJS (null, componentManager);
-		componentManager.Release ();
-	}
-
-	/* convert the resulting variant to a jsval */
-	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
-	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-	serviceManager.Release();
-
-	nsIMemory memory = new nsIMemory (result[0]);
-	result[0] = 0;
-	long /*int*/ jsVal = memory.Alloc (jsval_sizeof);
-	C.memset (jsVal, 0, jsval_sizeof);
-	long /*int*/ globalObject = 0;
-	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) {
-		globalObject = XPCOM.JS_GetGlobalForScopeChain24 (cx);
-	} else {
-		globalObject = XPCOM.JS_GetGlobalObject (Mozilla.getJSLibPathBytes (), cx);
-	}
-	rc = connect.VariantToJS (cx, globalObject, resultVariant.getAddress (), jsVal);
-	resultVariant.Release ();
-	connect.Release ();
-
-	long /*int*/ returnValue = XPCOM.JS_FALSE;
-	if (rc == XPCOM.NS_OK) {
-		/* write the jsval to the return value slot */
-		C.memmove (vp, jsVal, jsval_sizeof);
-		returnValue = XPCOM.JS_TRUE;
-	}
-	memory.Free (jsVal);
-	memory.Release ();
-	return returnValue;
-}
-
-/* this is the BrowserFunction entry point when the detected XULRunner version is < 4 */
 static int callJava (int functionId, long /*int*/ tokenVariant, long /*int*/ argsVariant, long /*int*/ returnPtr) {
 	long /*int*/ resultVariant = invokeFunction (functionId, tokenVariant, argsVariant);
 	C.memmove (returnPtr, new long /*int*/[] {resultVariant}, C.PTR_SIZEOF);
 	return XPCOM.NS_OK;
 }
 
-static Object convertToJava (nsIVariant variant, short type) {
-	switch (type) {
+static Object convertToJava (nsIVariant variant) {
+	short[] dataType = new short[1];
+	int rc = variant.GetDataType (dataType);
+	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
+	switch (dataType[0]) {
 		case nsIDataType.VTYPE_EMPTY:
 		case nsIDataType.VTYPE_VOID:
 			return null;
@@ -176,7 +54,7 @@
 			return new Object[0];
 		case nsIDataType.VTYPE_BOOL:
 			int[] boolResult = new int[1]; /*PRInt32*/
-			int rc = variant.GetAsBool (boolResult);
+			rc = variant.GetAsBool (boolResult);
 			if (rc != XPCOM.NS_OK) Mozilla.error (rc);
 			return new Boolean (boolResult[0] != 0);
 		case nsIDataType.VTYPE_INT32:
@@ -242,11 +120,9 @@
 
 					nsIVariant currentVariant = new nsIVariant (result[0]);
 					result[0] = 0;
-					currentType[0] = 0;
-					rc = currentVariant.GetDataType (currentType);
 					if (rc != XPCOM.NS_OK) Mozilla.error (rc);
 					try {
-						arrayReturn[i] = convertToJava (currentVariant, currentType[0]);
+						arrayReturn[i] = convertToJava (currentVariant);
 						currentVariant.Release ();
 					} catch (IllegalArgumentException e) {
 						/* invalid argument value type */
@@ -396,19 +272,13 @@
 
 	if (function != null) {
 		try {
-			short[] type = new short[1]; /* PRUint16 */
 			nsIVariant variant = new nsIVariant (tokenVariant);
-			int rc = variant.GetDataType (type);
-			if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-			Object temp = convertToJava (variant, type[0]);
-			type[0] = 0;
+			Object temp = convertToJava (variant);
 			if (temp instanceof String) {
 				String token = (String)temp;
 				if (token.equals (function.token)) {
 					variant = new nsIVariant (args);
-					rc = variant.GetDataType (type);
-					if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-					temp = convertToJava (variant, type[0]);
+					temp = convertToJava (variant);
 					if (temp instanceof Object[]) {
 						Object[] arguments = (Object[])temp;
 						try {
@@ -489,23 +359,6 @@
 		public long /*int*/ method10 (long /*int*/[] args) {return getClassIDNoAlloc (args[0]);}
 	};
 
-	securityCheckedComponent = new XPCOMObject (new int[] {2, 0, 0, 2, 3, 3, 3}) {
-		@Override
-		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
-		@Override
-		public long /*int*/ method1 (long /*int*/[] args) {return AddRef ();}
-		@Override
-		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
-		@Override
-		public long /*int*/ method3 (long /*int*/[] args) {return canCreateWrapper (args[0], args[1]);}
-		@Override
-		public long /*int*/ method4 (long /*int*/[] args) {return canCallMethod (args[0], args[1], args[2]);}
-		@Override
-		public long /*int*/ method5 (long /*int*/[] args) {return canGetProperty (args[0], args[1], args[2]);}
-		@Override
-		public long /*int*/ method6 (long /*int*/[] args) {return canSetProperty (args[0], args[1], args[2]);}
-	};
-
 	external = new XPCOMObject (new int[] {2, 0, 0, 4}) {
 		@Override
 		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
@@ -516,44 +369,6 @@
 		@Override
 		public long /*int*/ method3 (long /*int*/[] args) {return callJava ((int)/*64*/args[0], args[1], args[2], args[3]);}
 	};
-
-	scriptObjectOwner = new XPCOMObject (new int[] {2, 0, 0, 2, 1}) {
-		@Override
-		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
-		@Override
-		public long /*int*/ method1 (long /*int*/[] args) {return AddRef ();}
-		@Override
-		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
-		@Override
-		public long /*int*/ method3 (long /*int*/[] args) {return getScriptObject (args[0], args[1]);}
-		@Override
-		public long /*int*/ method4 (long /*int*/[] args) {return setScriptObject (args[0]);}
-	};
-
-	xpcScriptable = new XPCOMObject (new int[] {2, 0, 0, 1, 0, 4, 3, 3, 3, 6, 5, 6, 6, 4, 7, 7, 6, 3, 7, 5, 5, 6, 4, 2}) {
-		@Override
-		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
-		@Override
-		public long /*int*/ method1 (long /*int*/[] args) {return AddRef ();}
-		@Override
-		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
-		@Override
-		public long /*int*/ method3 (long /*int*/[] args) {return getClassName (args[0]);}
-		@Override
-		public long /*int*/ method4 (long /*int*/[] args) {return getScriptableFlags ();}
-		@Override
-		public long /*int*/ method7 (long /*int*/[] args) {return postCreate (args[0], args[1], args[2]);}
-	};
-
-	if (GetScriptableFlags24Proc != null) {
-		long /*int*/ ppVtable = xpcScriptable.getVtable ();
-		long /*int*/[] pVtable = new long /*int*/[1];
-		C.memmove (pVtable, ppVtable, C.PTR_SIZEOF);
-		long /*int*/[] funcs = new long /*int*/[24];
-		C.memmove (funcs, pVtable[0], C.PTR_SIZEOF * funcs.length);
-		funcs[4] = XPCOM.CALLBACK_GetScriptableFlags24 (GetScriptableFlags24Proc.getAddress ());
-		C.memmove (pVtable[0], funcs, C.PTR_SIZEOF * funcs.length);
-	}
 }
 
 void disposeCOMInterfaces () {
@@ -565,22 +380,10 @@
 		classInfo.dispose ();
 		classInfo = null;
 	}
-	if (securityCheckedComponent != null) {
-		securityCheckedComponent.dispose ();
-		securityCheckedComponent = null;
-	}
 	if (external != null) {
 		external.dispose ();
 		external = null;
 	}
-	if (scriptObjectOwner != null) {
-		scriptObjectOwner.dispose ();
-		scriptObjectOwner = null;
-	}
-	if (xpcScriptable != null) {
-		xpcScriptable.dispose ();
-		xpcScriptable = null;
-	}
 }
 
 long /*int*/ getAddress () {
@@ -602,32 +405,12 @@
 		AddRef();
 		return XPCOM.NS_OK;
 	}
-	if (guid.Equals (XPCOM.NS_ISECURITYCHECKEDCOMPONENT_IID)) {
-		XPCOM.memmove (ppvObject, new long /*int*/[] {securityCheckedComponent.getAddress ()}, C.PTR_SIZEOF);
-		AddRef();
-		return XPCOM.NS_OK;
-	}
 	if (guid.Equals (EXTERNAL_IID)) {
 		XPCOM.memmove (ppvObject, new long /*int*/[] {external.getAddress ()}, C.PTR_SIZEOF);
 		AddRef();
 		return XPCOM.NS_OK;
 	}
 
-	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR10)) {
-		if (guid.Equals (XPCOM.NS_ISCRIPTOBJECTOWNER_IID)) {
-			XPCOM.memmove (ppvObject, new long /*int*/[] {scriptObjectOwner.getAddress ()}, C.PTR_SIZEOF);
-			AddRef();
-			return XPCOM.NS_OK;
-		}
-		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) {
-			if (guid.Equals (XPCOM.NS_IXPCSCRIPTABLE_IID)) {
-				XPCOM.memmove (ppvObject, new long /*int*/[] {xpcScriptable.getAddress ()}, C.PTR_SIZEOF);
-				AddRef();
-				return XPCOM.NS_OK;
-			}
-		}
-	}
-
 	XPCOM.memmove (ppvObject, new long /*int*/[] {0}, C.PTR_SIZEOF);
 	return XPCOM.NS_ERROR_NO_INTERFACE;
 }
@@ -678,7 +461,7 @@
 }
 
 int getFlags (long /*int*/ flags) {
-	C.memmove (flags, new int[] {nsIClassInfo.MAIN_THREAD_ONLY}, 4); /* PRUint32 */
+	C.memmove (flags, new int[] {nsIClassInfo.DOM_OBJECT}, 4); /* PRUint32 */
 	return XPCOM.NS_OK;
 }
 
@@ -708,187 +491,16 @@
 
 	nsIMemory memory = new nsIMemory (result[0]);
 	result[0] = 0;
-	long /*int*/ securityCheckedComponentIID = memory.Alloc (nsID.sizeof);
-	XPCOM.memmove (securityCheckedComponentIID, XPCOM.NS_ISECURITYCHECKEDCOMPONENT_IID, nsID.sizeof);
 	long /*int*/ externalIID = memory.Alloc (nsID.sizeof);
 	XPCOM.memmove (externalIID, EXTERNAL_IID, nsID.sizeof);
-	long /*int*/ ptrArray = memory.Alloc (3 * C.PTR_SIZEOF);
-	C.memmove (ptrArray, new long /*int*/[] {securityCheckedComponentIID}, C.PTR_SIZEOF);
-	C.memmove (ptrArray + C.PTR_SIZEOF, new long /*int*/[] {externalIID}, C.PTR_SIZEOF);
+	long /*int*/ ptrArray = memory.Alloc (C.PTR_SIZEOF);
+	C.memmove (ptrArray, new long /*int*/[] {externalIID}, C.PTR_SIZEOF);
 
 	C.memmove (array, new long /*int*/[] {ptrArray}, C.PTR_SIZEOF);
 	memory.Release ();
 
-	C.memmove (count, new int[] {2}, 4); /* PRUint */
+	C.memmove (count, new int[] {1}, 4); /* PRUint */
 	return XPCOM.NS_OK;
 }
 
-/* nsIScriptObjectOwner */
-
-int getScriptObject (long /*int*/ aContext, long /*int*/ aScriptObject) {
-	byte[] jsLibPath = Mozilla.getJSLibPathBytes ();
-	long /*int*/ nativeContext = XPCOM.nsIScriptContext_GetNativeContext (aContext);
-	long /*int*/ globalJSObject = XPCOM.JS_GetGlobalObject (jsLibPath, nativeContext);
-	long /*int*/ newObject = XPCOM.JS_NewObject (jsLibPath, nativeContext, 0, 0, globalJSObject);
-
-	byte[] functionName = MozillaDelegate.wcsToMbcs (null, CALLJAVA, true);
-	int flags = XPCOM.JSPROP_ENUMERATE | XPCOM.JSPROP_READONLY | XPCOM.JSPROP_PERMANENT;
-	XPCOM.JS_DefineFunction (jsLibPath, nativeContext, newObject, functionName, XPCOM.CALLBACK_JSNative (CallJavaProc.getAddress ()), 3, flags);
-	XPCOM.memmove (aScriptObject, new long /*int*/[] {newObject}, C.PTR_SIZEOF);
-	return XPCOM.NS_OK;
-}
-
-int setScriptObject (long /*int*/ aScriptObject) {
-	return XPCOM.NS_COMFALSE;
-}
-
-/* nsISecurityCheckedComponent */
-
-int canCreateWrapper (long /*int*/ iid, long /*int*/ _retVal) {
-	long /*int*/[] result = new long /*int*/[1];
-	int rc = XPCOM.NS_GetServiceManager (result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-
-	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-	result[0] = 0;
-	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
-	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
-	serviceManager.Release ();
-
-	nsIMemory memory = new nsIMemory (result[0]);
-	result[0] = 0;
-	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "allAccess", true); //$NON-NLS-1$
-	long /*int*/ ptr = memory.Alloc (bytes.length);
-	C.memmove (ptr, bytes, bytes.length);
-	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
-	memory.Release ();
-
-	return XPCOM.NS_OK;
-}
-
-int canCallMethod (long /*int*/ iid, long /*int*/ methodName, long /*int*/ _retVal) {
-	long /*int*/[] result = new long /*int*/[1];
-	int rc = XPCOM.NS_GetServiceManager (result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-
-	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-	result[0] = 0;
-	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
-	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
-	serviceManager.Release ();
-
-	nsIMemory memory = new nsIMemory (result[0]);
-	result[0] = 0;
-	int length = XPCOM.strlen_PRUnichar (methodName);
-	char[] dest = new char[length];
-	XPCOM.memmove (dest, methodName, length * 2);
-	String string = new String (dest);
-	byte[] bytes;
-	if (string.equals (CALLJAVA)) {
-		bytes = MozillaDelegate.wcsToMbcs (null, "allAccess", true); //$NON-NLS-1$ 
-	} else {
-		bytes = MozillaDelegate.wcsToMbcs (null, "noAccess", true); //$NON-NLS-1$
-	}
-	long /*int*/ ptr = memory.Alloc (bytes.length);
-	C.memmove (ptr, bytes, bytes.length);
-	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
-	memory.Release ();
-
-	return XPCOM.NS_OK;
-}
-
-int canGetProperty (long /*int*/ iid, long /*int*/ propertyName, long /*int*/ _retVal) {
-	long /*int*/[] result = new long /*int*/[1];
-	int rc = XPCOM.NS_GetServiceManager (result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-
-	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-	result[0] = 0;
-	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
-	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
-	serviceManager.Release ();
-
-	nsIMemory memory = new nsIMemory (result[0]);
-	result[0] = 0;
-	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "noAccess", true); //$NON-NLS-1$
-	long /*int*/ ptr = memory.Alloc (bytes.length);
-	C.memmove (ptr, bytes, bytes.length);
-	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
-	memory.Release ();
-
-	return XPCOM.NS_OK;
-}
-
-int canSetProperty (long /*int*/ iid, long /*int*/ propertyName, long /*int*/ _retVal) {
-	long /*int*/[] result = new long /*int*/[1];
-	int rc = XPCOM.NS_GetServiceManager (result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-
-	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-	result[0] = 0;
-	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
-	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
-	serviceManager.Release ();
-
-	nsIMemory memory = new nsIMemory (result[0]);
-	result[0] = 0;
-	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "noAccess", true); //$NON-NLS-1$
-	long /*int*/ ptr = memory.Alloc (bytes.length);
-	C.memmove (ptr, bytes, bytes.length);
-	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
-	memory.Release ();
-
-	return XPCOM.NS_OK;
-}
-
-/* nsIXPCScriptable */
-
-long /*int*/ getClassName (long /*int*/ aClassName) {
-	long /*int*/[] result = new long /*int*/[1];
-	int rc = XPCOM.NS_GetServiceManager (result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
-
-	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
-	result[0] = 0;
-	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
-	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
-	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
-	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
-	serviceManager.Release ();
-
-	nsIMemory memory = new nsIMemory (result[0]);
-	result[0] = 0;
-	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "external", true); //$NON-NLS-1$
-	long /*int*/ ptr = memory.Alloc (bytes.length);
-	C.memmove (ptr, bytes, bytes.length);
-	C.memmove (aClassName, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
-	memory.Release ();
-
-	return 0;
-}
-
-static long /*int*/ getScriptableFlags () {
-	return XPCOM.WANT_POSTCREATE | XPCOM.USE_JSSTUB_FOR_ADDPROPERTY;
-}
-
-int postCreate (long /*int*/ wrapper, long /*int*/ cx, long /*int*/ obj) {
-	byte[] functionName = MozillaDelegate.wcsToMbcs (null, CALLJAVA, true);
-	int flags = XPCOM.JSPROP_ENUMERATE | XPCOM.JSPROP_READONLY | XPCOM.JSPROP_PERMANENT;
-	XPCOM.JS_DefineFunction24 (cx, obj, functionName, XPCOM.CALLBACK_JSNative (CallJavaProc.getAddress ()), 3, flags);
-	return 0;
-}
-
 }
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
index b4c7d11..101b09a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2015 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Neil Rashbrook <neil@parkwaycc.co.uk> - Bug 429739
+ *     Matthew Painter <matthew.painter@import.io>
  *******************************************************************************/
 package org.eclipse.swt.browser;
 
@@ -702,7 +704,7 @@
 			LocationProvider = new AppFileLocProvider (MozillaPath, profilePath, cacheParentPath, IsXULRunner);
 			LocationProvider.AddRef ();
 
-			/* write external.xpt to the file system if needed */
+			/* write swt.xpt to the file system if needed */
 			initExternal (LocationProvider.profilePath);
 
 			/* invoke appropriate Init function (based on mozilla version) */
@@ -1392,6 +1394,51 @@
 }
 
 @Override
+public Object evaluate (String script) throws SWTException {
+	if (!MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24))
+		return super.evaluate (script);
+
+	delegate.removeWindowSubclass ();
+
+	long /*int*/[] result = new long /*int*/[1];
+	int rc = webBrowser.QueryInterface(IIDStore.GetIID (nsIInterfaceRequestor.class), result);
+	if (rc != XPCOM.NS_OK) error (rc);
+	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+	nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor (result[0]);
+	result[0] = 0;
+	rc = XPCOM.NS_GetServiceManager (result);
+	if (rc != XPCOM.NS_OK) error (rc);
+	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
+	result[0] = 0;
+	rc = interfaceRequestor.GetInterface (IIDStore.GetIID (nsIDOMWindow.class), result);
+	interfaceRequestor.Release ();
+	if (rc != XPCOM.NS_OK) error (rc);
+	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+	nsIDOMWindow window = new nsIDOMWindow (result[0]);
+	result[0] = 0;
+	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.EXECUTE_CONTRACTID, true);
+	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (Execute.class), result);
+	if (rc != XPCOM.NS_OK) error (rc);
+	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+	Execute execute = new Execute (result[0]);
+	result[0] = 0;
+	nsEmbedString data = new nsEmbedString ("(function(){" + script + "}())");
+	execute.EvalInWindow (window, data, result);
+	data.dispose ();
+	execute.Release ();
+	if (result[0] == 0)
+		return null;
+
+	nsIVariant variant = new nsIVariant (result[0]);
+	Object retval = External.convertToJava (variant);
+	variant.Release ();
+	return retval;
+}
+@Override
 public boolean execute (String script) {
 	/*
 	* This could be the first content that is set into the browser, so
@@ -1400,6 +1447,50 @@
 	*/
 	delegate.removeWindowSubclass ();
 
+	long /*int*/[] result = new long /*int*/[1];
+	/*
+	* As of mozilla 1.9 executing javascript via the javascript: protocol no
+	* longer happens synchronously.  As a result, the result of executing JS
+	* is not returned to the java side when expected by the client.  The
+	* workaround for version 24 is to use a javascript-implemented component
+	* which then executes synchronously.
+	*/
+	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) {
+		result[0] = 0;
+		int rc = webBrowser.QueryInterface(IIDStore.GetIID (nsIInterfaceRequestor.class), result);
+		if (rc != XPCOM.NS_OK) error (rc);
+		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+		nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor (result[0]);
+		result[0] = 0;
+		rc = XPCOM.NS_GetServiceManager (result);
+		if (rc != XPCOM.NS_OK) error (rc);
+		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+		nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
+		result[0] = 0;
+		rc = interfaceRequestor.GetInterface (IIDStore.GetIID (nsIDOMWindow.class), result);
+		interfaceRequestor.Release ();
+		if (rc != XPCOM.NS_OK) error (rc);
+		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+		nsIDOMWindow window = new nsIDOMWindow (result[0]);
+		result[0] = 0;
+		byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.EXECUTE_CONTRACTID, true);
+		rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (Execute.class), result);
+		if (rc != XPCOM.NS_OK) error (rc);
+		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+		Execute execute = new Execute (result[0]);
+		result[0] = 0;
+		nsEmbedString data = new nsEmbedString (script);
+		rc = execute.EvalInWindow (window, data, result);
+		if (result[0] != 0)
+			new nsIVariant (result[0]).Release ();
+		data.dispose ();
+		execute.Release ();
+		return rc == XPCOM.NS_OK;
+	}
+
 	/*
 	* As of mozilla 1.9 executing javascript via the javascript: protocol no
 	* longer happens synchronously.  As a result, the result of executing JS
@@ -1407,7 +1498,6 @@
 	* workaround is to invoke the javascript handler directly via C++, which is
 	* exposed as of mozilla 1.9.
 	*/
-	long /*int*/[] result = new long /*int*/[1];
 	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR1_9)) {
 		int rc = XPCOM.NS_GetServiceManager (result);
 		if (rc != XPCOM.NS_OK) error (rc);
@@ -1439,20 +1529,11 @@
 				if (rc == XPCOM.NS_OK && result[0] != 0) {
 					long /*int*/ scriptGlobalObject = result[0];
 					result[0] = 0;
-					if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
-						rc = (int/*64*/)XPCOM.nsIScriptGlobalObject24_EnsureScriptEnvironment (scriptGlobalObject);
-					} else {
-						rc = (int/*64*/)XPCOM.nsIScriptGlobalObject_EnsureScriptEnvironment (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
-					}
+					rc = (int/*64*/)XPCOM.nsIScriptGlobalObject_EnsureScriptEnvironment (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
 					if (rc != XPCOM.NS_OK) {
 						new nsISupports (scriptGlobalObject).Release ();
 					} else {
-						long /*int*/ scriptContext;
-						if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
-							scriptContext = XPCOM.nsIScriptGlobalObject24_GetScriptContext (scriptGlobalObject);
-						} else {
-							scriptContext = XPCOM.nsIScriptGlobalObject_GetScriptContext (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
-						}
+						long /*int*/ scriptContext = XPCOM.nsIScriptGlobalObject_GetScriptContext (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
 
 						if (scriptContext != 0) {
 							/* ensure that the received nsIScriptContext implements the expected interface */
@@ -1462,12 +1543,7 @@
 								new nsISupports (result[0]).Release ();
 								result[0] = 0;
 
-								long /*int*/ jsContext;
-								if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
-									jsContext = XPCOM.nsIScriptContext24_GetNativeContext (scriptContext);
-								} else {
-									jsContext = XPCOM.nsIScriptContext_GetNativeContext (scriptContext);
-								}
+								long /*int*/ jsContext = XPCOM.nsIScriptContext_GetNativeContext (scriptContext);
 								if (jsContext != 0) {
 									int length = script.length ();
 									char[] scriptChars = new char[length];
@@ -1480,22 +1556,8 @@
 										result[0] = 0;
 									}
 									byte[] jsLibPath = getJSLibPathBytes ();
-									long /*int*/ globalJSObject;
-									if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
-										globalJSObject = XPCOM.nsIScriptGlobalObject24_GetGlobalJSObject (scriptGlobalObject);
-									} else {
-										globalJSObject = XPCOM.JS_GetGlobalObject (jsLibPath, jsContext);
-									}
+									long /*int*/ globalJSObject = XPCOM.JS_GetGlobalObject (jsLibPath, jsContext);
 									if (globalJSObject != 0) {
-										if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
-											boolean success = XPCOM.JS_EvaluateUCScriptForPrincipals24 (jsLibPath, jsContext, globalJSObject, principals, scriptChars, length, urlbytes, 0, 0) != 0;
-											// should principals be Release()d too?
-											new nsISupports (scriptGlobalObject).Release ();
-											principal.Release ();
-											serviceManager.Release ();
-											return success;
-										}
-										/* 1.9.x - 10.x */
 										aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_CONTEXTSTACK_CONTRACTID, true);
 										rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIJSContextStack.class), result);
 										if (rc == XPCOM.NS_OK && result[0] != 0) {
@@ -1810,6 +1872,8 @@
 		webBrowser.AddRef ();
 		return webBrowserObject;
 	} catch (ClassNotFoundException e) {
+		webBrowserObject = webBrowser;
+		return webBrowserObject;
 	} catch (NoSuchMethodException e) {
 	} catch (IllegalArgumentException e) {
 	} catch (IllegalAccessException e) {
@@ -1891,14 +1955,49 @@
 
 void initExternal (String profilePath) {
 	File componentsDir = new File (profilePath, AppFileLocProvider.COMPONENTS_DIR);
-	java.io.InputStream is = Library.class.getResourceAsStream ("/external.xpt"); //$NON-NLS-1$
+	java.io.InputStream is = Library.class.getResourceAsStream ("/swt.xpt"); //$NON-NLS-1$
 	if (is != null) {
 		if (!componentsDir.exists ()) {
 			componentsDir.mkdirs ();
 		}
 		int read;
 		byte [] buffer = new byte [4096];
-		File file = new File (componentsDir, "external.xpt"); //$NON-NLS-1$
+		File file = new File (componentsDir, "swt.xpt"); //$NON-NLS-1$
+		try {
+			FileOutputStream os = new FileOutputStream (file);
+			while ((read = is.read (buffer)) != -1) {
+				os.write(buffer, 0, read);
+			}
+			os.close ();
+			is.close ();
+		} catch (FileNotFoundException e) {
+		} catch (IOException e) {
+		}
+	}
+	is = Library.class.getResourceAsStream ("/swt.js"); //$NON-NLS-1$
+	if (is != null) {
+		if (!componentsDir.exists ()) {
+			componentsDir.mkdirs ();
+		}
+		int read;
+		byte [] buffer = new byte [4096];
+		File file = new File (componentsDir, "swt.js"); //$NON-NLS-1$
+		try {
+			FileOutputStream os = new FileOutputStream (file);
+			while ((read = is.read (buffer)) != -1) {
+				os.write(buffer, 0, read);
+			}
+			os.close ();
+			is.close ();
+		} catch (FileNotFoundException e) {
+		} catch (IOException e) {
+		}
+	}
+	is = Library.class.getResourceAsStream ("/chrome.manifest"); //$NON-NLS-1$
+	if (is != null) {
+		int read;
+		byte [] buffer = new byte [4096];
+		File file = new File (profilePath, "chrome.manifest"); //$NON-NLS-1$
 		try {
 			FileOutputStream os = new FileOutputStream (file);
 			while ((read = is.read (buffer)) != -1) {
@@ -2177,9 +2276,6 @@
 			error (XPCOM.NS_ERROR_NULL_POINTER);
 		}
 
-		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24, true)) {
-			Library.loadLibrary("swt-xulrunner24"); //$NON-NLS-1$
-		}
 		MozillaDelegate.loadAdditionalLibraries (mozillaPath, true);
 
 		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR10)) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/Execute.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/Execute.java
new file mode 100644
index 0000000..1b02ebe
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/Execute.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Neil Rashbrook and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Neil Rashbrook <neil@parkwaycc.co.uk> - Bug 429739
+ *    Matthew Painter <matthew.painter@import.io>
+ *******************************************************************************/
+package org.eclipse.swt.internal.mozilla;
+
+
+public class Execute extends nsISupports {
+
+	static final int LAST_METHOD_ID = nsISupports.LAST_METHOD_ID + 3;
+
+	static final String EXECUTE_IID_STR = "75a03044-d129-4d96-9292-bc1623876de1";
+
+	static {
+		IIDStore.RegisterIID(Execute.class, MozillaVersion.VERSION_BASE, new nsID(EXECUTE_IID_STR));
+	}
+
+	public Execute(long /*int*/ address) {
+		super(address);
+	}
+
+	public int EvalInWindow(nsIDOMWindow aWindow, nsEmbedString code, long /*int*/[] aVariant) {
+		return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 1, getAddress(), aWindow.getAddress(), code.getAddress(), aVariant);
+	}
+	
+	public int EvalAsChrome(nsIDOMWindow aWindow, nsEmbedString code, long /*int*/[] aVariant) {
+		return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 2, getAddress(), aWindow.getAddress(), code.getAddress(), aVariant);
+ 	}
+	
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java
index d129f06..876c89c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java
@@ -22,7 +22,8 @@
  *
  * IBM
  * -  Binding to permit interfacing between Mozilla and SWT
- * -  Copyright (C) 2003, 2013 IBM Corp.  All Rights Reserved.
+ * -  Copyright (C) 2003, 2014 IBM Corp.  All Rights Reserved.
+ *    Neil Rashbrook <neil@parkwaycc.co.uk> - Bug 429739
  *
  * ***** END LICENSE BLOCK ***** */
 package org.eclipse.swt.internal.mozilla;
@@ -92,6 +93,7 @@
 	public static final nsID NS_IXPCSCRIPTABLE_IID = new nsID ("155d1863-2b0b-4f5e-b800-05184944156b"); //$NON-NLS-1$
 
 	/* contract ID constants */
+	public static final String EXECUTE_CONTRACTID = "@eclipse.org/execute;1"; //$NON-NLS-1$
 	public static final String EXTERNAL_CONTRACTID = "@eclipse.org/external;1"; //$NON-NLS-1$
 	public static final String NS_AUTHPROMPTER_CONTRACTID = "@mozilla.org/passwordmanager/authpromptfactory;1"; //$NON-NLS-1$
 	public static final String NS_CERTOVERRIDE_CONTRACTID = "@mozilla.org/security/certoverride;1"; //$NON-NLS-1$
@@ -175,15 +177,6 @@
 	public static final int SEC_ERROR_UNTRUSTED_CERT = 0x805A1FEB;
 	public static final int SEC_ERROR_UNTRUSTED_ISSUER = 0x805A1FEC;
 	public static final int SSL_ERROR_BAD_CERT_DOMAIN = 0x805A2FF4;
-	public static final int USE_JSSTUB_FOR_ADDPROPERTY = 1 << 17;
-	public static final int WANT_POSTCREATE = 4;
-
-	/* JSAPI constants */
-	public static final int JSPROP_ENUMERATE = 0x1;
-	public static final int JSPROP_PERMANENT = 0x4;
-	public static final int JSPROP_READONLY = 0x2;
-	public static final int JS_FALSE = 0x0;
-	public static final int JS_TRUE = 0x1;
 
 public static final native int nsDynamicFunctionLoad_sizeof ();
 
@@ -234,27 +227,7 @@
 public static final native long /*int*/ CALLBACK_JSNative(long /*int*/ func);
 
 /** @method flags=no_gen */
-public static final native long /*int*/ _JS_DefineFunction(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, byte[] name, long /*int*/ call, int nargs, int flags);	
-public static final long /*int*/ JS_DefineFunction(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, byte[] name, long /*int*/ call, int nargs, int flags) {
-	lock.lock();
-	try {
-		return _JS_DefineFunction(mozillaPath, cx, obj, name, call, nargs, flags);
-	} finally {
-		lock.unlock();
-	}
-}
-/** @method flags=no_gen */
-public static final native long /*int*/ _JS_DefineFunction24(long /*int*/ cx, long /*int*/ obj, byte[] name, long /*int*/ call, int nargs, int flags);	
-public static final long /*int*/ JS_DefineFunction24(long /*int*/ cx, long /*int*/ obj, byte[] name, long /*int*/ call, int nargs, int flags) {
-	lock.lock();
-	try {
-		return _JS_DefineFunction24(cx, obj, name, call, nargs, flags);
-	} finally {
-		lock.unlock();
-	}
-}
-/** @method flags=no_gen */
-public static final native int _JS_EvaluateUCScriptForPrincipals(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, long /*int*/ principals, char[] chars, int length, byte[] filename, int lineno, long /*int*/[] retVal);	
+public static final native int _JS_EvaluateUCScriptForPrincipals(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, long /*int*/ principals, char[] chars, int length, byte[] filename, int lineno, long /*int*/[] retVal);
 public static final int JS_EvaluateUCScriptForPrincipals(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, long /*int*/ principals, char[] chars, int length, byte[] filename, int lineno, long /*int*/[] retVal) {
 	lock.lock();
 	try {
@@ -274,27 +247,7 @@
 	}
 }
 /** @method flags=no_gen */
-public static final native int _JS_EvaluateUCScriptForPrincipals24(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, long /*int*/ principals, char[] chars, int length, byte[] filename, int lineno, long /*int*/ retVal);	
-public static final int JS_EvaluateUCScriptForPrincipals24(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, long /*int*/ principals, char[] chars, int length, byte[] filename, int lineno, long /*int*/ retVal) {
-	lock.lock();
-	try {
-		return _JS_EvaluateUCScriptForPrincipals24(mozillaPath, cx, obj, principals, chars, length, filename, lineno, retVal);
-	} finally {
-		lock.unlock();
-	}
-}
-/** @method flags=no_gen */
-public static final native long /*int*/ _JS_GetGlobalForScopeChain24(long /*int*/ cx);	
-public static final long /*int*/ JS_GetGlobalForScopeChain24(long /*int*/ cx) {
-	lock.lock();
-	try {
-		return _JS_GetGlobalForScopeChain24(cx);
-	} finally {
-		lock.unlock();
-	}
-}
-/** @method flags=no_gen */
-public static final native long /*int*/ _JS_GetGlobalObject(byte[] mozillaPath, long /*int*/ cx);	
+public static final native long /*int*/ _JS_GetGlobalObject(byte[] mozillaPath, long /*int*/ cx);
 public static final long /*int*/ JS_GetGlobalObject(byte[] mozillaPath, long /*int*/ cx) {
 	lock.lock();
 	try {
@@ -304,16 +257,6 @@
 	}
 }
 /** @method flags=no_gen */
-public static final native long /*int*/ _JS_NewObject(byte[] mozillaPath, long /*int*/ cx, long /*int*/ clasp, long /*int*/ proto, long /*int*/ parent);	
-public static final long /*int*/ JS_NewObject(byte[] mozillaPath, long /*int*/ cx, long /*int*/ clasp, long /*int*/ proto, long /*int*/ parent) {
-	lock.lock();
-	try {
-		return _JS_NewObject(mozillaPath, cx, clasp, proto, parent);
-	} finally {
-		lock.unlock();
-	}
-}
-/** @method flags=no_gen */
 public static final native boolean _NS_Free(byte[] mozillaPath, long /*int*/ aPtr);
 public static final boolean NS_Free(byte[] mozillaPath, long /*int*/ aPtr) {
 	lock.lock();
@@ -445,26 +388,6 @@
 		lock.unlock();
 	}
 }
-/** @method flags=no_gen */
-public static final native int _nsIScriptGlobalObject24_EnsureScriptEnvironment(long /*int*/ ptr);
-public static final int nsIScriptGlobalObject24_EnsureScriptEnvironment(long /*int*/ ptr) {
-	lock.lock();
-	try {
-		return _nsIScriptGlobalObject24_EnsureScriptEnvironment(ptr);
-	} finally {
-		lock.unlock();
-	}
-}
-/** @method flags=no_gen */
-public static final native long /*int*/ _nsIScriptGlobalObject24_GetGlobalJSObject(long /*int*/ ptr);
-public static final long /*int*/ nsIScriptGlobalObject24_GetGlobalJSObject(long /*int*/ ptr) {
-	lock.lock();
-	try {
-		return _nsIScriptGlobalObject24_GetGlobalJSObject(ptr);
-	} finally {
-		lock.unlock();
-	}
-}
 /**
  * @method flags=cpp
  * @param ptr cast=(nsIScriptGlobalObject *)
@@ -478,16 +401,6 @@
 		lock.unlock();
 	}
 }
-/** @method flags=no_gen */
-public static final native long /*int*/ _nsIScriptGlobalObject24_GetScriptContext(long /*int*/ ptr);
-public static final long /*int*/ nsIScriptGlobalObject24_GetScriptContext(long /*int*/ ptr) {
-	lock.lock();
-	try {
-		return _nsIScriptGlobalObject24_GetScriptContext(ptr);
-	} finally {
-		lock.unlock();
-	}
-}
 /**
  * @method flags=cpp
  * @param ptr cast=(nsIScriptContext *)
@@ -501,16 +414,6 @@
 		lock.unlock();
 	}
 }
-/** @method flags=no_gen */
-public static final native long /*int*/ _nsIScriptContext24_GetNativeContext(long /*int*/ ptr);
-public static final long /*int*/ nsIScriptContext24_GetNativeContext(long /*int*/ ptr) {
-	lock.lock();
-	try {
-		return _nsIScriptContext24_GetNativeContext(ptr);
-	} finally {
-		lock.unlock();
-	}
-}
 /**
  * @method flags=cpp
  * @param ptr cast=(nsEmbedCString *)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
old mode 100644
new mode 100755
index b5a57c0..a6cc5df
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh
@@ -20,21 +20,22 @@
 	export GTK_VERSION
 fi
 
-# Check if we have to compile external.xpt from external.idl
-COMPONENTS_DIR=`pwd`/../../components
-if test ! -f ${COMPONENTS_DIR}/external.xpt; then
-	if test ! -f ${COMPONENTS_DIR}/external.idl; then
-		echo "Can't find ${COMPONENTS_DIR}/external.idl"
-	else
-		IDLDIR=`pkg-config --variable=idldir libxul | sed 's@/stable$@@'`/unstable
-		if test ! -d ${IDLDIR}; then
-			IDLDIR=`pkg-config --variable=idldir libxul`
-		fi
-		XPIDL=`pkg-config --variable=sdkdir libxul`/bin/xpidl
-		echo "${XPIDL} -m typelib -I ${IDLDIR} -e ${COMPONENTS_DIR}/external.xpt ${COMPONENTS_DIR}/external.idl"
-		${XPIDL} -m typelib -I ${IDLDIR} -e ${COMPONENTS_DIR}/external.xpt ${COMPONENTS_DIR}/external.idl
-	fi
-fi
+# No longer necessary, but may be useful in future if we want to compile swt.idl rather than using a static one
+#
+# COMPONENTS_DIR=`pwd`/../../components
+# if test ! -f ${COMPONENTS_DIR}/external.xpt; then
+#	if test ! -f ${COMPONENTS_DIR}/external.idl; then
+#		echo "Can't find ${COMPONENTS_DIR}/external.idl"
+#	else
+#		IDLDIR=`pkg-config --variable=idldir libxul | sed 's@/stable$@@'`/unstable
+#		if test ! -d ${IDLDIR}; then
+#			IDLDIR=`pkg-config --variable=idldir libxul`
+#		fi
+#		XPIDL=`pkg-config --variable=sdkdir libxul`/bin/xpidl
+#		echo "${XPIDL} -m typelib -I ${IDLDIR} -e ${COMPONENTS_DIR}/external.xpt ${COMPONENTS_DIR}/external.idl"
+#		${XPIDL} -m typelib -I ${IDLDIR} -e ${COMPONENTS_DIR}/external.xpt ${COMPONENTS_DIR}/external.idl
+#	fi
+# fi
 
 # Determine which OS we are on
 if [ "${OS}" = "" ]; then
diff --git a/bundles/org.eclipse.swt/components/chrome.manifest b/bundles/org.eclipse.swt/components/chrome.manifest
new file mode 100644
index 0000000..5421a52
--- /dev/null
+++ b/bundles/org.eclipse.swt/components/chrome.manifest
@@ -0,0 +1,3 @@
+interfaces components/swt.xpt
+component {0aebcff1-f7b3-4522-a64b-1706d65dc232} components/swt.js
+contract @eclipse.org/execute;1 {0aebcff1-f7b3-4522-a64b-1706d65dc232}
diff --git a/bundles/org.eclipse.swt/components/external.xpt b/bundles/org.eclipse.swt/components/external.xpt
deleted file mode 100644
index 88a803d..0000000
--- a/bundles/org.eclipse.swt/components/external.xpt
+++ /dev/null
Binary files differ
diff --git a/bundles/org.eclipse.swt/components/external.idl b/bundles/org.eclipse.swt/components/swt.idl
similarity index 61%
rename from bundles/org.eclipse.swt/components/external.idl
rename to bundles/org.eclipse.swt/components/swt.idl
index 441fc09..744625c 100644
--- a/bundles/org.eclipse.swt/components/external.idl
+++ b/bundles/org.eclipse.swt/components/swt.idl
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2014 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -7,15 +7,25 @@
  *
  * Contributors:
  *    IBM Corporation - initial API and implementation
+ *    Neil Rashbrook <neil@parkwaycc.co.uk> - Bug 429739
  *******************************************************************************/
 
-// to compile: xpidl -m typelib -I S:\swt-builddir\gecko-sdk\idl\ -e external.xpt external.idl
+// to compile: xpidl -m typelib -I S:\swt-builddir\gecko-sdk\idl\ -e swt.xpt swt.idl
 
 #include "nsISupports.idl"
-#include "nsIVariant.idl"
+interface nsIVariant;
+interface nsIDOMWindow;
 
 [scriptable, uuid(ded01d20-ba6f-11dd-ad8b-0800200c9a66)]
 
 interface External : nsISupports {
     nsIVariant callJava (in unsigned long index, in nsIVariant token, in nsIVariant args);
 };
+
+[scriptable, uuid(75a03044-d129-4d96-9292-bc1623876de1)]
+
+interface Execute : nsISupports {
+    nsIVariant evalInWindow (in nsIDOMWindow window, in AString code);
+    nsIVariant evalAsChrome (in nsIDOMWindow window, in AString code);
+    void evalAsync (in nsIDOMWindow window, in AString code);
+};
diff --git a/bundles/org.eclipse.swt/components/swt.js b/bundles/org.eclipse.swt/components/swt.js
new file mode 100644
index 0000000..8b120b6
--- /dev/null
+++ b/bundles/org.eclipse.swt/components/swt.js
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Neil Rashbrook and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Neil Rashbrook <neil@parkwaycc.co.uk> - Bug 429739
+ *******************************************************************************/
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function execute() {
+}
+
+execute.prototype.evalInWindow = function(aWindow, aString) {
+    aWindow = XPCNativeWrapper.unwrap(aWindow);
+    try {
+        aWindow.external.QueryInterface(Components.interfaces.External);
+    } catch (e) {
+        aWindow.external = Components.classes["@eclipse.org/external;1"].createInstance();
+    }
+    return aWindow.eval(aString);
+};
+
+execute.prototype.evalAsChrome = function(aWindow, aString) {
+    var window = XPCNativeWrapper.unwrap(aWindow);
+    return eval(aString);
+};
+
+execute.prototype.evalAsync = function(aWindow, aString) {
+    aWindow.location = "javascript:" + unescape(aString) + ";void(0);";
+};
+
+execute.prototype.QueryInterface = XPCOMUtils.generateQI([Components.interfaces.Execute]);
+
+execute.prototype.classID = Components.ID("{0aebcff1-f7b3-4522-a64b-1706d65dc232}");
+
+var NSGetFactory = XPCOMUtils.generateNSGetFactory([execute]);
diff --git a/bundles/org.eclipse.swt/components/swt.xpt b/bundles/org.eclipse.swt/components/swt.xpt
new file mode 100644
index 0000000..6f6aca7
--- /dev/null
+++ b/bundles/org.eclipse.swt/components/swt.xpt
Binary files differ