Minor formatting changes to CefCertificateCallbackWrapper

Update WinFormsRequestHandler so the X509Certificate2UI.SelectFromCollection is made on the UI thread and
Follow up to #1878
This commit is contained in:
amaitland
2016-12-13 10:20:25 +10:00
parent fa41529853
commit b7f7cc4dc6
2 changed files with 16 additions and 8 deletions
@@ -9,7 +9,8 @@
#include "include\cef_request_handler.h"
#include "CefWrapper.h"
using namespace System::Text;
using namespace System::Security::Cryptography::X509Certificates;
namespace CefSharp
{
namespace Internals
@@ -39,9 +40,10 @@ namespace CefSharp
_disposed = true;
}
virtual void Select(System::Security::Cryptography::X509Certificates::X509Certificate2^ cert)
virtual void Select(X509Certificate2^ cert)
{
ThrowIfDisposed();
if (cert == nullptr)
{
_callback->Select(NULL);
@@ -50,7 +52,7 @@ namespace CefSharp
{
auto certSerial = cert->SerialNumber;
std::vector<CefRefPtr<CefX509Certificate> >::const_iterator it =
std::vector<CefRefPtr<CefX509Certificate>>::const_iterator it =
_certificateList.begin();
for (; it != _certificateList.end(); ++it)
{
@@ -31,18 +31,24 @@ namespace CefSharp.WinForms.Example.Handlers
control.InvokeOnUiThreadIfRequired(delegate ()
{
openNewTab(targetUrl, null);
});
});
return true;
}
protected override bool OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, X509Certificate2Collection certificates, ISelectClientCertificateCallback callback)
{
X509Certificate2Collection selectedCertificateCollection = X509Certificate2UI.SelectFromCollection(certificates, "Certificates Dialog", "Select Certificate for authentication", X509SelectionFlag.SingleSelection);
foreach (X509Certificate2 x509 in selectedCertificateCollection)
var control = (Control)browserControl;
control.InvokeOnUiThreadIfRequired(delegate()
{
callback.Select(x509);
}
var selectedCertificateCollection = X509Certificate2UI.SelectFromCollection(certificates, "Certificates Dialog", "Select Certificate for authentication", X509SelectionFlag.SingleSelection);
//X509Certificate2UI.SelectFromCollection returns a collection, we've used SingleSelection, so just take the first
//The underlying CEF implementation only accepts a single certificate
callback.Select(selectedCertificateCollection[0]);
});
return true;
}
}