From 23d61b35fb6fdbfb84f77b6d99ff155a0ff868e6 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 2 May 2018 15:19:50 -0700 Subject: [PATCH] Breaking change - Disable WebView geolocation by default Reviewed By: yungsters Differential Revision: D7846198 fbshipit-source-id: 8d6daff4b794d3569b5ddba2d8d62af8c7ff5b03 --- Libraries/Components/WebView/WebView.android.js | 7 +++++++ .../facebook/react/views/webview/ReactWebViewManager.java | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/Libraries/Components/WebView/WebView.android.js b/Libraries/Components/WebView/WebView.android.js index a457298f96f65f..6f0ac9b57fb033 100644 --- a/Libraries/Components/WebView/WebView.android.js +++ b/Libraries/Components/WebView/WebView.android.js @@ -138,6 +138,12 @@ class WebView extends React.Component { */ domStorageEnabled: PropTypes.bool, + /** + * Sets whether Geolocation is enabled. The default is false. + * @platform android + */ + geolocationEnabled: PropTypes.bool, + /** * Sets the JS to be injected when the webpage loads. */ @@ -310,6 +316,7 @@ class WebView extends React.Component { onLoadingFinish={this.onLoadingFinish} onLoadingError={this.onLoadingError} testID={this.props.testID} + geolocationEnabled={this.props.geolocationEnabled} mediaPlaybackRequiresUserAction={this.props.mediaPlaybackRequiresUserAction} allowUniversalAccessFromFileURLs={this.props.allowUniversalAccessFromFileURLs} mixedContentMode={this.props.mixedContentMode} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java index 3097beea5aadd6..a580a2bc4a18af 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java @@ -384,6 +384,7 @@ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermiss new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + setGeolocationEnabled(webView, false); if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } @@ -538,6 +539,13 @@ public void setUrlPrefixesForDefaultIntent( } } + @ReactProp(name = "geolocationEnabled") + public void setGeolocationEnabled( + WebView view, + @Nullable Boolean isGeolocationEnabled) { + view.getSettings().setGeolocationEnabled(isGeolocationEnabled != null && isGeolocationEnabled); + } + @Override protected void addEventEmitters(ThemedReactContext reactContext, WebView view) { // Do not register default touch emitter and let WebView implementation handle touches