Skip to content

Commit 492d22c

Browse files
committed
Feature: Expose OnCertificateError to allow host application to decide whether or not it should continue
1 parent 907cca8 commit 492d22c

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

CefSharp.Core/Internals/ClientAdapter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ namespace CefSharp
207207
return handler->OnBeforeBrowse(_browserControl, wrapper, isRedirect);
208208
}
209209

210+
bool ClientAdapter::OnCertificateError(cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr<CefAllowCertificateErrorCallback> callback)
211+
{
212+
IRequestHandler^ handler = _browserControl->RequestHandler;
213+
if (handler == nullptr)
214+
{
215+
return false;
216+
}
217+
218+
if (handler->OnCertificateError(_browserControl, (CefErrorCode)cert_error, StringUtils::ToClr(request_url)))
219+
{
220+
callback->Continue(true);
221+
return true;
222+
}
223+
224+
return false;
225+
}
226+
210227
// CEF3 API: public virtual bool OnBeforePluginLoad( CefRefPtr< CefBrowser > browser, const CefString& url, const CefString& policy_url, CefRefPtr< CefWebPluginInfo > info );
211228
// ---
212229
// return value:

CefSharp.Core/Internals/ClientAdapter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ namespace CefSharp
8787
virtual DECL bool GetAuthCredentials(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isProxy,
8888
const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr<CefAuthCallback> callback) OVERRIDE;
8989
virtual DECL bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool isRedirect) OVERRIDE;
90+
virtual DECL bool OnCertificateError(cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr<CefAllowCertificateErrorCallback> callback) OVERRIDE;
91+
9092
virtual DECL bool OnBeforePluginLoad( CefRefPtr< CefBrowser > browser, const CefString& url, const CefString& policy_url, CefRefPtr< CefWebPluginInfo > info ) OVERRIDE;
9193
virtual DECL void OnPluginCrashed(CefRefPtr<CefBrowser> browser, const CefString& plugin_path) OVERRIDE;
9294
virtual DECL void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser, TerminationStatus status) OVERRIDE;

CefSharp.Example/RequestHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ bool IRequestHandler.OnBeforeBrowse(IWebBrowser browser, IRequest request, bool
1414
return false;
1515
}
1616

17+
bool IRequestHandler.OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl)
18+
{
19+
return false;
20+
}
21+
1722
void IRequestHandler.OnPluginCrashed(IWebBrowser browser, string pluginPath)
1823
{
1924
// TODO: Add your own code here for handling scenarios where a plugin crashed, for one reason or another.

CefSharp.WinForms.Example/BrowserTabUserControl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public BrowserTabUserControl(string url)
2424
Browser = browser;
2525

2626
browser.MenuHandler = new MenuHandler();
27+
browser.RequestHandler = new RequestHandler();
2728
browser.NavStateChanged += OnBrowserNavStateChanged;
2829
browser.ConsoleMessage += OnBrowserConsoleMessage;
2930
browser.TitleChanged += OnBrowserTitleChanged;

CefSharp/IRequestHandler.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ public interface IRequestHandler
1818
/// <returns>Return true to cancel the navigation or false to allow the navigation to proceed.</returns>
1919
bool OnBeforeBrowse(IWebBrowser browser, IRequest request, bool isRedirect);
2020

21+
/// <summary>
22+
/// Called when a certificate error is thrown.
23+
/// </summary>
24+
/// <param name="browser">the browser object</param>
25+
/// <param name="errorCode">the error code for this invalid certificate</param>
26+
/// <param name="requestUrl">the url of the request for the invalid certificate</param>
27+
/// <returns>Return true to allow the invalid certificate and continue the request.</returns>
28+
bool OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl);
29+
2130
/// <summary>
2231
/// Called when a plugin has crashed
2332
/// </summary>

0 commit comments

Comments
 (0)