Add OnContextInitialized delegate (Simple .Net Action that is called after the context has been initialized)

This commit is contained in:
amaitland
2015-04-07 21:45:08 +10:00
parent a434d3ca6a
commit a3a0f15517
2 changed files with 26 additions and 4 deletions
+6 -1
View File
@@ -62,6 +62,11 @@ namespace CefSharp
}
public:
/// <summary>
/// Called on the browser process UI thread immediately after the CEF context has been initialized.
/// </summary>
static property Action^ OnContextInitialized;
static void AddDisposable(IDisposable^ item)
{
msclr::lock l(_sync);
@@ -161,7 +166,7 @@ namespace CefSharp
}
CefMainArgs main_args;
CefRefPtr<CefSharpApp> app(new CefSharpApp(cefSettings));
CefRefPtr<CefSharpApp> app(new CefSharpApp(cefSettings, OnContextInitialized));
success = CefInitialize(main_args, *(cefSettings->_cefSettings), app.get(), NULL);
app->CompleteSchemeRegistrations();
+20 -3
View File
@@ -11,19 +11,36 @@
namespace CefSharp
{
class CefSharpApp : public CefApp
private class CefSharpApp : public CefApp,
public CefBrowserProcessHandler
{
gcroot<CefSettings^> _cefSettings;
gcroot<Action^> _onContextInitialized;
public:
CefSharpApp(CefSettings^ cefSettings) :
_cefSettings(cefSettings)
CefSharpApp(CefSettings^ cefSettings, Action^ onContextInitialized) :
_cefSettings(cefSettings),
_onContextInitialized(onContextInitialized)
{
}
~CefSharpApp()
{
_cefSettings = nullptr;
_onContextInitialized = nullptr;
}
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE
{
return this;
}
virtual void OnContextInitialized() OVERRIDE
{
if (static_cast<Action^>(_onContextInitialized) != nullptr)
{
_onContextInitialized->Invoke();
}
}
virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) OVERRIDE