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
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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<nsIEventQueueService> eqs =
|
||||
do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID);
|
||||
if (!eqs) {
|
||||
NS_ERROR("Failed to get EventQueue service");
|
||||
return;
|
||||
}
|
||||
|
||||
// get ui thread's event queue
|
||||
nsCOMPtr<nsIEventQueue> 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<nsIEventQueueService> eqs =
|
||||
do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID);
|
||||
if (!eqs) {
|
||||
NS_ERROR("Failed to get EventQueue service");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// get ui thread's event queue
|
||||
nsCOMPtr<nsIEventQueue> 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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
@@ -139,6 +139,7 @@
|
||||
pref="true" preftype="string" prefstring="network.proxy.autoconfig_url"
|
||||
prefattribute="value"/>
|
||||
<button id="autoReload" class="dialog" label="&reload.label;" accesskey="&reload.accesskey;"
|
||||
oncommand="ReloadPAC();"
|
||||
pref="true" preftype="bool"
|
||||
prefstring="pref.advanced.proxies.disable_button.reload" prefattribute="disabled"/>
|
||||
</hbox>
|
||||
|
||||
Reference in New Issue
Block a user