blob: 9a9bb50d1a78393d9019b9ab6d0ff76263807838 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*******************************************************************************
* Copyright (c) 2005, 2011 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.browser;
import java.net.URL;
import org.eclipse.jface.util.Util;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.browser.AbstractWebBrowser;
/**
* An instance of a running Web browser. rundll32.exe
* url.dll,FileProtocolHandler www.ibm.com
*/
public class ExternalBrowserInstance extends AbstractWebBrowser {
protected IBrowserDescriptor browser;
protected Process process;
public ExternalBrowserInstance(String id, IBrowserDescriptor browser) {
super(id);
this.browser = browser;
}
public void openURL(URL url) throws PartInitException {
String urlText = url.toExternalForm();
String location = browser.getLocation();
String parameters = browser.getParameters();
Trace
.trace(
Trace.FINEST,
"Launching external Web browser: " + location + " - " + parameters + " - " + urlText); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String params = WebBrowserUtil.createParameterString(parameters, urlText);
try {
if ( Util.isMac()) {
location = "open -a " + location; //$NON-NLS-1$
}
Trace.trace(Trace.FINEST, "Launching " + location + " " + params); //$NON-NLS-1$//$NON-NLS-2$
if (params == null || params.length() == 0)
process = Runtime.getRuntime().exec(location);
else
process = Runtime.getRuntime().exec(location + " " + params); //$NON-NLS-1$
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Could not launch external browser", e); //$NON-NLS-1$
WebBrowserUtil.openError(NLS.bind(
Messages.errorCouldNotLaunchWebBrowser, urlText));
}
Thread thread = new Thread() {
public void run() {
try {
process.waitFor();
DefaultBrowserSupport.getInstance().removeBrowser(
ExternalBrowserInstance.this);
} catch (Exception e) {
// ignore
}
}
};
thread.setDaemon(true);
thread.start();
}
public boolean close() {
try {
process.destroy();
return true;
} catch (Exception e) {
return false;
}
}
}
|