Skip to content
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

Closed

Conversation

pglotov
Copy link
Contributor

@pglotov pglotov commented Mar 16, 2016

This PR implements onShouldStartLoadWithRequest callback for WebView on Android. Similar to iOS approach in PR#3643.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @dmmiller and @korDen to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Mar 16, 2016
@pglotov pglotov force-pushed the android-shouldOverrideUrlLoading branch from 243054f to d9e336b Compare March 16, 2016 03:15
@facebook-github-bot
Copy link
Contributor

@pglotov updated the pull request.

@jordaaash
Copy link

I love you so much right now.

@ide
Copy link
Contributor

ide commented Mar 16, 2016

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]

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.

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
Copy link
Contributor Author

pglotov commented Mar 16, 2016

@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.

@dmmiller
Copy link

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.

@pglotov
Copy link
Contributor Author

pglotov commented Mar 16, 2016

@dmmiller Yes I looked at iOS onShouldStartLoadWithRequest before implementing this, and tried to follow that approach. No I didn't check back/forward. I need it to intercept link clicks in webview and open them in browser instead. Makes sense to have a single property name for both platforms.

@pglotov pglotov force-pushed the android-shouldOverrideUrlLoading branch from d9e336b to f497da8 Compare March 16, 2016 15:50
@pglotov pglotov changed the title [Android][WebView] shouldOverrideUrlLoading callback [Android][WebView] onShouldStartLoadWithRequest callback Mar 16, 2016
@facebook-github-bot
Copy link
Contributor

@pglotov updated the pull request.

UIManager.dispatchViewManagerCommandSync(
this.getWebViewHandle(),
UIManager.RCTWebView.Commands.shouldOverrideWithResult,
[shouldOverride]

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
Copy link
Contributor

ide commented Mar 16, 2016

@pglotov ah sorry I must have misread what is going on

@pglotov pglotov force-pushed the android-shouldOverrideUrlLoading branch from f497da8 to 11385ba Compare March 17, 2016 00:50
@facebook-github-bot
Copy link
Contributor

@pglotov updated the pull request.

@pglotov pglotov force-pushed the android-shouldOverrideUrlLoading branch from 11385ba to 39a04bb Compare March 17, 2016 00:58
@facebook-github-bot
Copy link
Contributor

@pglotov updated the pull request.

@pglotov pglotov force-pushed the android-shouldOverrideUrlLoading branch from 39a04bb to 9c4132a Compare March 17, 2016 01:00
@facebook-github-bot
Copy link
Contributor

@pglotov updated the pull request.

@pglotov
Copy link
Contributor Author

pglotov commented Mar 17, 2016

@davidaurelio Thanks, made changes.

@davidaurelio
Copy link
Contributor

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;

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@dmmiller
Copy link

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.

@younthu
Copy link
Contributor

younthu commented Jan 3, 2017

Strong need this.

@evanidul
Copy link

evanidul commented Feb 1, 2017

+1

@astreet
Copy link
Contributor

astreet commented Feb 1, 2017

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.

@younthu
Copy link
Contributor

younthu commented Feb 2, 2017

@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.

@mattiashalldin
Copy link

When will onShouldStartLoadWithRequest be available for Android?

@zheng-liu-seattle
Copy link

+1 need this.

@coyer
Copy link

coyer commented May 27, 2017

+1 need this

2 similar comments
@caigehui
Copy link

+1 need this

@Livyli
Copy link

Livyli commented Aug 15, 2017

+1 need this

@ybolaris
Copy link

+1

4 similar comments
@miguelocarvajal
Copy link

+1

@tourze
Copy link

tourze commented Oct 16, 2017

+1

@kyangy
Copy link

kyangy commented Nov 10, 2017

+1

@stanleycyang
Copy link

+1

@0x5e
Copy link

0x5e commented Nov 29, 2017

Without onShouldStartLoadWithRequest implemented on Android, the same method on iOS is useless. :-(

@wesleymooiman
Copy link

wesleymooiman commented Dec 4, 2017

+1 we need this

@MikePodgorniy
Copy link
Contributor

+1

11 similar comments
@punksta
Copy link

punksta commented Jan 8, 2018

+1

@ghost
Copy link

ghost commented Jan 29, 2018

+1

@shashankwadi
Copy link

+1

@pulkitsharma99
Copy link

+1

@pramodinwadi
Copy link

+1

@akhilwadi
Copy link

+1

@manjeetwadi
Copy link

+1

@simranjeet-sawhney
Copy link

+1

@rschef
Copy link

rschef commented Mar 26, 2018

+1

@prademak
Copy link

+1

@SanlinBlackball
Copy link

+1

@iamarkdev
Copy link

In the meantime, there is a pending PR on the react-native-webview-android module with a working implementation of onShouldStartLoadWithRequest for Android here: lucasferreira/react-native-webview-android#98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.