Skip to content

Commit

Permalink
Breaking change - Disable WebView geolocation by default
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D7846198

fbshipit-source-id: 8d6daff4b794d3569b5ddba2d8d62af8c7ff5b03
  • Loading branch information
mdvacca authored and facebook-github-bot committed May 2, 2018
1 parent ba88292 commit 23d61b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Libraries/Components/WebView/WebView.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23d61b3

Please sign in to comment.