feat(webview): Allow javascript to open windows automatically (#1409 by @trcoffman)

[skip ci]
This commit is contained in:
trcoffman 2020-05-28 09:54:20 -07:00 committed by GitHub
parent 3cbf1490f4
commit 91df544fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 0 deletions

View File

@ -376,6 +376,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
}
@ReactProp(name = "javaScriptCanOpenWindowsAutomatically")
public void setJavaScriptCanOpenWindowsAutomatically(WebView view, boolean enabled) {
view.getSettings().setJavaScriptCanOpenWindowsAutomatically(enabled);
}
@ReactProp(name = "allowFileAccessFromFileURLs")
public void setAllowFileAccessFromFileURLs(WebView view, boolean allow) {
view.getSettings().setAllowFileAccessFromFileURLs(allow);

View File

@ -54,6 +54,7 @@
@property (nonatomic, copy) NSString * _Nullable applicationNameForUserAgent;
@property (nonatomic, assign) BOOL cacheEnabled;
@property (nonatomic, assign) BOOL javaScriptEnabled;
@property (nonatomic, assign) BOOL javaScriptCanOpenWindowsAutomatically;
@property (nonatomic, assign) BOOL allowFileAccessFromFileURLs;
@property (nonatomic, assign) BOOL allowsLinkPreview;
@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;

View File

@ -209,6 +209,10 @@ static NSDictionary* customCertificatesForHost;
[prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
_prefsUsed = YES;
}
if (_javaScriptCanOpenWindowsAutomatically) {
[prefs setValue:@TRUE forKey:@"javaScriptCanOpenWindowsAutomatically"];
_prefsUsed = YES;
}
if (_prefsUsed) {
wkWebViewConfig.preferences = prefs;
}

View File

@ -47,6 +47,7 @@ RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoaded, NSString)
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptForMainFrameOnly, BOOL)
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoadedForMainFrameOnly, BOOL)
RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(javaScriptCanOpenWindowsAutomatically, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)

View File

@ -32,6 +32,7 @@ This document lays out the current public properties and methods for the React N
- [`decelerationRate`](Reference.md#decelerationrate)
- [`domStorageEnabled`](Reference.md#domstorageenabled)
- [`javaScriptEnabled`](Reference.md#javascriptenabled)
- [`javaScriptCanOpenWindowsAutomatically`](Reference.md#javascriptcanopenwindowsautomatically)
- [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
- [`mixedContentMode`](Reference.md#mixedcontentmode)
- [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
@ -732,6 +733,16 @@ Boolean value to enable JavaScript in the `WebView`. The default value is `true`
---
### `javaScriptCanOpenWindowsAutomatically`
A Boolean value indicating whether JavaScript can open windows without user interaction. The default value is `false`.
| Type | Required |
| ---- | -------- |
| bool | No |
---
### `androidHardwareAccelerationDisabled`
Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only as Hardware Acceleration is a feature only for Android. The default value is `false`.

View File

@ -240,6 +240,7 @@ export interface CommonNativeWebViewProps extends ViewProps {
incognito?: boolean;
injectedJavaScript?: string;
injectedJavaScriptBeforeContentLoaded?: string;
javaScriptCanOpenWindowsAutomatically?: boolean;
mediaPlaybackRequiresUserAction?: boolean;
messagingEnabled: boolean;
onScroll?: (event: NativeScrollEvent) => void;
@ -821,6 +822,12 @@ export interface WebViewSharedProps extends ViewProps {
*/
javaScriptEnabled?: boolean;
/**
* A Boolean value indicating whether JavaScript can open windows without user interaction.
* The default value is `false`.
*/
javaScriptCanOpenWindowsAutomatically?: boolean;
/**
* Stylesheet object to set the style of the container view.
*/