New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-17754] Throw an event from webview #6528
Conversation
Test code. Replace link with the ajax site you want to test with. shouldInterceptRequest is only available on API level 11 aka Honeycomb devices. If used on Gingerbread (level 10), it won't be available.
|
5fe37a1
to
00c8a25
Compare
@Override | ||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) | ||
{ | ||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'shouldInterceptRequest' event seems to return the same thing as 'onloadResource' event. Why do we need to fire 2 events back to back if they give the same information? Perhaps I'm missing something here? Also 'shouldInterceptRequest' event is deprecated in Lollipop, so I'm not sure we should add a feature that is already deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's actually 2 versions of 'shouldInterceptRequest'.
'WebResourceResponse shouldInterceptRequest(WebView view, String url)' is deprecated from Lollipop.
'WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request)' is the new API available from Lollipop onwards to replace the deprecated one.
The 2 events fire on slightly different occasions but, at the end, for the user, it might be the same.
'shouldInterceptRequest' -> Notify the host application of a resource request
'onLoadResource' -> Notify the host application that the WebView will load the resource
Ref: http://developer.android.com/reference/android/webkit/WebViewClient.html
Thus, for this use case, would it be better to remove 'shouldInterceptRequest' and only use 'onLoadResource'? 'onLoadResource' would be cleaner too as it is available from API level 1. If so, I'll remove 'shouldInterceptRequest'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think 'onLoadResource' event is satisfactory. We shouldn't add any feature that is already deprecated.
Code reviewed and functionally tested. Please address comment |
super.onLoadResource(view, url); | ||
KrollDict data = new KrollDict(); | ||
data.put(TiC.PROPERTY_URL, url); | ||
webView.getProxy().fireSyncEvent(TiC.EVENT_WEBVIEW_ON_LOAD_RESOURCE, data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on why this event needs to be synchronous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't have to be synchronous. I'll change this.
Looks good functional, just a few minor comments |
4b07cd0
to
d44430b
Compare
Looks good, merging |
[TIMOB-17754] Throw an event from webview
Jira: https://jira.appcelerator.org/browse/TIMOB-17754