Q:

Can a Native Client module render HTML generated by C++ code?

I have some data analysis code that processes an input file and outputs HTML and/or SVG.  It is C++ and CPU-intensive.
I would like to create a browser plugin so that my code can be used without leaving the browser.  Google's Native Client framework and the Pepper API sound interesting but perhaps is a little too restrictive.  From a Native Client module is it possible to do the following via Pepper?

Access a local file on the users filesystem.  I know NaCl sandbox
generally prevents this but there is surely a way to pass a
user-selected file from the Javascript layer down into NaCL?
Output HTML or SVG back to the browser.  Is there any way that the C++ can modify the containing document's DOM?

A:

i am less certain for (1), but (2) is definitely not directly possible.
for (1), the Pepper API is supposed to allow file pickers to make files available to NaCl modules, the same way that WebFS allows it for JavaScript.  i'm not sure of the implementation status of this.
for (2), C++ code cannot directly manipulate the DOM.  however, the NaCl module can use the PostMessage interface to send strings to JavaScript code, which can then do the actual DOM manipulation.  note that in Chrome, NaCl modules are event handlers.  this means that if the computation is started by some event and run synchronously (and it is CPU intensive), it would cause the browser to lose interactive responsiveness, or to become janky, since the event handler would take too long to return.  a better way is to spawn a background thread to do the work in the event handler (or wake a worker thread up), and return from the event handler immediately.  when the computation is done and results are ready, PostMessage the result back to let the JavaScript thread wake up (again as an event handler) and do the DOM manipulation.  note that currently PostMessage must be invoked on the main thread, so the worker thread must use CallOnMainThread to wake up the main event handler thread so that it can in turn do the PostMessage.
isn't continuation passing style fun?

