Ivari Tölp 4 years ago
parent
commit
06b03d9808
No account linked to committer's email address
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,6 +70,10 @@
70 70
 @property (nonatomic, assign) WKContentMode contentMode;
71 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 77
 + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
74 78
 + (void)setCustomCertificatesForHost:(nullable NSDictionary *)certificates;
75 79
 - (void)postMessage:(NSString *_Nullable)message;

+ 8
- 0
apple/RNCWebView.m View File

@@ -235,6 +235,14 @@ static NSDictionary* customCertificatesForHost;
235 235
   }
236 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 246
   // Shim the HTML5 history API:
239 247
   [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
240 248
                                                             name:HistoryShimName];

+ 4
- 0
apple/RNCWebViewManager.m View File

@@ -85,6 +85,10 @@ RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInse
85 85
 RCT_EXPORT_VIEW_PROPERTY(contentMode, WKContentMode)
86 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 93
  * Expose methods to enable messaging the webview.
90 94
  */

+ 12
- 0
src/WebViewTypes.ts View File

@@ -327,6 +327,7 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
327 327
   injectedJavaScriptForMainFrameOnly?: boolean;
328 328
   injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
329 329
   onFileDownload?: (event: FileDownloadEvent) => void;
330
+  limitsNavigationsToAppBoundDomains?: boolean;
330 331
 }
331 332
 
332 333
 export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
@@ -583,6 +584,17 @@ export interface IOSWebViewProps extends WebViewSharedProps {
583 584
    * If not provided, the default is to let the webview try to render the file.
584 585
    */
585 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 600
 export interface MacOSWebViewProps extends WebViewSharedProps {