I am actually developping on windows 7 using visual Studio 2017.
As a preparation i actually am trying to implement the following sequence:
When a User pushes a Button in the toolbar, from the handler Method, a message gets sent to the RenderProcessHandler (ClientApp).
As a result a javascript-function, that has been registered afore, should be called.
1.) The Registration of the javascript already is working:
//========================================
// A.) this function definitly gets called during program start.
//========================================
- Code: Select all
1 void ClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefV8Context> context) {
2
3 CefRefPtr<CefV8Handler> handler = new MyV8Handler(this);
4
5
6 // Retrieve the context's window object.
7 CefRefPtr<CefV8Value> object = context->GetGlobal();
8 object->SetValue("register",CefV8Value::CreateFunction("register", handler),V8_PROPERTY_ATTRIBUTE_NONE);
9 }
//========================================
// B.) And MyHandler actually looks like this.
//========================================
- Code: Select all
1 CefV8Value *MyV8Handler::callback_func_=NULL; // static variable
2 CefRefPtr<CefV8Context> MyV8Handler::callback_context_ = NULL; // static variable
3
4 MyV8Handler::MyV8Handler(ClientApp *) {
5 }
6
7 bool MyV8Handler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
CefString& exception) {
8
9 if (name == "register") {
10 if (arguments.size() == 1 && arguments[0]->IsFunction()) {
11 callback_func_ = arguments[0];
12 callback_context_ = CefV8Context::GetCurrentContext();
13 CefV8ValueList args;
14 MyV8Handler::callback_func_->ExecuteFunctionWithContext(callback_context_, NULL, args);
15 return true;
16 }
17 }
18
19 // Function does not exist.
20 return false;
21 }
//========================================
// C.) The Javascript function that gets registered: (works)
//========================================
- Code: Select all
1 <script>
2 function myFunc() {
3 alert("Hello From Javascript!");
4 };
5 window.register(myFunc);
6 </script>
With the exectution of line B.)14 a messagebox appears. ("Hello From Javascript!")
So we know, that the registration has been successfully completed.
//========================================
// D.) Now, if the user pushes the Toolbar button, the following handler gets called: (works)
//========================================
- Code: Select all
1 void CCEFMFCApp::OnAppAbout(){
2 CCEFMFCView *pView = (CCEFMFCView*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
3 CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("TESTA");
4 pView->m_cefBrowser->SendProcessMessage(PID_RENDERER,msg);
5 }
//========================================
// E.) As a result this Method gets called (works), but crashes in lcodeline E)14 - within >ExecuteFunctionWithContext(...)
//========================================
- Code: Select all
1 bool ClientApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message){
2 const std::string& msg = message->GetName();
3
4 if (CefCurrentlyOn(TID_RENDERER))
5 {
6 if (MyV8Handler::callback_func_ != NULL){
7
8 CefRefPtr<CefFrame> frame = browser->GetMainFrame();
9 CefRefPtr<CefV8Context> v8Context = frame->GetV8Context();
10 if (v8Context != NULL)
11 {
12 CefV8ValueList args;
13 MyV8Handler::callback_func_->ExecuteFunctionWithContext(v8Context, NULL, args);
14 }
15 }
16 return true;
17 }
18 return false;
19 }
I also already tried to use MyV8Handler::(callback_context_, NULL, args); without success.
What action is required, that the javascript function gets called as reaction upon the user pushing the toolbar button?
Thank you, for having a look...