33 #include <nsNetUtil.h>
34 #include <nsIPrefService.h>
35 #include <nsIMutableArray.h>
41 #include "nsIWindowsRegKey.h"
52 { ImportProxySettings_IE,
"Internet Explorer" },
80 NS_IMETHODIMP CNetworkProxyImport::ImportProxySettings(
const nsAString &aSource,
83 NS_ENSURE_ARG_POINTER(_retval);
86 for (
unsigned int i=0;
i<NS_ARRAY_LENGTH(networkProxyImportSources);
i++) {
88 Equals(NS_ConvertASCIItoUTF16(networkProxyImportSources[
i].sourceName))) {
93 return NS_ERROR_INVALID_ARG;
98 NS_IMETHODIMP CNetworkProxyImport::GetImportSources(nsIArray **_retval)
100 NS_ENSURE_ARG_POINTER(_retval);
103 nsCOMPtr<nsIMutableArray>
array =
104 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
105 NS_ENSURE_SUCCESS(rv, rv);
107 for (
unsigned int i=0;
i<NS_ARRAY_LENGTH(networkProxyImportSources);
i++) {
108 nsCOMPtr<nsISupportsString> source =
109 do_CreateInstance(
"@mozilla.org/supports-string;1", &rv);
111 SetData(NS_ConvertASCIItoUTF16(networkProxyImportSources[
i].sourceName));
112 rv = array->AppendElement(source, PR_FALSE);
115 return CallQueryInterface(array, _retval);
123 nsCOMPtr<nsISupportsString> supportsString =
124 do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
125 if (supportsString) {
126 supportsString->SetData(aValue);
140 nsAutoString
override(aServers);
144 const nsAString& host =
145 Substring(
override, left,
146 (
right < 0 ?
override.Length() :
right) - left);
147 if (host.EqualsLiteral(
"<local>"))
148 override.Replace(left, 7, NS_LITERAL_STRING(
"localhost,127.0.0.1"));
152 override.Replace(
right, 1, NS_LITERAL_STRING(
","));
162 const char* aPortPref,
165 nsCOMPtr<nsIURI>
uri;
170 if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aHostPort))
171 && NS_SUCCEEDED(uri->GetHost(host))
173 && NS_SUCCEEDED(uri->GetPort(&portValue))) {
175 NS_ConvertUTF8toUTF16(host),
177 aPrefs->SetIntPref(aPortPref, portValue);
179 nsAutoString hostPort(aHostPort);
180 PRInt32 portDelimOffset = hostPort.RFindChar(
':');
181 if (portDelimOffset > 0) {
184 Substring(hostPort, 0, portDelimOffset),
186 nsAutoString port(Substring(hostPort, portDelimOffset + 1));
188 portValue = port.ToInteger(&stringErr);
189 if (NS_SUCCEEDED(stringErr))
190 aPrefs->SetIntPref(aPortPref, portValue);
202 nsCOMPtr<nsIPrefBranch>
prefs;
205 pserve->GetBranch(
"", getter_AddRefs(prefs));
208 return NS_ERROR_FAILURE;
211 prefs->SetIntPref(
"network.proxy.type", 4);
223 nsresult ImportProxySettings_IE(PRBool *_retval)
225 nsCOMPtr<nsIPrefBranch>
prefs;
228 pserve->GetBranch(
"", getter_AddRefs(prefs));
230 return NS_ERROR_FAILURE;
232 nsCOMPtr<nsIWindowsRegKey> regKey =
233 do_CreateInstance(
"@mozilla.org/windows-registry-key;1");
234 NS_NAMED_LITERAL_STRING(
key,
235 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
237 NS_SUCCEEDED(regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
241 PRUint32 proxyType = 0;
244 if (NS_SUCCEEDED(regKey->
245 ReadStringValue(NS_LITERAL_STRING(
"AutoConfigURL"), buf))) {
256 if (NS_SUCCEEDED(regKey->
257 ReadIntValue(NS_LITERAL_STRING(
"ProxyEnable"), &enabled))) {
262 prefs->SetIntPref(
"network.proxy.type", proxyType);
264 if (NS_SUCCEEDED(regKey->
265 ReadStringValue(NS_LITERAL_STRING(
"ProxyOverride"), buf)))
268 if (NS_SUCCEEDED(regKey->
269 ReadStringValue(NS_LITERAL_STRING(
"ProxyServer"), buf))) {
272 {
"ftp=", 4, PR_FALSE,
"network.proxy.ftp",
273 "network.proxy.ftp_port" },
274 {
"gopher=", 7, PR_FALSE,
"network.proxy.gopher",
275 "network.proxy.gopher_port" },
276 {
"http=", 5, PR_FALSE,
"network.proxy.http",
277 "network.proxy.http_port" },
278 {
"https=", 6, PR_FALSE,
"network.proxy.ssl",
279 "network.proxy.ssl_port" },
280 {
"socks=", 6, PR_FALSE,
"network.proxy.socks",
281 "network.proxy.socks_port" },
284 PRInt32 startIndex = 0,
count = 0;
285 PRBool foundSpecificProxy = PR_FALSE;
286 for (PRUint32
i = 0;
i < NS_ARRAY_LENGTH(data); ++
i) {
287 PRInt32
offset = buf.Find(NS_ConvertASCIItoUTF16(data[
i].prefix));
289 foundSpecificProxy = PR_TRUE;
295 PRInt32 terminal = buf.FindChar(
';', offset);
296 count = terminal > startIndex ? terminal - startIndex :
297 buf.Length() - startIndex;
302 data[
i].portPref, prefs);
306 if (!foundSpecificProxy) {
310 for (PRUint32
i = 0;
i < 5; ++
i)
315 prefs->SetBoolPref(
"network.proxy.share_proxy_settings", PR_TRUE);
virtual ~CNetworkProxyImport()
static void SetProxyPref(const nsAString &aHostPort, const char *aPref, const char *aPortPref, nsIPrefBranch *aPrefs)
const NS_PREFSERVICE_CONTRACTID
static void ParseOverrideServers(const nsAString &aServers, nsIPrefBranch *aBranch)
NS_IMPL_ISUPPORTS1(CNetworkProxyImport, sbINetworkProxyImport)
Songbird NetworkProxyImport Component Definition.
nsresult ImportProxySettings_Auto(PRBool *_retval)
nsresult(* ImportProxySettingsFunction)(PRBool *)
static void SetUnicharPref(const char *aPref, const nsAString &aValue, nsIPrefBranch *aPrefs)
NS_DECL_ISUPPORTS NS_DECL_SBINETWORKPROXYIMPORT CNetworkProxyImport()
A service to import network proxy settings from several sources.
NetworkProxyImportSource networkProxyImportSources[]
_getSelectedPageStyle s i