guarding ScriptCore against null references after dispose

This commit is contained in:
Jack O'Connor
2012-05-11 14:34:13 -07:00
parent 7f60e46b76
commit e595b4ff1d
+25 -2
View File
@@ -5,14 +5,37 @@
namespace CefSharp
{
bool TryGetMainFrame(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>& mainFrame)
{
if (browser != nullptr)
{
mainFrame = browser->GetMainFrame();
return mainFrame != nullptr;
}
else
{
return false;
}
}
void ScriptCore::UIT_Execute(CefRefPtr<CefBrowser> browser, CefString script)
{
browser->GetMainFrame()->ExecuteJavaScript(script, "about:blank", 0);
CefRefPtr<CefFrame> mainFrame;
if (TryGetMainFrame(browser, mainFrame))
{
mainFrame->ExecuteJavaScript(script, "about:blank", 0);
}
}
void ScriptCore::UIT_Evaluate(CefRefPtr<CefBrowser> browser, CefString script)
{
CefRefPtr<CefV8Context> context = browser->GetMainFrame()->GetV8Context();
CefRefPtr<CefFrame> mainFrame;
if (!TryGetMainFrame(browser, mainFrame))
{
return;
}
CefRefPtr<CefV8Context> context = mainFrame->GetV8Context();
if (context.get() &&
context->Enter())