Permalink
Browse files

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
  • Loading branch information...
1 parent 07295e3 commit b6a38e80e01d711205bc09348b8e005d49cebbbc Thomas Beverley committed with Facebook Github Bot Nov 8, 2016
@@ -152,6 +152,14 @@ class WebView extends React.Component {
* start playing. The default value is `false`.
*/
mediaPlaybackRequiresUserAction: PropTypes.bool,
+
+ /**
+ * Boolean that sets whether JavaScript running in the context of a file
+ * scheme URL should be allowed to access content from any origin.
+ * Including accessing content from other file scheme URLs
+ * @platform android
+ */
+ allowUniversalAccessFromFileURLs: PropTypes.bool,
};
static defaultProps = {
@@ -227,6 +235,7 @@ class WebView extends React.Component {
onLoadingError={this.onLoadingError}
testID={this.props.testID}
mediaPlaybackRequiresUserAction={this.props.mediaPlaybackRequiresUserAction}
+ allowUniversalAccessFromFileURLs={this.props.allowUniversalAccessFromFileURLs}
/>;
return (
@@ -375,6 +375,11 @@ public void setMediaPlaybackRequiresUserAction(WebView view, boolean requires) {
view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
}
+ @ReactProp(name = "allowUniversalAccessFromFileURLs")
+ public void setAllowUniversalAccessFromFileURLs(WebView view, boolean allow) {
+ view.getSettings().setAllowUniversalAccessFromFileURLs(allow);
+ }
+
@ReactProp(name = "injectedJavaScript")
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
((ReactWebView) view).setInjectedJavaScript(injectedJavaScript);

0 comments on commit b6a38e8

Please sign in to comment.