Преглед изворни кода

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

[skip ci]
trcoffman пре 4 година
родитељ
комит
91df544fae
No account linked to committer's email address

+ 5
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Прегледај датотеку

@@ -376,6 +376,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
376 376
     view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
377 377
   }
378 378
 
379
+  @ReactProp(name = "javaScriptCanOpenWindowsAutomatically")
380
+  public void setJavaScriptCanOpenWindowsAutomatically(WebView view, boolean enabled) {
381
+    view.getSettings().setJavaScriptCanOpenWindowsAutomatically(enabled);
382
+  }
383
+
379 384
   @ReactProp(name = "allowFileAccessFromFileURLs")
380 385
   public void setAllowFileAccessFromFileURLs(WebView view, boolean allow) {
381 386
     view.getSettings().setAllowFileAccessFromFileURLs(allow);

+ 1
- 0
apple/RNCWebView.h Прегледај датотеку

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

+ 4
- 0
apple/RNCWebView.m Прегледај датотеку

@@ -209,6 +209,10 @@ static NSDictionary* customCertificatesForHost;
209 209
     [prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
210 210
     _prefsUsed = YES;
211 211
   }
212
+  if (_javaScriptCanOpenWindowsAutomatically) {
213
+    [prefs setValue:@TRUE forKey:@"javaScriptCanOpenWindowsAutomatically"];
214
+    _prefsUsed = YES;
215
+  }
212 216
   if (_prefsUsed) {
213 217
     wkWebViewConfig.preferences = prefs;
214 218
   }

+ 1
- 0
apple/RNCWebViewManager.m Прегледај датотеку

@@ -47,6 +47,7 @@ RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoaded, NSString)
47 47
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptForMainFrameOnly, BOOL)
48 48
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoadedForMainFrameOnly, BOOL)
49 49
 RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
50
+RCT_EXPORT_VIEW_PROPERTY(javaScriptCanOpenWindowsAutomatically, BOOL)
50 51
 RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
51 52
 RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
52 53
 RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)

+ 11
- 0
docs/Reference.md Прегледај датотеку

@@ -32,6 +32,7 @@ This document lays out the current public properties and methods for the React N
32 32
 - [`decelerationRate`](Reference.md#decelerationrate)
33 33
 - [`domStorageEnabled`](Reference.md#domstorageenabled)
34 34
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
35
+- [`javaScriptCanOpenWindowsAutomatically`](Reference.md#javascriptcanopenwindowsautomatically)
35 36
 - [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
36 37
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
37 38
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
@@ -732,6 +733,16 @@ Boolean value to enable JavaScript in the `WebView`. The default value is `true`
732 733
 
733 734
 ---
734 735
 
736
+### `javaScriptCanOpenWindowsAutomatically`
737
+
738
+A Boolean value indicating whether JavaScript can open windows without user interaction. The default value is `false`.
739
+
740
+| Type | Required |
741
+| ---- | -------- |
742
+| bool | No       |
743
+
744
+---
745
+
735 746
 ### `androidHardwareAccelerationDisabled`
736 747
 
737 748
 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`.

+ 7
- 0
src/WebViewTypes.ts Прегледај датотеку

@@ -240,6 +240,7 @@ export interface CommonNativeWebViewProps extends ViewProps {
240 240
   incognito?: boolean;
241 241
   injectedJavaScript?: string;
242 242
   injectedJavaScriptBeforeContentLoaded?: string;
243
+  javaScriptCanOpenWindowsAutomatically?: boolean;
243 244
   mediaPlaybackRequiresUserAction?: boolean;
244 245
   messagingEnabled: boolean;
245 246
   onScroll?: (event: NativeScrollEvent) => void;
@@ -821,6 +822,12 @@ export interface WebViewSharedProps extends ViewProps {
821 822
    */
822 823
   javaScriptEnabled?: boolean;
823 824
 
825
+  /**
826
+   * A Boolean value indicating whether JavaScript can open windows without user interaction.
827
+   * The default value is `false`.
828
+   */
829
+  javaScriptCanOpenWindowsAutomatically?: boolean;
830
+
824 831
   /**
825 832
    * Stylesheet object to set the style of the container view.
826 833
    */