java.lang.Object
net.i2p.apps.systray.UrlLauncher
- All Implemented Interfaces:
ClientApp
A quick and simple multi-platform URL launcher. It attempts to launch the default browser for the host platform first, then popular third-party browsers if that was not successful.
Handles Galeon, Internet Explorer, Falkon, Konqueror, Links, Lynx, Mozilla, Mozilla Firefox, Netscape, Opera, and Safari.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classThread waiting for the console then opening it.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String[]The command line arguments given.private final I2PAppContextThe app context.private final LogLogger for the URL launcher.private final ClientAppManagerThe manager notified of the state changes.private final ShellCommandHelper running the browser command.private ClientAppStateCurrent state of the launcher.private static final String[]Browsers to try IN-ORDER.private static final booleanTrue when running as a system service.private static final intMost readiness checks before giving up.private static final intLongest wait for the console to come up.private static final StringConfig key of the browser command.private static final StringName the launcher registers with the manager.private static final intTime between the console readiness checks.Constructor Summary
ConstructorsConstructorDescriptionConstructor from SysTray.UrlLauncher(I2PAppContext context, ClientAppManager mgr, String[] args) ClientApp constructor used fromclients.config.Method Summary
Modifier and TypeMethodDescriptionprivate voidchangeState(ClientAppState state) React to a client app state change.private voidchangeState(ClientAppState state, Exception e) React to a state change with an error.private StringfollowProgIdToCommand(String progid) Cross-references a progId obtained by followUserConfiguredBrowserToCommand against HKEY_CLASSES_ROOT\%ProgId%\shell\open\command, which holds the value of the command which we need to run to launch the default browser.private StringfollowUserConfiguredBrowserToCommand(String hkeyquery) If following a query back to the Default value doesn't work, what we have is a "ProgID", registered under \HKEY_CLASSES_ROOT\%ProgId% with a \shell\open\command entry whose value contains the command it needs.private StringgetDefaultOutOfRegistry(String hkeyquery) Obtains a default browsing command out of the Windows registry.private StringObtains the default browser for the Windows platform, which by now should be Edgium in the worst-case scenario but in case it isn't, we can use this function to figure it out.ClientApp interface.getName()ClientApp interface.getState()ClientApp interface.static voidObsolete, now uses ClientApp interface.booleanDiscovers the operating system the installer is running under and tries 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.booleanOpens the given URL with the given browser.private static String[]Parse args into arguments separated by spaces or tabs.private StringregistryQuery(String hkeyquery, String key) Obtains a value matching a key contained in the windows registry at a path represented by hkeyquery.voidClientApp interface.voidstartup()ClientApp interface As of 0.9.46, stops immediately if JVM is a Windows or Linux Service.private static booleanvalidateUrlFormat(String urlString) Checks whether a URL is safe to open.private static booleanwaitForServer(String urlString) Prevent bad user experience by waiting for the server to be there before launching the browser.
Field Details
_shellCommand
Helper running the browser command._state
Current state of the launcher._context
The app context._mgr
The manager notified of the state changes._args
The command line arguments given._log
Logger for the URL launcher.WAIT_TIME
private static final int WAIT_TIMETime between the console readiness checks.- See Also:
MAX_WAIT_TIME
private static final int MAX_WAIT_TIMELongest wait for the console to come up.- See Also:
MAX_TRIES
private static final int MAX_TRIESMost readiness checks before giving up.- See Also:
REGISTERED_NAME
Name the launcher registers with the manager.- See Also:
PROP_BROWSER
Config key of the browser command.- See Also:
IS_SERVICE
private static final boolean IS_SERVICETrue when running as a system service.BROWSERS
Browsers to try IN-ORDER.
Constructor Details
UrlLauncher
ClientApp constructor used fromclients.config.- Parameters:
context- the router context supplying the console URL used when args is emptymgr- null OKargs- URL in args[0] or null args for router console
UrlLauncher
public UrlLauncher()Constructor from SysTray.
Method Details
waitForServer
Prevent bad user experience by waiting for the server to be there before launching the browser.- Parameters:
urlString- the URL to probe, host and port are used for the socket- Returns:
- true once the socket connects, false if the retries run out or the URL cannot be parsed
getDefaultWindowsBrowser
Obtains the default browser for the Windows platform, which by now should be Edgium in the worst-case scenario but in case it isn't, we can use this function to figure it out. It can find:- The current user's HTTPS default browser if they configured it to be non-default
- The current user's HTTP default browser if they configured it to be non-default
- Edgium if it's available
- iexplore if it's not
- Parameters:
url- containing full scheme, i.e. http://127.0.0.1:7657- Returns:
- path to command[0] and target URL[1] to the default browser ready for execution, non-null
registryQuery
Obtains a value matching a key contained in the windows registry at a path represented by hkeyquery.- Parameters:
hkeyquery- registry entry to ask for.key- key to retrieve value from- Returns:
- either a registry "Default" value or null if one does not exist/is empty
followUserConfiguredBrowserToCommand
If following a query back to the Default value doesn't work, what we have is a "ProgID", registered under \HKEY_CLASSES_ROOT\%ProgId% with a \shell\open\command entry whose value contains the command it needs. Takes a registry query in the same format as getDefaultOutOfRegistry but follows the ProgID instead of the default entry.- Parameters:
hkeyquery- the registry query in the same format as getDefaultOutOfRegistry, whose ProgID entry is followed- Returns:
- the command required to run the application referenced in hkeyquery, or null
followProgIdToCommand
Cross-references a progId obtained by followUserConfiguredBrowserToCommand against HKEY_CLASSES_ROOT\%ProgId%\shell\open\command, which holds the value of the command which we need to run to launch the default browser.- Parameters:
progid- the ProgID obtained by followUserConfiguredBrowserToCommand, interpolated into the registry path- Returns:
- the command required to run the application referenced in hkeyquery, or null
getDefaultOutOfRegistry
openUrl
Discovers the operating system the installer is running under and tries 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.- Parameters:
url- The URL to open.- Returns:
trueif the operation was successful, otherwisefalse.
openUrl
Opens the given URL with the given browser. As of 0.9.38, the browser parameter will be parsed into arguments separated by spaces or tabs. %1, if present, will be replaced with the url. 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. BLOCKING. However, this does NOT probe the server port to see if it is ready.- Parameters:
url- The URL to open.browser- The browser to use. See above for quoting rules.- Returns:
trueif the operation was successful, otherwisefalse.
parseArgs
Parse args into arguments separated by spaces or tabs. %1, if present, will be replaced with the url, otherwise it will be added as the last argument. 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. Adapted from i2ptunnel SSLHelper.- Parameters:
args- the command line template to parse, non-nullurl- the URL substituted for %1, or appended if no %1 is present- Returns:
- the parsed argument array with the URL substituted
validateUrlFormat
Checks whether a URL is safe to open.- Parameters:
urlString- the URL to check- Returns:
- true if the format is acceptable
startup
getState
ClientApp interface.getName
getDisplayName
ClientApp interface.- Specified by:
getDisplayNamein interfaceClientApp- Returns:
- the display name
changeState
React to a client app state change.- Parameters:
state- the new client app state
changeState
React to a state change with an error.- Parameters:
state- the new client app statee- the error that caused the change, null if none
shutdown
main
Obsolete, now uses ClientApp interface.- Parameters:
args- URL(s) to open