I am trying to figure out how WebView is able to give javascript code access to Java code via addJavascriptInterface, as well as redirect prompt and alert javascript functions to the event handlers (onJsPrompt, onJsAlert). What I've understood so far is that there is a mechanism called JNI, we can make certain Java functionality invokable by the code outside JVM through the use of JNI. There is also something called NPAPI that allows the use of plugins in web applications. A combination of these two will be used to allow javascript code running in a WebView to invoke methods of the exported Java class (via addJavascriptInterface).
However, I am not able to see how prompt and alert functions are redirected. Is it something similar to what I've described above, and if so how?
Also, it looks like NPAPI is deprecated in Chromium. Does this mean that it isn't used in WebViews anymore either and if so, what does it use now?
Finally, how is the WebView API connected to the Android System WebView app, what does this app actually do and is it connected to the libwebviewchromium.so library to perform webview functionality?
Thanks very much in advance for all the help!
WebViewProvider WebView → calls → WebViewFactory WebViewFactoryProvider
Android ↑ ↙ ↘ ↑
===================== implements calls =========================== creates ==== implements =======
Chrome creates/ ↑ ↙ ↘ ↑
AwContents ← calls ← WebViewChromium ←---------------- creates ←----------------- WebViewChromiumFactoryProvider--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To post to this group, send email to android-w...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/9d3e236b-c9fd-4d67-aa71-e7827d5ffb5e%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To post to this group, send email to android-w...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/17155aba-6ef6-4529-af87-60110844a9c2%40chromium.org.
Hi Paul,Thanks very much for your response. Would it be possible for you to redraw the diagram as it isn't aligned and I didn't understand where the arrows point to.
What I'm trying to do is that whenever some javascript code loaded in the webview wants to use an exported java method (through a javascript interface) or calls prompt or alert functions (hence onJsPrompt etc gets invoked), I want to intercept this call. I am not about to understand yet where I can intercept these calls. I would be glad if you could give me ideas.
Thanks!
--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To post to this group, send email to android-w...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/4ac8a977-d252-404e-b71e-80661342f82a%40chromium.org.
One thing that might help you is to know that addJavascriptInterface is a totally different mechanism to all the actual web API functions (like prompt/alert/etc) - they aren't related at all and you won't be able to find a single way to intercept both kinds of thing.
All regular web APIs are implemented by the chromium rendering engine, and some of them end up being passed up to the WebView-specific code. For things like alert/confirm we have callbacks in the WebView API which are expected to be invoked. This is implemented separately for each API, there isn't a single generic mechanism here, and so you'd have to trace the path that every call you care about takes through the chromium implementation.
addJavascriptInterface is a separate mechanism that is entirely webview-specific, and not handled by the common chromium code at all. This used to be implemented using some parts of the NPAPI plugin support, but it wasn't actually a plugin (it was just reusing some code), and this is no longer the case, it was reimplemented to remove all the dependencies on NPObject. We now use Gin instead, which is a generic interface for binding stuff across parts of chromium.
Thanks very much Paul. This helps a lot. So from this, I understand that Chromium project implements WebViewProvider and WebViewFactoryProvider interfaces, which is the back end of WebView. What I don't understand is how WebView API binds to this code that implements the interfaces. I do not see WebViewChromium or WebViewChromiumFactoryProvider objects being created anywhere in the android source code.
--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To post to this group, send email to android-w...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/ca36256d-4175-42e7-a9cf-f95bfb69109f%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To post to this group, send email to android-w...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/6e8103b5-3978-4c00-bace-c4140970986d%40chromium.org.
Thanks very much Mikhail and Paul for the helpful responses. I started tracing from the addJavascriptInterface method in WebView.java in AOSP, and I reached exactly the code Paul pointed. @Mikhail, do you mean that this code ( addObject in gin_java_bridge_dispatcher_host.cc ) makes an IPC call to gin_java_bridge_dispatcher.cc to insert the object into V8 (Though I fail to see where that IPC call is made.)? If not, could you elaborate what you mean by the previous answer?
One more question: Where in the code is the @Javascript annotation tag checked for the methods? I did not see it on the AOSP side.
Thanks again!
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview-dev+unsub...@chromium.org.
To post to this group, send email to android-w...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/6e8103b5-3978-4c00-bace-c4140970986d%40chromium.org.
--Guliz Seray TuncayPh.D.candidate in Computer ScienceUniversity of Illinois. at Urbana-Champaign
--Guliz Seray TuncayPh.D.candidate in Computer ScienceUniversity of Illinois. at Urbana-Champaign