-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Android][WebView] onShouldStartLoadWithRequest callback #6478
Conversation
243054f
to
d9e336b
Compare
@pglotov updated the pull request. |
I love you so much right now. |
cc @astreet this PR introduces synchronous JS execution by allowing the UI thread to invoke JSC. CCing you since you wrote the Worker implementation. Based on my experience with multicore JSC, calling into the same JSContext from two threads is going to introduce race conditions within JS itself since JSC will try to concurrently interleave two separate JS calls. @pglotov I don't think this approach is going to work. If the WebView method needs to be synchronous, you should queue up the JS command to be run on the JS thread and then block the UI thread until the JS command is processed. |
UIManager.dispatchViewManagerCommandSync( | ||
this.getWebViewHandle(), | ||
UIManager.RCTWebView.Commands.shouldOverrideWithResult, | ||
[shouldOverride] |
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.
no-extra-bind: The function binding is unnecessary.
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.
no-extra-bind: The function binding is unnecessary.
@ide Actually it synchronously calls Java from JS thread. UI thread sends an (async) event to JS and blocks. JS processes the event and posts result into Java object (synchronously), unblocking UI thread. Race conditions in Java world can be dealt with. |
Can you look at how iOS does this in WebView.ios.js? Also, would be nice if it had the same property name as in ios as well. Have you checked how this works for back/forward and history? Also shouldOverrideUrlLoading is not called in all instances. For instance, not on the initial load, nor when you explicitly tell the WebView to load a URL, only on link clicks which may be good enough. |
@dmmiller Yes I looked at iOS |
d9e336b
to
f497da8
Compare
@pglotov updated the pull request. |
UIManager.dispatchViewManagerCommandSync( | ||
this.getWebViewHandle(), | ||
UIManager.RCTWebView.Commands.shouldOverrideWithResult, | ||
[shouldOverride] |
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.
no-extra-bind: The function binding is unnecessary.
@pglotov ah sorry I must have misread what is going on |
f497da8
to
11385ba
Compare
@pglotov updated the pull request. |
11385ba
to
39a04bb
Compare
@pglotov updated the pull request. |
39a04bb
to
9c4132a
Compare
@pglotov updated the pull request. |
@davidaurelio Thanks, made changes. |
great, thank you! |
@@ -7,7 +7,7 @@ | |||
* of patent rights can be found in the PATENTS file in the same directory. | |||
*/ | |||
|
|||
package com.facebook.catalyst.views.webview.events; | |||
package com.facebook.react.views.webview.events; |
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.
Thanks for cleaning this, but this is really orthagonal. Want to put up a quick PR to fix these and then I can accept and then this one will be easier to read?
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.
Sure, will do it later today.
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.
Created PR for path changes here.
This question of whether we want to allow synchronous communication this way is pretty big. I'd like @andreicoman11 and @astreet to weigh in on it. |
Strong need this. |
+1 |
Like I mentioned above, I think a reasonable solution for the majority of cases would be to add a prop to WebView which is an array of regex's of urls to block synchronously. We would also want to add a new event for WebViews to be sent to JS when a URL is blocked this way so that JS can respond appropriately. Unfortunately, this isn't something we have a need for at FB so it's going to be up to an external contributor working on it, I can help review the code and offer advice. |
@astreet , i just implemented it in our project with the regex prop way you described, i will try to extract those code out and send a pr to the FB, hope it help others. Please help to review it then, Thanks. |
When will onShouldStartLoadWithRequest be available for Android? |
+1 need this. |
+1 need this |
2 similar comments
+1 need this |
+1 need this |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
Without |
+1 we need this |
+1 |
11 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
In the meantime, there is a pending PR on the |
This PR implements
onShouldStartLoadWithRequest
callback for WebView on Android. Similar to iOS approach in PR#3643.