From ce70ea25e4924f7826c52294160669c50da3ab6a Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 5 Jun 2015 12:26:28 +1000 Subject: [PATCH] Import basic error handling code from cefclient example (only added to WPF example for now) --- .../Views/BrowserTabView.xaml.cs | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs index 555ca01ec..cd37724a5 100644 --- a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs +++ b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs @@ -20,14 +20,40 @@ namespace CefSharp.Wpf.Example.Views browser.MenuHandler = new Handlers.MenuHandler(); browser.GeolocationHandler = new Handlers.GeolocationHandler(); browser.DownloadHandler = new DownloadHandler(); - browser.PreviewTextInput += (o, e) => + browser.PreviewTextInput += (sender, args) => { - foreach (var character in e.Text) + foreach (var character in args.Text) { browser.SendKeyEvent((int)WM.CHAR, character, 0); } - e.Handled = true; + args.Handled = true; + }; + + browser.LoadError += (sender, args) => + { + // Don't display an error for downloaded files. + if (args.ErrorCode == CefErrorCode.Aborted) + { + return; + } + + // Don't display an error for external protocols that we allow the OS to + // handle. See OnProtocolExecution(). + //if (args.ErrorCode == CefErrorCode.UnknownUrlScheme) + //{ + // var url = args.Frame.Url; + // if (url.StartsWith("spotify:")) + // { + // return; + // } + //} + + // Display a load error message. + var errorBody = string.Format("

Failed to load URL {0} with error {1} ({2}).

", + args.FailedUrl, args.ErrorText, args.ErrorCode); + + args.Frame.LoadStringForUrl(errorBody, args.FailedUrl); }; CefExample.RegisterTestResources(browser);