Async JS Binding Callback

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.

Async JS Binding Callback

Postby oznerol022 » Mon Sep 14, 2015 7:15 pm

Hi, I'm an absolute beginner with CEF and I'm not sure if I actually understood the Async JS Binding in CEF, but when I checked the sample "cefclient" example, in the binding_test.cpp:

Code: Select all
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
                       CefRefPtr<CefFrame> frame,
                       int64 query_id,
                       const CefString& request,
                       bool persistent,
                       CefRefPtr<Callback> callback) OVERRIDE {
    // Only handle messages from the test URL.
    const std::string& url = frame->GetURL();
    if (url.find(kTestUrl) != 0)
      return false;

    const std::string& message_name = request;
    if (message_name.find(kTestMessageName) == 0) {
      // Reverse the string and return.
      std::string result = message_name.substr(sizeof(kTestMessageName));
    //  std::reverse(result.begin(), result.end());
      callback->Success(result);
      return true;
    }

    return false;
  }


the callback->Success(result) seems to send the result to the browser, is there a way for me to be able to retrieve the value of the result from cefclient using the instance of the browser?

Thank you so much!
oznerol022
Newbie
 
Posts: 5
Joined: Sun Sep 13, 2015 9:28 pm

Re: Async JS Binding Callback

Postby magreenblatt » Tue Sep 15, 2015 3:36 am

oznerol022 wrote: is there a way for me to be able to retrieve the value of the result from cefclient using the instance of the browser?

In JavaScript the result is passed to the onSuccess or onFailure function that was passed to window.cefQuery. See binding.html for the associated JavaScript.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Async JS Binding Callback

Postby oznerol022 » Tue Sep 15, 2015 8:42 pm

magreenblatt wrote:
oznerol022 wrote: is there a way for me to be able to retrieve the value of the result from cefclient using the instance of the browser?

In JavaScript the result is passed to the onSuccess or onFailure function that was passed to window.cefQuery. See binding.html for the associated JavaScript.


Yes, but, what I'm trying to do is create another menu option to run the script, and then get the results back to the c++ side which I'll be using for another method. Do you have some tips?
oznerol022
Newbie
 
Posts: 5
Joined: Sun Sep 13, 2015 9:28 pm

Re: Async JS Binding Callback

Postby magreenblatt » Wed Sep 16, 2015 4:50 am

oznerol022 wrote:Yes, but, what I'm trying to do is create another menu option to run the script, and then get the results back to the c++ side which I'll be using for another method. Do you have some tips?

Can you explain in greater detail what exactly you're trying to do?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Async JS Binding Callback

Postby oznerol022 » Thu Sep 24, 2015 7:15 pm

magreenblatt wrote:
oznerol022 wrote:Yes, but, what I'm trying to do is create another menu option to run the script, and then get the results back to the c++ side which I'll be using for another method. Do you have some tips?

Can you explain in greater detail what exactly you're trying to do?


I have an Eclipse plugin project where in I need to use chrome as the default embedded browser. The most important function we need is the "evaluate" method similar to the SWT.Browser where I can run a javascript function and get the results from the browser to the eclipse plugin.
oznerol022
Newbie
 
Posts: 5
Joined: Sun Sep 13, 2015 9:28 pm

Re: Async JS Binding Callback

Postby amaitland » Thu Sep 24, 2015 7:41 pm

To execute some script I'd typically go with `Eval`.

apidocs3/projects/%28default%29/CefV8Context.html#Eval%28constCefString&,CefRefPtr%3CCefV8Value%3E&,CefRefPtr%3CCefV8Exception%3E&%29
https://bitbucket.org/chromiumembedded/ ... -functions

I'd check `cefclient` for an example, I'm guessing it has one.

You can also take a look at the `CefSharp` project for some examples, though they might not be so useful as they're `.Net/vc++`
https://github.com/cefsharp/CefSharp/bl ... r.cpp#L176
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 22 guests