Accessing ArrayBuffer or Uint8Array data from a CefV8Value

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Accessing ArrayBuffer or Uint8Array data from a CefV8Value

Postby Mayhew » Thu Feb 07, 2013 2:31 pm

Hi everyone,
I have a web page that I want to have pass an ArrayBuffer or Uint8Array in to my own V8 handler via javascript. The argument in my handlers Execute method shows up as an "object" but I am not sure how to easily access its data. I see an enhancement request for CEF to directly support ArrayBuffer but am wondering if anyone has found another solution in the meantime.

John
Mayhew
Expert
 
Posts: 303
Joined: Mon Apr 18, 2011 8:02 pm

Re: Accessing ArrayBuffer or Uint8Array data from a CefV8Val

Postby magreenblatt » Thu Feb 07, 2013 2:39 pm

ArrayBuffer provides methods and properties for accessing the underlying data: https://developer.mozilla.org/en-US/doc ... rrayBuffer

You should be able to call these methods from your native code using ExecuteFunction, GetValue, etc on the ArrayBuffer "object".
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Accessing ArrayBuffer or Uint8Array data from a CefV8Val

Postby Mayhew » Thu Feb 07, 2013 4:36 pm

I am a bit worried about the overhead of doing a loop and calling ExecuteFunction() to get each element when the array gets large. Would it be any better to just have the web app first copy to a standard javascript array and pass that to me? I still have to loop over the array object and call GetValue(someIndex)->GetUIntValue(); so I'm not sure if that will give me any better performance or not.
Mayhew
Expert
 
Posts: 303
Joined: Mon Apr 18, 2011 8:02 pm

Re: Accessing ArrayBuffer or Uint8Array data from a CefV8Val

Postby magreenblatt » Thu Feb 07, 2013 4:43 pm

If the amount of binary data is large, and you eventually want to use the data in the browser process, then the best option might be to implement a custom scheme handler and have JavaScript send the data via XMLHttpRequest. See for example https://developer.mozilla.org/en-US/doc ... inary_Data.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Accessing ArrayBuffer or Uint8Array data from a CefV8Val

Postby tml » Mon Aug 18, 2014 11:40 am

Do you happen to have measurements of how the XHR way you suggested compares with CefProcessMessage? Gut feelings and related insights are also welcome. Actually, I have been trying to measure the throughput of both approaches but so far I haven't seen a huge difference (XHR appears to be a tiny bit slower). Does XHR/resource loading use CefProcessMessage internally?
tml
Techie
 
Posts: 11
Joined: Thu Jul 31, 2014 7:55 am

Re: Accessing ArrayBuffer or Uint8Array data from a CefV8Val

Postby magreenblatt » Tue Aug 19, 2014 9:51 am

tml wrote:I have been trying to measure the throughput of both approaches but so far I haven't seen a huge difference (XHR appears to be a tiny bit slower).

That sounds about right. The advantages of XHR is that it's easier to use directly from JavaScript, it won't interfere with other data on the IPC channel (like rendering-related messages), and you don't need to worry about message size limits (approx 128MB for CefProcessMessage including structural overhead).

tml wrote:Does XHR/resource loading use CefProcessMessage internally?

Both network loading and CefProcessMessage use the same underlying IPC channel. There is no special scheduling/prioritization for CefProcessMessage so large messages may interfere with more critical communication.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 70 guests