Bug 356831 - Changed pref to be auto-detect via DHCP, not whole of WPAD draft
authorPolly Shaw <polly.shaw@gmail.com>
Sun, 18 Feb 2018 22:15:10 +0000
changeset 757626 97499a6bea7fdf8949ae75d7d170e91fc6f561ff
parent 757625 7af4f27a74871d8d4e1271481fa1dcff513d35c4
child 758638 415a8b8e011ad141c81d10281dd5bb68fa7c2bca
push id99804
push userbmo:polly.shaw@gmail.com
push dateTue, 20 Feb 2018 22:40:07 +0000
bugs356831
milestone60.0a1
Bug 356831 - Changed pref to be auto-detect via DHCP, not whole of WPAD MozReview-Commit-ID: 53smIbHWA8X
modules/libpref/init/all.js
netwerk/base/nsPACMan.cpp
netwerk/base/nsPACMan.h
netwerk/base/nsProtocolProxyService.cpp
netwerk/base/nsProtocolProxyService.h
netwerk/test/gtest/TestPACMan.cpp
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2331,17 +2331,17 @@ pref("network.cookie.cookieBehavior",   
 pref("network.cookie.thirdparty.sessionOnly", false);
 pref("network.cookie.thirdparty.nonsecureSessionOnly", false);
 pref("network.cookie.leave-secure-alone",   true);
 pref("network.cookie.ipc.sync",             false);
 pref("network.cookie.lifetimePolicy",       0); // 0-accept, 1-dontUse 2-acceptForSession, 3-acceptForNDays
 pref("network.cookie.prefsMigrated",        false);
 pref("network.cookie.lifetime.days",        90); // Ignored unless network.cookie.lifetimePolicy is 3.
 
-pref("network.proxy.enable_wpad", true);
+pref("network.proxy.enable_wpad_over_dhcp", true);
 // The PAC file to load.  Ignored unless network.proxy.type is 2.
 pref("network.proxy.autoconfig_url", "");
 // Strip off paths when sending URLs to PAC scripts
 pref("network.proxy.autoconfig_url.include_path", false);
 
 // If we cannot load the PAC file, then try again (doubling from interval_min
 // until we reach interval_max or the PAC file is successfully loaded).
 pref("network.proxy.autoconfig_retry_interval_min", 5);    // 5 seconds
--- a/netwerk/base/nsPACMan.cpp
+++ b/netwerk/base/nsPACMan.cpp
@@ -381,17 +381,17 @@ static const char *kPACIncludePath =
 
 nsPACMan::nsPACMan(nsIEventTarget *mainThreadEventTarget)
   : NeckoTargetHolder(mainThreadEventTarget)
   , mLoadPending(false)
   , mShutdown(false)
   , mLoadFailureCount(0)
   , mInProgress(false)
   , mAutoDetect(false)
-  , mWPADEnabled(false)
+  , mWPADOverDHCPEnabled(false)
 {
   MOZ_ASSERT(NS_IsMainThread(), "pacman must be created on main thread");
   if (!sThreadLocalSetup){
     sThreadLocalSetup = true;
     PR_NewThreadPrivateIndex(&sThreadLocalIndex, nullptr);
   }
   mPAC.SetThreadLocalIndex(sThreadLocalIndex);
   mIncludePath = Preferences::GetBool(kPACIncludePath, false);
@@ -507,17 +507,17 @@ nsPACMan::LoadPACFromURI(const nsACStrin
 
   CancelExistingLoad();
 
   mLoader = loader;
   if (!aIsScheduledReload) {
     mPACURIRedirectSpec.Truncate();
     mNormalPACURISpec.Truncate(); // set at load time
     mLoadFailureCount = 0;  // reset
-    mAutoDetect = aSpec.IsEmpty() && mWPADEnabled;
+    mAutoDetect = aSpec.IsEmpty();
     mPACURISpec.Assign(aSpec);
   }
 
   // reset to Null
   mScheduledReload = TimeStamp();
   return NS_OK;
 }
 
@@ -539,17 +539,19 @@ nsPACMan::GetPACFromDHCP(nsACString &aSp
   return rv;
 }
 
 nsresult
 nsPACMan::ConfigureWPAD(nsACString &aSpec)
 {
   MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
   aSpec.Truncate();
-  GetPACFromDHCP(aSpec);
+  if (mWPADOverDHCPEnabled) {
+    GetPACFromDHCP(aSpec);
+  }
 
   if (aSpec.IsEmpty()) {
     // We diverge from the WPAD spec here in that we don't walk the
     // hosts's FQDN, stripping components until we hit a TLD.  Doing so
     // is dangerous in the face of an incomplete list of TLDs, and TLDs
     // get added over time.  We could consider doing only a single
     // substitution of the first component, if that proves to help
     // compatibility.
@@ -573,17 +575,16 @@ nsPACMan::StartLoading()
 
   // CancelExistingLoad was called...
   if (!mLoader) {
     PostCancelPendingQ(NS_ERROR_ABORT);
     return;
   }
 
   if (mAutoDetect) {
-    MOZ_ASSERT(mWPADEnabled);
     RefPtr<ExecutePACThreadAction> wpadConfigurer =
       new ExecutePACThreadAction(this);
     wpadConfigurer->ConfigureWPAD();
     if (mPACThread) {
       mPACThread->Dispatch(wpadConfigurer, nsIEventTarget::DISPATCH_NORMAL);
     }
   } else {
     ContinueLoadingAfterPACUriKnown();
--- a/netwerk/base/nsPACMan.h
+++ b/netwerk/base/nsPACMan.h
@@ -173,17 +173,17 @@ public:
 
   nsresult Init(nsISystemProxySettings *);
   static nsPACMan *sInstance;
 
   // PAC thread operations only
   void ProcessPendingQ();
   void CancelPendingQ(nsresult);
 
-  void SetWPADEnabled(bool aValue) { mWPADEnabled = aValue; }
+  void SetWPADOverDHCPEnabled(bool aValue) { mWPADOverDHCPEnabled = aValue; }
 
 private:
   NS_DECL_NSISTREAMLOADEROBSERVER
   NS_DECL_NSIINTERFACEREQUESTOR
   NS_DECL_NSICHANNELEVENTSINK
 
   friend class PendingPACQuery;
   friend class PACLoadComplete;
@@ -256,17 +256,17 @@ private:
   bool                         mLoadPending;
   Atomic<bool, Relaxed>        mShutdown;
   TimeStamp                    mScheduledReload;
   uint32_t                     mLoadFailureCount;
 
   bool                         mInProgress;
   bool                         mIncludePath;
   bool                         mAutoDetect;
-  bool                         mWPADEnabled;
+  bool                         mWPADOverDHCPEnabled;
 };
 
 extern LazyLogModule gProxyLog;
 
 } // namespace net
 } // namespace mozilla
 
 #endif  // nsPACMan_h__
--- a/netwerk/base/nsProtocolProxyService.cpp
+++ b/netwerk/base/nsProtocolProxyService.cpp
@@ -817,17 +817,17 @@ nsProtocolProxyService::nsProtocolProxyS
     , mProxyConfig(PROXYCONFIG_DIRECT)
     , mHTTPProxyPort(-1)
     , mFTPProxyPort(-1)
     , mHTTPSProxyPort(-1)
     , mSOCKSProxyPort(-1)
     , mSOCKSProxyVersion(4)
     , mSOCKSProxyRemoteDNS(false)
     , mProxyOverTLS(true)
-    , mWPADEnabled(false)
+    , mWPADOverDHCPEnabled(false)
     , mPACMan(nullptr)
     , mSessionStart(PR_Now())
     , mFailedProxyTimeout(30 * 60) // 30 minute default
     , mIsShutdown(false)
 {
 }
 
 nsProtocolProxyService::~nsProtocolProxyService()
@@ -1084,19 +1084,19 @@ nsProtocolProxyService::PrefsChanged(nsI
         proxy_GetBoolPref(prefBranch, PROXY_PREF("socks_remote_dns"),
                           mSOCKSProxyRemoteDNS);
 
     if (!pref || !strcmp(pref, PROXY_PREF("proxy_over_tls"))) {
         proxy_GetBoolPref(prefBranch, PROXY_PREF("proxy_over_tls"),
                           mProxyOverTLS);
     }
 
-    if (!pref || !strcmp(pref, PROXY_PREF("enable_wpad"))) {
-        proxy_GetBoolPref(prefBranch, PROXY_PREF("enable_wpad"),
-                          mWPADEnabled);
+    if (!pref || !strcmp(pref, PROXY_PREF("enable_wpad_over_dhcp"))) {
+        proxy_GetBoolPref(prefBranch, PROXY_PREF("enable_wpad_over_dhcp"),
+                          mWPADOverDHCPEnabled);
         reloadPAC = true;
     }
 
     if (!pref || !strcmp(pref, PROXY_PREF("failover_timeout")))
         proxy_GetIntPref(prefBranch, PROXY_PREF("failover_timeout"),
                          mFailedProxyTimeout);
 
     if (!pref || !strcmp(pref, PROXY_PREF("no_proxies_on"))) {
@@ -1513,17 +1513,17 @@ nsProtocolProxyService::ConfigureFromPAC
     bool autodetect = spec.IsEmpty();
     if (!forceReload && ((!autodetect && mPACMan->IsPACURI(spec)) ||
                          (autodetect && mPACMan->IsUsingWPAD()))) {
         return NS_OK;
     }
 
     mFailedProxies.Clear();
 
-    mPACMan->SetWPADEnabled(mWPADEnabled);
+    mPACMan->SetWPADOverDHCPEnabled(mWPADOverDHCPEnabled);
     return mPACMan->LoadPACFromURI(spec);
 }
 
 void
 nsProtocolProxyService::ProcessPACString(const nsCString &pacString,
                                          uint32_t aResolveFlags,
                                          nsIProxyInfo **result)
 {
--- a/netwerk/base/nsProtocolProxyService.h
+++ b/netwerk/base/nsProtocolProxyService.h
@@ -395,17 +395,17 @@ protected:
 
     // mSOCKSProxyTarget could be a host, a domain socket path,
     // or a named-pipe name.
     nsCString                    mSOCKSProxyTarget;
     int32_t                      mSOCKSProxyPort;
     int32_t                      mSOCKSProxyVersion;
     bool                         mSOCKSProxyRemoteDNS;
     bool                         mProxyOverTLS;
-    bool                         mWPADEnabled;
+    bool                         mWPADOverDHCPEnabled;
 
     RefPtr<nsPACMan>           mPACMan;  // non-null if we are using PAC
     nsCOMPtr<nsISystemProxySettings> mSystemProxySettings;
 
     PRTime                       mSessionStart;
     nsFailedProxyTable           mFailedProxies;
     int32_t                      mFailedProxyTimeout;
 
--- a/netwerk/test/gtest/TestPACMan.cpp
+++ b/netwerk/test/gtest/TestPACMan.cpp
@@ -110,17 +110,19 @@ class TestPACMan : public ::testing::Tes
         rv = NS_ProcessPendingEvents(nullptr);
         ASSERT_EQ(NS_OK, rv);
         ProcessPendingEventsOnPACThread();
       }
       NS_WARNING("End of pending events on main thread");
     }
     
 
-    // This method exists because simply calling ProcessAllEvents once
+    // This method is used to ensure that all pending events on the main thread
+    // and the Proxy thread are processsed.
+    // It iterates over ProcessAllEvents because simply calling ProcessAllEvents once
     // did not reliably process the events on both threads on all platforms.
     void 
     ProcessAllEventsTenTimes(){
       for (int i = 0; i < 10; i++) {
         ProcessAllEvents();
       }
     }
 
@@ -131,17 +133,17 @@ class TestPACMan : public ::testing::Tes
           ->GetFactoryEntry(kNS_TESTDHCPCLIENTSERVICE_CID);
       if (factoryEntry) {
         nsresult rv = nsComponentManagerImpl::gComponentManager->UnregisterFactory(kNS_TESTDHCPCLIENTSERVICE_CID, factoryEntry->mFactory);
         ASSERT_EQ(NS_OK, rv);
       }
       nsComponentManagerImpl::gComponentManager->RegisterModule(&kSysDHCPClientModule, nullptr);
       
       mPACMan = new nsPACMan(nullptr);
-      mPACMan->SetWPADEnabled(true);
+      mPACMan->SetWPADOverDHCPEnabled(true);
       mPACMan->Init(nullptr);
     }
 
     virtual void
     TearDown()
     {
       mPACMan->Shutdown();
     }
@@ -229,16 +231,30 @@ TEST_F(TestPACMan, WhenThereIsNoDHCPClie
 
   ProcessAllEventsTenTimes();
 
   ASSERT_STREQ(TEST_WPAD_DHCP_OPTION, WPADOptionResult.Data());
   AssertPACSpecEqualTo("http://wpad/wpad.dat");
 
 }
 
+TEST_F(TestPACMan, WhenWPADOverDHCPIsPreffedOffWPADDefaultsToStandardURL) {
+
+  SetOptionResult(TEST_WPAD_DHCP_OPTION);
+
+  mPACMan->SetWPADOverDHCPEnabled(false);
+  mPACMan->LoadPACFromURI(EmptyCString());
+
+  ProcessAllEventsTenTimes();
+
+  ASSERT_STREQ(TEST_WPAD_DHCP_OPTION, WPADOptionResult.Data());
+  AssertPACSpecEqualTo("http://wpad/wpad.dat");
+
+}
+
 TEST_F(TestPACMan, WhenPACUriIsSetDirectlyItIsUsedRatherThanWPAD) {
 
   SetOptionResult(TEST_WPAD_DHCP_OPTION);
   
   nsCString spec;
   spec.AssignLiteral(TEST_ASSIGNED_PAC_URL);
   
   mPACMan->LoadPACFromURI(spec);