|
4 | 4 |
|
5 | 5 | using System; |
6 | 6 | using System.Security.Cryptography.X509Certificates; |
| 7 | +using System.Threading.Tasks; |
7 | 8 | using CefSharp.Handler; |
8 | 9 |
|
9 | 10 | namespace CefSharp.Example.Handlers |
@@ -31,23 +32,42 @@ protected override bool OnOpenUrlFromTab(IWebBrowser chromiumWebBrowser, IBrowse |
31 | 32 |
|
32 | 33 | protected override bool OnCertificateError(IWebBrowser chromiumWebBrowser, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback) |
33 | 34 | { |
34 | | - //NOTE: If you do not wish to implement this method returning false is the default behaviour |
35 | | - // We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource. |
36 | | - //callback.Dispose(); |
37 | | - //return false; |
| 35 | + //NOTE: We also suggest you wrap callback in a using statement or explicitly execute callback.Dispose as callback wraps an unmanaged resource. |
38 | 36 |
|
39 | | - //NOTE: When executing the callback in an async fashion need to check to see if it's disposed |
40 | | - if (!callback.IsDisposed) |
| 37 | + //Example #1 |
| 38 | + //Return true and call IRequestCallback.Continue() at a later time to continue or cancel the request. |
| 39 | + //In this instance we'll use a Task, typically you'd invoke a call to the UI Thread and display a Dialog to the user |
| 40 | + Task.Run(() => |
41 | 41 | { |
42 | | - using (callback) |
| 42 | + //NOTE: When executing the callback in an async fashion need to check to see if it's disposed |
| 43 | + if (!callback.IsDisposed) |
43 | 44 | { |
44 | | - //To allow certificate |
45 | | - //callback.Continue(true); |
46 | | - //return true; |
| 45 | + using (callback) |
| 46 | + { |
| 47 | + //We'll allow the expired certificate from badssl.com |
| 48 | + if (requestUrl.ToLower().Contains("https://expired.badssl.com/")) |
| 49 | + { |
| 50 | + callback.Continue(true); |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + callback.Continue(false); |
| 55 | + } |
| 56 | + } |
47 | 57 | } |
48 | | - } |
| 58 | + }); |
49 | 59 |
|
50 | | - return false; |
| 60 | + return true; |
| 61 | + |
| 62 | + //Example #2 |
| 63 | + //Execute the callback and return true to immediately allow the invalid certificate |
| 64 | + //callback.Continue(true); //Callback will Dispose it's self once exeucted |
| 65 | + //return true; |
| 66 | + |
| 67 | + //Example #3 |
| 68 | + //Return false for the default behaviour (cancel request immediately) |
| 69 | + //callback.Dispose(); //Dispose of callback |
| 70 | + //return false; |
51 | 71 | } |
52 | 72 |
|
53 | 73 | protected override void OnPluginCrashed(IWebBrowser chromiumWebBrowser, IBrowser browser, string pluginPath) |
|
0 commit comments