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 168597 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/hyades/execution/recorder/local/appadapters/InternetExplorerAdapter.java (-11 / +182 lines)
Lines 27-32 Link Here
27
import org.eclipse.hyades.test.core.internal.resources.TestCorePluginResourceBundle;
27
import org.eclipse.hyades.test.core.internal.resources.TestCorePluginResourceBundle;
28
28
29
29
30
31
30
/**
32
/**
31
 * This object is the client object for a RecorderApplication extension point (point org.eclipse.hyades.execution.recorder.RecorderApplication)
33
 * This object is the client object for a RecorderApplication extension point (point org.eclipse.hyades.execution.recorder.RecorderApplication)
32
 * it contains logic for initializing, starting, and stopping Internet Explorer.  In particular, this object is able
34
 * it contains logic for initializing, starting, and stopping Internet Explorer.  In particular, this object is able
Lines 78-90 Link Here
78
	// bugzilla 165310 mdd
80
	// bugzilla 165310 mdd
79
	final String mylocalhost = "127.0.0.1:";
81
	final String mylocalhost = "127.0.0.1:";
80
	
82
	
83
	// bugzilla 168597
84
	/* Later we may want to change this to always use native code
85
	 * to get and set Internet Explorer registry settings.
86
	 * 
87
	 * For this defect fix, we will determine that our attempt to run regedit.exe
88
	 * has failed running on Vista without using "Run as Administrator" elevated privileges
89
	 * 
90
	 * When this happens, we will set the boolean below true and create an instance of JNIWrapper class.
91
	 * The JNIWrapper class will load the native DLL and make the calls into native code.
92
	 * 
93
	 */
94
	private boolean bUseNativeRegistryInterface = false;
95
	private JNIWrapper jniWrapper = null;
96
	
81
	public void init(String initInfo) throws RecorderApplicationAdapterException
97
	public void init(String initInfo) throws RecorderApplicationAdapterException
82
	{
98
	{
99
				
83
		// bugzilla 114253 set the path of temp files to the workspace path
100
		// bugzilla 114253 set the path of temp files to the workspace path
84
		setTempFilePaths();
101
		setTempFilePaths();
85
				
102
				
86
		parseInitInfo(initInfo);	
103
		parseInitInfo(initInfo);
87
		StringBuffer inputFileContents = getRegistryInfo();
104
		StringBuffer inputFileContents = getRegistryInfo();
105
		// Bugilla 168597		
106
		if (bUseNativeRegistryInterface)
107
			inputFileContents = getRegistryInfoUsingNativeAPI();
108
		createOriginalRegSettingsFile(inputFileContents);
88
		
109
		
89
		StringBuffer outputFileContents = new StringBuffer();
110
		StringBuffer outputFileContents = new StringBuffer();
90
		// new mdd hyades 1.3 check for http
111
		// new mdd hyades 1.3 check for http
Lines 101-116 Link Here
101
				StringTokenizer lineTokenizer = new StringTokenizer(line,":");//$NON-NLS-1$
122
				StringTokenizer lineTokenizer = new StringTokenizer(line,":");//$NON-NLS-1$
102
				newLine=lineTokenizer.nextToken();
123
				newLine=lineTokenizer.nextToken();
103
				newLine+=":00000001";//$NON-NLS-1$
124
				newLine+=":00000001";//$NON-NLS-1$
125
				setNativeRegistryValue(newLine);
126
				outputFileContents.append(newLine+"\r\n");//$NON-NLS-1$				
104
				if (isProxyEnabled){
127
				if (isProxyEnabled){
105
					// newLine+="\r\n\"ProxyServer\"=\"http=localhost:" + portnum;//$NON-NLS-1$
128
					// newLine+="\r\n\"ProxyServer\"=\"http=localhost:" + portnum;//$NON-NLS-1$
106
					newLine+="\r\n\"ProxyServer\"=\"http=" + mylocalhost+  portnum;//$NON-NLS-1$
129
					newLine="\"ProxyServer\"=\"http=" + mylocalhost+  portnum;//$NON-NLS-1$
107
					newLine += ";https=" + mylocalhost + portnum + "\"";
130
					newLine += ";https=" + mylocalhost + portnum + "\"";
108
				}
131
				}
109
				else {
132
				else {
110
					// newLine+="\r\n\"ProxyServer\"=\"socks=localhost:";//$NON-NLS-1$
133
					// newLine+="\r\n\"ProxyServer\"=\"socks=localhost:";//$NON-NLS-1$
111
					newLine+="\r\n\"ProxyServer\"=\"socks=" + mylocalhost;//$NON-NLS-1$
134
					newLine="\"ProxyServer\"=\"socks=" + mylocalhost;//$NON-NLS-1$
112
					newLine+=portnum+"\"";//$NON-NLS-1$
135
					newLine+=portnum+"\"";//$NON-NLS-1$
113
				}				
136
				}								
137
				
114
			}
138
			}
115
			else if(line.startsWith("\"ProxyHttp1.1"))//$NON-NLS-1$
139
			else if(line.startsWith("\"ProxyHttp1.1"))//$NON-NLS-1$
116
			{
140
			{
Lines 121-126 Link Here
121
			}
145
			}
122
			else if(line.startsWith("\"ProxyServer"))//$NON-NLS-1$
146
			else if(line.startsWith("\"ProxyServer"))//$NON-NLS-1$
123
			{
147
			{
148
				
124
				//it has been found that if the target computer has never been pointed to a proxy.  This 
149
				//it has been found that if the target computer has never been pointed to a proxy.  This 
125
				//entry may not be present.  Therefore, we will ignore it if it is there and always create it from scratch.
150
				//entry may not be present.  Therefore, we will ignore it if it is there and always create it from scratch.
126
				newLine=null;				
151
				newLine=null;				
Lines 176-192 Link Here
176
				}
201
				}
177
				newLine = null; //don't update this
202
				newLine = null; //don't update this
178
			}
203
			}
179
			if(newLine!=null)
204
			if(newLine!=null){
205
				setNativeRegistryValue(newLine);
180
				outputFileContents.append(newLine+"\r\n");//$NON-NLS-1$
206
				outputFileContents.append(newLine+"\r\n");//$NON-NLS-1$
207
			}
181
		}
208
		}
182
209
183
			
210
			
184
		
211
		
185
		createRegSettingsFile(outputFileContents);
212
		createRegSettingsFile(outputFileContents);
213
		if (bUseNativeRegistryInterface){
214
			launchPath = launchPath.replaceAll("%1", "");
215
			int n = launchPath.indexOf("\\\\");  //replaceAll doesn't work for these cases
216
			int m = launchPath.indexOf("\\\"");
217
			while (n > -1 || m > -1)
218
			{						
219
				if (n > -1)
220
				{
221
					launchPath = launchPath.substring(0, n) + launchPath.substring(n+1, launchPath.length());
222
					
223
				}
224
				else if (m > -1) //wait until next loop (have to reassign indeces) 
225
				{ 
226
					launchPath = launchPath.substring(0, m) + launchPath.substring(m+1, launchPath.length());
227
					
228
				}	
229
				n = launchPath.indexOf("\\\\");
230
				m = launchPath.indexOf("\\\"");
231
			}
232
			System.out.println(launchPath);
233
		}
234
	
186
		
235
		
187
		try
236
		try
188
		{
237
		{
189
			pushRegFile(tempSettingsFilePath);
238
			if (!bUseNativeRegistryInterface)
239
				pushRegFile(tempSettingsFilePath);
190
		}
240
		}
191
		catch (Exception e)
241
		catch (Exception e)
192
		{
242
		{
Lines 207-212 Link Here
207
		}
257
		}
208
		
258
		
209
	}
259
	}
260
	
261
	private void setNativeRegistryValue(String newLine){
262
		if (bUseNativeRegistryInterface){
263
			int index1 = 1;  // next character after beginning quote
264
			int index2 = newLine.indexOf("=");
265
			String keyname = newLine.substring(index1, index2 - 1);
266
			String value = newLine.substring(index2 + 1);
267
			if (value.charAt(0) == '\"')
268
				value = value.substring(1);
269
			if (value.endsWith("\""))
270
				value = value.substring(0, value.length() - 1);
271
			jniWrapper.setInternetSetting(keyname, value);
272
		}
273
	}
210
274
211
	/*
275
	/*
212
	 * Bugzilla 114253  - move location of temp files
276
	 * Bugzilla 114253  - move location of temp files
Lines 291-296 Link Here
291
		
355
		
292
	}
356
	}
293
357
358
	/**
359
	 * method which creates a registry settings file (*.reg)
360
	 * @param StringBuffer ouputFileContents
361
	 */
362
	private void createOriginalRegSettingsFile(StringBuffer inputFileContents)
363
	{
364
		// Bugzilla 114253 - use new path for temp files to put them in workspace
365
		File newFile = new File(originalSettingsFilePath);
366
				
367
		try
368
		{
369
			OutputStreamWriter outputWriter = new OutputStreamWriter(new FileOutputStream(newFile),"UnicodeLittle");//$NON-NLS-1$
370
			outputWriter.write(inputFileContents.toString());
371
			outputWriter.close();
372
		}
373
		catch (UnsupportedEncodingException e1)
374
		{
375
			e1.printStackTrace();
376
		}
377
		catch (FileNotFoundException e1)
378
		{
379
			e1.printStackTrace();
380
		} 
381
		catch (IOException e)
382
		{
383
			e.printStackTrace();
384
		}
385
		
386
	}
387
	
294
388
295
	/**
389
	/**
296
	 * method which exports the registry keys of interested into a file using regedit and then reads the file
390
	 * method which exports the registry keys of interested into a file using regedit and then reads the file
Lines 299-304 Link Here
299
	private StringBuffer getRegistryInfo()
393
	private StringBuffer getRegistryInfo()
300
	{	
394
	{	
301
		
395
		
396
302
		String[] regInfo = {"\"HKEY_CLASSES_ROOT\\Applications\\iexplore.exe\\shell\\open\\command\"",
397
		String[] regInfo = {"\"HKEY_CLASSES_ROOT\\Applications\\iexplore.exe\\shell\\open\\command\"",
303
				"\"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\"",
398
				"\"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\"",
304
				"\"HKEY_CURRENT_USER\\Software\\Microsoft\\Java VM\""};
399
				"\"HKEY_CURRENT_USER\\Software\\Microsoft\\Java VM\""};
Lines 328-337 Link Here
328
			{
423
			{
329
				if (i == 2){
424
				if (i == 2){
330
					registryChange = Runtime.getRuntime().exec(consolecmdLine + regInfo[i],null);	
425
					registryChange = Runtime.getRuntime().exec(consolecmdLine + regInfo[i],null);	
426
					
331
				} 
427
				} 
332
				else {
428
				else {
333
					registryChange = Runtime.getRuntime().exec(cmdLine + regInfo[i],null);
429
					try{
430
						// the reason for putting this try catch block in at the point
431
						// is to catch the first failure of CreateProcess on regedit.exe
432
						
433
						registryChange = Runtime.getRuntime().exec(cmdLine + regInfo[i],null);
434
					}
435
					catch (IOException e){
436
						// running on Vista, so regedit.exe would not start because we
437
						// did not kick off eclipse with "Run as Administrator"
438
						String currentOS = Platform.getOS();
439
						if (currentOS.equals("win32")) {
440
							String myVersion = System.getProperty("os.version");
441
							if (myVersion.startsWith("6")) {
442
								bUseNativeRegistryInterface = true;
443
								// re-throw the IOException to break out
444
								throw e;
445
							}
446
						}
447
					}
334
				}
448
				}
449
					
335
				registryChange.waitFor();
450
				registryChange.waitFor();
336
				if (i == 2){
451
				if (i == 2){
337
					inputReader= new InputStreamReader(new FileInputStream(consoleFile),"UTF-16");//$NON-NLS-1$
452
					inputReader= new InputStreamReader(new FileInputStream(consoleFile),"UTF-16");//$NON-NLS-1$
Lines 373-379 Link Here
373
		}
488
		}
374
		return inputFileContents;
489
		return inputFileContents;
375
	}
490
	}
376
491
	//Bugilla 168597
492
	StringBuffer getRegistryInfoUsingNativeAPI(){
493
		bUseNativeRegistryInterface = true;
494
		
495
		StringBuffer inputFileContents = new StringBuffer();		
496
		// fire up an instance of the JNI layer to start using native code
497
		jniWrapper = new JNIWrapper();
498
		launchPath = jniWrapper.getIEPath();
499
		AddSettingToBuffer(jniWrapper, inputFileContents, "ProxyEnable");
500
		AddSettingToBuffer(jniWrapper, inputFileContents, "AutoConfigURL");
501
		AddSettingToBuffer(jniWrapper, inputFileContents, "ProxyServer");
502
		AddSettingToBuffer(jniWrapper, inputFileContents, "ProxyOverride");
503
		AddSettingToBuffer(jniWrapper, inputFileContents, "ProxyHttp1.1");
504
		AddSettingToBuffer(jniWrapper, inputFileContents, "WarnonBadCertRecving");
505
		AddSettingToBuffer(jniWrapper, inputFileContents, "WarnOnBadCertRecving");
506
		AddSettingToBuffer(jniWrapper, inputFileContents, "WarnonZoneCrossing");
507
		AddSettingToBuffer(jniWrapper, inputFileContents, "WarnOnZoneCrossing");
508
		
509
		// left out ZonesMixedContent for now, that would require reading many more keys
510
		// to set all that
511
		
512
		return inputFileContents;
513
	}
514
	
515
	private void AddSettingToBuffer(JNIWrapper jniWrapper, StringBuffer inputFileContents, String name){
516
		String setting = jniWrapper.getInternetSetting(name);
517
		if (setting != null  && setting.length() > 0){
518
			inputFileContents.append("\"" + name + "\"=" + setting + "\r\n");
519
		}
520
		return;
521
	}
522
			
377
	
523
	
378
	/**
524
	/**
379
	 * method called by the recorder to start the target application (Internet Explorer)
525
	 * method called by the recorder to start the target application (Internet Explorer)
Lines 404-412 Link Here
404
		{
550
		{
405
			// bugzilla 114253 - write temp files in workspace instead of eclipse instance location
551
			// bugzilla 114253 - write temp files in workspace instead of eclipse instance location
406
			// use the new path for the temp files
552
			// use the new path for the temp files
407
			pushRegFile(originalSettingsFilePath);
553
			if (bUseNativeRegistryInterface){
408
			
554
				StringBuffer inputFileContents = new StringBuffer();
409
			pushRegFile(consoleSettingsFilePath);
555
				String str;
556
				byte [] buffer = new byte[4096];
557
				int bytes_read;
558
				File newFile = new File(originalSettingsFilePath);				
559
				FileInputStream inputStream = new FileInputStream(newFile);//$NON-NLS-1$
560
				while ((bytes_read = inputStream.read(buffer)) != -1){
561
					str = new String(buffer, 0, bytes_read, "UnicodeLittle");
562
					inputFileContents.append(str);
563
				}
564
				inputStream.close();				
565
				StringTokenizer fileTokenizer = new StringTokenizer(inputFileContents.toString(),"\r\n");//$NON-NLS-1$
566
				while(fileTokenizer.hasMoreTokens())
567
				{
568
					String line=fileTokenizer.nextToken();
569
					// check to see if it is a real setting or a blank line
570
					int index = line.indexOf('=');
571
					if (index > 0)
572
						setNativeRegistryValue(line);
573
				}
574
								
575
			}
576
			else{
577
				pushRegFile(originalSettingsFilePath);
578
				
579
				pushRegFile(consoleSettingsFilePath);
580
			}
410
		}
581
		}
411
		catch (Exception e)
582
		catch (Exception e)
412
		{
583
		{
(-)src/org/eclipse/hyades/execution/recorder/local/appadapters/JNIWrapper.java (+103 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2007 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
 * $Id: JNIWrapper.java,v 1 2007/08/24 1:03:39 dmorris Exp $
8
 * 
9
 * Contributors: 
10
 * IBM Corporation - initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.execution.recorder.local.appadapters;
14
15
16
import java.net.URL;
17
18
import org.eclipse.core.runtime.FileLocator;
19
import org.eclipse.core.runtime.Platform;
20
import org.osgi.framework.Bundle;
21
import java.io.IOException;
22
23
24
// added this file for bugzilla 168597
25
26
public class JNIWrapper {
27
	
28
	private static final native String getLastError();
29
	private static final native String getIEAppPath();
30
	private static final native String getEnableJavaConsole();
31
	private static final native String getIESetting(String name);
32
	private static final native int setIESetting(String name, String value, int type);
33
	
34
	public static final int REG_SZ = 1;
35
	public static final int REG_DWORD = 4;
36
	
37
	public synchronized String getIEPath(){
38
		
39
		String path = getIEAppPath();
40
		return path;
41
	}
42
	
43
	public synchronized String getEnableJava(){
44
		
45
		String path = getEnableJavaConsole();
46
		return path;
47
	}
48
	
49
	
50
	public synchronized String getInternetSetting(String name){
51
		String setting = getIESetting(name);
52
		
53
		
54
		return setting;
55
	}
56
	
57
	public synchronized boolean setInternetSetting(String name, String value){
58
		int i = 0;
59
	
60
		if (value.startsWith("dword:", 0)){
61
			int index = value.indexOf(":");
62
			index++;
63
			value = value.substring(index);
64
			value = value.trim();
65
			Integer intVal = new Integer(value);
66
			value = intVal.toString();
67
			i = setIESetting(name, value, REG_DWORD);
68
			
69
			
70
		}else{
71
			i = setIESetting(name, value, REG_SZ);
72
		}
73
		if (i > 0)
74
			return true;
75
		else
76
			return false;
77
	}
78
	
79
	public synchronized String getErrorMessage(){
80
		String errorMsg = getLastError();
81
		return errorMsg;
82
		
83
	}
84
	
85
	
86
	static {
87
		// load our utility dll, it should be in the org.eclipse.hyades.test.core plugin directory
88
		try{
89
			Bundle b = Platform.getBundle("org.eclipse.hyades.test.core");
90
			URL u = FileLocator.resolve(b.getEntry("/"));
91
			String path = u.getPath();
92
			path = path.substring(1);
93
			String finalPath = path + "TPTPRegistryUpdater.dll";
94
			System.load(finalPath);
95
		}
96
		catch (IOException e){
97
		
98
		}
99
	}
100
	
101
}
102
103

Return to bug 168597