Bug 1540145 - [Linux] Don't use GConf service to get proxy configuration, r=glandium
authorMartin Stransky <stransky@redhat.com>
Thu, 04 Apr 2019 05:57:23 +0000
changeset 467916 65082301659031124bb713ea8ae547abbc6681ee
parent 467915 4fc66ecdfa1633868673913533d23f0ef377da4f
child 467917 017eefc950b05f3e1760356a6aa4024f3d16f3df
push id35813
push useraiakab@mozilla.com
push dateThu, 04 Apr 2019 16:07:30 +0000
treeherdermozilla-central@aa623df2ae8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1540145
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540145 - [Linux] Don't use GConf service to get proxy configuration, r=glandium Differential Revision: https://phabricator.services.mozilla.com/D25460
toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
--- a/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
+++ b/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISystemProxySettings.h"
 #include "mozilla/Components.h"
 #include "nsIServiceManager.h"
-#include "nsIGConfService.h"
 #include "nsIURI.h"
 #include "nsReadableUtils.h"
 #include "nsArrayUtils.h"
 #include "prnetdb.h"
 #include "prenv.h"
 #include "nsPrintfCString.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
@@ -29,26 +28,20 @@ class nsUnixSystemProxySettings final : 
   NS_DECL_NSISYSTEMPROXYSETTINGS
 
   nsUnixSystemProxySettings() : mSchemeProxySettings(4) {}
   void Init();
 
  private:
   ~nsUnixSystemProxySettings() = default;
 
-  nsCOMPtr<nsIGConfService> mGConf;
   nsCOMPtr<nsIGSettingsService> mGSettings;
   nsCOMPtr<nsIGSettingsCollection> mProxySettings;
   nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection>
       mSchemeProxySettings;
-  bool IsProxyMode(const char* aMode);
-  nsresult SetProxyResultFromGConf(const char* aKeyBase, const char* aType,
-                                   nsACString& aResult);
-  nsresult GetProxyFromGConf(const nsACString& aScheme, const nsACString& aHost,
-                             int32_t aPort, nsACString& aResult);
   nsresult GetProxyFromGSettings(const nsACString& aScheme,
                                  const nsACString& aHost, int32_t aPort,
                                  nsACString& aResult);
   nsresult SetProxyResultFromGSettings(const char* aKeyBase, const char* aType,
                                        nsACString& aResult);
 };
 
 NS_IMPL_ISUPPORTS(nsUnixSystemProxySettings, nsISystemProxySettings)
@@ -63,48 +56,30 @@ nsUnixSystemProxySettings::GetMainThread
 
 void nsUnixSystemProxySettings::Init() {
   mGSettings = do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
   if (mGSettings) {
     mGSettings->GetCollectionForSchema(
         NS_LITERAL_CSTRING("org.gnome.system.proxy"),
         getter_AddRefs(mProxySettings));
   }
-  if (!mProxySettings) {
-    mGConf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
-  }
-}
-
-bool nsUnixSystemProxySettings::IsProxyMode(const char* aMode) {
-  nsAutoCString mode;
-  return NS_SUCCEEDED(mGConf->GetString(
-             NS_LITERAL_CSTRING("/system/proxy/mode"), mode)) &&
-         mode.EqualsASCII(aMode);
 }
 
 nsresult nsUnixSystemProxySettings::GetPACURI(nsACString& aResult) {
   if (mProxySettings) {
     nsCString proxyMode;
     // Check if mode is auto
     nsresult rv =
         mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
     if (rv == NS_OK && proxyMode.EqualsLiteral("auto")) {
       return mProxySettings->GetString(NS_LITERAL_CSTRING("autoconfig-url"),
                                        aResult);
     }
-    /* The org.gnome.system.proxy schema has been found, but auto mode is not
-     * set. Don't try the GConf and return empty string. */
-    aResult.Truncate();
-    return NS_OK;
   }
 
-  if (mGConf && IsProxyMode("auto")) {
-    return mGConf->GetString(NS_LITERAL_CSTRING("/system/proxy/autoconfig_url"),
-                             aResult);
-  }
   // Return an empty string when auto mode is not set.
   aResult.Truncate();
   return NS_OK;
 }
 
 static bool IsInNoProxyList(const nsACString& aHost, int32_t aPort,
                             const char* noProxyVal) {
   NS_ASSERTION(aPort >= 0, "Negative port?");
@@ -212,40 +187,16 @@ static nsresult GetProxyFromEnvironment(
   int32_t proxyPort;
   rv = proxyURI->GetPort(&proxyPort);
   NS_ENSURE_SUCCESS(rv, rv);
 
   SetProxyResult("PROXY", proxyHost, proxyPort, aResult);
   return NS_OK;
 }
 
-nsresult nsUnixSystemProxySettings::SetProxyResultFromGConf(
-    const char* aKeyBase, const char* aType, nsACString& aResult) {
-  nsAutoCString hostKey;
-  hostKey.AppendASCII(aKeyBase);
-  hostKey.AppendLiteral("host");
-  nsAutoCString host;
-  nsresult rv = mGConf->GetString(hostKey, host);
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (host.IsEmpty()) return NS_ERROR_FAILURE;
-
-  nsAutoCString portKey;
-  portKey.AppendASCII(aKeyBase);
-  portKey.AppendLiteral("port");
-  int32_t port;
-  rv = mGConf->GetInt(portKey, &port);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  /* When port is 0, proxy is not considered as enabled even if host is set. */
-  if (port == 0) return NS_ERROR_FAILURE;
-
-  SetProxyResult(aType, host, port, aResult);
-  return NS_OK;
-}
-
 nsresult nsUnixSystemProxySettings::SetProxyResultFromGSettings(
     const char* aKeyBase, const char* aType, nsACString& aResult) {
   nsDependentCString key(aKeyBase);
 
   nsCOMPtr<nsIGSettingsCollection> proxy_settings =
       mSchemeProxySettings.Get(key);
   nsresult rv;
   if (!proxy_settings) {
@@ -361,73 +312,16 @@ static bool HostIgnoredByProxy(const nsA
     return false;
 
   proxy_MaskIPv6Addr(ignoreAddr, mask);
   proxy_MaskIPv6Addr(hostAddr, mask);
 
   return memcmp(&ignoreAddr, &hostAddr, sizeof(PRIPv6Addr)) == 0;
 }
 
-nsresult nsUnixSystemProxySettings::GetProxyFromGConf(const nsACString& aScheme,
-                                                      const nsACString& aHost,
-                                                      int32_t aPort,
-                                                      nsACString& aResult) {
-  bool masterProxySwitch = false;
-  mGConf->GetBool(NS_LITERAL_CSTRING("/system/http_proxy/use_http_proxy"),
-                  &masterProxySwitch);
-  // if no proxy is set in GConf return NS_ERROR_FAILURE
-  if (!(IsProxyMode("manual") || masterProxySwitch)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  nsCOMPtr<nsIArray> ignoreList;
-  if (NS_SUCCEEDED(mGConf->GetStringList(
-          NS_LITERAL_CSTRING("/system/http_proxy/ignore_hosts"),
-          getter_AddRefs(ignoreList))) &&
-      ignoreList) {
-    uint32_t len = 0;
-    ignoreList->GetLength(&len);
-    for (uint32_t i = 0; i < len; ++i) {
-      nsCOMPtr<nsISupportsString> str = do_QueryElementAt(ignoreList, i);
-      if (str) {
-        nsAutoString s;
-        if (NS_SUCCEEDED(str->GetData(s)) && !s.IsEmpty()) {
-          if (HostIgnoredByProxy(NS_ConvertUTF16toUTF8(s), aHost)) {
-            aResult.AppendLiteral("DIRECT");
-            return NS_OK;
-          }
-        }
-      }
-    }
-  }
-
-  bool useHttpProxyForAll = false;
-  // This setting sometimes doesn't exist, don't bail on failure
-  mGConf->GetBool(NS_LITERAL_CSTRING("/system/http_proxy/use_same_proxy"),
-                  &useHttpProxyForAll);
-
-  nsresult rv;
-  if (!useHttpProxyForAll) {
-    rv = SetProxyResultFromGConf("/system/proxy/socks_", "SOCKS", aResult);
-    if (NS_SUCCEEDED(rv)) return rv;
-  }
-
-  if (aScheme.LowerCaseEqualsLiteral("http") || useHttpProxyForAll) {
-    rv = SetProxyResultFromGConf("/system/http_proxy/", "PROXY", aResult);
-  } else if (aScheme.LowerCaseEqualsLiteral("https")) {
-    rv = SetProxyResultFromGConf("/system/proxy/secure_", "PROXY", aResult);
-  } else if (aScheme.LowerCaseEqualsLiteral("ftp")) {
-    rv = SetProxyResultFromGConf("/system/proxy/ftp_", "PROXY", aResult);
-  } else {
-    rv = NS_ERROR_FAILURE;
-  }
-
-  return rv;
-}
-
 nsresult nsUnixSystemProxySettings::GetProxyFromGSettings(
     const nsACString& aScheme, const nsACString& aHost, int32_t aPort,
     nsACString& aResult) {
   nsCString proxyMode;
   nsresult rv =
       mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -489,17 +383,16 @@ nsresult nsUnixSystemProxySettings::GetP
                                                    const nsACString& aScheme,
                                                    const nsACString& aHost,
                                                    const int32_t aPort,
                                                    nsACString& aResult) {
   if (mProxySettings) {
     nsresult rv = GetProxyFromGSettings(aScheme, aHost, aPort, aResult);
     if (NS_SUCCEEDED(rv)) return rv;
   }
-  if (mGConf) return GetProxyFromGConf(aScheme, aHost, aPort, aResult);
 
   return GetProxyFromEnvironment(aScheme, aHost, aPort, aResult);
 }
 
 NS_IMPL_COMPONENT_FACTORY(nsUnixSystemProxySettings) {
   auto result = MakeRefPtr<nsUnixSystemProxySettings>();
   result->Init();
   return result.forget().downcast<nsISupports>();