Browse Source

Add support for iOS-specific prop `limitsNavigationsToAppBoundDomains`

Ivari Tölp 4 years ago
parent
commit
755d990b8c
4 changed files with 28 additions and 0 deletions
  1. 4
    0
      apple/RNCWebView.h
  2. 8
    0
      apple/RNCWebView.m
  3. 4
    0
      apple/RNCWebViewManager.m
  4. 12
    0
      src/WebViewTypes.ts

+ 4
- 0
apple/RNCWebView.h View File

70
 @property (nonatomic, assign) WKContentMode contentMode;
70
 @property (nonatomic, assign) WKContentMode contentMode;
71
 #endif
71
 #endif
72
 
72
 
73
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */
74
+@property (nonatomic, assign) BOOL limitsNavigationsToAppBoundDomains;
75
+#endif
76
+
73
 + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
77
 + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
74
 + (void)setCustomCertificatesForHost:(nullable NSDictionary *)certificates;
78
 + (void)setCustomCertificatesForHost:(nullable NSDictionary *)certificates;
75
 - (void)postMessage:(NSString *_Nullable)message;
79
 - (void)postMessage:(NSString *_Nullable)message;

+ 8
- 0
apple/RNCWebView.m View File

235
   }
235
   }
236
 #endif
236
 #endif
237
 
237
 
238
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */
239
+  if (@available(iOS 14.0, *)) {
240
+    if (_limitsNavigationsToAppBoundDomains) {
241
+      wkWebViewConfig.limitsNavigationsToAppBoundDomains = YES;
242
+    }
243
+  }
244
+#endif
245
+
238
   // Shim the HTML5 history API:
246
   // Shim the HTML5 history API:
239
   [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
247
   [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
240
                                                             name:HistoryShimName];
248
                                                             name:HistoryShimName];

+ 4
- 0
apple/RNCWebViewManager.m View File

85
 RCT_EXPORT_VIEW_PROPERTY(contentMode, WKContentMode)
85
 RCT_EXPORT_VIEW_PROPERTY(contentMode, WKContentMode)
86
 #endif
86
 #endif
87
 
87
 
88
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */
89
+RCT_EXPORT_VIEW_PROPERTY(limitsNavigationsToAppBoundDomains, BOOL)
90
+#endif
91
+
88
 /**
92
 /**
89
  * Expose methods to enable messaging the webview.
93
  * Expose methods to enable messaging the webview.
90
  */
94
  */

+ 12
- 0
src/WebViewTypes.ts View File

327
   injectedJavaScriptForMainFrameOnly?: boolean;
327
   injectedJavaScriptForMainFrameOnly?: boolean;
328
   injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
328
   injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
329
   onFileDownload?: (event: FileDownloadEvent) => void;
329
   onFileDownload?: (event: FileDownloadEvent) => void;
330
+  limitsNavigationsToAppBoundDomains?: boolean;
330
 }
331
 }
331
 
332
 
332
 export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
333
 export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
583
    * If not provided, the default is to let the webview try to render the file.
584
    * If not provided, the default is to let the webview try to render the file.
584
    */
585
    */
585
   onFileDownload?: (event: FileDownloadEvent) => void;
586
   onFileDownload?: (event: FileDownloadEvent) => void;
587
+
588
+  /**
589
+   * A Boolean value which, when set to `true`, indicates to WebKit that a WKWebView
590
+   * will only navigate to app-bound domains. Once set, any attempt to navigate away
591
+   * from an app-bound domain will fail with the error: “App-bound domain failure.”
592
+   * 
593
+   * Applications can specify up to 10 “app-bound” domains using a new
594
+   * Info.plist key — `WKAppBoundDomains`.
595
+   * @platform ios
596
+   */
597
+  limitsNavigationsToAppBoundDomains?: boolean;
586
 }
598
 }
587
 
599
 
588
 export interface MacOSWebViewProps extends WebViewSharedProps {
600
 export interface MacOSWebViewProps extends WebViewSharedProps {