Bug 621429 - Added button to allow WPAD while using system proxy settings. r=necko-reviewers,fluent-reviewers,settings-reviewers,kershaw,bolsson,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D183429
This commit is contained in:
dylan 2024-03-08 04:38:55 +00:00
parent 0634f2533b
commit db2b454318
13 changed files with 150 additions and 38 deletions

View File

@ -16,6 +16,7 @@ Preferences.addAll([
// both initialized when network.proxy.type initialization triggers a call to
// gConnectionsDialog.updateReloadButton().
{ id: "network.proxy.autoconfig_url", type: "string" },
{ id: "network.proxy.system_wpad", type: "bool" },
{ id: "network.proxy.type", type: "int" },
{ id: "network.proxy.http", type: "string" },
{ id: "network.proxy.http_port", type: "int" },
@ -130,11 +131,20 @@ var gConnectionsDialog = {
checkForSystemProxy() {
if ("@mozilla.org/system-proxy-settings;1" in Cc) {
document.getElementById("systemPref").removeAttribute("hidden");
var systemWpadAllowed = Preferences.get(
"network.proxy.system_wpad.allowed"
);
if (systemWpadAllowed) {
document.getElementById("systemWpad").removeAttribute("hidden");
}
}
},
proxyTypeChanged() {
var proxyTypePref = Preferences.get("network.proxy.type");
var systemWpadPref = Preferences.get("network.proxy.system_wpad");
systemWpadPref.updateControlDisabledState(proxyTypePref.value != 5);
// Update http
var httpProxyURLPref = Preferences.get("network.proxy.http");

View File

@ -78,6 +78,14 @@
id="systemPref"
hidden="true"
/>
<checkbox
value="true"
data-l10n-id="connection-proxy-option-wpad"
id="systemWpad"
hidden="true"
preference="network.proxy.system_wpad"
class="indent"
/>
<radio value="1" data-l10n-id="connection-proxy-option-manual" />
<box id="proxy-grid" class="indent" flex="1">
<html:div class="proxy-grid-row">

View File

@ -813,6 +813,7 @@
connection-proxy-option-no.label,
connection-proxy-option-auto.label,
connection-proxy-option-system.label,
connection-proxy-option-wpad.label,
connection-proxy-option-manual.label,
connection-proxy-http,
connection-proxy-https,

View File

@ -24,6 +24,9 @@ connection-proxy-option-no =
connection-proxy-option-system =
.label = Use system proxy settings
.accesskey = U
connection-proxy-option-wpad =
.label = Use system Web Proxy Auto-Discovery setting
.accesskey = g
connection-proxy-option-auto =
.label = Auto-detect proxy settings for this network
.accesskey = w

View File

@ -12273,6 +12273,18 @@
value: 5
mirror: always
# Whether to use WPAD while configuring proxy with system settings
- name: network.proxy.system_wpad
type: bool
value: false
mirror: always
# Whether to allow the use of WPAD while configuring proxy with system settings
- name: network.proxy.system_wpad.allowed
type: bool
value: false
mirror: always
# Whether the SOCKS proxy should be in charge of DNS resolution.
- name: network.proxy.socks_remote_dns
type: RelaxedAtomicBool

View File

@ -39,4 +39,9 @@ interface nsISystemProxySettings : nsISupports
in AUTF8String testScheme,
in AUTF8String testHost,
in int32_t testPort);
/**
* Check if system settings are configured to use WPAD
*/
readonly attribute bool systemWPADSetting;
};

View File

@ -502,6 +502,13 @@ nsresult nsPACMan::PostQuery(PendingPACQuery* query) {
return NS_OK;
}
// check if proxy settings are configured for WPAD
bool IsProxyConfigValidForWPAD(int proxyConfigType, bool wpadSystemSettings) {
return proxyConfigType == nsIProtocolProxyService::PROXYCONFIG_WPAD ||
(proxyConfigType == nsIProtocolProxyService::PROXYCONFIG_SYSTEM &&
wpadSystemSettings);
}
nsresult nsPACMan::LoadPACFromURI(const nsACString& aSpec) {
return LoadPACFromURI(aSpec, true);
}
@ -541,7 +548,7 @@ nsresult nsPACMan::LoadPACFromURI(const nsACString& aSpec,
if (NS_FAILED(rv)) {
return rv;
}
if (mProxyConfigType != nsIProtocolProxyService::PROXYCONFIG_WPAD) {
if (!IsProxyConfigValidForWPAD(mProxyConfigType, mAutoDetect)) {
LOG(
("LoadPACFromURI - Aborting WPAD autodetection because the pref "
"doesn't match anymore"));
@ -595,7 +602,7 @@ nsresult nsPACMan::GetPACFromDHCP(nsACString& aSpec) {
nsresult nsPACMan::ConfigureWPAD(nsACString& aSpec) {
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
if (mProxyConfigType != nsIProtocolProxyService::PROXYCONFIG_WPAD) {
if (!IsProxyConfigValidForWPAD(mProxyConfigType, mAutoDetect)) {
LOG(
("ConfigureWPAD - Aborting WPAD autodetection because the pref "
"doesn't match anymore"));

View File

@ -621,28 +621,29 @@ nsAsyncResolveRequest::AsyncApplyFilters::Cancel(nsresult reason) {
return NS_OK;
}
// Bug 1366133: make GetPACURI off-main-thread since it may hang on Windows
// platform
class AsyncGetPACURIRequest final : public nsIRunnable {
// Bug 1366133: make GetPACURI and GetSystemWPADSetting off-main-thread since it
// may hang on Windows platform
class AsyncGetPACURIRequestOrSystemWPADSetting final : public nsIRunnable {
public:
NS_DECL_THREADSAFE_ISUPPORTS
using CallbackFunc = nsresult (nsProtocolProxyService::*)(bool, bool,
nsresult,
const nsACString&);
const nsACString&,
bool);
AsyncGetPACURIRequest(nsProtocolProxyService* aService,
CallbackFunc aCallback,
nsISystemProxySettings* aSystemProxySettings,
bool aMainThreadOnly, bool aForceReload,
bool aResetPACThread)
AsyncGetPACURIRequestOrSystemWPADSetting(
nsProtocolProxyService* aService, CallbackFunc aCallback,
nsISystemProxySettings* aSystemProxySettings, bool aMainThreadOnly,
bool aForceReload, bool aResetPACThread, bool aSystemWPADAllowed)
: mIsMainThreadOnly(aMainThreadOnly),
mService(aService),
mServiceHolder(do_QueryObject(aService)),
mCallback(aCallback),
mSystemProxySettings(aSystemProxySettings),
mForceReload(aForceReload),
mResetPACThread(aResetPACThread) {
mResetPACThread(aResetPACThread),
mSystemWPADAllowed(aSystemWPADAllowed) {
MOZ_ASSERT(NS_IsMainThread());
Unused << mIsMainThreadOnly;
}
@ -650,21 +651,30 @@ class AsyncGetPACURIRequest final : public nsIRunnable {
NS_IMETHOD Run() override {
MOZ_ASSERT(NS_IsMainThread() == mIsMainThreadOnly);
nsresult rv;
nsCString pacUri;
nsresult rv = mSystemProxySettings->GetPACURI(pacUri);
bool systemWPADSetting = false;
if (mSystemWPADAllowed) {
mSystemProxySettings->GetSystemWPADSetting(&systemWPADSetting);
}
rv = mSystemProxySettings->GetPACURI(pacUri);
nsCOMPtr<nsIRunnable> event =
NewNonOwningCancelableRunnableMethod<bool, bool, nsresult, nsCString>(
"AsyncGetPACURIRequestCallback", mService, mCallback, mForceReload,
mResetPACThread, rv, pacUri);
NewNonOwningCancelableRunnableMethod<bool, bool, nsresult, nsCString,
bool>(
"AsyncGetPACURIRequestOrSystemWPADSettingCallback", mService,
mCallback, mForceReload, mResetPACThread, rv, pacUri,
systemWPADSetting);
return NS_DispatchToMainThread(event);
}
private:
~AsyncGetPACURIRequest() {
NS_ReleaseOnMainThread("AsyncGetPACURIRequest::mServiceHolder",
mServiceHolder.forget());
~AsyncGetPACURIRequestOrSystemWPADSetting() {
NS_ReleaseOnMainThread(
"AsyncGetPACURIRequestOrSystemWPADSetting::mServiceHolder",
mServiceHolder.forget());
}
bool mIsMainThreadOnly;
@ -676,9 +686,10 @@ class AsyncGetPACURIRequest final : public nsIRunnable {
bool mForceReload;
bool mResetPACThread;
bool mSystemWPADAllowed;
};
NS_IMPL_ISUPPORTS(AsyncGetPACURIRequest, nsIRunnable)
NS_IMPL_ISUPPORTS(AsyncGetPACURIRequestOrSystemWPADSetting, nsIRunnable)
//----------------------------------------------------------------------------
@ -847,8 +858,8 @@ nsresult nsProtocolProxyService::ReloadNetworkPAC() {
return NS_OK;
}
nsresult nsProtocolProxyService::AsyncConfigureFromPAC(bool aForceReload,
bool aResetPACThread) {
nsresult nsProtocolProxyService::AsyncConfigureWPADOrFromPAC(
bool aForceReload, bool aResetPACThread, bool aSystemWPADAllowed) {
MOZ_ASSERT(NS_IsMainThread());
bool mainThreadOnly;
@ -857,9 +868,10 @@ nsresult nsProtocolProxyService::AsyncConfigureFromPAC(bool aForceReload,
return rv;
}
nsCOMPtr<nsIRunnable> req = new AsyncGetPACURIRequest(
this, &nsProtocolProxyService::OnAsyncGetPACURI, mSystemProxySettings,
mainThreadOnly, aForceReload, aResetPACThread);
nsCOMPtr<nsIRunnable> req = new AsyncGetPACURIRequestOrSystemWPADSetting(
this, &nsProtocolProxyService::OnAsyncGetPACURIOrSystemWPADSetting,
mSystemProxySettings, mainThreadOnly, aForceReload, aResetPACThread,
aSystemWPADAllowed);
if (mainThreadOnly) {
return req->Run();
@ -869,17 +881,24 @@ nsresult nsProtocolProxyService::AsyncConfigureFromPAC(bool aForceReload,
nsIEventTarget::DISPATCH_NORMAL);
}
nsresult nsProtocolProxyService::OnAsyncGetPACURI(bool aForceReload,
bool aResetPACThread,
nsresult aResult,
const nsACString& aUri) {
nsresult nsProtocolProxyService::OnAsyncGetPACURIOrSystemWPADSetting(
bool aForceReload, bool aResetPACThread, nsresult aResult,
const nsACString& aUri, bool aSystemWPADSetting) {
MOZ_ASSERT(NS_IsMainThread());
if (aResetPACThread) {
ResetPACThread();
}
if (NS_SUCCEEDED(aResult) && !aUri.IsEmpty()) {
if (aSystemWPADSetting) {
if (mSystemProxySettings || !mPACMan) {
mSystemProxySettings = nullptr;
ResetPACThread();
}
nsAutoCString tempString;
ConfigureFromPAC(EmptyCString(), false);
} else if (NS_SUCCEEDED(aResult) && !aUri.IsEmpty()) {
ConfigureFromPAC(PromiseFlatCString(aUri), aForceReload);
}
@ -960,7 +979,8 @@ void nsProtocolProxyService::PrefsChanged(nsIPrefBranch* prefBranch,
auto invokeCallback =
MakeScopeExit([&] { NotifyProxyConfigChangedInternal(); });
if (!pref || !strcmp(pref, PROXY_PREF("type"))) {
if (!pref || !strcmp(pref, PROXY_PREF("type")) ||
!strcmp(pref, PROXY_PREF("system_wpad"))) {
int32_t type = -1;
rv = prefBranch->GetIntPref(PROXY_PREF("type"), &type);
if (NS_SUCCEEDED(rv)) {
@ -1076,9 +1096,12 @@ void nsProtocolProxyService::PrefsChanged(nsIPrefBranch* prefBranch,
} else if (mProxyConfig == PROXYCONFIG_WPAD) {
LOG(("Auto-detecting proxy - Reset Pac Thread"));
ResetPACThread();
} else if (mSystemProxySettings && mProxyConfig == PROXYCONFIG_SYSTEM &&
StaticPrefs::network_proxy_system_wpad()) {
AsyncConfigureWPADOrFromPAC(false, false, true);
} else if (mSystemProxySettings) {
// Get System Proxy settings if available
AsyncConfigureFromPAC(false, false);
AsyncConfigureWPADOrFromPAC(false, false, false);
}
if (!tempString.IsEmpty() || mProxyConfig == PROXYCONFIG_WPAD) {
ConfigureFromPAC(tempString, false);
@ -1478,7 +1501,8 @@ nsProtocolProxyService::ReloadPAC() {
prefs->GetCharPref(PROXY_PREF("autoconfig_url"), pacSpec);
} else if (type == PROXYCONFIG_SYSTEM) {
if (mSystemProxySettings) {
AsyncConfigureFromPAC(true, true);
AsyncConfigureWPADOrFromPAC(true, true,
StaticPrefs::network_proxy_system_wpad());
} else {
ResetPACThread();
}
@ -1555,7 +1579,8 @@ nsresult nsProtocolProxyService::AsyncResolveInternal(
bool usePACThread;
// adapt to realtime changes in the system proxy service
if (mProxyConfig == PROXYCONFIG_SYSTEM) {
if (mProxyConfig == PROXYCONFIG_SYSTEM &&
!StaticPrefs::network_proxy_system_wpad()) {
nsCOMPtr<nsISystemProxySettings> sp2 =
do_GetService(NS_SYSTEMPROXYSETTINGS_CONTRACTID);
if (sp2 != mSystemProxySettings) {
@ -2190,7 +2215,8 @@ nsresult nsProtocolProxyService::Resolve_Internal(nsIChannel* channel,
}
// Proxy auto config magic...
if (mProxyConfig == PROXYCONFIG_PAC || mProxyConfig == PROXYCONFIG_WPAD) {
if (mProxyConfig == PROXYCONFIG_PAC || mProxyConfig == PROXYCONFIG_WPAD ||
StaticPrefs::network_proxy_system_wpad()) {
// Do not query PAC now.
*usePACThread = true;
return NS_OK;

View File

@ -320,9 +320,13 @@ class nsProtocolProxyService final : public nsIProtocolProxyService2,
nsresult ResetPACThread();
nsresult ReloadNetworkPAC();
nsresult AsyncConfigureFromPAC(bool aForceReload, bool aResetPACThread);
nsresult OnAsyncGetPACURI(bool aForceReload, bool aResetPACThread,
nsresult aResult, const nsACString& aUri);
nsresult AsyncConfigureWPADOrFromPAC(bool aForceReload, bool aResetPACThread,
bool aSystemWPADAllowed);
nsresult OnAsyncGetPACURIOrSystemWPADSetting(bool aForceReload,
bool aResetPACThread,
nsresult aResult,
const nsACString& aUri,
bool aSystemWPADSetting);
public:
// The Sun Forte compiler and others implement older versions of the

View File

@ -43,6 +43,12 @@ nsresult nsAndroidSystemProxySettings::GetProxyForURI(const nsACString& aSpec,
aPort, aResult);
}
NS_IMETHODIMP
nsAndroidSystemProxySettings::GetSystemWPADSetting(bool* aSystemWPADSetting) {
*aSystemWPADSetting = false;
return NS_OK;
}
void test(){};
NS_IMPL_COMPONENT_FACTORY(nsAndroidSystemProxySettings) {

View File

@ -68,6 +68,12 @@ nsOSXSystemProxySettings::GetMainThreadOnly(bool* aMainThreadOnly) {
return NS_OK;
}
NS_IMETHODIMP
nsOSXSystemProxySettings::GetSystemWPADSetting(bool* aSystemWPADSetting) {
*aSystemWPADSetting = false;
return NS_OK;
}
// Mapping of URI schemes to SystemConfiguration keys
const nsOSXSystemProxySettings::SchemeMapping
nsOSXSystemProxySettings::gSchemeMappingList[] = {
@ -399,6 +405,11 @@ OSXSystemProxySettingsAsync::GetPACURI(nsACString& aResult) {
return NS_OK;
}
NS_IMETHODIMP
OSXSystemProxySettingsAsync::GetSystemWPADSetting(bool* aSystemWPADSetting) {
return nsOSXSystemProxySettings::GetSystemWPADSetting(aSystemWPADSetting);
}
NS_IMETHODIMP
OSXSystemProxySettingsAsync::GetProxyForURI(const nsACString& aSpec,
const nsACString& aScheme,

View File

@ -398,6 +398,12 @@ nsresult nsUnixSystemProxySettings::GetProxyForURI(const nsACString& aSpec,
return GetProxyFromEnvironment(aScheme, aHost, aPort, aResult);
}
NS_IMETHODIMP
nsUnixSystemProxySettings::GetSystemWPADSetting(bool* aSystemWPADSetting) {
*aSystemWPADSetting = false;
return NS_OK;
}
NS_IMPL_COMPONENT_FACTORY(nsUnixSystemProxySettings) {
auto result = MakeRefPtr<nsUnixSystemProxySettings>();
result->Init();

View File

@ -241,6 +241,19 @@ nsresult nsWindowsSystemProxySettings::GetProxyForURI(const nsACString& aSpec,
return NS_OK;
}
NS_IMETHODIMP nsWindowsSystemProxySettings::GetSystemWPADSetting(
bool* aSystemWPADSetting) {
nsresult rv;
uint32_t flags = 0;
nsAutoString buf;
rv = ReadInternetOption(INTERNET_PER_CONN_AUTOCONFIG_URL, flags, buf);
*aSystemWPADSetting =
(flags & (PROXY_TYPE_AUTO_PROXY_URL | PROXY_TYPE_AUTO_DETECT)) ==
PROXY_TYPE_AUTO_DETECT;
return rv;
}
NS_IMPL_COMPONENT_FACTORY(nsWindowsSystemProxySettings) {
return mozilla::MakeAndAddRef<nsWindowsSystemProxySettings>()
.downcast<nsISupports>();