[ 
https://issues.apache.org/jira/browse/CB-3927?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13688072#comment-13688072
 ] 

Andrew Grieve commented on CB-3927:
-----------------------------------

I just verified that onPageStarted is called on the UI thread, whereas bridge 
calls run on the WebCore thread. So, I think the reason for the wrong order 
here is that:

1. WebView posts the onPageStarted event to the UI thread
2. WebView loads the page
3. exec() happens during start-up
4. UI thread receives the onPageStarted event
5. Plugins get reset and exec() queue gets flushed.

One way to fix this would be to send all exec() calls to the UI thread, but 
that would suck for performance.

Would it still be correct if we put the page-change logic into 
WebViewClient::shouldOverrideUrlLoading? Can we tell for certain that the page 
will change when this method is called?

Otherwise, I think we'll need to move page resetting logic into JS. E.g. have 
an explicit "reset" Exec call during start-up
                
> Exec Can Fail to Issue Callback Immediately After onCordovaReady
> ----------------------------------------------------------------
>
>                 Key: CB-3927
>                 URL: https://issues.apache.org/jira/browse/CB-3927
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, CordovaJS
>            Reporter: Jeffrey Willms
>            Assignee: Joe Bowser
>
> If javascript issues an exec to native after waiting for onCordovaReady the 
> exec can possibly fail to issue any callback. The bug is caused when 
> CordovaWebViewClient.onPageStarted, which resets the NativeToJsMessageQueue, 
> is called between native queuing the response message and the javascript 
> polling for that response. While webView.loadUrl is called near the entry 
> point of the app, the onPageStarted event can happen very far in the future, 
> after cordova-ready.
> These are the order of events that typically need to happen for this bug to 
> manifest:
> - webView.loadUrl is called near entry point of app
> - At some point in the future after cordova-ready, exec is called by 
> javascript
> - Native handler processes exec but gets blocked before the response message 
> can be added to the queue because another thread is currently accessing the 
> queue
> - Native exec returns without response
> - Handler gets unblocked and adds the response message to the queue and 
> signals to javascript that there are messages to be read
> - CordovaWebViewClient.onPageStarted is called which resets the message queue 
> - javascript receives signal from native and polls for messages, but gets 
> none in response because the queue was reset
> The end result is that neither the success or failure callback of the exec 
> ever gets issued.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to