From 852e887d5c3f5caa5006cc86625d4cddd8016daa Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 12 Jun 2014 14:16:39 +1000 Subject: [PATCH 1/3] Add OnRenderProcessTerminated - Resolves issue #207 --- CefSharp.Core/Internals/ClientAdapter.cpp | 9 +++++++++ CefSharp.Core/Internals/ClientAdapter.h | 1 + CefSharp.Example/RequestHandler.cs | 5 +++++ CefSharp/CefSharp.csproj | 1 + CefSharp/CefTerminationStatus.cs | 20 ++++++++++++++++++++ CefSharp/IRequestHandler.cs | 7 +++++++ 6 files changed, 43 insertions(+) create mode 100644 CefSharp/CefTerminationStatus.cs diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index 1df7d77c0..163bd7346 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -225,6 +225,15 @@ namespace CefSharp } } + void ClientAdapter::OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status) + { + IRequestHandler^ handler = _browserControl->RequestHandler; + if (handler != nullptr) + { + handler->OnRenderProcessTerminated(_browserControl, (CefTerminationStatus)status); + } + } + bool ClientAdapter::OnBeforeResourceLoad(CefRefPtr browser, CefRefPtr frame, CefRefPtr request) { // TOOD: Try to support with CEF3; seems quite difficult because the method signature has changed greatly with many parts diff --git a/CefSharp.Core/Internals/ClientAdapter.h b/CefSharp.Core/Internals/ClientAdapter.h index a4964919a..2375b15b5 100644 --- a/CefSharp.Core/Internals/ClientAdapter.h +++ b/CefSharp.Core/Internals/ClientAdapter.h @@ -87,6 +87,7 @@ namespace CefSharp virtual DECL bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool isRedirect) 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; // CefDisplayHandler virtual DECL void OnLoadingStateChange(CefRefPtr browser, bool isLoading, bool canGoBack, bool canGoForward) OVERRIDE; diff --git a/CefSharp.Example/RequestHandler.cs b/CefSharp.Example/RequestHandler.cs index 2ada2e881..284fe80dd 100644 --- a/CefSharp.Example/RequestHandler.cs +++ b/CefSharp.Example/RequestHandler.cs @@ -48,5 +48,10 @@ namespace CefSharp.Example //blockPluginLoad = info.Name.ToLower().Contains("flash"); return blockPluginLoad; } + + void IRequestHandler.OnRenderProcessTerminated(IWebBrowser browser, CefTerminationStatus status) + { + // TODO: Add your own code here for handling scenarios where the Render Process terminated for one reason or another. + } } } diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 4280a28e1..915f4c599 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -87,6 +87,7 @@ + diff --git a/CefSharp/CefTerminationStatus.cs b/CefSharp/CefTerminationStatus.cs new file mode 100644 index 000000000..be53f9eac --- /dev/null +++ b/CefSharp/CefTerminationStatus.cs @@ -0,0 +1,20 @@ +namespace CefSharp +{ + public enum CefTerminationStatus + { + /// + // Non-zero exit status. + /// + AbnormalTermination = 0, + + /// + // SIGKILL or task manager kill. + /// + ProcessWasKilled, + + /// + // Segmentation fault. + /// + ProcessCrashed + } +} diff --git a/CefSharp/IRequestHandler.cs b/CefSharp/IRequestHandler.cs index add1dbf1b..c447c92fe 100644 --- a/CefSharp/IRequestHandler.cs +++ b/CefSharp/IRequestHandler.cs @@ -55,5 +55,12 @@ /// plugin information /// Return true to block loading of the plugin. bool OnBeforePluginLoad(IWebBrowser browser, string url, string policyUrl, IWebPluginInfo info); + + /// + /// Called when the render process terminates unexpectedly. + /// + /// the browser object + /// indicates how the process terminated. + void OnRenderProcessTerminated(IWebBrowser browser, CefTerminationStatus status); } } From 22c8a8b113baeb135337a2a04ca9793a98de5f53 Mon Sep 17 00:00:00 2001 From: taylorjonl Date: Tue, 15 Jul 2014 16:55:19 -0600 Subject: [PATCH 2/3] Implemented Cut, Copy, Paste and other text based actions for WPF --- CefSharp.Wpf/ChromiumWebBrowser.cs | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 5e3ba5a17..ca3848671 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -933,6 +933,41 @@ namespace CefSharp.Wpf managedCefBrowserAdapter.LoadHtml(html, url); } + public void Undo() + { + managedCefBrowserAdapter.Undo(); + } + + public void Redo() + { + managedCefBrowserAdapter.Redo(); + } + + public void Cut() + { + managedCefBrowserAdapter.Cut(); + } + + public void Copy() + { + managedCefBrowserAdapter.Copy(); + } + + public void Paste() + { + managedCefBrowserAdapter.Paste(); + } + + public void Delete() + { + managedCefBrowserAdapter.Delete(); + } + + public void SelectAll() + { + managedCefBrowserAdapter.SelectAll(); + } + public void Stop() { managedCefBrowserAdapter.Stop(); From 454d0dfbf571ee55f953bec20def5f3afd566751 Mon Sep 17 00:00:00 2001 From: jankurianski Date: Thu, 31 Jul 2014 18:43:28 +1000 Subject: [PATCH 3/3] Fix crash when responding to request that was previously cancelled by CEF (e.g. due to page reload) --- CefSharp.Core/SchemeHandlerWrapper.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CefSharp.Core/SchemeHandlerWrapper.cpp b/CefSharp.Core/SchemeHandlerWrapper.cpp index e563c2092..5d44aaa2b 100644 --- a/CefSharp.Core/SchemeHandlerWrapper.cpp +++ b/CefSharp.Core/SchemeHandlerWrapper.cpp @@ -61,7 +61,11 @@ namespace CefSharp _headers = ToHeaderMap(response->ResponseHeaders); - _callback->Continue(); + // If CEF has cancelled the initial request, throw away a response that comes afterwards. + if (_callback != nullptr) + { + _callback->Continue(); + } // Must be done AFTER CEF has been allowed to consume the headers etc. After this call is made, the SchemeHandlerWrapper // instance has likely been deallocated.