1 /** 2 * Copyright (c) 2015-present, Facebook, Inc. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 */ 7 8 #import <React/RCTView.h> 9 #import <React/RCTDefines.h> 10 #import <WebKit/WKDataDetectorTypes.h> 11 #import <WebKit/WebKit.h> 12 13 #if !TARGET_OS_OSX 14 #import <UIKit/UIScrollView.h> 15 #endif // !TARGET_OS_OSX 16 17 #import "RNCWebViewDecisionManager.h" 18 19 typedef enum RNCWebViewPermissionGrantType : NSUInteger { 20 RNCWebViewPermissionGrantType_GrantIfSameHost_ElsePrompt, 21 RNCWebViewPermissionGrantType_GrantIfSameHost_ElseDeny, 22 RNCWebViewPermissionGrantType_Deny, 23 RNCWebViewPermissionGrantType_Grant, 24 RNCWebViewPermissionGrantType_Prompt 25 } RNCWebViewPermissionGrantType; 26 27 @class RNCWebViewImpl; 28 29 NS_ASSUME_NONNULL_BEGIN 30 31 @protocol RNCWebViewDelegate <NSObject> 32 33 - (BOOL)webView:(RNCWebViewImpl *)webView 34 shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request 35 withCallback:(RCTDirectEventBlock)callback; 36 37 @end 38 39 @interface RNCWeakScriptMessageDelegate : NSObject<WKScriptMessageHandler> 40 41 @property (nonatomic, weak, nullable) id<WKScriptMessageHandler> scriptDelegate; 42 43 - (nullable instancetype)initWithDelegate:(id<WKScriptMessageHandler> _Nullable)scriptDelegate; 44 45 @end 46 47 @interface RNCWebViewImpl : RCTView 48 @property (nonatomic, strong) NSString *scopeKey; 49 @property (nonatomic, copy) RCTDirectEventBlock onFileDownload; 50 @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart; 51 @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish; 52 @property (nonatomic, copy) RCTDirectEventBlock onLoadingError; 53 @property (nonatomic, copy) RCTDirectEventBlock onLoadingProgress; 54 @property (nonatomic, copy) RCTDirectEventBlock onShouldStartLoadWithRequest; 55 @property (nonatomic, copy) RCTDirectEventBlock onHttpError; 56 @property (nonatomic, copy) RCTDirectEventBlock onMessage; 57 @property (nonatomic, copy) RCTDirectEventBlock onScroll; 58 @property (nonatomic, copy) RCTDirectEventBlock onContentProcessDidTerminate; 59 60 61 @property (nonatomic, weak) id<RNCWebViewDelegate> _Nullable delegate; 62 @property (nonatomic, copy) NSDictionary * _Nullable source; 63 @property (nonatomic, assign) BOOL messagingEnabled; 64 @property (nonatomic, copy) NSString * _Nullable injectedJavaScript; 65 @property (nonatomic, copy) NSString * _Nullable injectedJavaScriptBeforeContentLoaded; 66 @property (nonatomic, assign) BOOL injectedJavaScriptForMainFrameOnly; 67 @property (nonatomic, assign) BOOL injectedJavaScriptBeforeContentLoadedForMainFrameOnly; 68 @property (nonatomic, assign) BOOL scrollEnabled; 69 @property (nonatomic, assign) BOOL sharedCookiesEnabled; 70 @property (nonatomic, assign) BOOL autoManageStatusBarEnabled; 71 @property (nonatomic, assign) BOOL pagingEnabled; 72 @property (nonatomic, assign) CGFloat decelerationRate; 73 @property (nonatomic, assign) BOOL allowsInlineMediaPlayback; 74 @property (nonatomic, assign) BOOL webviewDebuggingEnabled; 75 @property (nonatomic, assign) BOOL allowsAirPlayForMediaPlayback; 76 @property (nonatomic, assign) BOOL bounces; 77 @property (nonatomic, assign) BOOL mediaPlaybackRequiresUserAction; 78 @property (nonatomic, assign) UIEdgeInsets contentInset; 79 @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; 80 @property (nonatomic, assign) BOOL keyboardDisplayRequiresUserAction; 81 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView; 82 @property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures; 83 @property (nonatomic, assign) BOOL incognito; 84 @property (nonatomic, assign) BOOL useSharedProcessPool; 85 @property (nonatomic, copy) NSString * _Nullable userAgent; 86 @property (nonatomic, copy) NSString * _Nullable applicationNameForUserAgent; 87 @property (nonatomic, assign) BOOL cacheEnabled; 88 @property (nonatomic, assign) BOOL javaScriptEnabled; 89 @property (nonatomic, assign) BOOL javaScriptCanOpenWindowsAutomatically; 90 @property (nonatomic, assign) BOOL allowFileAccessFromFileURLs; 91 @property (nonatomic, assign) BOOL allowUniversalAccessFromFileURLs; 92 @property (nonatomic, assign) BOOL allowsLinkPreview; 93 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator; 94 @property (nonatomic, assign) BOOL showsVerticalScrollIndicator; 95 @property (nonatomic, assign) BOOL directionalLockEnabled; 96 @property (nonatomic, assign) BOOL ignoreSilentHardwareSwitch; 97 @property (nonatomic, copy) NSString * _Nullable allowingReadAccessToURL; 98 @property (nonatomic, copy) NSDictionary * _Nullable basicAuthCredential; 99 @property (nonatomic, assign) BOOL pullToRefreshEnabled; 100 @property (nonatomic, assign) BOOL enableApplePay; 101 @property (nonatomic, copy) NSArray<NSDictionary *> * _Nullable menuItems; 102 @property (nonatomic, copy) RCTDirectEventBlock onCustomMenuSelection; 103 #if !TARGET_OS_OSX 104 @property (nonatomic, assign) WKDataDetectorTypes dataDetectorTypes; 105 @property (nonatomic, weak) UIRefreshControl * _Nullable refreshControl; 106 #endif 107 108 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */ 109 @property (nonatomic, assign) WKContentMode contentMode; 110 @property (nonatomic, assign) BOOL fraudulentWebsiteWarningEnabled; 111 #endif 112 113 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 /* iOS 14 */ 114 @property (nonatomic, assign) BOOL limitsNavigationsToAppBoundDomains; 115 #endif 116 117 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140500 /* iOS 14.5 */ 118 @property (nonatomic, assign) BOOL textInteractionEnabled; 119 #endif 120 121 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 /* iOS 15 */ 122 @property (nonatomic, assign) RNCWebViewPermissionGrantType mediaCapturePermissionGrantType; 123 #endif 124 125 #if !TARGET_OS_OSX 126 - (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBehavior)behavior; 127 #endif // !TARGET_OS_OSX 128 129 + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential; 130 + (void)setCustomCertificatesForHost:(nullable NSDictionary *)certificates; 131 - (void)postMessage:(NSString *_Nullable)message; 132 - (void)injectJavaScript:(NSString *_Nullable)script; 133 - (void)goForward; 134 - (void)goBack; 135 - (void)reload; 136 - (void)stopLoading; 137 - (void)requestFocus; 138 #ifdef RCT_NEW_ARCH_ENABLED 139 - (void)destroyWebView; 140 #endif 141 #if !TARGET_OS_OSX 142 - (void)addPullToRefreshControl; 143 - (void)pullToRefresh:(UIRefreshControl *)refreshControl; 144 #endif 145 146 @end 147 148 NS_ASSUME_NONNULL_END 149