I have been looking over the JavaScript integration docs and need to clarify something.
I want to call CefFrame::ExecuteJavascript() to run some code in the main browser frame. I want to call ExecuteJavascript() from within my override of CefApp::OnProcessMessageReceived(). The docs state " The ExecuteFunction() method should only be used if V8 is already inside a context as described in the "Working with Contexts" section" and Working with Contexts states "V8 will be inside a context if the current code location has a CefV8Handler, CefV8Accessor or OnContextCreated()/OnContextReleased() callback higher in the call stack."
OnProcessMessageReceived() doesn't fall into any of the above categories so I assume it is unsafe to call CefFrame::ExecuteJavascript() there unless I
1) call GetCurrentContext() and ensure that the context is for the main frame, but I'm not sure what I do if it is not the context for the main frame.
2) Simply keep set a member boolean to true in my CefApps OnContextCreated() method when the context for the main frame is created. I set this boolean to false when OnContextReleased() is called with the main frames context. If that boolean is true, I can assume it is safe to call ExecuteJavascript() within my OnProcessMessageReceived() method.
Currently, I'm doing neither of the above and it is working, but I assume I'm just lucky. So, in order to make this bulletproof are either option above the right approach?
Thanks,
John