Why CefPostTask from CefV8Handler does not work

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Why CefPostTask from CefV8Handler does not work

Postby miteugene » Tue Dec 04, 2018 5:22 am

I'm trying to run MyMethod from class MyV8Handler : public CefV8Handler when i get a callback from js.
MyV8Handler::Execute - function is working properly.
MyMethod - never called.

How do I call a function in TID_UI thread from MyV8Handler::Execute?

Code: Select all
void MyMethod(int arg)
{
    cout << arg << endl;
}

bool MyV8Handler::Execute(  const CefString& name,
                            CefRefPtr<CefV8Value> object,
                            const CefV8ValueList& arguments,
                            CefRefPtr<CefV8Value>& retval,
                            CefString& exception )
{
    if (!CefCurrentlyOn(TID_UI)) {
        CefPostTask(TID_UI, base::Bind(&MyMethod, 5) );
        return true;
    }

    .
    .
    .


Code: Select all
class MyV8Handler : public CefV8Handler
{
public:
    MyV8Handler( );

    virtual bool Execute(   const CefString& name,
                            CefRefPtr<CefV8Value> object,
                            const CefV8ValueList& arguments,
                            CefRefPtr<CefV8Value>& retval,
                            CefString& exception ) override;
   
private:
    // Provide the reference counting implementation for this class.
    IMPLEMENT_REFCOUNTING(MyV8Handler);
};


Thanks.
miteugene
Newbie
 
Posts: 2
Joined: Tue Dec 04, 2018 5:06 am

Re: Why CefPostTask from CefV8Handler does not work

Postby miteugene » Wed Dec 05, 2018 3:30 am

I solved the problem with this:

Sender:
Code: Select all
bool MyV8Handler::Execute(  const CefString& name,
                            CefRefPtr<CefV8Value> object,
                            const CefV8ValueList& arguments,
                            CefRefPtr<CefV8Value>& retval,
                            CefString& exception )
{
    CefRefPtr<CefBrowser> browser = CefV8Context::GetCurrentContext()->GetBrowser();
    CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create(name);
    browser->SendProcessMessage( PID_BROWSER, message );
    .
    .
    .
}


Receiver:
Code: Select all
bool SimpleClient::OnProcessMessageReceived(
                                CefRefPtr<CefBrowser> browser,
                                CefProcessId source_process,
                                CefRefPtr<CefProcessMessage> message)
{
    // receiving a message ...
    .
    .
    .
}
miteugene
Newbie
 
Posts: 2
Joined: Tue Dec 04, 2018 5:06 am

Re: Why CefPostTask from CefV8Handler does not work

Postby G0apher » Thu Mar 11, 2021 6:37 am

This no longer seems to be working with new 87.1.13+g481a82a+chromium-87.0.4280.141.

The execute handler for the extension (subclassed from CefV8Handler) is not getting called. Any ideas on resolving the same?
G0apher
Techie
 
Posts: 13
Joined: Sat Sep 22, 2018 12:16 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 47 guests