From a3a0f155173677288cea38ddee22ce0da245fa61 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 7 Apr 2015 21:45:08 +1000 Subject: [PATCH] Add OnContextInitialized delegate (Simple .Net Action that is called after the context has been initialized) --- CefSharp.Core/Cef.h | 7 ++++++- CefSharp.Core/Internals/CefSharpApp.h | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index 23ecd81e7..38266e340 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -62,6 +62,11 @@ namespace CefSharp } public: + /// + /// Called on the browser process UI thread immediately after the CEF context has been initialized. + /// + static property Action^ OnContextInitialized; + static void AddDisposable(IDisposable^ item) { msclr::lock l(_sync); @@ -161,7 +166,7 @@ namespace CefSharp } CefMainArgs main_args; - CefRefPtr app(new CefSharpApp(cefSettings)); + CefRefPtr app(new CefSharpApp(cefSettings, OnContextInitialized)); success = CefInitialize(main_args, *(cefSettings->_cefSettings), app.get(), NULL); app->CompleteSchemeRegistrations(); diff --git a/CefSharp.Core/Internals/CefSharpApp.h b/CefSharp.Core/Internals/CefSharpApp.h index 1237a1941..52ae1409a 100644 --- a/CefSharp.Core/Internals/CefSharpApp.h +++ b/CefSharp.Core/Internals/CefSharpApp.h @@ -11,19 +11,36 @@ namespace CefSharp { - class CefSharpApp : public CefApp + private class CefSharpApp : public CefApp, + public CefBrowserProcessHandler { gcroot _cefSettings; + gcroot _onContextInitialized; public: - CefSharpApp(CefSettings^ cefSettings) : - _cefSettings(cefSettings) + CefSharpApp(CefSettings^ cefSettings, Action^ onContextInitialized) : + _cefSettings(cefSettings), + _onContextInitialized(onContextInitialized) { } ~CefSharpApp() { _cefSettings = nullptr; + _onContextInitialized = nullptr; + } + + virtual CefRefPtr GetBrowserProcessHandler() OVERRIDE + { + return this; + } + + virtual void OnContextInitialized() OVERRIDE + { + if (static_cast(_onContextInitialized) != nullptr) + { + _onContextInitialized->Invoke(); + } } virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr command_line) OVERRIDE