Files
cefsharp/CefSharp.WinForms.Example/Handlers/WinFormsRequestHandler.cs
T
amaitland 464dd14b6f Update Example RequestHandler to inherit from DefaultRequestHandler
A new default implementation was added in #2157
BrowserTabView - cleanup usings and remove unused code
2017-12-20 10:01:34 +10:00

56 lines
2.0 KiB
C#

// 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.
using System;
using System.Windows.Forms;
using CefSharp.Example.Handlers;
using CefSharp.WinForms.Internals;
using System.Security.Cryptography.X509Certificates;
namespace CefSharp.WinForms.Example.Handlers
{
public class WinFormsRequestHandler : RequestHandler
{
private Action<string, int?> openNewTab;
public WinFormsRequestHandler(Action<string, int?> openNewTab)
{
this.openNewTab = openNewTab;
}
public override bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
{
if(openNewTab == null)
{
return false;
}
var control = (Control)browserControl;
control.InvokeOnUiThreadIfRequired(delegate ()
{
openNewTab(targetUrl, null);
});
return true;
}
public override bool OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, X509Certificate2Collection certificates, ISelectClientCertificateCallback callback)
{
var control = (Control)browserControl;
control.InvokeOnUiThreadIfRequired(delegate()
{
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;
}
}
}