зеркало из https://github.com/mozilla/gecko-dev.git
Bug 939318 - protocolproxy service acts on network change. r=mcmanus
Reloads the PAC on network change, but avoids the reload if the specified PAC URL is a file: or a data: one - as those are not likely to have changed just because the network changed.
This commit is contained in:
Родитель
3815268a76
Коммит
b8ca3775b3
|
@ -29,6 +29,7 @@
|
|||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/CondVar.h"
|
||||
#include "nsISystemProxySettings.h"
|
||||
#include "nsINetworkLinkService.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
@ -414,14 +415,59 @@ nsProtocolProxyService::Init()
|
|||
PrefsChanged(prefBranch, nullptr);
|
||||
}
|
||||
|
||||
// register for shutdown notification so we can clean ourselves up properly.
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs)
|
||||
if (obs) {
|
||||
// register for shutdown notification so we can clean ourselves up
|
||||
// properly.
|
||||
obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
||||
|
||||
obs->AddObserver(this, NS_NETWORK_LINK_TOPIC, false);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// ReloadNetworkPAC() checks if there's a non-networked PAC in use then avoids
|
||||
// to call ReloadPAC()
|
||||
nsresult
|
||||
nsProtocolProxyService::ReloadNetworkPAC()
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs =
|
||||
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (!prefs) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int32_t type;
|
||||
nsresult rv = prefs->GetIntPref(PROXY_PREF("type"), &type);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (type == PROXYCONFIG_PAC) {
|
||||
nsXPIDLCString pacSpec;
|
||||
prefs->GetCharPref(PROXY_PREF("autoconfig_url"),
|
||||
getter_Copies(pacSpec));
|
||||
if (!pacSpec.IsEmpty()) {
|
||||
nsCOMPtr<nsIURI> pacURI;
|
||||
NS_NewURI(getter_AddRefs(pacURI), pacSpec);
|
||||
nsProtocolInfo pac;
|
||||
GetProtocolInfo(pacURI, &pac);
|
||||
|
||||
if (!pac.scheme.EqualsLiteral("file") &&
|
||||
!pac.scheme.EqualsLiteral("data")) {
|
||||
LOG((": received network changed event, reload PAC"));
|
||||
ReloadPAC();
|
||||
}
|
||||
}
|
||||
} else if ((type == PROXYCONFIG_WPAD) || (type == PROXYCONFIG_SYSTEM)) {
|
||||
ReloadPAC();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProtocolProxyService::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
|
@ -440,6 +486,12 @@ nsProtocolProxyService::Observe(nsISupports *aSubject,
|
|||
mPACMan->Shutdown();
|
||||
mPACMan = nullptr;
|
||||
}
|
||||
} else if (strcmp(aTopic, NS_NETWORK_LINK_TOPIC) == 0) {
|
||||
nsCString converted = NS_ConvertUTF16toUTF8(aData);
|
||||
const char *state = converted.get();
|
||||
if (!strcmp(state, NS_NETWORK_LINK_DATA_CHANGED)) {
|
||||
ReloadNetworkPAC();
|
||||
}
|
||||
}
|
||||
else {
|
||||
NS_ASSERTION(strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0,
|
||||
|
|
|
@ -280,6 +280,7 @@ protected:
|
|||
private:
|
||||
nsresult SetupPACThread();
|
||||
nsresult ResetPACThread();
|
||||
nsresult ReloadNetworkPAC();
|
||||
|
||||
public:
|
||||
// The Sun Forte compiler and others implement older versions of the
|
||||
|
|
Загрузка…
Ссылка в новой задаче