Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 429739 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/AppFileLocProvider.java (-3 / +3 lines)
Lines 293-307 int getFile(long /*int*/ prop, long /*int*/ persistent, long /*int*/ _retval) { Link Here
293
	} else if (propertyName.equals (XPCOM.NS_GRE_DIR)) {
293
	} else if (propertyName.equals (XPCOM.NS_GRE_DIR)) {
294
		propertyValue = mozillaPath;
294
		propertyValue = mozillaPath;
295
	} else if (propertyName.equals (XPCOM.NS_GRE_COMPONENT_DIR)) {
295
	} else if (propertyName.equals (XPCOM.NS_GRE_COMPONENT_DIR)) {
296
		propertyValue = profilePath + COMPONENTS_DIR;
296
		propertyValue = mozillaPath + COMPONENTS_DIR;
297
	} else if (propertyName.equals (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) {
297
	} else if (propertyName.equals (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) {
298
		propertyValue = mozillaPath;
298
		propertyValue = mozillaPath;
299
	} else if (propertyName.equals (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) {
299
	} else if (propertyName.equals (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) {
300
		propertyValue = mozillaPath;
300
		propertyValue = mozillaPath;
301
	} else if (propertyName.equals (XPCOM.NS_XPCOM_COMPONENT_DIR)) {
301
	} else if (propertyName.equals (XPCOM.NS_XPCOM_COMPONENT_DIR)) {
302
		propertyValue = mozillaPath + COMPONENTS_DIR;
302
		propertyValue = profilePath + COMPONENTS_DIR;
303
	} else if (propertyName.equals (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) {
303
	} else if (propertyName.equals (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) {
304
		propertyValue = mozillaPath;
304
		propertyValue = profilePath;
305
	} else if (propertyName.equals (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) {
305
	} else if (propertyName.equals (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) {
306
		/*
306
		/*
307
		* Answering a value for this property causes problems in Mozilla versions
307
		* Answering a value for this property causes problems in Mozilla versions
(-)a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java (-403 / +13 lines)
Lines 25-51 class External { Link Here
25
	XPCOMObject supports;
25
	XPCOMObject supports;
26
	XPCOMObject external;
26
	XPCOMObject external;
27
	XPCOMObject classInfo;
27
	XPCOMObject classInfo;
28
	XPCOMObject securityCheckedComponent;
29
	XPCOMObject scriptObjectOwner;
30
	XPCOMObject xpcScriptable;
31
	int refCount = 0;
28
	int refCount = 0;
32
	
33
	static final String CALLJAVA = "callJava"; //$NON-NLS-1$
34
35
	static Callback CallJavaProc, GetScriptableFlags24Proc = null;
36
	static {
37
		CallJavaProc = new Callback (External.class, CALLJAVA, 3);
38
		if (CallJavaProc.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
39
40
		/*
41
		 * On win32 a substitute callback is provided for nsIXPCScriptable.getScriptableFlags()
42
		 * because it does not use the standard XPCOM calling convention.
43
		 */
44
		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24) && SWT.getPlatform ().equals ("win32")) { //$NON-NLS-1$
45
			GetScriptableFlags24Proc = new Callback (External.class, "getScriptableFlags", 0); //$NON-NLS-1$
46
			if (GetScriptableFlags24Proc.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
47
		}
48
	}
49
29
50
External () {
30
External () {
51
	createCOMInterfaces ();
31
	createCOMInterfaces ();
Lines 53-173 External () { Link Here
53
33
54
/* external */
34
/* external */
55
35
56
/*
57
 * This is the BrowserFunction entry point for XULRunner releases >= 4 because
58
 * QueryInterface answers an nsIScriptObjectOwner implementation (which points
59
 * at this function) iff the detected XULRunner version is >= 4.
60
 */
61
static long /*int*/ callJava (long /*int*/ cx, long /*int*/ argc, long /*int*/ vp) {
62
	int jsval_sizeof = 8;
63
	long /*int*/ argsPtr = vp + 2 * jsval_sizeof;
64
	nsIVariant resultVariant = null;
65
66
	long /*int*/[] result = new long /*int*/[1];
67
	int rc = XPCOM.NS_GetServiceManager (result);
68
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
69
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
70
71
	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
72
	result[0] = 0;
73
	rc = serviceManager.GetService (XPCOM.NS_IXPCONNECT_CID, IIDStore.GetIID (nsIXPConnect.class), result);
74
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
75
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
76
77
	nsIXPConnect connect = new nsIXPConnect (result[0]);
78
	result[0] = 0;
79
80
	/* extract the first argument value (the function id) */
81
	rc = connect.JSValToVariant (cx, argsPtr, result);
82
	if (rc == XPCOM.NS_OK && result[0] != 0) {
83
		nsIVariant idVariant = new nsIVariant (result[0]);
84
		result[0] = 0;
85
		short[] dataType = new short[1];
86
		rc = idVariant.GetDataType (dataType);
87
		if (rc == XPCOM.NS_OK && dataType[0] == nsIDataType.VTYPE_INT32) {
88
			int[] intResult = new int[1];
89
			rc = idVariant.GetAsInt32 (intResult); /* PRInt32 */
90
			if (rc == XPCOM.NS_OK) {
91
				int functionId = intResult[0];
92
93
				/* get the second argument variant (the token string) */
94
				argsPtr += jsval_sizeof;
95
				rc = connect.JSValToVariant (cx, argsPtr, result);
96
				if (rc == XPCOM.NS_OK && result[0] != 0) {
97
					long /*int*/ tokenVariant = result[0];
98
					result[0] = 0;
99
100
					/* get the third argument variant (the invocation args) */
101
					argsPtr += jsval_sizeof;
102
					rc = connect.JSValToVariant (cx, argsPtr, result);
103
					if (rc == XPCOM.NS_OK && result[0] != 0) {
104
						long /*int*/ argsVariant = result[0];
105
						result[0] = 0;
106
107
						/* invoke the BrowserFunction */
108
						resultVariant = new nsIVariant (invokeFunction (functionId, tokenVariant, argsVariant));
109
						new nsISupports (argsVariant).Release ();
110
					}
111
					new nsISupports (tokenVariant).Release ();
112
				}
113
			}
114
		}
115
		idVariant.Release ();
116
	}
117
	result[0] = 0;
118
119
	/* if the BrowserFunction could not be invoked for some reason then return null to JS */
120
	if (resultVariant == null) {
121
		rc = XPCOM.NS_GetComponentManager (result);
122
		if (rc != XPCOM.NS_OK) Mozilla.error (rc);
123
		if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
124
		nsIComponentManager componentManager = new nsIComponentManager (result[0]);
125
		result[0] = 0;
126
		resultVariant = convertToJS (null, componentManager);
127
		componentManager.Release ();
128
	}
129
130
	/* convert the resulting variant to a jsval */
131
	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
132
	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
133
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
134
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
135
	serviceManager.Release();
136
137
	nsIMemory memory = new nsIMemory (result[0]);
138
	result[0] = 0;
139
	long /*int*/ jsVal = memory.Alloc (jsval_sizeof);
140
	C.memset (jsVal, 0, jsval_sizeof);
141
	long /*int*/ globalObject = 0;
142
	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) {
143
		globalObject = XPCOM.JS_GetGlobalForScopeChain24 (cx);
144
	} else {
145
		globalObject = XPCOM.JS_GetGlobalObject (Mozilla.getJSLibPathBytes (), cx);
146
	}
147
	rc = connect.VariantToJS (cx, globalObject, resultVariant.getAddress (), jsVal);
148
	resultVariant.Release ();
149
	connect.Release ();
150
151
	long /*int*/ returnValue = XPCOM.JS_FALSE;
152
	if (rc == XPCOM.NS_OK) {
153
		/* write the jsval to the return value slot */
154
		C.memmove (vp, jsVal, jsval_sizeof);
155
		returnValue = XPCOM.JS_TRUE;
156
	}
157
	memory.Free (jsVal);
158
	memory.Release ();
159
	return returnValue;
160
}
161
162
/* this is the BrowserFunction entry point when the detected XULRunner version is < 4 */
163
static int callJava (int functionId, long /*int*/ tokenVariant, long /*int*/ argsVariant, long /*int*/ returnPtr) {
36
static int callJava (int functionId, long /*int*/ tokenVariant, long /*int*/ argsVariant, long /*int*/ returnPtr) {
164
	long /*int*/ resultVariant = invokeFunction (functionId, tokenVariant, argsVariant);
37
	long /*int*/ resultVariant = invokeFunction (functionId, tokenVariant, argsVariant);
165
	C.memmove (returnPtr, new long /*int*/[] {resultVariant}, C.PTR_SIZEOF);
38
	C.memmove (returnPtr, new long /*int*/[] {resultVariant}, C.PTR_SIZEOF);
166
	return XPCOM.NS_OK;
39
	return XPCOM.NS_OK;
167
}
40
}
168
41
169
static Object convertToJava (nsIVariant variant, short type) {
42
static Object convertToJava (nsIVariant variant) {
170
	switch (type) {
43
	short[] dataType = new short[1];
44
	int rc = variant.GetDataType (dataType);
45
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
46
	switch (dataType[0]) {
171
		case nsIDataType.VTYPE_EMPTY:
47
		case nsIDataType.VTYPE_EMPTY:
172
		case nsIDataType.VTYPE_VOID:
48
		case nsIDataType.VTYPE_VOID:
173
			return null;
49
			return null;
Lines 175-181 static Object convertToJava (nsIVariant variant, short type) { Link Here
175
			return new Object[0];
51
			return new Object[0];
176
		case nsIDataType.VTYPE_BOOL:
52
		case nsIDataType.VTYPE_BOOL:
177
			int[] boolResult = new int[1]; /*PRInt32*/
53
			int[] boolResult = new int[1]; /*PRInt32*/
178
			int rc = variant.GetAsBool (boolResult);
54
			rc = variant.GetAsBool (boolResult);
179
			if (rc != XPCOM.NS_OK) Mozilla.error (rc);
55
			if (rc != XPCOM.NS_OK) Mozilla.error (rc);
180
			return new Boolean (boolResult[0] != 0);
56
			return new Boolean (boolResult[0] != 0);
181
		case nsIDataType.VTYPE_INT32:
57
		case nsIDataType.VTYPE_INT32:
Lines 241-251 static Object convertToJava (nsIVariant variant, short type) { Link Here
241
117
242
					nsIVariant currentVariant = new nsIVariant (result[0]);
118
					nsIVariant currentVariant = new nsIVariant (result[0]);
243
					result[0] = 0;
119
					result[0] = 0;
244
					currentType[0] = 0;
245
					rc = currentVariant.GetDataType (currentType);
246
					if (rc != XPCOM.NS_OK) Mozilla.error (rc);
120
					if (rc != XPCOM.NS_OK) Mozilla.error (rc);
247
					try {
121
					try {
248
						arrayReturn[i] = convertToJava (currentVariant, currentType[0]);
122
						arrayReturn[i] = convertToJava (currentVariant);
249
						currentVariant.Release ();
123
						currentVariant.Release ();
250
					} catch (IllegalArgumentException e) {
124
					} catch (IllegalArgumentException e) {
251
						/* invalid argument value type */
125
						/* invalid argument value type */
Lines 395-413 static long /*int*/ invokeFunction (int functionId, long /*int*/ tokenVariant, l Link Here
395
269
396
	if (function != null) {
270
	if (function != null) {
397
		try {
271
		try {
398
			short[] type = new short[1]; /* PRUint16 */
399
			nsIVariant variant = new nsIVariant (tokenVariant);
272
			nsIVariant variant = new nsIVariant (tokenVariant);
400
			int rc = variant.GetDataType (type);
273
			Object temp = convertToJava (variant);
401
			if (rc != XPCOM.NS_OK) Mozilla.error (rc);
402
			Object temp = convertToJava (variant, type[0]);
403
			type[0] = 0;
404
			if (temp instanceof String) {
274
			if (temp instanceof String) {
405
				String token = (String)temp;
275
				String token = (String)temp;
406
				if (token.equals (function.token)) {
276
				if (token.equals (function.token)) {
407
					variant = new nsIVariant (args);
277
					variant = new nsIVariant (args);
408
					rc = variant.GetDataType (type);
278
					temp = convertToJava (variant);
409
					if (rc != XPCOM.NS_OK) Mozilla.error (rc);
410
					temp = convertToJava (variant, type[0]);
411
					if (temp instanceof Object[]) {
279
					if (temp instanceof Object[]) {
412
						Object[] arguments = (Object[])temp;
280
						Object[] arguments = (Object[])temp;
413
						try {
281
						try {
Lines 488-510 void createCOMInterfaces () { Link Here
488
		public long /*int*/ method10 (long /*int*/[] args) {return getClassIDNoAlloc (args[0]);}
356
		public long /*int*/ method10 (long /*int*/[] args) {return getClassIDNoAlloc (args[0]);}
489
	};
357
	};
490
358
491
	securityCheckedComponent = new XPCOMObject (new int[] {2, 0, 0, 2, 3, 3, 3}) {
492
		@Override
493
		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
494
		@Override
495
		public long /*int*/ method1 (long /*int*/[] args) {return AddRef ();}
496
		@Override
497
		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
498
		@Override
499
		public long /*int*/ method3 (long /*int*/[] args) {return canCreateWrapper (args[0], args[1]);}
500
		@Override
501
		public long /*int*/ method4 (long /*int*/[] args) {return canCallMethod (args[0], args[1], args[2]);}
502
		@Override
503
		public long /*int*/ method5 (long /*int*/[] args) {return canGetProperty (args[0], args[1], args[2]);}
504
		@Override
505
		public long /*int*/ method6 (long /*int*/[] args) {return canSetProperty (args[0], args[1], args[2]);}
506
	};
507
508
	external = new XPCOMObject (new int[] {2, 0, 0, 4}) {
359
	external = new XPCOMObject (new int[] {2, 0, 0, 4}) {
509
		@Override
360
		@Override
510
		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
361
		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
Lines 515-558 void createCOMInterfaces () { Link Here
515
		@Override
366
		@Override
516
		public long /*int*/ method3 (long /*int*/[] args) {return callJava ((int)/*64*/args[0], args[1], args[2], args[3]);}
367
		public long /*int*/ method3 (long /*int*/[] args) {return callJava ((int)/*64*/args[0], args[1], args[2], args[3]);}
517
	};
368
	};
518
519
	scriptObjectOwner = new XPCOMObject (new int[] {2, 0, 0, 2, 1}) {
520
		@Override
521
		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
522
		@Override
523
		public long /*int*/ method1 (long /*int*/[] args) {return AddRef ();}
524
		@Override
525
		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
526
		@Override
527
		public long /*int*/ method3 (long /*int*/[] args) {return getScriptObject (args[0], args[1]);}
528
		@Override
529
		public long /*int*/ method4 (long /*int*/[] args) {return setScriptObject (args[0]);}
530
	};
531
532
	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}) {
533
		@Override
534
		public long /*int*/ method0 (long /*int*/[] args) {return QueryInterface (args[0], args[1]);}
535
		@Override
536
		public long /*int*/ method1 (long /*int*/[] args) {return AddRef ();}
537
		@Override
538
		public long /*int*/ method2 (long /*int*/[] args) {return Release ();}
539
		@Override
540
		public long /*int*/ method3 (long /*int*/[] args) {return getClassName (args[0]);}
541
		@Override
542
		public long /*int*/ method4 (long /*int*/[] args) {return getScriptableFlags ();}
543
		@Override
544
		public long /*int*/ method7 (long /*int*/[] args) {return postCreate (args[0], args[1], args[2]);}
545
	};
546
547
	if (GetScriptableFlags24Proc != null) {
548
		long /*int*/ ppVtable = xpcScriptable.getVtable ();
549
		long /*int*/[] pVtable = new long /*int*/[1];
550
		C.memmove (pVtable, ppVtable, C.PTR_SIZEOF);
551
		long /*int*/[] funcs = new long /*int*/[24];
552
		C.memmove (funcs, pVtable[0], C.PTR_SIZEOF * funcs.length);
553
		funcs[4] = XPCOM.CALLBACK_GetScriptableFlags24 (GetScriptableFlags24Proc.getAddress ());
554
		C.memmove (pVtable[0], funcs, C.PTR_SIZEOF * funcs.length);
555
	}
556
}
369
}
557
370
558
void disposeCOMInterfaces () {
371
void disposeCOMInterfaces () {
Lines 564-585 void disposeCOMInterfaces () { Link Here
564
		classInfo.dispose ();
377
		classInfo.dispose ();
565
		classInfo = null;
378
		classInfo = null;
566
	}
379
	}
567
	if (securityCheckedComponent != null) {
568
		securityCheckedComponent.dispose ();
569
		securityCheckedComponent = null;
570
	}
571
	if (external != null) {
380
	if (external != null) {
572
		external.dispose ();
381
		external.dispose ();
573
		external = null;
382
		external = null;
574
	}
383
	}
575
	if (scriptObjectOwner != null) {
576
		scriptObjectOwner.dispose ();
577
		scriptObjectOwner = null;
578
	}
579
	if (xpcScriptable != null) {
580
		xpcScriptable.dispose ();
581
		xpcScriptable = null;
582
	}
583
}
384
}
584
385
585
long /*int*/ getAddress () {
386
long /*int*/ getAddress () {
Lines 601-632 int QueryInterface (long /*int*/ riid, long /*int*/ ppvObject) { Link Here
601
		AddRef();
402
		AddRef();
602
		return XPCOM.NS_OK;
403
		return XPCOM.NS_OK;
603
	}
404
	}
604
	if (guid.Equals (XPCOM.NS_ISECURITYCHECKEDCOMPONENT_IID)) {
605
		XPCOM.memmove (ppvObject, new long /*int*/[] {securityCheckedComponent.getAddress ()}, C.PTR_SIZEOF);
606
		AddRef();
607
		return XPCOM.NS_OK;
608
	}
609
	if (guid.Equals (EXTERNAL_IID)) {
405
	if (guid.Equals (EXTERNAL_IID)) {
610
		XPCOM.memmove (ppvObject, new long /*int*/[] {external.getAddress ()}, C.PTR_SIZEOF);
406
		XPCOM.memmove (ppvObject, new long /*int*/[] {external.getAddress ()}, C.PTR_SIZEOF);
611
		AddRef();
407
		AddRef();
612
		return XPCOM.NS_OK;
408
		return XPCOM.NS_OK;
613
	}
409
	}
614
410
615
	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR10)) {
616
		if (guid.Equals (XPCOM.NS_ISCRIPTOBJECTOWNER_IID)) {
617
			XPCOM.memmove (ppvObject, new long /*int*/[] {scriptObjectOwner.getAddress ()}, C.PTR_SIZEOF);
618
			AddRef();
619
			return XPCOM.NS_OK;
620
		}
621
		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) {
622
			if (guid.Equals (XPCOM.NS_IXPCSCRIPTABLE_IID)) {
623
				XPCOM.memmove (ppvObject, new long /*int*/[] {xpcScriptable.getAddress ()}, C.PTR_SIZEOF);
624
				AddRef();
625
				return XPCOM.NS_OK;
626
			}
627
		}
628
	}
629
630
	XPCOM.memmove (ppvObject, new long /*int*/[] {0}, C.PTR_SIZEOF);
411
	XPCOM.memmove (ppvObject, new long /*int*/[] {0}, C.PTR_SIZEOF);
631
	return XPCOM.NS_ERROR_NO_INTERFACE;
412
	return XPCOM.NS_ERROR_NO_INTERFACE;
632
}
413
}
Lines 677-683 int getContractID (long /*int*/ _retValue) { Link Here
677
}
458
}
678
459
679
int getFlags (long /*int*/ flags) {
460
int getFlags (long /*int*/ flags) {
680
	C.memmove (flags, new int[] {nsIClassInfo.MAIN_THREAD_ONLY}, 4); /* PRUint32 */
461
	C.memmove (flags, new int[] {nsIClassInfo.DOM_OBJECT}, 4); /* PRUint32 */
681
	return XPCOM.NS_OK;
462
	return XPCOM.NS_OK;
682
}
463
}
683
464
Lines 707-893 int getInterfaces (long /*int*/ count, long /*int*/ array) { Link Here
707
488
708
	nsIMemory memory = new nsIMemory (result[0]);
489
	nsIMemory memory = new nsIMemory (result[0]);
709
	result[0] = 0;
490
	result[0] = 0;
710
	long /*int*/ securityCheckedComponentIID = memory.Alloc (nsID.sizeof);
711
	XPCOM.memmove (securityCheckedComponentIID, XPCOM.NS_ISECURITYCHECKEDCOMPONENT_IID, nsID.sizeof);
712
	long /*int*/ externalIID = memory.Alloc (nsID.sizeof);
491
	long /*int*/ externalIID = memory.Alloc (nsID.sizeof);
713
	XPCOM.memmove (externalIID, EXTERNAL_IID, nsID.sizeof);
492
	XPCOM.memmove (externalIID, EXTERNAL_IID, nsID.sizeof);
714
	long /*int*/ ptrArray = memory.Alloc (3 * C.PTR_SIZEOF);
493
	long /*int*/ ptrArray = memory.Alloc (C.PTR_SIZEOF);
715
	C.memmove (ptrArray, new long /*int*/[] {securityCheckedComponentIID}, C.PTR_SIZEOF);
494
	C.memmove (ptrArray, new long /*int*/[] {externalIID}, C.PTR_SIZEOF);
716
	C.memmove (ptrArray + C.PTR_SIZEOF, new long /*int*/[] {externalIID}, C.PTR_SIZEOF);
717
495
718
	C.memmove (array, new long /*int*/[] {ptrArray}, C.PTR_SIZEOF);
496
	C.memmove (array, new long /*int*/[] {ptrArray}, C.PTR_SIZEOF);
719
	memory.Release ();
497
	memory.Release ();
720
498
721
	C.memmove (count, new int[] {2}, 4); /* PRUint */
499
	C.memmove (count, new int[] {1}, 4); /* PRUint */
722
	return XPCOM.NS_OK;
723
}
724
725
/* nsIScriptObjectOwner */
726
727
int getScriptObject (long /*int*/ aContext, long /*int*/ aScriptObject) {
728
	byte[] jsLibPath = Mozilla.getJSLibPathBytes ();
729
	long /*int*/ nativeContext = XPCOM.nsIScriptContext_GetNativeContext (aContext);
730
	long /*int*/ globalJSObject = XPCOM.JS_GetGlobalObject (jsLibPath, nativeContext);
731
	long /*int*/ newObject = XPCOM.JS_NewObject (jsLibPath, nativeContext, 0, 0, globalJSObject);
732
733
	byte[] functionName = MozillaDelegate.wcsToMbcs (null, CALLJAVA, true);
734
	int flags = XPCOM.JSPROP_ENUMERATE | XPCOM.JSPROP_READONLY | XPCOM.JSPROP_PERMANENT;
735
	XPCOM.JS_DefineFunction (jsLibPath, nativeContext, newObject, functionName, XPCOM.CALLBACK_JSNative (CallJavaProc.getAddress ()), 3, flags);
736
	XPCOM.memmove (aScriptObject, new long /*int*/[] {newObject}, C.PTR_SIZEOF);
737
	return XPCOM.NS_OK;
500
	return XPCOM.NS_OK;
738
}
501
}
739
502
740
int setScriptObject (long /*int*/ aScriptObject) {
741
	return XPCOM.NS_COMFALSE;
742
}
743
744
/* nsISecurityCheckedComponent */
745
746
int canCreateWrapper (long /*int*/ iid, long /*int*/ _retVal) {
747
	long /*int*/[] result = new long /*int*/[1];
748
	int rc = XPCOM.NS_GetServiceManager (result);
749
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
750
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
751
752
	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
753
	result[0] = 0;
754
	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
755
	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
756
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
757
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
758
	serviceManager.Release ();
759
760
	nsIMemory memory = new nsIMemory (result[0]);
761
	result[0] = 0;
762
	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "allAccess", true); //$NON-NLS-1$
763
	long /*int*/ ptr = memory.Alloc (bytes.length);
764
	C.memmove (ptr, bytes, bytes.length);
765
	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
766
	memory.Release ();
767
768
	return XPCOM.NS_OK;
769
}
770
771
int canCallMethod (long /*int*/ iid, long /*int*/ methodName, long /*int*/ _retVal) {
772
	long /*int*/[] result = new long /*int*/[1];
773
	int rc = XPCOM.NS_GetServiceManager (result);
774
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
775
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
776
777
	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
778
	result[0] = 0;
779
	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
780
	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
781
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
782
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
783
	serviceManager.Release ();
784
785
	nsIMemory memory = new nsIMemory (result[0]);
786
	result[0] = 0;
787
	int length = XPCOM.strlen_PRUnichar (methodName);
788
	char[] dest = new char[length];
789
	XPCOM.memmove (dest, methodName, length * 2);
790
	String string = new String (dest);
791
	byte[] bytes;
792
	if (string.equals (CALLJAVA)) {
793
		bytes = MozillaDelegate.wcsToMbcs (null, "allAccess", true); //$NON-NLS-1$ 
794
	} else {
795
		bytes = MozillaDelegate.wcsToMbcs (null, "noAccess", true); //$NON-NLS-1$
796
	}
797
	long /*int*/ ptr = memory.Alloc (bytes.length);
798
	C.memmove (ptr, bytes, bytes.length);
799
	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
800
	memory.Release ();
801
802
	return XPCOM.NS_OK;
803
}
804
805
int canGetProperty (long /*int*/ iid, long /*int*/ propertyName, long /*int*/ _retVal) {
806
	long /*int*/[] result = new long /*int*/[1];
807
	int rc = XPCOM.NS_GetServiceManager (result);
808
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
809
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
810
811
	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
812
	result[0] = 0;
813
	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
814
	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
815
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
816
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
817
	serviceManager.Release ();
818
819
	nsIMemory memory = new nsIMemory (result[0]);
820
	result[0] = 0;
821
	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "noAccess", true); //$NON-NLS-1$
822
	long /*int*/ ptr = memory.Alloc (bytes.length);
823
	C.memmove (ptr, bytes, bytes.length);
824
	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
825
	memory.Release ();
826
827
	return XPCOM.NS_OK;
828
}
829
830
int canSetProperty (long /*int*/ iid, long /*int*/ propertyName, long /*int*/ _retVal) {
831
	long /*int*/[] result = new long /*int*/[1];
832
	int rc = XPCOM.NS_GetServiceManager (result);
833
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
834
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
835
836
	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
837
	result[0] = 0;
838
	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
839
	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
840
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
841
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
842
	serviceManager.Release ();
843
844
	nsIMemory memory = new nsIMemory (result[0]);
845
	result[0] = 0;
846
	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "noAccess", true); //$NON-NLS-1$
847
	long /*int*/ ptr = memory.Alloc (bytes.length);
848
	C.memmove (ptr, bytes, bytes.length);
849
	C.memmove (_retVal, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
850
	memory.Release ();
851
852
	return XPCOM.NS_OK;
853
}
854
855
/* nsIXPCScriptable */
856
857
long /*int*/ getClassName (long /*int*/ aClassName) {
858
	long /*int*/[] result = new long /*int*/[1];
859
	int rc = XPCOM.NS_GetServiceManager (result);
860
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
861
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);
862
863
	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
864
	result[0] = 0;
865
	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_MEMORY_CONTRACTID, true);
866
	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIMemory.class), result);
867
	if (rc != XPCOM.NS_OK) Mozilla.error (rc);
868
	if (result[0] == 0) Mozilla.error (XPCOM.NS_NOINTERFACE);		
869
	serviceManager.Release ();
870
871
	nsIMemory memory = new nsIMemory (result[0]);
872
	result[0] = 0;
873
	byte[] bytes = MozillaDelegate.wcsToMbcs (null, "external", true); //$NON-NLS-1$
874
	long /*int*/ ptr = memory.Alloc (bytes.length);
875
	C.memmove (ptr, bytes, bytes.length);
876
	C.memmove (aClassName, new long /*int*/[] {ptr}, C.PTR_SIZEOF);
877
	memory.Release ();
878
879
	return 0;
880
}
881
882
static long /*int*/ getScriptableFlags () {
883
	return XPCOM.WANT_POSTCREATE | XPCOM.USE_JSSTUB_FOR_ADDPROPERTY;
884
}
885
886
int postCreate (long /*int*/ wrapper, long /*int*/ cx, long /*int*/ obj) {
887
	byte[] functionName = MozillaDelegate.wcsToMbcs (null, CALLJAVA, true);
888
	int flags = XPCOM.JSPROP_ENUMERATE | XPCOM.JSPROP_READONLY | XPCOM.JSPROP_PERMANENT;
889
	XPCOM.JS_DefineFunction24 (cx, obj, functionName, XPCOM.CALLBACK_JSNative (CallJavaProc.getAddress ()), 3, flags);
890
	return 0;
891
}
892
893
}
503
}
(-)a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java (-39 / +131 lines)
Lines 702-708 public void create (Composite parent, int style) { Link Here
702
			LocationProvider = new AppFileLocProvider (MozillaPath, profilePath, cacheParentPath, IsXULRunner);
702
			LocationProvider = new AppFileLocProvider (MozillaPath, profilePath, cacheParentPath, IsXULRunner);
703
			LocationProvider.AddRef ();
703
			LocationProvider.AddRef ();
704
704
705
			/* write external.xpt to the file system if needed */
705
			/* write swt.xpt to the file system if needed */
706
			initExternal (LocationProvider.profilePath);
706
			initExternal (LocationProvider.profilePath);
707
707
708
			/* invoke appropriate Init function (based on mozilla version) */
708
			/* invoke appropriate Init function (based on mozilla version) */
Lines 1392-1397 void disposeCOMInterfaces () { Link Here
1392
}
1392
}
1393
1393
1394
@Override
1394
@Override
1395
public Object evaluate (String script) throws SWTException {
1396
	if (!MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24))
1397
		return super.evaluate (script);
1398
1399
	delegate.removeWindowSubclass ();
1400
1401
	long /*int*/[] result = new long /*int*/[1];
1402
	int rc = webBrowser.QueryInterface(IIDStore.GetIID (nsIInterfaceRequestor.class), result);
1403
	if (rc != XPCOM.NS_OK) error (rc);
1404
	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1405
	nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor (result[0]);
1406
	result[0] = 0;
1407
	rc = XPCOM.NS_GetServiceManager (result);
1408
	if (rc != XPCOM.NS_OK) error (rc);
1409
	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1410
1411
	nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
1412
	result[0] = 0;
1413
	rc = interfaceRequestor.GetInterface (IIDStore.GetIID (nsIDOMWindow.class), result);
1414
	interfaceRequestor.Release ();
1415
	if (rc != XPCOM.NS_OK) error (rc);
1416
	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1417
1418
	nsIDOMWindow window = new nsIDOMWindow (result[0]);
1419
	result[0] = 0;
1420
	byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.EXECUTE_CONTRACTID, true);
1421
	rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (Execute.class), result);
1422
	if (rc != XPCOM.NS_OK) error (rc);
1423
	if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1424
1425
	Execute execute = new Execute (result[0]);
1426
	result[0] = 0;
1427
	nsEmbedString data = new nsEmbedString (script);
1428
	execute.EvalInWindow (window, data, result);
1429
	data.dispose ();
1430
	execute.Release ();
1431
	if (result[0] == 0)
1432
		return null;
1433
1434
	nsIVariant variant = new nsIVariant (result[0]);
1435
	Object retval = External.convertToJava (variant);
1436
	variant.Release ();
1437
	return retval;
1438
}
1439
@Override
1395
public boolean execute (String script) {
1440
public boolean execute (String script) {
1396
	/*
1441
	/*
1397
	* This could be the first content that is set into the browser, so
1442
	* This could be the first content that is set into the browser, so
Lines 1400-1405 public boolean execute (String script) { Link Here
1400
	*/
1445
	*/
1401
	delegate.removeWindowSubclass ();
1446
	delegate.removeWindowSubclass ();
1402
1447
1448
	long /*int*/[] result = new long /*int*/[1];
1449
	/*
1450
	* As of mozilla 1.9 executing javascript via the javascript: protocol no
1451
	* longer happens synchronously.  As a result, the result of executing JS
1452
	* is not returned to the java side when expected by the client.  The
1453
	* workaround for version 24 is to use a javascript-implemented component
1454
	* which then executes synchronously.
1455
	*/
1456
	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) {
1457
		result[0] = 0;
1458
		int rc = webBrowser.QueryInterface(IIDStore.GetIID (nsIInterfaceRequestor.class), result);
1459
		if (rc != XPCOM.NS_OK) error (rc);
1460
		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1461
		nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor (result[0]);
1462
		result[0] = 0;
1463
		rc = XPCOM.NS_GetServiceManager (result);
1464
		if (rc != XPCOM.NS_OK) error (rc);
1465
		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1466
1467
		nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
1468
		result[0] = 0;
1469
		rc = interfaceRequestor.GetInterface (IIDStore.GetIID (nsIDOMWindow.class), result);
1470
		interfaceRequestor.Release ();
1471
		if (rc != XPCOM.NS_OK) error (rc);
1472
		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1473
1474
		nsIDOMWindow window = new nsIDOMWindow (result[0]);
1475
		result[0] = 0;
1476
		byte[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.EXECUTE_CONTRACTID, true);
1477
		rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (Execute.class), result);
1478
		if (rc != XPCOM.NS_OK) error (rc);
1479
		if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
1480
1481
		Execute execute = new Execute (result[0]);
1482
		result[0] = 0;
1483
		nsEmbedString data = new nsEmbedString (script);
1484
		execute.EvalInWindow (window, data, result);
1485
		if (result[0] != 0)
1486
			new nsIVariant (result[0]).Release ();
1487
		data.dispose ();
1488
		execute.Release ();
1489
		return true;
1490
	}
1491
1403
	/*
1492
	/*
1404
	* As of mozilla 1.9 executing javascript via the javascript: protocol no
1493
	* As of mozilla 1.9 executing javascript via the javascript: protocol no
1405
	* longer happens synchronously.  As a result, the result of executing JS
1494
	* longer happens synchronously.  As a result, the result of executing JS
Lines 1407-1413 public boolean execute (String script) { Link Here
1407
	* workaround is to invoke the javascript handler directly via C++, which is
1496
	* workaround is to invoke the javascript handler directly via C++, which is
1408
	* exposed as of mozilla 1.9.
1497
	* exposed as of mozilla 1.9.
1409
	*/
1498
	*/
1410
	long /*int*/[] result = new long /*int*/[1];
1411
	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR1_9)) {
1499
	if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR1_9)) {
1412
		int rc = XPCOM.NS_GetServiceManager (result);
1500
		int rc = XPCOM.NS_GetServiceManager (result);
1413
		if (rc != XPCOM.NS_OK) error (rc);
1501
		if (rc != XPCOM.NS_OK) error (rc);
Lines 1439-1458 public boolean execute (String script) { Link Here
1439
				if (rc == XPCOM.NS_OK && result[0] != 0) {
1527
				if (rc == XPCOM.NS_OK && result[0] != 0) {
1440
					long /*int*/ scriptGlobalObject = result[0];
1528
					long /*int*/ scriptGlobalObject = result[0];
1441
					result[0] = 0;
1529
					result[0] = 0;
1442
					if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
1530
					rc = (int/*64*/)XPCOM.nsIScriptGlobalObject_EnsureScriptEnvironment (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
1443
						rc = (int/*64*/)XPCOM.nsIScriptGlobalObject24_EnsureScriptEnvironment (scriptGlobalObject);
1444
					} else {
1445
						rc = (int/*64*/)XPCOM.nsIScriptGlobalObject_EnsureScriptEnvironment (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
1446
					}
1447
					if (rc != XPCOM.NS_OK) {
1531
					if (rc != XPCOM.NS_OK) {
1448
						new nsISupports (scriptGlobalObject).Release ();
1532
						new nsISupports (scriptGlobalObject).Release ();
1449
					} else {
1533
					} else {
1450
						long /*int*/ scriptContext;
1534
						long /*int*/ scriptContext = XPCOM.nsIScriptGlobalObject_GetScriptContext (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
1451
						if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
1452
							scriptContext = XPCOM.nsIScriptGlobalObject24_GetScriptContext (scriptGlobalObject);
1453
						} else {
1454
							scriptContext = XPCOM.nsIScriptGlobalObject_GetScriptContext (scriptGlobalObject, 2); /* nsIProgrammingLanguage.JAVASCRIPT */
1455
						}
1456
1535
1457
						if (scriptContext != 0) {
1536
						if (scriptContext != 0) {
1458
							/* ensure that the received nsIScriptContext implements the expected interface */
1537
							/* ensure that the received nsIScriptContext implements the expected interface */
Lines 1462-1473 public boolean execute (String script) { Link Here
1462
								new nsISupports (result[0]).Release ();
1541
								new nsISupports (result[0]).Release ();
1463
								result[0] = 0;
1542
								result[0] = 0;
1464
1543
1465
								long /*int*/ jsContext;
1544
								long /*int*/ jsContext = XPCOM.nsIScriptContext_GetNativeContext (scriptContext);
1466
								if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
1467
									jsContext = XPCOM.nsIScriptContext24_GetNativeContext (scriptContext);
1468
								} else {
1469
									jsContext = XPCOM.nsIScriptContext_GetNativeContext (scriptContext);
1470
								}
1471
								if (jsContext != 0) {
1545
								if (jsContext != 0) {
1472
									int length = script.length ();
1546
									int length = script.length ();
1473
									char[] scriptChars = new char[length];
1547
									char[] scriptChars = new char[length];
Lines 1480-1501 public boolean execute (String script) { Link Here
1480
										result[0] = 0;
1554
										result[0] = 0;
1481
									}
1555
									}
1482
									byte[] jsLibPath = getJSLibPathBytes ();
1556
									byte[] jsLibPath = getJSLibPathBytes ();
1483
									long /*int*/ globalJSObject;
1557
									long /*int*/ globalJSObject = XPCOM.JS_GetGlobalObject (jsLibPath, jsContext);
1484
									if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
1485
										globalJSObject = XPCOM.nsIScriptGlobalObject24_GetGlobalJSObject (scriptGlobalObject);
1486
									} else {
1487
										globalJSObject = XPCOM.JS_GetGlobalObject (jsLibPath, jsContext);
1488
									}
1489
									if (globalJSObject != 0) {
1558
									if (globalJSObject != 0) {
1490
										if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24)) { /* >= 24.x */
1491
											boolean success = XPCOM.JS_EvaluateUCScriptForPrincipals24 (jsLibPath, jsContext, globalJSObject, principals, scriptChars, length, urlbytes, 0, 0) != 0;
1492
											// should principals be Release()d too?
1493
											new nsISupports (scriptGlobalObject).Release ();
1494
											principal.Release ();
1495
											serviceManager.Release ();
1496
											return success;
1497
										}
1498
										/* 1.9.x - 10.x */
1499
										aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_CONTEXTSTACK_CONTRACTID, true);
1559
										aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_CONTEXTSTACK_CONTRACTID, true);
1500
										rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIJSContextStack.class), result);
1560
										rc = serviceManager.GetServiceByContractID (aContractID, IIDStore.GetIID (nsIJSContextStack.class), result);
1501
										if (rc == XPCOM.NS_OK && result[0] != 0) {
1561
										if (rc == XPCOM.NS_OK && result[0] != 0) {
Lines 1896-1909 static String InitDiscoverXULRunner () { Link Here
1896
1956
1897
void initExternal (String profilePath) {
1957
void initExternal (String profilePath) {
1898
	File componentsDir = new File (profilePath, AppFileLocProvider.COMPONENTS_DIR);
1958
	File componentsDir = new File (profilePath, AppFileLocProvider.COMPONENTS_DIR);
1899
	java.io.InputStream is = Library.class.getResourceAsStream ("/external.xpt"); //$NON-NLS-1$
1959
	java.io.InputStream is = Library.class.getResourceAsStream ("/swt.xpt"); //$NON-NLS-1$
1900
	if (is != null) {
1960
	if (is != null) {
1901
		if (!componentsDir.exists ()) {
1961
		if (!componentsDir.exists ()) {
1902
			componentsDir.mkdirs ();
1962
			componentsDir.mkdirs ();
1903
		}
1963
		}
1904
		int read;
1964
		int read;
1905
		byte [] buffer = new byte [4096];
1965
		byte [] buffer = new byte [4096];
1906
		File file = new File (componentsDir, "external.xpt"); //$NON-NLS-1$
1966
		File file = new File (componentsDir, "swt.xpt"); //$NON-NLS-1$
1967
		try {
1968
			FileOutputStream os = new FileOutputStream (file);
1969
			while ((read = is.read (buffer)) != -1) {
1970
				os.write(buffer, 0, read);
1971
			}
1972
			os.close ();
1973
			is.close ();
1974
		} catch (FileNotFoundException e) {
1975
		} catch (IOException e) {
1976
		}
1977
	}
1978
	is = Library.class.getResourceAsStream ("/swt.js"); //$NON-NLS-1$
1979
	if (is != null) {
1980
		if (!componentsDir.exists ()) {
1981
			componentsDir.mkdirs ();
1982
		}
1983
		int read;
1984
		byte [] buffer = new byte [4096];
1985
		File file = new File (componentsDir, "swt.js"); //$NON-NLS-1$
1986
		try {
1987
			FileOutputStream os = new FileOutputStream (file);
1988
			while ((read = is.read (buffer)) != -1) {
1989
				os.write(buffer, 0, read);
1990
			}
1991
			os.close ();
1992
			is.close ();
1993
		} catch (FileNotFoundException e) {
1994
		} catch (IOException e) {
1995
		}
1996
	}
1997
	is = Library.class.getResourceAsStream ("/chrome.manifest"); //$NON-NLS-1$
1998
	if (is != null) {
1999
		int read;
2000
		byte [] buffer = new byte [4096];
2001
		File file = new File (profilePath, "chrome.manifest"); //$NON-NLS-1$
1907
		try {
2002
		try {
1908
			FileOutputStream os = new FileOutputStream (file);
2003
			FileOutputStream os = new FileOutputStream (file);
1909
			while ((read = is.read (buffer)) != -1) {
2004
			while ((read = is.read (buffer)) != -1) {
Lines 2182-2190 void initXPCOM (String mozillaPath, boolean isXULRunner) { Link Here
2182
			error (XPCOM.NS_ERROR_NULL_POINTER);
2277
			error (XPCOM.NS_ERROR_NULL_POINTER);
2183
		}
2278
		}
2184
2279
2185
		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR24, true)) {
2186
			Library.loadLibrary("swt-xulrunner24"); //$NON-NLS-1$
2187
		}
2188
		MozillaDelegate.loadAdditionalLibraries (mozillaPath, true);
2280
		MozillaDelegate.loadAdditionalLibraries (mozillaPath, true);
2189
2281
2190
		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR10)) {
2282
		if (MozillaVersion.CheckVersion (MozillaVersion.VERSION_XR10)) {
(-)a/bundles/org.eclipse.swt/Eclipse (+48 lines)
Added Link Here
1
/* ***** BEGIN LICENSE BLOCK *****
2
 * Version: MPL 1.1
3
 *
4
 * The contents of this file are subject to the Mozilla Public License Version
5
 * 1.1 (the "License"); you may not use this file except in compliance with
6
 * the License. You may obtain a copy of the License at
7
 * http://www.mozilla.org/MPL/
8
 *
9
 * Software distributed under the License is distributed on an "AS IS" basis,
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
 * for the specific language governing rights and limitations under the
12
 * License.
13
 *
14
 * The Original Code is Mozilla Communicator client code, released March 31, 1998.
15
 *
16
 * The Initial Developer of the Original Code is
17
 * Netscape Communications Corporation.
18
 * Portions created by Netscape are Copyright (C) 1998-1999
19
 * Netscape Communications Corporation.  All Rights Reserved.
20
 *
21
 * Contributor(s):
22
 *
23
 * IBM
24
 * -  Binding to permit interfacing between Mozilla and SWT
25
 * -  Copyright (C) 2003, 2012 IBM Corp.  All Rights Reserved.
26
 *
27
 * ***** END LICENSE BLOCK ***** */
28
package org.eclipse.swt.internal.mozilla;
29
30
31
public class Execute extends nsISupports {
32
33
	static final int LAST_METHOD_ID = nsISupports.LAST_METHOD_ID + 3;
34
35
	static final String EXECUTE_IID_STR = "75a03044-d129-4d96-9292-bc1623876de1";
36
37
	static {
38
		IIDStore.RegisterIID(Execute.class, MozillaVersion.VERSION_BASE, new nsID(EXECUTE_IID_STR));
39
	}
40
41
	public Execute(long /*int*/ address) {
42
		super(address);
43
	}
44
45
	public int EvalInWindow(nsIDOMWindow aWindow, nsEmbedString code, long /*int*/[] aVariant) {
46
    return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 1, getAddress(), aWindow.getAddress(), code.getAddress(), aVariant);
47
	}
48
}
(-)a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java (-99 / +1 lines)
Lines 92-97 public class XPCOM extends C { Link Here
92
	public static final nsID NS_IXPCSCRIPTABLE_IID = new nsID ("155d1863-2b0b-4f5e-b800-05184944156b"); //$NON-NLS-1$
92
	public static final nsID NS_IXPCSCRIPTABLE_IID = new nsID ("155d1863-2b0b-4f5e-b800-05184944156b"); //$NON-NLS-1$
93
93
94
	/* contract ID constants */
94
	/* contract ID constants */
95
	public static final String EXECUTE_CONTRACTID = "@eclipse.org/execute;1"; //$NON-NLS-1$
95
	public static final String EXTERNAL_CONTRACTID = "@eclipse.org/external;1"; //$NON-NLS-1$
96
	public static final String EXTERNAL_CONTRACTID = "@eclipse.org/external;1"; //$NON-NLS-1$
96
	public static final String NS_AUTHPROMPTER_CONTRACTID = "@mozilla.org/passwordmanager/authpromptfactory;1"; //$NON-NLS-1$
97
	public static final String NS_AUTHPROMPTER_CONTRACTID = "@mozilla.org/passwordmanager/authpromptfactory;1"; //$NON-NLS-1$
97
	public static final String NS_CERTOVERRIDE_CONTRACTID = "@mozilla.org/security/certoverride;1"; //$NON-NLS-1$
98
	public static final String NS_CERTOVERRIDE_CONTRACTID = "@mozilla.org/security/certoverride;1"; //$NON-NLS-1$
Lines 175-189 public class XPCOM extends C { Link Here
175
	public static final int SEC_ERROR_UNTRUSTED_CERT = 0x805A1FEB;
176
	public static final int SEC_ERROR_UNTRUSTED_CERT = 0x805A1FEB;
176
	public static final int SEC_ERROR_UNTRUSTED_ISSUER = 0x805A1FEC;
177
	public static final int SEC_ERROR_UNTRUSTED_ISSUER = 0x805A1FEC;
177
	public static final int SSL_ERROR_BAD_CERT_DOMAIN = 0x805A2FF4;
178
	public static final int SSL_ERROR_BAD_CERT_DOMAIN = 0x805A2FF4;
178
	public static final int USE_JSSTUB_FOR_ADDPROPERTY = 1 << 17;
179
	public static final int WANT_POSTCREATE = 4;
180
181
	/* JSAPI constants */
182
	public static final int JSPROP_ENUMERATE = 0x1;
183
	public static final int JSPROP_PERMANENT = 0x4;
184
	public static final int JSPROP_READONLY = 0x2;
185
	public static final int JS_FALSE = 0x0;
186
	public static final int JS_TRUE = 0x1;
187
179
188
public static final native int nsDynamicFunctionLoad_sizeof ();
180
public static final native int nsDynamicFunctionLoad_sizeof ();
189
181
Lines 234-259 public static final native long /*int*/ CALLBACK_GetScriptableFlags24(long /*int Link Here
234
public static final native long /*int*/ CALLBACK_JSNative(long /*int*/ func);
226
public static final native long /*int*/ CALLBACK_JSNative(long /*int*/ func);
235
227
236
/** @method flags=no_gen */
228
/** @method flags=no_gen */
237
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);	
238
public static final long /*int*/ JS_DefineFunction(byte[] mozillaPath, long /*int*/ cx, long /*int*/ obj, byte[] name, long /*int*/ call, int nargs, int flags) {
239
	lock.lock();
240
	try {
241
		return _JS_DefineFunction(mozillaPath, cx, obj, name, call, nargs, flags);
242
	} finally {
243
		lock.unlock();
244
	}
245
}
246
/** @method flags=no_gen */
247
public static final native long /*int*/ _JS_DefineFunction24(long /*int*/ cx, long /*int*/ obj, byte[] name, long /*int*/ call, int nargs, int flags);	
248
public static final long /*int*/ JS_DefineFunction24(long /*int*/ cx, long /*int*/ obj, byte[] name, long /*int*/ call, int nargs, int flags) {
249
	lock.lock();
250
	try {
251
		return _JS_DefineFunction24(cx, obj, name, call, nargs, flags);
252
	} finally {
253
		lock.unlock();
254
	}
255
}
256
/** @method flags=no_gen */
257
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);	
229
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);	
258
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) {
230
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) {
259
	lock.lock();
231
	lock.lock();
Lines 274-299 public static final int JS_EvaluateUCScriptForPrincipals191(byte[] mozillaPath, Link Here
274
	}
246
	}
275
}
247
}
276
/** @method flags=no_gen */
248
/** @method flags=no_gen */
277
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);	
278
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) {
279
	lock.lock();
280
	try {
281
		return _JS_EvaluateUCScriptForPrincipals24(mozillaPath, cx, obj, principals, chars, length, filename, lineno, retVal);
282
	} finally {
283
		lock.unlock();
284
	}
285
}
286
/** @method flags=no_gen */
287
public static final native long /*int*/ _JS_GetGlobalForScopeChain24(long /*int*/ cx);	
288
public static final long /*int*/ JS_GetGlobalForScopeChain24(long /*int*/ cx) {
289
	lock.lock();
290
	try {
291
		return _JS_GetGlobalForScopeChain24(cx);
292
	} finally {
293
		lock.unlock();
294
	}
295
}
296
/** @method flags=no_gen */
297
public static final native long /*int*/ _JS_GetGlobalObject(byte[] mozillaPath, long /*int*/ cx);	
249
public static final native long /*int*/ _JS_GetGlobalObject(byte[] mozillaPath, long /*int*/ cx);	
298
public static final long /*int*/ JS_GetGlobalObject(byte[] mozillaPath, long /*int*/ cx) {
250
public static final long /*int*/ JS_GetGlobalObject(byte[] mozillaPath, long /*int*/ cx) {
299
	lock.lock();
251
	lock.lock();
Lines 304-319 public static final long /*int*/ JS_GetGlobalObject(byte[] mozillaPath, long /*i Link Here
304
	}
256
	}
305
}
257
}
306
/** @method flags=no_gen */
258
/** @method flags=no_gen */
307
public static final native long /*int*/ _JS_NewObject(byte[] mozillaPath, long /*int*/ cx, long /*int*/ clasp, long /*int*/ proto, long /*int*/ parent);	
308
public static final long /*int*/ JS_NewObject(byte[] mozillaPath, long /*int*/ cx, long /*int*/ clasp, long /*int*/ proto, long /*int*/ parent) {
309
	lock.lock();
310
	try {
311
		return _JS_NewObject(mozillaPath, cx, clasp, proto, parent);
312
	} finally {
313
		lock.unlock();
314
	}
315
}
316
/** @method flags=no_gen */
317
public static final native boolean _NS_Free(byte[] mozillaPath, long /*int*/ aPtr);
259
public static final native boolean _NS_Free(byte[] mozillaPath, long /*int*/ aPtr);
318
public static final boolean NS_Free(byte[] mozillaPath, long /*int*/ aPtr) {
260
public static final boolean NS_Free(byte[] mozillaPath, long /*int*/ aPtr) {
319
	lock.lock();
261
	lock.lock();
Lines 445-470 public static final int nsIScriptGlobalObject_EnsureScriptEnvironment(long /*int Link Here
445
		lock.unlock();
387
		lock.unlock();
446
	}
388
	}
447
}
389
}
448
/** @method flags=no_gen */
449
public static final native int _nsIScriptGlobalObject24_EnsureScriptEnvironment(long /*int*/ ptr);
450
public static final int nsIScriptGlobalObject24_EnsureScriptEnvironment(long /*int*/ ptr) {
451
	lock.lock();
452
	try {
453
		return _nsIScriptGlobalObject24_EnsureScriptEnvironment(ptr);
454
	} finally {
455
		lock.unlock();
456
	}
457
}
458
/** @method flags=no_gen */
459
public static final native long /*int*/ _nsIScriptGlobalObject24_GetGlobalJSObject(long /*int*/ ptr);
460
public static final long /*int*/ nsIScriptGlobalObject24_GetGlobalJSObject(long /*int*/ ptr) {
461
	lock.lock();
462
	try {
463
		return _nsIScriptGlobalObject24_GetGlobalJSObject(ptr);
464
	} finally {
465
		lock.unlock();
466
	}
467
}
468
/**
390
/**
469
 * @method flags=cpp
391
 * @method flags=cpp
470
 * @param ptr cast=(nsIScriptGlobalObject *)
392
 * @param ptr cast=(nsIScriptGlobalObject *)
Lines 478-493 public static final long /*int*/ nsIScriptGlobalObject_GetScriptContext(long /*i Link Here
478
		lock.unlock();
400
		lock.unlock();
479
	}
401
	}
480
}
402
}
481
/** @method flags=no_gen */
482
public static final native long /*int*/ _nsIScriptGlobalObject24_GetScriptContext(long /*int*/ ptr);
483
public static final long /*int*/ nsIScriptGlobalObject24_GetScriptContext(long /*int*/ ptr) {
484
	lock.lock();
485
	try {
486
		return _nsIScriptGlobalObject24_GetScriptContext(ptr);
487
	} finally {
488
		lock.unlock();
489
	}
490
}
491
/**
403
/**
492
 * @method flags=cpp
404
 * @method flags=cpp
493
 * @param ptr cast=(nsIScriptContext *)
405
 * @param ptr cast=(nsIScriptContext *)
Lines 501-516 public static final long /*int*/ nsIScriptContext_GetNativeContext(long /*int*/ Link Here
501
		lock.unlock();
413
		lock.unlock();
502
	}
414
	}
503
}
415
}
504
/** @method flags=no_gen */
505
public static final native long /*int*/ _nsIScriptContext24_GetNativeContext(long /*int*/ ptr);
506
public static final long /*int*/ nsIScriptContext24_GetNativeContext(long /*int*/ ptr) {
507
	lock.lock();
508
	try {
509
		return _nsIScriptContext24_GetNativeContext(ptr);
510
	} finally {
511
		lock.unlock();
512
	}
513
}
514
/**
416
/**
515
 * @method flags=cpp
417
 * @method flags=cpp
516
 * @param ptr cast=(nsEmbedCString *)
418
 * @param ptr cast=(nsEmbedCString *)
(-)a/bundles/org.eclipse.swt/components/external.idl (-21 lines)
Lines 1-21 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
// to compile: xpidl -m typelib -I S:\swt-builddir\gecko-sdk\idl\ -e external.xpt external.idl
13
14
#include "nsISupports.idl"
15
#include "nsIVariant.idl"
16
17
[scriptable, uuid(ded01d20-ba6f-11dd-ad8b-0800200c9a66)]
18
19
interface External : nsISupports {
20
    nsIVariant callJava (in unsigned long index, in nsIVariant token, in nsIVariant args);
21
};
(-)a/bundles/org.eclipse.swt/components/swt.idl (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
// to compile: xpidl -m typelib -I S:\swt-builddir\gecko-sdk\idl\ -e external.xpt external.idl
13
14
#include "nsISupports.idl"
15
interface nsIVariant;
16
interface nsIDOMWindow;
17
18
[scriptable, uuid(ded01d20-ba6f-11dd-ad8b-0800200c9a66)]
19
20
interface External : nsISupports {
21
    nsIVariant callJava (in unsigned long index, in nsIVariant token, in nsIVariant args);
22
};
23
24
[scriptable, uuid(75a03044-d129-4d96-9292-bc1623876de1)]
25
26
interface Execute : nsISupports {
27
    nsIVariant evalInWindow (in nsIDOMWindow window, in AString code);
28
    nsIVariant evalAsChrome (in nsIDOMWindow window, in AString code);
29
    void evalAsync (in nsIDOMWindow window, in AString code);
30
};
(-)a/bundles/org.eclipse.swt/components/swt.js (+30 lines)
Added Link Here
1
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
2
3
function execute() {
4
}
5
6
execute.prototype.evalInWindow = function(aWindow, aString) {
7
    aWindow = XPCNativeWrapper.unwrap(aWindow);
8
    try {
9
        aWindow.external.QueryInterface(Components.interfaces.External);
10
    } catch (e) {
11
        aWindow.external = Components.classes["@eclipse.org/external;1"].createInstance();
12
    }
13
    return aWindow.eval(aString);
14
};
15
16
execute.prototype.evalAsChrome = function(aWindow, aString) {
17
    with (aWindow) {
18
        return eval(aString);
19
    }
20
};
21
22
execute.prototype.evalAsync = function(aWindow, aString) {
23
    aWindow.location = "javascript:" + unescape(aString) + ";void(0);";
24
};
25
26
execute.prototype.QueryInterface = XPCOMUtils.generateQI([Components.interfaces.Execute]);
27
28
execute.prototype.classID = Components.ID("{0aebcff1-f7b3-4522-a64b-1706d65dc232}");
29
30
var NSGetFactory = XPCOMUtils.generateNSGetFactory([execute]);

Return to bug 429739