Class FirefoxProxySearchStrategy
- java.lang.Object
-
- com.github.markusbernhardt.proxy.search.browser.firefox.FirefoxProxySearchStrategy
-
- All Implemented Interfaces:
ProxySearchStrategy
public class FirefoxProxySearchStrategy extends java.lang.Object implements ProxySearchStrategy
Loads the Firefox3 proxy settings from the users Firefox3 settings. This will load the file prefs.js that is located in the.mozilla/firefox/(profile)/ folder.
See Mozilla_Networking_Preferences for an explanation of the proxy settings.The following settings are extracted from this file:
Some generic settings:
- network.proxy.type -> n/a = use system settings, 0 = direct, 1 = Fixed proxy settings, 2 = proxy script (PAC), 3 = also direct , 4 = auto detect (WPAD)
- network.proxy.share_proxy_settings -> true = use same proxy for all protocols
- network.proxy.no_proxies_on -> a comma separated ignore list.
- network.proxy.autoconfig_url -> a URL to an proxy configuration script
- network.proxy.http
- network.proxy.http_port
- network.proxy.ssl
- network.proxy.ssl_port
- network.proxy.ftp
- network.proxy.ftp_port
- network.proxy.gopher
- network.proxy.gopher_port
- network.proxy.socks
- network.proxy.socks_port
- network.proxy.socks_version -> 4 or 5
Note that if there are more than one profile the first profile found will be used.
-
-
Field Summary
Fields Modifier and Type Field Description private FirefoxProfileSource
profileScanner
private FirefoxSettingParser
settingsParser
-
Constructor Summary
Constructors Constructor Description FirefoxProxySearchStrategy()
ProxySelector
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getName()
Gets the printable name of the search strategy.java.net.ProxySelector
getProxySelector()
Loads the proxy settings and initializes a proxy selector for the firefox proxy settings.private void
installFtpProxy(ProtocolDispatchSelector ps, java.util.Properties settings)
private void
installHttpProxy(ProtocolDispatchSelector ps, java.util.Properties settings)
private void
installSecureProxy(ProtocolDispatchSelector ps, java.util.Properties settings)
private void
installSelectorForProtocol(ProtocolDispatchSelector ps, java.util.Properties settings, java.lang.String protocol)
Installs a proxy selector for the given protocol when settings are available.private void
installSharedProxy(ProtocolDispatchSelector ps)
private void
installSocksProxy(ProtocolDispatchSelector ps, java.util.Properties settings)
private boolean
isProxyShared(java.util.Properties settings)
Checks if the "share proxy settings" option is setjava.util.Properties
readSettings()
Reads the settings file and stores all settings in a Properties map.private java.net.ProxySelector
setupFixedProxySelector(java.util.Properties settings)
Parse the fixed proxy settings and build an ProxySelector for this a chained configuration.
-
-
-
Field Detail
-
profileScanner
private FirefoxProfileSource profileScanner
-
settingsParser
private FirefoxSettingParser settingsParser
-
-
Method Detail
-
getProxySelector
public java.net.ProxySelector getProxySelector() throws ProxyException
Loads the proxy settings and initializes a proxy selector for the firefox proxy settings.- Specified by:
getProxySelector
in interfaceProxySearchStrategy
- Returns:
- a configured ProxySelector, null if none is found.
- Throws:
ProxyException
- on file reading error.
-
getName
public java.lang.String getName()
Gets the printable name of the search strategy.- Specified by:
getName
in interfaceProxySearchStrategy
- Returns:
- the printable name of the search strategy
-
readSettings
public java.util.Properties readSettings() throws ProxyException
Reads the settings file and stores all settings in a Properties map.- Returns:
- the parsed settings.
- Throws:
ProxyException
- on read error.
-
setupFixedProxySelector
private java.net.ProxySelector setupFixedProxySelector(java.util.Properties settings)
Parse the fixed proxy settings and build an ProxySelector for this a chained configuration.- Parameters:
settings
- the proxy settings to evaluate.
-
installFtpProxy
private void installFtpProxy(ProtocolDispatchSelector ps, java.util.Properties settings) throws java.lang.NumberFormatException
- Parameters:
ps
-settings
-- Throws:
java.lang.NumberFormatException
-
installHttpProxy
private void installHttpProxy(ProtocolDispatchSelector ps, java.util.Properties settings) throws java.lang.NumberFormatException
- Parameters:
ps
-settings
-- Throws:
java.lang.NumberFormatException
-
isProxyShared
private boolean isProxyShared(java.util.Properties settings)
Checks if the "share proxy settings" option is set- Parameters:
settings
- to parse- Returns:
- true if the option is set else false
-
installSharedProxy
private void installSharedProxy(ProtocolDispatchSelector ps)
- Parameters:
ps
-
-
installSocksProxy
private void installSocksProxy(ProtocolDispatchSelector ps, java.util.Properties settings) throws java.lang.NumberFormatException
- Parameters:
ps
-settings
-- Throws:
java.lang.NumberFormatException
-
installSecureProxy
private void installSecureProxy(ProtocolDispatchSelector ps, java.util.Properties settings) throws java.lang.NumberFormatException
- Parameters:
ps
-settings
-- Throws:
java.lang.NumberFormatException
-
installSelectorForProtocol
private void installSelectorForProtocol(ProtocolDispatchSelector ps, java.util.Properties settings, java.lang.String protocol) throws java.lang.NumberFormatException
Installs a proxy selector for the given protocol when settings are available.- Parameters:
ps
- a ProtocolDispatchSelector to configure.settings
- to read the config from.protocol
- to configure.- Throws:
java.lang.NumberFormatException
-
-