Browse Source

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

[skip ci]
trcoffman 4 years ago
parent
commit
91df544fae
No account linked to committer's email address

+ 5
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

376
     view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
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
   @ReactProp(name = "allowFileAccessFromFileURLs")
384
   @ReactProp(name = "allowFileAccessFromFileURLs")
380
   public void setAllowFileAccessFromFileURLs(WebView view, boolean allow) {
385
   public void setAllowFileAccessFromFileURLs(WebView view, boolean allow) {
381
     view.getSettings().setAllowFileAccessFromFileURLs(allow);
386
     view.getSettings().setAllowFileAccessFromFileURLs(allow);

+ 1
- 0
apple/RNCWebView.h View File

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

+ 4
- 0
apple/RNCWebView.m View File

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

+ 1
- 0
apple/RNCWebViewManager.m View File

47
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptForMainFrameOnly, BOOL)
47
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptForMainFrameOnly, BOOL)
48
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoadedForMainFrameOnly, BOOL)
48
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoadedForMainFrameOnly, BOOL)
49
 RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
49
 RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
50
+RCT_EXPORT_VIEW_PROPERTY(javaScriptCanOpenWindowsAutomatically, BOOL)
50
 RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
51
 RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
51
 RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
52
 RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
52
 RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
53
 RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)

+ 11
- 0
docs/Reference.md View File

32
 - [`decelerationRate`](Reference.md#decelerationrate)
32
 - [`decelerationRate`](Reference.md#decelerationrate)
33
 - [`domStorageEnabled`](Reference.md#domstorageenabled)
33
 - [`domStorageEnabled`](Reference.md#domstorageenabled)
34
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
34
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
35
+- [`javaScriptCanOpenWindowsAutomatically`](Reference.md#javascriptcanopenwindowsautomatically)
35
 - [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
36
 - [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
36
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
37
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
37
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
38
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
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
 ### `androidHardwareAccelerationDisabled`
746
 ### `androidHardwareAccelerationDisabled`
736
 
747
 
737
 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`.
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 View File

240
   incognito?: boolean;
240
   incognito?: boolean;
241
   injectedJavaScript?: string;
241
   injectedJavaScript?: string;
242
   injectedJavaScriptBeforeContentLoaded?: string;
242
   injectedJavaScriptBeforeContentLoaded?: string;
243
+  javaScriptCanOpenWindowsAutomatically?: boolean;
243
   mediaPlaybackRequiresUserAction?: boolean;
244
   mediaPlaybackRequiresUserAction?: boolean;
244
   messagingEnabled: boolean;
245
   messagingEnabled: boolean;
245
   onScroll?: (event: NativeScrollEvent) => void;
246
   onScroll?: (event: NativeScrollEvent) => void;
821
    */
822
    */
822
   javaScriptEnabled?: boolean;
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
    * Stylesheet object to set the style of the container view.
832
    * Stylesheet object to set the style of the container view.
826
    */
833
    */