bug 819902 - system settings pac file failed redirect r=biesi
authorPatrick McManus <mcmanus@ducksong.com>
Tue, 01 Jan 2013 16:05:07 -0500
changeset 126401 19296526f23d7e7bfae15ec93c15a38d7041217c
parent 126400 639330081e9f08d51f960efd649a72ae65653c06
child 126402 9d29a67f90b6324088ceb393cde563a6644a6866
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbiesi
bugs819902
milestone20.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 819902 - system settings pac file failed redirect r=biesi
netwerk/base/src/nsPACMan.cpp
netwerk/base/src/nsPACMan.h
--- a/netwerk/base/src/nsPACMan.cpp
+++ b/netwerk/base/src/nsPACMan.cpp
@@ -363,16 +363,17 @@ nsPACMan::LoadPACFromURI(const nsCString
     mLoadPending = true;
   }
 
   CancelExistingLoad();
 
   mLoader = loader;
   if (!spec.IsEmpty()) {
     mPACURISpec = spec;
+    mPACURIRedirectSpec.Truncate();
     mLoadFailureCount = 0;  // reset
   }
 
   // reset to Null
   mScheduledReload = TimeStamp();
   return NS_OK;
 }
 
@@ -653,20 +654,30 @@ nsPACMan::AsyncOnChannelRedirect(nsIChan
                                  nsIAsyncVerifyRedirectCallback *callback)
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(), "wrong thread");
   
   nsresult rv = NS_OK;
   nsCOMPtr<nsIURI> pacURI;
   if (NS_FAILED((rv = newChannel->GetURI(getter_AddRefs(pacURI)))))
       return rv;
-  rv = pacURI->GetSpec(mPACURISpec);
+
+  rv = pacURI->GetSpec(mPACURIRedirectSpec);
   if (NS_FAILED(rv))
       return rv;
 
+  LOG(("nsPACMan redirect from original %s to redirected %s\n",
+       mPACURISpec.get(), mPACURIRedirectSpec.get()));
+
+  // do not update mPACURISpec - that needs to stay as the
+  // configured URI so that we can determine when the config changes.
+  // However do track the most recent URI in the redirect change
+  // as mPACURIRedirectSpec so that URI can be allowed to bypass
+  // the proxy and actually fetch the pac file.
+
   callback->OnRedirectVerifyCallback(NS_OK);
   return NS_OK;
 }
 
 void
 nsPACMan::NamePACThread()
 {
   NS_ABORT_IF_FALSE(!NS_IsMainThread(), "wrong thread");
--- a/netwerk/base/src/nsPACMan.h
+++ b/netwerk/base/src/nsPACMan.h
@@ -122,32 +122,37 @@ public:
   nsresult LoadPACFromURI(const nsCString &pacSpec);
 
   /**
    * Returns true if we are currently loading the PAC file.
    */
   bool IsLoading() { return mLoader != nullptr; }
 
   /**
-   * Returns true if the given URI matches the URI of our PAC file.
+   * Returns true if the given URI matches the URI of our PAC file or the
+   * URI it has been redirected to. In the case of a chain of redirections
+   * only the current one being followed and the original are considered
+   * becuase this information is used, respectively, to determine if we
+   * should bypass the proxy (to fetch the pac file) or if the pac
+   * configuration has changed (and we should reload the pac file)
    */
+  bool IsPACURI(const nsACString &spec)
+  {
+    return mPACURISpec.Equals(spec) || mPACURIRedirectSpec.Equals(spec);
+  }
+
   bool IsPACURI(nsIURI *uri) {
-    if (mPACURISpec.IsEmpty())
+    if (mPACURISpec.IsEmpty() && mPACURIRedirectSpec.IsEmpty())
       return false;
 
     nsAutoCString tmp;
     uri->GetSpec(tmp);
     return IsPACURI(tmp);
   }
 
-  bool IsPACURI(const nsACString &spec)
-  {
-    return mPACURISpec.Equals(spec);
-  }
-
   NS_HIDDEN_(nsresult) Init(nsISystemProxySettings *);
   static nsPACMan *sInstance;
 
   // PAC thread operations only
   void ProcessPendingQ();
   void CancelPendingQ(nsresult);
 
 private:
@@ -197,16 +202,17 @@ private:
 private:
   mozilla::net::ProxyAutoConfig mPAC;
   nsCOMPtr<nsIThread>           mPACThread;
   nsCOMPtr<nsISystemProxySettings> mSystemProxySettings;
 
   mozilla::LinkedList<PendingPACQuery> mPendingQ; /* pac thread only */
 
   nsCString                    mPACURISpec; // Not an nsIRUI for use off main thread
+  nsCString                    mPACURIRedirectSpec;
   nsCOMPtr<nsIStreamLoader>    mLoader;
   bool                         mLoadPending;
   bool                         mShutdown;
   mozilla::TimeStamp           mScheduledReload;
   uint32_t                     mLoadFailureCount;
 
   bool                         mInProgress;
 };