From 492d22c8a34101cddcf92a2750b4442ce5fcc1bf Mon Sep 17 00:00:00 2001 From: Sylvain Hamel Date: Tue, 25 Nov 2014 15:51:55 -0500 Subject: [PATCH] Feature: Expose OnCertificateError to allow host application to decide whether or not it should continue --- CefSharp.Core/Internals/ClientAdapter.cpp | 17 +++++++++++++++++ CefSharp.Core/Internals/ClientAdapter.h | 2 ++ CefSharp.Example/RequestHandler.cs | 5 +++++ .../BrowserTabUserControl.cs | 1 + CefSharp/IRequestHandler.cs | 9 +++++++++ 5 files changed, 34 insertions(+) diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index ecb393e94..d14128ec9 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -207,6 +207,23 @@ namespace CefSharp return handler->OnBeforeBrowse(_browserControl, wrapper, isRedirect); } + bool ClientAdapter::OnCertificateError(cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr callback) + { + IRequestHandler^ handler = _browserControl->RequestHandler; + if (handler == nullptr) + { + return false; + } + + if (handler->OnCertificateError(_browserControl, (CefErrorCode)cert_error, StringUtils::ToClr(request_url))) + { + callback->Continue(true); + return true; + } + + return false; + } + // CEF3 API: public virtual bool OnBeforePluginLoad( CefRefPtr< CefBrowser > browser, const CefString& url, const CefString& policy_url, CefRefPtr< CefWebPluginInfo > info ); // --- // return value: diff --git a/CefSharp.Core/Internals/ClientAdapter.h b/CefSharp.Core/Internals/ClientAdapter.h index 37ecaebb2..249863b6e 100644 --- a/CefSharp.Core/Internals/ClientAdapter.h +++ b/CefSharp.Core/Internals/ClientAdapter.h @@ -87,6 +87,8 @@ namespace CefSharp virtual DECL bool GetAuthCredentials(CefRefPtr browser, CefRefPtr frame, bool isProxy, const CefString& host, int port, const CefString& realm, const CefString& scheme, CefRefPtr callback) OVERRIDE; virtual DECL bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool isRedirect) OVERRIDE; + virtual DECL bool OnCertificateError(cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr callback) OVERRIDE; + virtual DECL bool OnBeforePluginLoad( CefRefPtr< CefBrowser > browser, const CefString& url, const CefString& policy_url, CefRefPtr< CefWebPluginInfo > info ) OVERRIDE; virtual DECL void OnPluginCrashed(CefRefPtr browser, const CefString& plugin_path) OVERRIDE; virtual DECL void OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status) OVERRIDE; diff --git a/CefSharp.Example/RequestHandler.cs b/CefSharp.Example/RequestHandler.cs index 545ca7f07..20343b3f2 100644 --- a/CefSharp.Example/RequestHandler.cs +++ b/CefSharp.Example/RequestHandler.cs @@ -14,6 +14,11 @@ namespace CefSharp.Example return false; } + bool IRequestHandler.OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl) + { + return false; + } + void IRequestHandler.OnPluginCrashed(IWebBrowser browser, string pluginPath) { // TODO: Add your own code here for handling scenarios where a plugin crashed, for one reason or another. diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.cs b/CefSharp.WinForms.Example/BrowserTabUserControl.cs index 34568c639..386e46d0a 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.cs +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.cs @@ -24,6 +24,7 @@ namespace CefSharp.WinForms.Example Browser = browser; browser.MenuHandler = new MenuHandler(); + browser.RequestHandler = new RequestHandler(); browser.NavStateChanged += OnBrowserNavStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; browser.TitleChanged += OnBrowserTitleChanged; diff --git a/CefSharp/IRequestHandler.cs b/CefSharp/IRequestHandler.cs index 672a8bc34..7c31f54b6 100644 --- a/CefSharp/IRequestHandler.cs +++ b/CefSharp/IRequestHandler.cs @@ -18,6 +18,15 @@ namespace CefSharp /// Return true to cancel the navigation or false to allow the navigation to proceed. bool OnBeforeBrowse(IWebBrowser browser, IRequest request, bool isRedirect); + /// + /// Called when a certificate error is thrown. + /// + /// the browser object + /// the error code for this invalid certificate + /// the url of the request for the invalid certificate + /// Return true to allow the invalid certificate and continue the request. + bool OnCertificateError(IWebBrowser browser, CefErrorCode errorCode, string requestUrl); + /// /// Called when a plugin has crashed ///