Skip to content

Commit 23d61b3

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Breaking change - Disable WebView geolocation by default
Reviewed By: yungsters Differential Revision: D7846198 fbshipit-source-id: 8d6daff4b794d3569b5ddba2d8d62af8c7ff5b03
1 parent ba88292 commit 23d61b3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Libraries/Components/WebView/WebView.android.js

+7
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ class WebView extends React.Component {
138138
*/
139139
domStorageEnabled: PropTypes.bool,
140140

141+
/**
142+
* Sets whether Geolocation is enabled. The default is false.
143+
* @platform android
144+
*/
145+
geolocationEnabled: PropTypes.bool,
146+
141147
/**
142148
* Sets the JS to be injected when the webpage loads.
143149
*/
@@ -310,6 +316,7 @@ class WebView extends React.Component {
310316
onLoadingFinish={this.onLoadingFinish}
311317
onLoadingError={this.onLoadingError}
312318
testID={this.props.testID}
319+
geolocationEnabled={this.props.geolocationEnabled}
313320
mediaPlaybackRequiresUserAction={this.props.mediaPlaybackRequiresUserAction}
314321
allowUniversalAccessFromFileURLs={this.props.allowUniversalAccessFromFileURLs}
315322
mixedContentMode={this.props.mixedContentMode}

ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java

+8
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermiss
384384
new LayoutParams(LayoutParams.MATCH_PARENT,
385385
LayoutParams.MATCH_PARENT));
386386

387+
setGeolocationEnabled(webView, false);
387388
if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
388389
WebView.setWebContentsDebuggingEnabled(true);
389390
}
@@ -538,6 +539,13 @@ public void setUrlPrefixesForDefaultIntent(
538539
}
539540
}
540541

542+
@ReactProp(name = "geolocationEnabled")
543+
public void setGeolocationEnabled(
544+
WebView view,
545+
@Nullable Boolean isGeolocationEnabled) {
546+
view.getSettings().setGeolocationEnabled(isGeolocationEnabled != null && isGeolocationEnabled);
547+
}
548+
541549
@Override
542550
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
543551
// Do not register default touch emitter and let WebView implementation handle touches

0 commit comments

Comments
 (0)