I've checked in the first round of changes for this. Modes can be tested in the mobile-spec exec() benchmark.
LOCATION_CHANGE: 2 // Not yet implemented
// Polls for messages using the prompt() bridge.
// Does an XHR to a local server, which will send back messages. This is
// broken on ICS when a proxy server is configured.
// For LOAD_URL to be viable, it would need to have a work-around for
// the bug where the soft-keyboard gets dismissed when a message is sent.
// For the ONLINE_EVENT to be viable, it would need to intercept all event
// listeners (both through addEventListener and window.ononline) as well
// as set the navigator property itself.
// Uses reflection to access private APIs of the WebView that can send JS
// to be executed.
// Requires Android 3.2.4 or above.
-I've not implemented the any keyboard work-arounds for LOAD_URL
-I've not added a workaround for hiding online/offline events from changing
Some initial benchmark results from my Galaxy Nexus (echos per second, bigger is better, payload size=500 bytes):
Using JS_OBJECT for JS->Native and async Native->Response:
Native->JS POLLING+PROMPT: 100
Native->JS HANGING_GET: 75-90
Native->JS LOAD_URL: 160
Native->JS ONLINE_EVENT+PROMPT: 200-270
Native->JS PRIVATE_API: 340
ONLINE_EVENT being faster than LOAD_URL surprised me. Especially since it can be made even a bit faster if it uses JS_OBJECT to retrieve the message instead of PROMPT.
Still to do:
Implement LOCATION_CHANGE JS>Native mode
-Add detection logic for JS_OBJECT support (this will involve loading a test page to run some JS)
-Add hiding of ONLINE_EVENTS changes from the app via cordova.addWindowEventHandler() and navigator._defineGetter_('onLine', ...)
-Make POLLING and ONLINE_EVENT be able to use JS_OBJECT instead of always PROMPT.
-Make POLLING & HANGING_GET retrieve all pending messages in one call instead of one at a time
-Add mobile-spec test that ensures all modes work (when expected to)
-Discuss changing the default bridge mode, as well as how to implement fall-back modes.