forked from I2P_Developers/i2p.i2p
Compare commits
3 Commits
i2p-2.6.1-
...
advanced-u
Author | SHA1 | Date | |
---|---|---|---|
8922dfeb63 | |||
0904616a59 | |||
a701af21c6 |
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* I2P - An anonymous, secure, and fully-distributed communication network.
|
||||
*
|
||||
*
|
||||
* UrlLauncher.java
|
||||
* 2004 The I2P Project
|
||||
* http://www.i2p.net
|
||||
@ -39,13 +39,11 @@ import net.i2p.util.SystemVersion;
|
||||
* browsers if that was not successful.
|
||||
* <p>
|
||||
* Handles Galeon, Internet Explorer, Konqueror, Links, Lynx, Mozilla, Mozilla
|
||||
* Firefox, Netscape, Opera, and Safari.
|
||||
*
|
||||
* Firefox, Netscape, Opera, and Safari.
|
||||
*
|
||||
* @author hypercubus
|
||||
*/
|
||||
public class UrlLauncher implements ClientApp {
|
||||
|
||||
private final ShellCommand _shellCommand;
|
||||
private volatile ClientAppState _state;
|
||||
private final I2PAppContext _context;
|
||||
private final ClientAppManager _mgr;
|
||||
@ -85,7 +83,7 @@ public class UrlLauncher implements ClientApp {
|
||||
"links",
|
||||
"lynx"
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ClientApp constructor used from clients.config
|
||||
*
|
||||
@ -101,10 +99,10 @@ public class UrlLauncher implements ClientApp {
|
||||
if (args == null || args.length <= 0)
|
||||
args = new String[] { context.portMapper().getConsoleURL() };
|
||||
_args = args;
|
||||
_shellCommand = new ShellCommand();
|
||||
//_shellCommand = new ShellCommand();
|
||||
_state = INITIALIZED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor from SysTray
|
||||
*
|
||||
@ -116,7 +114,7 @@ public class UrlLauncher implements ClientApp {
|
||||
_log = _context.logManager().getLog(UrlLauncher.class);
|
||||
_mgr = null;
|
||||
_args = null;
|
||||
_shellCommand = new ShellCommand();
|
||||
//_shellCommand = new ShellCommand();
|
||||
_state = INITIALIZED;
|
||||
}
|
||||
|
||||
@ -177,18 +175,18 @@ public class UrlLauncher implements ClientApp {
|
||||
* to launch the given URL using the default browser for that platform; if
|
||||
* unsuccessful, an attempt is made to launch the URL using the most common
|
||||
* browsers.
|
||||
*
|
||||
*
|
||||
* As of 0.9.46, fails immediately if JVM is a Windows or Linux Service.
|
||||
*
|
||||
*
|
||||
* BLOCKING. This repeatedly probes the server port at the given url
|
||||
* until it is apparently ready.
|
||||
*
|
||||
*
|
||||
* @param url The URL to open.
|
||||
* @return <code>true</code> if the operation was successful, otherwise
|
||||
* <code>false</code>.
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
*/
|
||||
public boolean openUrl(String url) throws IOException {
|
||||
if (IS_SERVICE)
|
||||
return false;
|
||||
@ -200,76 +198,9 @@ public class UrlLauncher implements ClientApp {
|
||||
if (cbrowser != null) {
|
||||
return openUrl(url, cbrowser);
|
||||
}
|
||||
if (SystemVersion.isMac()) {
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName.toLowerCase(Locale.US).startsWith("mac os x")) {
|
||||
String[] args = new String[] { "open", url };
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args , 5))
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
String[] args = new String[] { "iexplore", url };
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args , 5))
|
||||
return true;
|
||||
} else if (SystemVersion.isWindows()) {
|
||||
String[] browserString = new String[] { "C:\\Program Files\\Internet Explorer\\iexplore.exe", "-nohome", url };
|
||||
File foo = new File(_context.getTempDir(), "browser" + _context.random().nextLong() + ".reg");
|
||||
String[] args = new String[] { "regedit", "/E", foo.getAbsolutePath(), "HKEY_CLASSES_ROOT\\http\\shell\\open\\command" };
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
boolean ok = _shellCommand.executeSilentAndWait(args);
|
||||
if (ok) {
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(foo), "UTF-16"));
|
||||
for (String line; (line = bufferedReader.readLine()) != null; ) {
|
||||
// @="\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\" -osint -url \"%1\""
|
||||
if (line.startsWith("@=")) {
|
||||
if (_log.shouldDebug()) _log.debug("From RegEdit: " + line);
|
||||
line = line.substring(2).trim();
|
||||
if (line.startsWith("\"") && line.endsWith("\""))
|
||||
line = line.substring(1, line.length() - 1);
|
||||
line = line.replace("\\\\", "\\");
|
||||
line = line.replace("\\\"", "\"");
|
||||
if (_log.shouldDebug()) _log.debug("Mod RegEdit: " + line);
|
||||
// "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -osint -url "%1"
|
||||
// use the whole line
|
||||
String[] aarg = parseArgs(line, url);
|
||||
if (aarg.length > 0) {
|
||||
browserString = aarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Reading regedit output", e);
|
||||
} finally {
|
||||
if (bufferedReader != null)
|
||||
try { bufferedReader.close(); } catch (IOException ioe) {}
|
||||
foo.delete();
|
||||
}
|
||||
} else if (_log.shouldWarn()) {
|
||||
_log.warn("Regedit Failed: " + Arrays.toString(args));
|
||||
}
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(browserString));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(browserString, 5))
|
||||
return true;
|
||||
if (_log.shouldInfo()) _log.info("Failed: " + Arrays.toString(browserString));
|
||||
} else {
|
||||
// fall through
|
||||
}
|
||||
String[] args = new String[2];
|
||||
args[1] = url;
|
||||
for (int i = 0; i < BROWSERS.length; i++) {
|
||||
args[0] = BROWSERS[i];
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args, 5))
|
||||
return true;
|
||||
if (_log.shouldInfo()) _log.info("Failed: " + Arrays.toString(args));
|
||||
}
|
||||
//I2PBrowser i2pBrowser = new I2PBrowser();
|
||||
//i2pBrowser.launchAndDetach(false, String[]{url});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -282,16 +213,16 @@ public class UrlLauncher implements ClientApp {
|
||||
* Arguments may be surrounded by single or double quotes if
|
||||
* they contain spaces or tabs.
|
||||
* There is no mechanism to escape quotes or other chars with backslashes.
|
||||
*
|
||||
*
|
||||
* As of 0.9.46, fails immediately if JVM is a Windows or Linux Service.
|
||||
*
|
||||
*
|
||||
* BLOCKING. However, this does NOT probe the server port to see if it is ready.
|
||||
*
|
||||
*
|
||||
* @param url The URL to open.
|
||||
* @param browser The browser to use. See above for quoting rules.
|
||||
* @return <code>true</code> if the operation was successful,
|
||||
* otherwise <code>false</code>.
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean openUrl(String url, String browser) throws IOException {
|
||||
@ -301,9 +232,16 @@ public class UrlLauncher implements ClientApp {
|
||||
if (validateUrlFormat(url)) {
|
||||
String[] args = parseArgs(browser, url);
|
||||
if (args.length > 0) {
|
||||
if (_log.shouldDebug()) _log.debug("Execute: " + Arrays.toString(args));
|
||||
if (_shellCommand.executeSilentAndWaitTimed(args, 5))
|
||||
return true;
|
||||
//I2PBrowser i2pBrowser = new I2PBrowser();
|
||||
//ArrayList<String> visitURL = new ArrayList<String>();
|
||||
//for (String arg : args){
|
||||
// if (arg != args[0])
|
||||
// visitURL.append(arg);
|
||||
//}
|
||||
//I2PBrowser.generic = true;
|
||||
//I2PBrowser.setBrowser(args[0]);
|
||||
//i2pBrowser.launchAndDetatch(false, visitURL.toArray(new String[visitURL.size()]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -393,7 +331,7 @@ public class UrlLauncher implements ClientApp {
|
||||
/**
|
||||
* ClientApp interface
|
||||
* As of 0.9.46, stops immediately if JVM is a Windows or Linux Service.
|
||||
*
|
||||
*
|
||||
* @since 0.9.18
|
||||
*/
|
||||
public void startup() {
|
||||
|
Reference in New Issue
Block a user