2005-03-25 06:41:33 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
#include "nsPACMan.h"
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2006-06-13 05:14:20 +04:00
|
|
|
#include "nsIAuthPrompt.h"
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
#include "nsIDHCPClient.h"
|
2006-06-13 05:14:20 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
#include "nsIPromptFactory.h"
|
|
|
|
#include "nsIProtocolProxyService.h"
|
2018-07-10 18:42:01 +03:00
|
|
|
#include "nsISystemProxySettings.h"
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2018-07-17 02:05:39 +03:00
|
|
|
#include "mozilla/Result.h"
|
|
|
|
#include "mozilla/ResultExtensions.h"
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2015-11-03 07:35:29 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
2016-05-19 05:02:57 +03:00
|
|
|
|
2015-11-03 07:35:29 +03:00
|
|
|
LazyLogModule gProxyLog("proxy");
|
|
|
|
|
2013-11-21 02:55:44 +04:00
|
|
|
#undef LOG
|
2016-05-19 05:02:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gProxyLog, LogLevel::Debug, args)
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
#define MOZ_WPAD_URL "http://wpad/wpad.dat"
|
|
|
|
#define MOZ_DHCP_WPAD_OPTION 252
|
2012-12-04 01:28:19 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// The PAC thread does evaluations of both PAC files and
|
|
|
|
// nsISystemProxySettings because they can both block the calling thread and we
|
|
|
|
// don't want that on the main thread
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2006-06-13 05:14:20 +04:00
|
|
|
// Check to see if the underlying request was not an error page in the case of
|
|
|
|
// a HTTP request. For other types of channels, just return true.
|
|
|
|
static bool HttpRequestSucceeded(nsIStreamLoader *loader) {
|
|
|
|
nsCOMPtr<nsIRequest> request;
|
|
|
|
loader->GetRequest(getter_AddRefs(request));
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool result = true; // default to assuming success
|
2006-06-13 05:14:20 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(request);
|
2016-12-27 14:05:13 +03:00
|
|
|
if (httpChannel) {
|
|
|
|
// failsafe
|
|
|
|
Unused << httpChannel->GetRequestSucceeded(&result);
|
|
|
|
}
|
2006-06-13 05:14:20 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-05-24 09:24:55 +03:00
|
|
|
// Read preference setting of extra JavaScript context heap size.
|
|
|
|
// PrefService tends to be run on main thread, where ProxyAutoConfig runs on
|
|
|
|
// ProxyResolution thread, so it's read here and passed to ProxyAutoConfig.
|
|
|
|
static uint32_t GetExtraJSContextHeapSize() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
static int32_t extraSize = -1;
|
|
|
|
|
|
|
|
if (extraSize < 0) {
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
int32_t value;
|
|
|
|
|
|
|
|
if (prefs &&
|
|
|
|
NS_SUCCEEDED(prefs->GetIntPref(
|
|
|
|
"network.proxy.autoconfig_extra_jscontext_heap_size", &value))) {
|
|
|
|
LOG(("autoconfig_extra_jscontext_heap_size: %d\n", value));
|
|
|
|
|
|
|
|
extraSize = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return extraSize < 0 ? 0 : extraSize;
|
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
// Read network proxy type from preference
|
|
|
|
// Used to verify that the preference is WPAD in nsPACMan::ConfigureWPAD
|
|
|
|
nsresult GetNetworkProxyTypeFromPref(int32_t *type) {
|
|
|
|
*type = 0;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (!prefs) {
|
|
|
|
LOG(("Failed to get a preference service object"));
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
|
|
|
nsresult rv = prefs->GetIntPref("network.proxy.type", type);
|
2018-10-04 11:42:21 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
LOG(("Failed to retrieve network.proxy.type from prefs"));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
LOG(("network.proxy.type pref retrieved: %d\n", *type));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-05-24 09:24:55 +03:00
|
|
|
|
2006-06-13 05:14:20 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// The ExecuteCallback runnable is triggered by
|
|
|
|
// nsPACManCallback::OnQueryComplete on the Main thread when its completion is
|
|
|
|
// discovered on the pac thread
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ExecuteCallback final : public Runnable {
|
2005-03-25 06:41:33 +03:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
ExecuteCallback(nsPACManCallback *aCallback, nsresult status)
|
|
|
|
: Runnable("net::ExecuteCallback"),
|
|
|
|
mCallback(aCallback),
|
2012-09-15 00:27:46 +04:00
|
|
|
mStatus(status) {}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
void SetPACString(const nsACString &pacString) { mPACString = pacString; }
|
2005-03-25 06:41:33 +03:00
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
void SetPACURL(const nsACString &pacURL) { mPACURL = pacURL; }
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2012-09-15 00:27:46 +04:00
|
|
|
mCallback->OnQueryComplete(mStatus, mPACString, mPACURL);
|
|
|
|
mCallback = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPACManCallback> mCallback;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsresult mStatus;
|
|
|
|
nsCString mPACString;
|
|
|
|
nsCString mPACURL;
|
2005-03-25 06:41:33 +03:00
|
|
|
};
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// The PAC thread must be deleted from the main thread, this class
|
|
|
|
// acts as a proxy to do that, as the PACMan is reference counted
|
|
|
|
// and might be destroyed on either thread
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ShutdownThread final : public Runnable {
|
2012-09-15 00:27:46 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit ShutdownThread(nsIThread *thread)
|
|
|
|
: Runnable("net::ShutdownThread"), mThread(thread) {}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2012-09-15 00:27:46 +04:00
|
|
|
mThread->Shutdown();
|
|
|
|
return NS_OK;
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
};
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2014-08-14 09:59:00 +04:00
|
|
|
// Dispatch this to wait until the PAC thread shuts down.
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class WaitForThreadShutdown final : public Runnable {
|
2014-08-14 09:59:00 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit WaitForThreadShutdown(nsPACMan *aPACMan)
|
|
|
|
: Runnable("net::WaitForThreadShutdown"), mPACMan(aPACMan) {}
|
2014-08-14 09:59:00 +04:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2014-08-14 09:59:00 +04:00
|
|
|
if (mPACMan->mPACThread) {
|
|
|
|
mPACMan->mPACThread->Shutdown();
|
|
|
|
mPACMan->mPACThread = nullptr;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPACMan> mPACMan;
|
2014-08-14 09:59:00 +04:00
|
|
|
};
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// PACLoadComplete allows the PAC thread to tell the main thread that
|
|
|
|
// the javascript PAC file has been installed (perhaps unsuccessfully)
|
|
|
|
// and that there is no reason to queue executions anymore
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class PACLoadComplete final : public Runnable {
|
2012-09-15 00:27:46 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit PACLoadComplete(nsPACMan *aPACMan)
|
|
|
|
: Runnable("net::PACLoadComplete"), mPACMan(aPACMan) {}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2012-09-15 00:27:46 +04:00
|
|
|
mPACMan->mLoader = nullptr;
|
|
|
|
mPACMan->PostProcessPendingQ();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
RefPtr<nsPACMan> mPACMan;
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// ConfigureWPADComplete allows the PAC thread to tell the main thread that
|
|
|
|
// the URL for the PAC file has been found
|
|
|
|
class ConfigureWPADComplete final : public Runnable {
|
|
|
|
public:
|
|
|
|
ConfigureWPADComplete(nsPACMan *aPACMan, const nsACString &aPACURISpec)
|
|
|
|
: Runnable("net::ConfigureWPADComplete"),
|
|
|
|
mPACMan(aPACMan),
|
|
|
|
mPACURISpec(aPACURISpec) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
|
|
|
mPACMan->AssignPACURISpec(mPACURISpec);
|
|
|
|
mPACMan->ContinueLoadingAfterPACUriKnown();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<nsPACMan> mPACMan;
|
|
|
|
nsCString mPACURISpec;
|
2012-09-15 00:27:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// ExecutePACThreadAction is used to proxy actions from the main
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
// thread onto the PAC thread. There are 4 options: process the queue,
|
|
|
|
// cancel the queue, query DHCP for the PAC option
|
|
|
|
// and setup the javascript context with a new PAC file
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ExecutePACThreadAction final : public Runnable {
|
2012-09-15 00:27:46 +04:00
|
|
|
public:
|
|
|
|
// by default we just process the queue
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit ExecutePACThreadAction(nsPACMan *aPACMan)
|
|
|
|
: Runnable("net::ExecutePACThreadAction"),
|
|
|
|
mPACMan(aPACMan),
|
2012-09-15 00:27:46 +04:00
|
|
|
mCancel(false),
|
2016-05-30 15:48:05 +03:00
|
|
|
mCancelStatus(NS_OK),
|
2012-09-15 00:27:46 +04:00
|
|
|
mSetupPAC(false),
|
2017-05-24 09:24:55 +03:00
|
|
|
mExtraHeapSize(0),
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
mConfigureWPAD(false),
|
2018-07-17 02:05:39 +03:00
|
|
|
mShutdown(false) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-17 02:05:39 +03:00
|
|
|
void CancelQueue(nsresult status, bool aShutdown) {
|
2012-09-15 00:27:46 +04:00
|
|
|
mCancel = true;
|
|
|
|
mCancelStatus = status;
|
2018-07-17 02:05:39 +03:00
|
|
|
mShutdown = aShutdown;
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
2018-12-04 22:40:45 +03:00
|
|
|
void SetupPAC(const char *data, uint32_t dataLen, const nsACString &pacURI,
|
2017-05-24 09:24:55 +03:00
|
|
|
uint32_t extraHeapSize) {
|
2012-09-15 00:27:46 +04:00
|
|
|
mSetupPAC = true;
|
2018-12-04 22:40:45 +03:00
|
|
|
mSetupPACData.Assign(data, dataLen);
|
2012-09-15 00:27:46 +04:00
|
|
|
mSetupPACURI = pacURI;
|
2017-05-24 09:24:55 +03:00
|
|
|
mExtraHeapSize = extraHeapSize;
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
void ConfigureWPAD() { mConfigureWPAD = true; }
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mCancel) {
|
2018-07-17 02:05:39 +03:00
|
|
|
mPACMan->CancelPendingQ(mCancelStatus, mShutdown);
|
2012-09-15 00:27:46 +04:00
|
|
|
mCancel = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSetupPAC) {
|
|
|
|
mSetupPAC = false;
|
|
|
|
|
2017-07-05 01:48:00 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> target = mPACMan->GetNeckoTarget();
|
2012-09-15 00:27:46 +04:00
|
|
|
mPACMan->mPAC.Init(mSetupPACURI, mSetupPACData, mPACMan->mIncludePath,
|
2017-07-05 01:48:00 +03:00
|
|
|
mExtraHeapSize, target);
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PACLoadComplete> runnable = new PACLoadComplete(mPACMan);
|
2017-07-05 01:48:00 +03:00
|
|
|
mPACMan->Dispatch(runnable.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
if (mConfigureWPAD) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
mConfigureWPAD = false;
|
|
|
|
mPACMan->ConfigureWPAD(spec);
|
|
|
|
RefPtr<ConfigureWPADComplete> runnable =
|
|
|
|
new ConfigureWPADComplete(mPACMan, spec);
|
|
|
|
mPACMan->Dispatch(runnable.forget());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
mPACMan->ProcessPendingQ();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPACMan> mPACMan;
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
bool mCancel;
|
|
|
|
nsresult mCancelStatus;
|
|
|
|
|
|
|
|
bool mSetupPAC;
|
2017-05-24 09:24:55 +03:00
|
|
|
uint32_t mExtraHeapSize;
|
2018-04-30 16:34:39 +03:00
|
|
|
nsCString mSetupPACData;
|
|
|
|
nsCString mSetupPACURI;
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
bool mConfigureWPAD;
|
2018-07-17 02:05:39 +03:00
|
|
|
bool mShutdown;
|
2012-09-15 00:27:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
PendingPACQuery::PendingPACQuery(nsPACMan *pacMan, nsIURI *uri,
|
|
|
|
nsPACManCallback *callback,
|
2012-09-15 00:27:46 +04:00
|
|
|
bool mainThreadResponse)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("net::PendingPACQuery"),
|
2018-06-14 11:19:07 +03:00
|
|
|
mPort(0),
|
2017-06-12 22:34:10 +03:00
|
|
|
mPACMan(pacMan),
|
2012-09-15 00:27:46 +04:00
|
|
|
mCallback(callback),
|
|
|
|
mOnMainThreadOnly(mainThreadResponse) {
|
|
|
|
uri->GetAsciiSpec(mSpec);
|
|
|
|
uri->GetAsciiHost(mHost);
|
|
|
|
uri->GetScheme(mScheme);
|
|
|
|
uri->GetPort(&mPort);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
void PendingPACQuery::Complete(nsresult status, const nsACString &pacString) {
|
2005-03-25 06:41:33 +03:00
|
|
|
if (!mCallback) return;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ExecuteCallback> runnable = new ExecuteCallback(mCallback, status);
|
2012-09-15 00:27:46 +04:00
|
|
|
runnable->SetPACString(pacString);
|
|
|
|
if (mOnMainThreadOnly)
|
2017-07-05 01:48:00 +03:00
|
|
|
mPACMan->Dispatch(runnable.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
else
|
|
|
|
runnable->Run();
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
2012-09-14 01:42:29 +04:00
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
void PendingPACQuery::UseAlternatePACFile(const nsACString &pacURL) {
|
2012-09-17 19:54:09 +04:00
|
|
|
if (!mCallback) return;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ExecuteCallback> runnable = new ExecuteCallback(mCallback, NS_OK);
|
2012-09-15 00:27:46 +04:00
|
|
|
runnable->SetPACURL(pacURL);
|
|
|
|
if (mOnMainThreadOnly)
|
2017-07-05 01:48:00 +03:00
|
|
|
mPACMan->Dispatch(runnable.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
else
|
|
|
|
runnable->Run();
|
|
|
|
}
|
2012-09-17 19:54:09 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PendingPACQuery::Run() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
2012-09-15 00:27:46 +04:00
|
|
|
mPACMan->PostQuery(this);
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-08-07 19:38:41 +04:00
|
|
|
static bool sThreadLocalSetup = false;
|
|
|
|
static uint32_t sThreadLocalIndex = 0xdeadbeef; // out of range
|
|
|
|
|
2016-09-21 04:42:52 +03:00
|
|
|
static const char *kPACIncludePath =
|
|
|
|
"network.proxy.autoconfig_url.include_path";
|
|
|
|
|
2017-07-05 01:48:00 +03:00
|
|
|
nsPACMan::nsPACMan(nsIEventTarget *mainThreadEventTarget)
|
|
|
|
: NeckoTargetHolder(mainThreadEventTarget),
|
|
|
|
mLoadPending(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mShutdown(false),
|
2006-06-13 05:14:20 +04:00
|
|
|
mLoadFailureCount(0),
|
2012-09-15 00:27:46 +04:00
|
|
|
mInProgress(false),
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
mAutoDetect(false),
|
|
|
|
mWPADOverDHCPEnabled(false),
|
|
|
|
mProxyConfigType(0) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "pacman must be created on main thread");
|
2014-08-07 19:38:41 +04:00
|
|
|
if (!sThreadLocalSetup) {
|
|
|
|
sThreadLocalSetup = true;
|
|
|
|
PR_NewThreadPrivateIndex(&sThreadLocalIndex, nullptr);
|
|
|
|
}
|
|
|
|
mPAC.SetThreadLocalIndex(sThreadLocalIndex);
|
2016-09-21 04:42:52 +03:00
|
|
|
mIncludePath = Preferences::GetBool(kPACIncludePath, false);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPACMan::~nsPACMan() {
|
2017-09-04 12:17:44 +03:00
|
|
|
MOZ_ASSERT(mShutdown, "Shutdown must be called before dtor.");
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mPACThread) {
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
mPACThread->Shutdown();
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
mPACThread = nullptr;
|
2012-09-15 00:27:46 +04:00
|
|
|
} else {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ShutdownThread> runnable = new ShutdownThread(mPACThread);
|
2017-07-05 01:48:00 +03:00
|
|
|
Dispatch(runnable.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(mLoader == nullptr, "pac man not shutdown properly");
|
2012-09-15 00:27:46 +04:00
|
|
|
NS_ASSERTION(mPendingQ.isEmpty(), "pac man not shutdown properly");
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsPACMan::Shutdown() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "pacman must be shutdown on main thread");
|
2014-08-14 09:59:00 +04:00
|
|
|
if (mShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-17 02:05:39 +03:00
|
|
|
|
2018-07-17 08:51:20 +03:00
|
|
|
CancelExistingLoad();
|
2018-07-17 02:05:39 +03:00
|
|
|
|
2018-07-17 02:05:39 +03:00
|
|
|
if (mPACThread) {
|
|
|
|
PostCancelPendingQ(NS_ERROR_ABORT, /*aShutdown =*/true);
|
2018-07-17 02:05:39 +03:00
|
|
|
|
2018-07-17 02:05:39 +03:00
|
|
|
// Shutdown is initiated from an observer. We don't want to block the
|
|
|
|
// observer service on thread shutdown so we post a shutdown runnable that
|
|
|
|
// will run after we return instead.
|
|
|
|
RefPtr<WaitForThreadShutdown> runnable = new WaitForThreadShutdown(this);
|
|
|
|
Dispatch(runnable.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
mShutdown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPACMan::DispatchToPAC(already_AddRefed<nsIRunnable> aEvent,
|
|
|
|
bool aSync) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> e(aEvent);
|
|
|
|
|
|
|
|
if (mShutdown) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lazily create the PAC thread. This method is main-thread only so we don't
|
|
|
|
// have to worry about threading issues here.
|
|
|
|
if (!mPACThread) {
|
|
|
|
MOZ_TRY(NS_NewNamedThread("ProxyResolution", getter_AddRefs(mPACThread)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPACThread->Dispatch(
|
|
|
|
e.forget(),
|
|
|
|
aSync ? nsIEventTarget::DISPATCH_SYNC : nsIEventTarget::DISPATCH_NORMAL);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2016-10-15 19:41:32 +03:00
|
|
|
nsresult nsPACMan::AsyncGetProxyForURI(nsIURI *uri, nsPACManCallback *callback,
|
2012-09-15 00:27:46 +04:00
|
|
|
bool mainThreadResponse) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mShutdown) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
// Maybe Reload PAC
|
2012-12-04 01:28:19 +04:00
|
|
|
if (!mPACURISpec.IsEmpty() && !mScheduledReload.IsNull() &&
|
2016-03-29 06:23:00 +03:00
|
|
|
TimeStamp::Now() > mScheduledReload) {
|
|
|
|
LOG(("nsPACMan::AsyncGetProxyForURI reload as scheduled\n"));
|
|
|
|
|
2018-10-19 12:13:16 +03:00
|
|
|
LoadPACFromURI(mAutoDetect ? EmptyCString() : mPACURISpec, false);
|
2016-03-29 06:23:00 +03:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PendingPACQuery> query =
|
2016-10-15 19:41:32 +03:00
|
|
|
new PendingPACQuery(this, uri, callback, mainThreadResponse);
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2005-07-01 00:21:34 +04:00
|
|
|
if (IsPACURI(uri)) {
|
2012-09-15 00:27:46 +04:00
|
|
|
// deal with this directly instead of queueing it
|
|
|
|
query->Complete(NS_OK, EmptyCString());
|
2005-06-25 03:58:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-07-17 02:05:39 +03:00
|
|
|
return DispatchToPAC(query.forget());
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsresult nsPACMan::PostQuery(PendingPACQuery *query) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mShutdown) {
|
|
|
|
query->Complete(NS_ERROR_NOT_AVAILABLE, EmptyCString());
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// add a reference to the query while it is in the pending list
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PendingPACQuery> addref(query);
|
2014-03-15 23:00:15 +04:00
|
|
|
mPendingQ.insertBack(addref.forget().take());
|
2012-09-15 00:27:46 +04:00
|
|
|
ProcessPendingQ();
|
|
|
|
return NS_OK;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
nsresult nsPACMan::LoadPACFromURI(const nsACString &aSpec) {
|
2018-10-19 12:13:16 +03:00
|
|
|
return LoadPACFromURI(aSpec, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPACMan::LoadPACFromURI(const nsACString &aSpec,
|
|
|
|
bool aResetLoadFailureCount) {
|
2005-03-25 06:41:33 +03:00
|
|
|
NS_ENSURE_STATE(!mShutdown);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamLoader> loader =
|
|
|
|
do_CreateInstance(NS_STREAMLOADER_CONTRACTID);
|
|
|
|
NS_ENSURE_STATE(loader);
|
|
|
|
|
2018-10-19 12:13:16 +03:00
|
|
|
LOG(("nsPACMan::LoadPACFromURI aSpec: %s, aResetLoadFailureCount: %s\n",
|
|
|
|
aSpec.BeginReading(), aResetLoadFailureCount ? "true" : "false"));
|
2018-10-01 12:11:33 +03:00
|
|
|
|
|
|
|
CancelExistingLoad();
|
|
|
|
|
|
|
|
mLoader = loader;
|
|
|
|
mPACURIRedirectSpec.Truncate();
|
|
|
|
mNormalPACURISpec.Truncate(); // set at load time
|
2018-10-19 12:13:16 +03:00
|
|
|
if (aResetLoadFailureCount) {
|
|
|
|
mLoadFailureCount = 0;
|
|
|
|
}
|
2018-10-01 12:11:33 +03:00
|
|
|
mAutoDetect = aSpec.IsEmpty();
|
|
|
|
mPACURISpec.Assign(aSpec);
|
|
|
|
|
|
|
|
// reset to Null
|
|
|
|
mScheduledReload = TimeStamp();
|
|
|
|
|
|
|
|
// if we're on the main thread here so we can get hold of prefs,
|
|
|
|
// we check that we have WPAD preffed on if we're auto-detecting
|
|
|
|
if (mAutoDetect && NS_IsMainThread()) {
|
|
|
|
nsresult rv = GetNetworkProxyTypeFromPref(&mProxyConfigType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-10-04 11:42:21 +03:00
|
|
|
if (mProxyConfigType != nsIProtocolProxyService::PROXYCONFIG_WPAD) {
|
|
|
|
LOG(
|
|
|
|
("LoadPACFromURI - Aborting WPAD autodetection because the pref "
|
|
|
|
"doesn't match anymore"));
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
2018-10-01 12:11:33 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
// Since we might get called from nsProtocolProxyService::Init, we need to
|
|
|
|
// post an event back to the main thread before we try to use the IO service.
|
|
|
|
//
|
|
|
|
// But, we need to flag ourselves as loading, so that we queue up any PAC
|
|
|
|
// queries the enter between now and when we actually load the PAC file.
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
if (!mLoadPending) {
|
2017-07-05 01:48:00 +03:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = NewRunnableMethod(
|
|
|
|
"nsPACMan::StartLoading", this, &nsPACMan::StartLoading);
|
|
|
|
nsresult rv =
|
|
|
|
NS_IsMainThread()
|
|
|
|
? Dispatch(runnable.forget())
|
|
|
|
: GetCurrentThreadEventTarget()->Dispatch(runnable.forget());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoadPending = true;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
nsresult nsPACMan::GetPACFromDHCP(nsACString &aSpec) {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
|
|
|
if (!mDHCPClient) {
|
|
|
|
LOG(
|
|
|
|
("nsPACMan::GetPACFromDHCP DHCP option %d query failed because there "
|
|
|
|
"is no DHCP client available\n",
|
|
|
|
MOZ_DHCP_WPAD_OPTION));
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
nsresult rv;
|
|
|
|
rv = mDHCPClient->GetOption(MOZ_DHCP_WPAD_OPTION, aSpec);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG((
|
|
|
|
"nsPACMan::GetPACFromDHCP DHCP option %d query failed with result %d\n",
|
|
|
|
MOZ_DHCP_WPAD_OPTION, (uint32_t)rv));
|
|
|
|
} else {
|
|
|
|
LOG(
|
|
|
|
("nsPACMan::GetPACFromDHCP DHCP option %d query succeeded, finding PAC "
|
|
|
|
"URL %s\n",
|
|
|
|
MOZ_DHCP_WPAD_OPTION, aSpec.BeginReading()));
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPACMan::ConfigureWPAD(nsACString &aSpec) {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
|
|
|
|
2018-10-04 11:42:21 +03:00
|
|
|
if (mProxyConfigType != nsIProtocolProxyService::PROXYCONFIG_WPAD) {
|
|
|
|
LOG(
|
|
|
|
("ConfigureWPAD - Aborting WPAD autodetection because the pref "
|
|
|
|
"doesn't match anymore"));
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
|
|
|
|
aSpec.Truncate();
|
|
|
|
if (mWPADOverDHCPEnabled) {
|
|
|
|
GetPACFromDHCP(aSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSpec.IsEmpty()) {
|
|
|
|
// We diverge from the WPAD spec here in that we don't walk the
|
|
|
|
// hosts's FQDN, stripping components until we hit a TLD. Doing so
|
|
|
|
// is dangerous in the face of an incomplete list of TLDs, and TLDs
|
|
|
|
// get added over time. We could consider doing only a single
|
|
|
|
// substitution of the first component, if that proves to help
|
|
|
|
// compatibility.
|
|
|
|
aSpec.AssignLiteral(MOZ_WPAD_URL);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPACMan::AssignPACURISpec(const nsACString &aSpec) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
|
|
|
mPACURISpec.Assign(aSpec);
|
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
void nsPACMan::StartLoading() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoadPending = false;
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// CancelExistingLoad was called...
|
|
|
|
if (!mLoader) {
|
2012-09-15 00:27:46 +04:00
|
|
|
PostCancelPendingQ(NS_ERROR_ABORT);
|
2006-05-10 21:30:15 +04:00
|
|
|
return;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
if (mAutoDetect) {
|
2018-10-01 12:11:33 +03:00
|
|
|
nsresult rv = GetNetworkProxyTypeFromPref(&mProxyConfigType);
|
2018-10-04 11:42:21 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2018-10-01 12:11:33 +03:00
|
|
|
NS_WARNING(
|
|
|
|
"Could not retrieve Network Proxy Type pref when auto-detecting "
|
|
|
|
"proxy. Halting.");
|
|
|
|
return;
|
|
|
|
}
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
RefPtr<ExecutePACThreadAction> wpadConfigurer =
|
|
|
|
new ExecutePACThreadAction(this);
|
|
|
|
wpadConfigurer->ConfigureWPAD();
|
2018-07-17 02:05:39 +03:00
|
|
|
DispatchToPAC(wpadConfigurer.forget());
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
} else {
|
|
|
|
ContinueLoadingAfterPACUriKnown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsPACMan::ContinueLoadingAfterPACUriKnown() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
|
|
|
|
|
|
|
// CancelExistingLoad was called...
|
|
|
|
if (!mLoader) {
|
|
|
|
PostCancelPendingQ(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
2015-05-04 17:17:47 +03:00
|
|
|
if (NS_SUCCEEDED(mLoader->Init(this, nullptr))) {
|
2006-10-25 01:47:40 +04:00
|
|
|
// Always hit the origin server when loading PAC.
|
|
|
|
nsCOMPtr<nsIIOService> ios = do_GetIOService();
|
|
|
|
if (ios) {
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2012-12-04 01:28:19 +04:00
|
|
|
nsCOMPtr<nsIURI> pacURI;
|
|
|
|
NS_NewURI(getter_AddRefs(pacURI), mPACURISpec);
|
2006-10-25 01:47:40 +04:00
|
|
|
|
|
|
|
// NOTE: This results in GetProxyForURI being called
|
2012-12-04 01:28:19 +04:00
|
|
|
if (pacURI) {
|
2016-08-26 09:40:57 +03:00
|
|
|
nsresult rv = pacURI->GetSpec(mNormalPACURISpec);
|
|
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
2015-02-17 21:09:31 +03:00
|
|
|
NS_NewChannel(getter_AddRefs(channel), pacURI,
|
|
|
|
nsContentUtils::GetSystemPrincipal(),
|
2015-09-12 04:52:08 +03:00
|
|
|
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
2015-02-17 21:09:31 +03:00
|
|
|
nsIContentPolicy::TYPE_OTHER,
|
2019-03-07 13:21:15 +03:00
|
|
|
nullptr, // nsICookieSettings
|
|
|
|
nullptr, // PerformanceStorage
|
2015-02-17 21:09:31 +03:00
|
|
|
nullptr, // aLoadGroup
|
|
|
|
nullptr, // aCallbacks
|
|
|
|
nsIRequest::LOAD_NORMAL, ios);
|
2012-12-04 01:28:19 +04:00
|
|
|
} else {
|
|
|
|
LOG(("nsPACMan::StartLoading Failed pacspec uri conversion %s\n",
|
|
|
|
mPACURISpec.get()));
|
|
|
|
}
|
2006-10-25 01:47:40 +04:00
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
channel->SetLoadFlags(nsIRequest::LOAD_BYPASS_CACHE);
|
|
|
|
channel->SetNotificationCallbacks(this);
|
2019-02-12 19:08:25 +03:00
|
|
|
if (NS_SUCCEEDED(channel->AsyncOpen(mLoader))) return;
|
2006-10-25 01:47:40 +04:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CancelExistingLoad();
|
2012-09-15 00:27:46 +04:00
|
|
|
PostCancelPendingQ(NS_ERROR_UNEXPECTED);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2006-06-13 05:14:20 +04:00
|
|
|
void nsPACMan::OnLoadFailure() {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t minInterval = 5; // 5 seconds
|
|
|
|
int32_t maxInterval = 300; // 5 minutes
|
2006-06-13 05:14:20 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefs) {
|
|
|
|
prefs->GetIntPref("network.proxy.autoconfig_retry_interval_min",
|
|
|
|
&minInterval);
|
|
|
|
prefs->GetIntPref("network.proxy.autoconfig_retry_interval_max",
|
|
|
|
&maxInterval);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t interval = minInterval << mLoadFailureCount++; // seconds
|
2006-06-13 05:14:20 +04:00
|
|
|
if (!interval || interval > maxInterval) interval = maxInterval;
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
mScheduledReload = TimeStamp::Now() + TimeDuration::FromSeconds(interval);
|
2006-06-13 05:14:20 +04:00
|
|
|
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("OnLoadFailure: retry in %d seconds (%d fails)\n", interval,
|
|
|
|
mLoadFailureCount));
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// while we wait for the retry queued members should try direct
|
|
|
|
// even if that means fast failure.
|
|
|
|
PostCancelPendingQ(NS_ERROR_NOT_AVAILABLE);
|
2006-06-13 05:14:20 +04:00
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
void nsPACMan::CancelExistingLoad() {
|
|
|
|
if (mLoader) {
|
|
|
|
nsCOMPtr<nsIRequest> request;
|
|
|
|
mLoader->GetRequest(getter_AddRefs(request));
|
|
|
|
if (request) request->Cancel(NS_ERROR_ABORT);
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoader = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
void nsPACMan::PostProcessPendingQ() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ExecutePACThreadAction> pending = new ExecutePACThreadAction(this);
|
2018-07-17 02:05:39 +03:00
|
|
|
DispatchToPAC(pending.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
2018-07-17 02:05:39 +03:00
|
|
|
void nsPACMan::PostCancelPendingQ(nsresult status, bool aShutdown) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ExecutePACThreadAction> pending = new ExecutePACThreadAction(this);
|
2018-07-17 02:05:39 +03:00
|
|
|
pending->CancelQueue(status, aShutdown);
|
|
|
|
DispatchToPAC(pending.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
2018-07-17 02:05:39 +03:00
|
|
|
void nsPACMan::CancelPendingQ(nsresult status, bool aShutdown) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PendingPACQuery> query;
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
while (!mPendingQ.isEmpty()) {
|
|
|
|
query = dont_AddRef(mPendingQ.popLast());
|
|
|
|
query->Complete(status, EmptyCString());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
if (aShutdown) mPAC.Shutdown();
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
void nsPACMan::ProcessPendingQ() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
|
2012-09-15 00:27:46 +04:00
|
|
|
while (ProcessPending())
|
|
|
|
;
|
|
|
|
|
2014-08-14 09:59:00 +04:00
|
|
|
if (mShutdown) {
|
2012-09-15 00:27:46 +04:00
|
|
|
mPAC.Shutdown();
|
2014-08-14 09:59:00 +04:00
|
|
|
} else {
|
|
|
|
// do GC while the thread has nothing pending
|
|
|
|
mPAC.GC();
|
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if progress was made by shortening the queue
|
|
|
|
bool nsPACMan::ProcessPending() {
|
|
|
|
if (mPendingQ.isEmpty()) return false;
|
|
|
|
|
|
|
|
// queue during normal load, but if we are retrying a failed load then
|
|
|
|
// fast fail the queries
|
|
|
|
if (mInProgress || (IsLoading() && !mLoadFailureCount)) return false;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PendingPACQuery> query(dont_AddRef(mPendingQ.popFirst()));
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
if (mShutdown || IsLoading()) {
|
|
|
|
query->Complete(NS_ERROR_NOT_AVAILABLE, EmptyCString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString pacString;
|
|
|
|
bool completed = false;
|
|
|
|
mInProgress = true;
|
|
|
|
nsAutoCString PACURI;
|
|
|
|
|
|
|
|
// first we need to consider the system proxy changing the pac url
|
|
|
|
if (mSystemProxySettings &&
|
|
|
|
NS_SUCCEEDED(mSystemProxySettings->GetPACURI(PACURI)) &&
|
|
|
|
!PACURI.IsEmpty() && !PACURI.Equals(mPACURISpec)) {
|
|
|
|
query->UseAlternatePACFile(PACURI);
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("Use PAC from system settings: %s\n", PACURI.get()));
|
2012-09-15 00:27:46 +04:00
|
|
|
completed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now try the system proxy settings for this particular url if
|
|
|
|
// PAC was not specified
|
|
|
|
if (!completed && mSystemProxySettings && PACURI.IsEmpty() &&
|
|
|
|
NS_SUCCEEDED(mSystemProxySettings->GetProxyForURI(
|
|
|
|
query->mSpec, query->mScheme, query->mHost, query->mPort,
|
|
|
|
pacString))) {
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("Use proxy from system settings: %s\n", pacString.get()));
|
2012-09-15 00:27:46 +04:00
|
|
|
query->Complete(NS_OK, pacString);
|
|
|
|
completed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the systemproxysettings didn't complete the resolution. try via PAC
|
|
|
|
if (!completed) {
|
2015-03-26 10:11:05 +03:00
|
|
|
nsresult status =
|
|
|
|
mPAC.GetProxyForURI(query->mSpec, query->mHost, pacString);
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("Use proxy from PAC: %s\n", pacString.get()));
|
2012-09-15 00:27:46 +04:00
|
|
|
query->Complete(status, pacString);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInProgress = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsPACMan, nsIStreamLoaderObserver, nsIInterfaceRequestor,
|
|
|
|
nsIChannelEventSink)
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPACMan::OnStreamComplete(nsIStreamLoader *loader, nsISupports *context,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult status, uint32_t dataLen,
|
|
|
|
const uint8_t *data) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2005-03-25 06:41:33 +03:00
|
|
|
if (mLoader != loader) {
|
|
|
|
// If this happens, then it means that LoadPACFromURI was called more
|
|
|
|
// than once before the initial call completed. In this case, status
|
|
|
|
// should be NS_ERROR_ABORT, and if so, then we know that we can and
|
|
|
|
// should delay any processing.
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("OnStreamComplete: called more than once\n"));
|
2005-03-25 06:41:33 +03:00
|
|
|
if (status == NS_ERROR_ABORT) return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("OnStreamComplete: entry\n"));
|
|
|
|
|
2006-06-13 05:14:20 +04:00
|
|
|
if (NS_SUCCEEDED(status) && HttpRequestSucceeded(loader)) {
|
2005-03-25 06:41:33 +03:00
|
|
|
// Get the URI spec used to load this PAC script.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString pacURI;
|
2005-03-25 06:41:33 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRequest> request;
|
|
|
|
loader->GetRequest(getter_AddRefs(request));
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
if (channel) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (uri) uri->GetAsciiSpec(pacURI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 22:40:45 +03:00
|
|
|
// We succeeded in loading the pac file using a bunch of interfaces that are
|
|
|
|
// main thread only. Unfortunately, we have to initialize the instance of
|
|
|
|
// the PAC evaluator (NS_PROXYAUTOCONFIG_CONTRACTID) on the PAC thread,
|
|
|
|
// because that's where it will be used.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ExecutePACThreadAction> pending = new ExecutePACThreadAction(this);
|
2018-12-04 22:40:45 +03:00
|
|
|
pending->SetupPAC(reinterpret_cast<const char *>(data), dataLen, pacURI,
|
|
|
|
GetExtraJSContextHeapSize());
|
2018-07-17 02:05:39 +03:00
|
|
|
DispatchToPAC(pending.forget());
|
2006-06-13 05:14:20 +04:00
|
|
|
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("OnStreamComplete: process the PAC contents\n"));
|
|
|
|
|
2006-06-13 05:14:20 +04:00
|
|
|
// Even if the PAC file could not be parsed, we did succeed in loading the
|
|
|
|
// data for it.
|
|
|
|
mLoadFailureCount = 0;
|
|
|
|
} else {
|
|
|
|
// We were unable to load the PAC file (presumably because of a network
|
|
|
|
// failure). Try again a little later.
|
2016-03-29 06:23:00 +03:00
|
|
|
LOG(("OnStreamComplete: unable to load PAC, retry later\n"));
|
2006-06-13 05:14:20 +04:00
|
|
|
OnLoadFailure();
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (NS_SUCCEEDED(status))
|
|
|
|
PostProcessPendingQ();
|
|
|
|
else
|
|
|
|
PostCancelPendingQ(status);
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPACMan::GetInterface(const nsIID &iid, void **result) {
|
|
|
|
// In case loading the PAC file requires authentication.
|
2010-06-17 04:06:17 +04:00
|
|
|
if (iid.Equals(NS_GET_IID(nsIAuthPrompt))) {
|
|
|
|
nsCOMPtr<nsIPromptFactory> promptFac =
|
|
|
|
do_GetService("@mozilla.org/prompter;1");
|
|
|
|
NS_ENSURE_TRUE(promptFac, NS_ERROR_FAILURE);
|
2012-07-30 18:20:58 +04:00
|
|
|
return promptFac->GetPrompt(nullptr, iid,
|
|
|
|
reinterpret_cast<void **>(result));
|
2010-06-17 04:06:17 +04:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2005-07-01 00:21:34 +04:00
|
|
|
// In case loading the PAC file results in a redirect.
|
|
|
|
if (iid.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
|
|
|
NS_ADDREF_THIS();
|
2007-07-08 11:08:04 +04:00
|
|
|
*result = static_cast<nsIChannelEventSink *>(this);
|
2005-07-01 00:21:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
2005-07-01 00:21:34 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-05 06:15:55 +04:00
|
|
|
nsPACMan::AsyncOnChannelRedirect(nsIChannel *oldChannel, nsIChannel *newChannel,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags,
|
2010-08-05 06:15:55 +04:00
|
|
|
nsIAsyncVerifyRedirectCallback *callback) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
|
2016-02-18 05:55:57 +03:00
|
|
|
|
2010-08-05 06:15:55 +04:00
|
|
|
nsresult rv = NS_OK;
|
2012-12-04 01:28:19 +04:00
|
|
|
nsCOMPtr<nsIURI> pacURI;
|
|
|
|
if (NS_FAILED((rv = newChannel->GetURI(getter_AddRefs(pacURI))))) return rv;
|
2013-01-02 01:05:07 +04:00
|
|
|
|
|
|
|
rv = pacURI->GetSpec(mPACURIRedirectSpec);
|
2012-12-04 01:28:19 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2010-08-05 06:15:55 +04:00
|
|
|
|
2013-01-02 01:05:07 +04:00
|
|
|
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.
|
|
|
|
|
2010-08-05 06:15:55 +04:00
|
|
|
callback->OnRedirectVerifyCallback(NS_OK);
|
|
|
|
return NS_OK;
|
2005-07-01 00:21:34 +04:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
nsresult nsPACMan::Init(nsISystemProxySettings *systemProxySettings) {
|
|
|
|
mSystemProxySettings = systemProxySettings;
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
mDHCPClient = do_GetService(NS_DHCPCLIENT_CONTRACTID);
|
2018-07-17 02:05:39 +03:00
|
|
|
return NS_OK;
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
2016-05-19 05:02:57 +03:00
|
|
|
|
|
|
|
} // namespace net
|
2018-07-17 02:05:39 +03:00
|
|
|
} // namespace mozilla
|