Skip to content

Commit b6a38e8

Browse files
Thomas101Facebook Github Bot
authored and
Facebook Github Bot
committed
Expose setAllowUniversalAccessFromFileURLs in Android WebView
Summary: This pull request exposes the `setAllowUniversalAccessFromFileURLs` method of Android WebViewSettings as a property. The reason for this is when loading pages with a `file://` baseUrl it's sometimes desirable to allow loading other assets from a file base url. (For example loading an image into a canvas). More information on its use and purpose can be found [in the android docs here](https://developer.android.com/reference/android/webkit/WebSettings.html#setAllowUniversalAccessFromFileURLs%28boolean%29) Usage example: ``` jsx return ( <WebView source={{ html: myhtml, baseUrl: 'file://' }} allowUniversalAccessFromFileURLs={true} javaScriptEnabled={true} /> ) ``` Closes #8905 Differential Revision: D4147245 Pulled By: hramos fbshipit-source-id: 7eaa884b8c0268de52b284954a34acec0fbd4061
1 parent 07295e3 commit b6a38e8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Libraries/Components/WebView/WebView.android.js

+9
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ class WebView extends React.Component {
152152
* start playing. The default value is `false`.
153153
*/
154154
mediaPlaybackRequiresUserAction: PropTypes.bool,
155+
156+
/**
157+
* Boolean that sets whether JavaScript running in the context of a file
158+
* scheme URL should be allowed to access content from any origin.
159+
* Including accessing content from other file scheme URLs
160+
* @platform android
161+
*/
162+
allowUniversalAccessFromFileURLs: PropTypes.bool,
155163
};
156164

157165
static defaultProps = {
@@ -227,6 +235,7 @@ class WebView extends React.Component {
227235
onLoadingError={this.onLoadingError}
228236
testID={this.props.testID}
229237
mediaPlaybackRequiresUserAction={this.props.mediaPlaybackRequiresUserAction}
238+
allowUniversalAccessFromFileURLs={this.props.allowUniversalAccessFromFileURLs}
230239
/>;
231240

232241
return (

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

+5
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ public void setMediaPlaybackRequiresUserAction(WebView view, boolean requires) {
375375
view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
376376
}
377377

378+
@ReactProp(name = "allowUniversalAccessFromFileURLs")
379+
public void setAllowUniversalAccessFromFileURLs(WebView view, boolean allow) {
380+
view.getSettings().setAllowUniversalAccessFromFileURLs(allow);
381+
}
382+
378383
@ReactProp(name = "injectedJavaScript")
379384
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
380385
((ReactWebView) view).setInjectedJavaScript(injectedJavaScript);

0 commit comments

Comments
 (0)