proxy_configuration.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_WINHTTP_PROXY_CONFIGURATION_H_
  5. #define COMPONENTS_WINHTTP_PROXY_CONFIGURATION_H_
  6. #include <windows.h>
  7. #include <winhttp.h>
  8. #include "base/memory/ref_counted.h"
  9. #include "components/winhttp/proxy_info.h"
  10. #include "components/winhttp/scoped_winttp_proxy_info.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. class GURL;
  13. namespace winhttp {
  14. // On Windows 8.1 and above, we can use Auto Proxy mode in WinHTTP and let
  15. // the OS configure the proxy.
  16. // This is represented by the AutoProxyConfiguration class.
  17. // When a proxy related policy is set or when using Windows 8 or below,
  18. // we'd set proxy manually using ProxyConfiguration class.
  19. //
  20. // Default WinHTTP proxy strategy - provide proxy server info to WinHTTP.
  21. // Used when policy is set or on Windows 8 and below.
  22. // This class can use either provided proxy information from the
  23. // IE Config or a policy policy setting or query per request proxy info
  24. // with WPAD (Web Proxy Auto Discovery).
  25. class ProxyConfiguration : public base::RefCounted<ProxyConfiguration> {
  26. public:
  27. ProxyConfiguration() = default;
  28. explicit ProxyConfiguration(const ProxyInfo& proxy_info);
  29. ProxyConfiguration(const ProxyConfiguration&) = delete;
  30. ProxyConfiguration& operator=(const ProxyConfiguration&) = delete;
  31. int access_type() const;
  32. absl::optional<ScopedWinHttpProxyInfo> GetProxyForUrl(
  33. HINTERNET session_handle,
  34. const GURL& url) const;
  35. protected:
  36. virtual ~ProxyConfiguration() = default;
  37. private:
  38. friend class base::RefCounted<ProxyConfiguration>;
  39. virtual int DoGetAccessType() const;
  40. virtual absl::optional<ScopedWinHttpProxyInfo> DoGetProxyForUrl(
  41. HINTERNET session_handle,
  42. const GURL& url) const;
  43. ProxyInfo proxy_info_;
  44. };
  45. // Auto proxy strategy - let WinHTTP detect proxy settings.
  46. // This is only available on Windows 8.1 and above.
  47. class AutoProxyConfiguration final : public ProxyConfiguration {
  48. protected:
  49. ~AutoProxyConfiguration() override = default;
  50. private:
  51. // Overrides for ProxyConfiguration.
  52. int DoGetAccessType() const override;
  53. absl::optional<ScopedWinHttpProxyInfo> DoGetProxyForUrl(
  54. HINTERNET session_handle,
  55. const GURL& url) const override;
  56. };
  57. // Sets proxy info on a request handle, if WINHTTP_PROXY_INFO is provided.
  58. void SetProxyForRequest(
  59. const HINTERNET request_handle,
  60. const absl::optional<ScopedWinHttpProxyInfo>& winhttp_proxy_info);
  61. } // namespace winhttp
  62. #endif // COMPONENTS_WINHTTP_PROXY_CONFIGURATION_H_