mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 11:42:36 +00:00
Expanded proxy support, made it easier to set proxy settings (#2007)
- Added a ProxyOptions class - Added a CefSharpSettings.Proxy property - Made ClientAdapter::GetAuthCredentials take care of the authentication for the proxy
This commit is contained in:
@@ -182,6 +182,16 @@ namespace CefSharp
|
||||
DependencyChecker::AssertAllDependenciesPresent(cefSettings->Locale, cefSettings->LocalesDirPath, cefSettings->ResourcesDirPath, cefSettings->PackLoadingDisabled, cefSettings->BrowserSubprocessPath);
|
||||
}
|
||||
|
||||
if (CefSharpSettings::Proxy != nullptr && !cefSettings->CommandLineArgsDisabled)
|
||||
{
|
||||
cefSettings->CefCommandLineArgs->Add("proxy-server", CefSharpSettings::Proxy->IP + ":" + CefSharpSettings::Proxy->Port);
|
||||
|
||||
if (!String::IsNullOrEmpty(CefSharpSettings::Proxy->BypassList))
|
||||
{
|
||||
cefSettings->CefCommandLineArgs->Add("proxy-bypass-list", CefSharpSettings::Proxy->BypassList);
|
||||
}
|
||||
}
|
||||
|
||||
UIThreadTaskFactory = gcnew TaskFactory(gcnew CefTaskScheduler(TID_UI));
|
||||
IOThreadTaskFactory = gcnew TaskFactory(gcnew CefTaskScheduler(TID_IO));
|
||||
FileThreadTaskFactory = gcnew TaskFactory(gcnew CefTaskScheduler(TID_FILE));
|
||||
|
||||
@@ -732,6 +732,12 @@ namespace CefSharp
|
||||
bool ClientAdapter::GetAuthCredentials(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isProxy,
|
||||
const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr<CefAuthCallback> callback)
|
||||
{
|
||||
if (isProxy && CefSharpSettings::Proxy != nullptr && CefSharpSettings::Proxy->IP == StringUtils::ToClr(host) && CefSharpSettings::Proxy->HasUsernameAndPassword())
|
||||
{
|
||||
callback->Continue(StringUtils::ToNative(CefSharpSettings::Proxy->Username), StringUtils::ToNative(CefSharpSettings::Proxy->Password));
|
||||
return true;
|
||||
}
|
||||
|
||||
auto handler = _browserControl->RequestHandler;
|
||||
|
||||
if (handler == nullptr)
|
||||
|
||||
@@ -199,6 +199,7 @@
|
||||
<Compile Include="PdfPrintSettings.cs" />
|
||||
<Compile Include="ICookieManager.cs" />
|
||||
<Compile Include="IMenuModel.cs" />
|
||||
<Compile Include="ProxyOptions.cs" />
|
||||
<Compile Include="DefaultResourceHandlerFactoryItem.cs" />
|
||||
<Compile Include="Structs\ViewRect.cs" />
|
||||
<Compile Include="ISslInfo.cs" />
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace CefSharp
|
||||
|
||||
/// <summary>
|
||||
/// Change the Close timeout for the WCF channel used by the sync JSB binding.
|
||||
/// The default value is currently 2 seconds. Chaning this to <see cref="TimeSpan.Zero"/>
|
||||
/// The default value is currently 2 seconds. Changing this to <see cref="TimeSpan.Zero"/>
|
||||
/// will result on Abort() being called on the WCF Channel Host
|
||||
/// </summary>
|
||||
public static TimeSpan WcfTimeout { get; set; }
|
||||
@@ -41,5 +41,16 @@ namespace CefSharp
|
||||
/// the event handlers are hooked in the static constructor for the ChromiumWebBrowser class
|
||||
/// </summary>
|
||||
public static bool ShutdownOnExit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The proxy options that will be used for all connections
|
||||
///
|
||||
/// If set before the call to Cef.Initialize, command line arguments will be set for you
|
||||
/// If a username and password is provided and the IPs match authentication is done automatically
|
||||
///
|
||||
/// NOTE: GetAuthCredentials won't be called for a proxy server that matches the IP
|
||||
/// NOTE: It isn't possble to change the proxy after the call to Cef.Initialize
|
||||
/// </summary>
|
||||
public static ProxyOptions Proxy { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
public class ProxyOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The IP address for the proxy
|
||||
/// </summary>
|
||||
public string IP { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The port for the proxy
|
||||
/// </summary>
|
||||
public string Port { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The username for authentication
|
||||
/// </summary>
|
||||
public string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The password for authentication
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of domains that shouldn't be affected by the proxy, Format: example.com;example2.com
|
||||
/// </summary>
|
||||
public string BypassList { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks if username and password is set
|
||||
/// </summary>
|
||||
/// <returns>Returns true if both username and password is set, otherwise false</returns>
|
||||
public bool HasUsernameAndPassword()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password);
|
||||
}
|
||||
|
||||
/// <param name="ip">The IP address for the proxy</param>
|
||||
/// <param name="port">The port for the proxy</param>
|
||||
/// <param name="username">The username required for authentication</param>
|
||||
/// <param name="password">The password required for authentication</param>
|
||||
/// <param name="bypassList">The list of domains that shouldn't be affected by the proxy, Format: example.com;example2.com</param>
|
||||
public ProxyOptions(string ip, string port, string username = "", string password = "", string bypassList = "")
|
||||
{
|
||||
IP = ip;
|
||||
Port = port;
|
||||
Username = username;
|
||||
Password = password;
|
||||
BypassList = bypassList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user