How do I configure Javascript to access Mojo in the (Webview) renderer?

702 views
Skip to first unread message

Anthony Berent

unread,
May 16, 2016, 12:49:55 PM5/16/16
to chromium-mojo
I am trying to support supervised users in Android Webview. To do this I need to create a complex error page (with lots of information from the browser, and a button to request access). In Chrome this is an interstitial, however Webview doesn't support interstitial.

It seems to me that the correct way to handle this is to create the page in renderer, and to use Mojo to access the data it needs, and to send the access request to the browser. I have tried to implement this, following the other examples I have found, but when I try to use it I get:

VM43 html,chromewebdata:1403 Uncaught ReferenceError: define is not defined

How do I enable modules for my page/script? What else do I need to do (if anything) to get Mojo working from Javascript?

P.S. I have a previous version of my CL where the Mojo client is in C++, and I then use gin to enable to actions in Javascript, so I know my Mojo interfaces work; but using Mojo directly from Javascript seems as if it should be far cleaner.

Ken Rockot

unread,
May 16, 2016, 1:08:51 PM5/16/16
to Anthony Berent, chromium-mojo
We'd like to make Mojo JS bindings more easily available to blink embedders without using gin modules or async loading, but for now you can use gin. In content we do this via MojoContextState for JS hosted in render views when BINDINGS_POLICY_MOJO (or BINDINGS_POLICY_WEB_UI) is enabled, and in layout tests.

Maybe you can reuse that stuff somehow? I don't know much about how AW works.

Note that on its own, MojoContextState only handles the builtin bindings modules. To load mojom-generated modules, you'll have to either manually load the JS or help FetchModule find the resources somehow. e.g. for layout tests we use a special protocol handler to let it hit disk.

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To post to this group, send email to chromi...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/CABdZ6yDPy680otoU3BLMw%2BAxn-eH%2BCgvhVx80saY9pZbvTAnKQ%40mail.gmail.com.

Anthony Berent

unread,
May 17, 2016, 8:44:21 AM5/17/16
to Ken Rockot, chromium-mojo, Bernhard Bauer
Sadly, because MojoContextState etc. are all currently within content/renderer, with no public interfaces, it looks as if I would have to duplicate much of this stuff, or refactor it, to use it . As such, since this is a one off, I am reverting to my original plan of using Mojo from C++ and then communicating with the error page using gin. 

Ken Rockot

unread,
May 17, 2016, 8:56:26 AM5/17/16
to Anthony Berent, Bernhard Bauer, chromium-mojo


On May 17, 2016 5:44 AM, "Anthony Berent" <abe...@chromium.org> wrote:
>
> Sadly, because MojoContextState etc. are all currently within content/renderer, with no public interfaces, it looks as if I would have to duplicate much of this stuff, or refactor it, to use it . As such, since this is a one off, I am reverting to my original plan of using Mojo from C++ and then communicating with the error page using gin.

If the API surface you need in JS is small and unlikely to expand, this is probably the right choice.

If not, it would be comparatively little work to refactor the bits out of content; especially if the your custom bindings are exposing things which will eventually have mojom analogs anyway.

In any case, we can always revisit this later if necessary.

Reply all
Reply to author
Forward
0 new messages