From 67c90e46e4f92203245e1d609d88c449fa41d677 Mon Sep 17 00:00:00 2001 From: "serge%netscape.com" Date: Sat, 4 Aug 2001 01:53:49 +0000 Subject: [PATCH] bug 79246 PAC: reload of PAC file fails; submitted by tingley@sundell.net, r=serge, sr=darin git-svn-id: svn://10.0.0.236/trunk@100342 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/public/nsIProtocolProxyService.idl | 2 +- .../base/src/nsProtocolProxyService.cpp | 109 ++++++++++-------- mozilla/netwerk/base/src/nsProxyAutoConfig.js | 3 + .../resources/content/pref-proxies.xul | 1 + 4 files changed, 63 insertions(+), 52 deletions(-) diff --git a/mozilla/netwerk/base/public/nsIProtocolProxyService.idl b/mozilla/netwerk/base/public/nsIProtocolProxyService.idl index df79c8a721a..34f350770ce 100644 --- a/mozilla/netwerk/base/public/nsIProtocolProxyService.idl +++ b/mozilla/netwerk/base/public/nsIProtocolProxyService.idl @@ -42,6 +42,6 @@ interface nsIProtocolProxyService : nsISupports */ void addNoProxyFor(in string host, in long port); void removeNoProxyFor(in string host, in long port); - + void configureFromPAC(in string url); }; diff --git a/mozilla/netwerk/base/src/nsProtocolProxyService.cpp b/mozilla/netwerk/base/src/nsProtocolProxyService.cpp index 467010bb871..2a2d89464e0 100644 --- a/mozilla/netwerk/base/src/nsProtocolProxyService.cpp +++ b/mozilla/netwerk/base/src/nsProtocolProxyService.cpp @@ -227,57 +227,8 @@ nsProtocolProxyService::PrefsChanged(const char* pref) { { rv = mPrefs->CopyCharPref("network.proxy.autoconfig_url", getter_Copies(tempString)); - if (NS_SUCCEEDED(rv) && (!reloadPAC || PL_strcmp(tempString, mPACURL))) { - mPACURL.Adopt(nsCRT::strdup(tempString)); - - // create pac js component - mPAC = do_CreateInstance(NS_PROXY_AUTO_CONFIG_CONTRACTID, &rv); - if (!mPAC || NS_FAILED(rv)) { - NS_ERROR("Cannot load PAC js component"); - return; - } - - /* now we need to setup a callback from the main ui thread - in which we will load the pac file from the specified - url. loading it now, in the current thread results in a - browser crash */ - - // get event queue service - nsCOMPtr eqs = - do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID); - if (!eqs) { - NS_ERROR("Failed to get EventQueue service"); - return; - } - - // get ui thread's event queue - nsCOMPtr eq = nsnull; - rv = eqs->GetThreadEventQueue(NS_UI_THREAD, getter_AddRefs(eq)); - if (NS_FAILED(rv) || !eqs) { - NS_ERROR("Failed to get UI EventQueue"); - return; - } - - // create an event - PLEvent* event = new PLEvent; - // AddRef this because it is being placed in the PLEvent struct - // It will be Released when DestroyPACLoadEvent is called - NS_ADDREF_THIS(); - PL_InitEvent(event, - this, - (PLHandleEventProc) - nsProtocolProxyService::HandlePACLoadEvent, - (PLDestroyEventProc) - nsProtocolProxyService::DestroyPACLoadEvent); - - // post the event into the ui event queue - if (eq->PostEvent(event) == PR_FAILURE) { - NS_ERROR("Failed to post PAC load event to UI EventQueue"); - NS_RELEASE_THIS(); - delete event; - return; - } - } + if (NS_SUCCEEDED(rv) && (!reloadPAC || PL_strcmp(tempString, mPACURL))) + ConfigureFromPAC(tempString); } } @@ -487,6 +438,62 @@ nsProtocolProxyService::ExamineForProxy(nsIURI *aURI, char * *aProxyHost, PRInt3 return NS_OK; } +NS_IMETHODIMP +nsProtocolProxyService::ConfigureFromPAC(const char *url) +{ + nsresult rv = NS_OK; + mPACURL.Adopt(nsCRT::strdup(url)); + + // create pac js component + mPAC = do_CreateInstance(NS_PROXY_AUTO_CONFIG_CONTRACTID, &rv); + if (!mPAC || NS_FAILED(rv)) { + NS_ERROR("Cannot load PAC js component"); + return rv; + } + + /* now we need to setup a callback from the main ui thread + in which we will load the pac file from the specified + url. loading it now, in the current thread results in a + browser crash */ + + // get event queue service + nsCOMPtr eqs = + do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID); + if (!eqs) { + NS_ERROR("Failed to get EventQueue service"); + return rv; + } + + // get ui thread's event queue + nsCOMPtr eq = nsnull; + rv = eqs->GetThreadEventQueue(NS_UI_THREAD, getter_AddRefs(eq)); + if (NS_FAILED(rv) || !eqs) { + NS_ERROR("Failed to get UI EventQueue"); + return rv; + } + + // create an event + PLEvent* event = new PLEvent; + // AddRef this because it is being placed in the PLEvent struct + // It will be Released when DestroyPACLoadEvent is called + NS_ADDREF_THIS(); + PL_InitEvent(event, + this, + (PLHandleEventProc) + nsProtocolProxyService::HandlePACLoadEvent, + (PLDestroyEventProc) + nsProtocolProxyService::DestroyPACLoadEvent); + + // post the event into the ui event queue + if (eq->PostEvent(event) == PR_FAILURE) { + NS_ERROR("Failed to post PAC load event to UI EventQueue"); + NS_RELEASE_THIS(); + delete event; + return NS_ERROR_FAILURE; + } + return NS_OK; +} + NS_IMETHODIMP nsProtocolProxyService::GetProxyEnabled(PRBool* o_Enabled) { diff --git a/mozilla/netwerk/base/src/nsProxyAutoConfig.js b/mozilla/netwerk/base/src/nsProxyAutoConfig.js index 5b42f396ef1..255c1a9b226 100644 --- a/mozilla/netwerk/base/src/nsProxyAutoConfig.js +++ b/mozilla/netwerk/base/src/nsProxyAutoConfig.js @@ -34,6 +34,7 @@ const kPAC_CID = Components.ID("{63ac8c66-1dd2-11b2-b070-84d00d3eaece}"); const nsIProxyAutoConfig = Components.interfaces.nsIProxyAutoConfig; const nsIIOService = Components.interfaces['nsIIOService']; const nsIDNSService = Components.interfaces.nsIDNSService; +const nsIRequest = Components.interfaces.nsIRequest; // implementor of nsIProxyAutoConfig function nsProxyAutoConfig() {}; @@ -85,6 +86,8 @@ nsProxyAutoConfig.prototype = { LoadPACFromURL: function(uri, ioService) { this.done = false; var channel = ioService.newChannelFromURI(uri); + // don't cache the PAC content + channel.loadFlags |= nsIRequest.LOAD_BYPASS_CACHE; pacURL = uri.spec; channel.asyncOpen(this, null); }, diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-proxies.xul b/mozilla/xpfe/components/prefwindow/resources/content/pref-proxies.xul index 67783addf13..e70f365639b 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-proxies.xul +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-proxies.xul @@ -139,6 +139,7 @@ pref="true" preftype="string" prefstring="network.proxy.autoconfig_url" prefattribute="value"/>