@exodus/react-native-webview 13.16.0-exodus.0 → 13.16.0-exodus.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apple/RNCWebViewDecisionManager.h +6 -6
- package/apple/RNCWebViewDecisionManager.m +41 -19
- package/apple/RNCWebViewImpl.m +15 -2
- package/apple/RNCWebViewModule.mm +1 -1
- package/lib/WebView.android.js +1 -1
- package/lib/WebView.ios.js +1 -1
- package/lib/WebViewShared.d.ts +1 -1
- package/lib/WebViewShared.js +1 -1
- package/lib/WebViewTypes.d.ts +12 -0
- package/package.json +1 -1
- package/src/WebView.android.tsx +68 -3
- package/src/WebView.ios.tsx +26 -16
- package/src/WebViewShared.tsx +2 -1
- package/src/WebViewTypes.ts +14 -0
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
typedef void (^DecisionBlock)(BOOL);
|
|
6
6
|
|
|
7
7
|
@interface RNCWebViewDecisionManager : NSObject {
|
|
8
|
-
|
|
8
|
+
NSInteger nextLockIdentifier;
|
|
9
9
|
NSMutableDictionary *decisionHandlers;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
@property (nonatomic)
|
|
12
|
+
@property (nonatomic) NSInteger nextLockIdentifier;
|
|
13
13
|
@property (nonatomic, retain) NSMutableDictionary *decisionHandlers;
|
|
14
14
|
|
|
15
|
-
+ (id)
|
|
15
|
+
+ (id)getInstance;
|
|
16
16
|
|
|
17
|
-
- (
|
|
18
|
-
- (void)
|
|
19
|
-
|
|
17
|
+
- (NSInteger)setDecisionHandler:(DecisionBlock)handler;
|
|
18
|
+
- (void)setResult:(BOOL)shouldStart forLockIdentifier:(NSInteger)lockIdentifier;
|
|
19
|
+
- (void)cancelDecisionForLockIdentifier:(NSInteger)lockIdentifier;
|
|
20
20
|
@end
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
#import "RNCWebViewDecisionManager.h"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Exodus: Thread-safe singleton that manages navigation decision handlers.
|
|
5
|
+
*
|
|
6
|
+
* Security improvements over upstream:
|
|
7
|
+
* - Uses NSInteger (64-bit) instead of int to prevent overflow
|
|
8
|
+
* - Adds collision checking to skip identifiers still in use
|
|
9
|
+
* - All public methods use @synchronized for thread safety
|
|
10
|
+
* - Explicitly copies blocks to heap to prevent use-after-free
|
|
11
|
+
* - Provides cancelDecisionForLockIdentifier: for cleanup on WebView dealloc
|
|
12
|
+
*/
|
|
5
13
|
@implementation RNCWebViewDecisionManager
|
|
6
14
|
|
|
7
15
|
@synthesize nextLockIdentifier;
|
|
@@ -16,30 +24,44 @@
|
|
|
16
24
|
return lockManager;
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
- (
|
|
20
|
-
|
|
27
|
+
- (NSInteger)setDecisionHandler:(DecisionBlock)decisionHandler {
|
|
28
|
+
@synchronized (self) {
|
|
29
|
+
NSInteger lockIdentifier = self.nextLockIdentifier++;
|
|
30
|
+
|
|
31
|
+
while ([self.decisionHandlers objectForKey:@(lockIdentifier)] != nil) {
|
|
32
|
+
lockIdentifier = self.nextLockIdentifier++;
|
|
33
|
+
}
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
[self.decisionHandlers setObject:[decisionHandler copy] forKey:@(lockIdentifier)];
|
|
36
|
+
return lockIdentifier;
|
|
37
|
+
}
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
- (void)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
- (void)setResult:(BOOL)shouldStart forLockIdentifier:(NSInteger)lockIdentifier {
|
|
41
|
+
@synchronized (self) {
|
|
42
|
+
DecisionBlock handler = [self.decisionHandlers objectForKey:@(lockIdentifier)];
|
|
43
|
+
if (handler == nil) {
|
|
44
|
+
RCTLogWarn(@"Lock not found for identifier: %ld", (long)lockIdentifier);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
handler(shouldStart);
|
|
48
|
+
[self.decisionHandlers removeObjectForKey:@(lockIdentifier)];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
- (void)cancelDecisionForLockIdentifier:(NSInteger)lockIdentifier {
|
|
54
|
+
@synchronized (self) {
|
|
55
|
+
[self.decisionHandlers removeObjectForKey:@(lockIdentifier)];
|
|
32
56
|
}
|
|
33
|
-
handler(shouldStart);
|
|
34
|
-
[self.decisionHandlers removeObjectForKey:@(lockIdentifier)];
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
- (id)init {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
if (self = [super init]) {
|
|
61
|
+
self.nextLockIdentifier = 1;
|
|
62
|
+
self.decisionHandlers = [[NSMutableDictionary alloc] init];
|
|
63
|
+
}
|
|
64
|
+
return self;
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
- (void)dealloc {}
|
package/apple/RNCWebViewImpl.m
CHANGED
|
@@ -156,6 +156,9 @@ RCTAutoInsetsProtocol>
|
|
|
156
156
|
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
|
|
157
157
|
BOOL _savedAutomaticallyAdjustsScrollIndicatorInsets;
|
|
158
158
|
#endif
|
|
159
|
+
|
|
160
|
+
// Exodus: Track pending navigation decision lock identifiers for cleanup on dealloc
|
|
161
|
+
NSMutableSet<NSNumber *> *_pendingLockIdentifiers;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
@@ -166,6 +169,7 @@ RCTAutoInsetsProtocol>
|
|
|
166
169
|
#else
|
|
167
170
|
super.backgroundColor = [RCTUIColor clearColor];
|
|
168
171
|
#endif // !TARGET_OS_OSX
|
|
172
|
+
_pendingLockIdentifiers = [[NSMutableSet alloc] init];
|
|
169
173
|
_bounces = YES;
|
|
170
174
|
_scrollEnabled = YES;
|
|
171
175
|
_showsHorizontalScrollIndicator = YES;
|
|
@@ -318,6 +322,10 @@ RCTAutoInsetsProtocol>
|
|
|
318
322
|
if (@available(iOS 11.0, *)) {
|
|
319
323
|
[self.webView.configuration.websiteDataStore.httpCookieStore removeObserver:self];
|
|
320
324
|
}
|
|
325
|
+
|
|
326
|
+
for (NSNumber *lockId in _pendingLockIdentifiers) {
|
|
327
|
+
[[RNCWebViewDecisionManager getInstance] cancelDecisionForLockIdentifier:[lockId integerValue]];
|
|
328
|
+
}
|
|
321
329
|
}
|
|
322
330
|
|
|
323
331
|
- (void)tappedMenuItem:(NSString *)eventType
|
|
@@ -1117,7 +1125,7 @@ RCTAutoInsetsProtocol>
|
|
|
1117
1125
|
{
|
|
1118
1126
|
NSDictionary *eventInitDict = @{@"data": message};
|
|
1119
1127
|
NSString *source = [NSString
|
|
1120
|
-
stringWithFormat:@"
|
|
1128
|
+
stringWithFormat:@"document.dispatchEvent(new MessageEvent('message', %@));",
|
|
1121
1129
|
RCTJSONStringify(eventInitDict, NULL)
|
|
1122
1130
|
];
|
|
1123
1131
|
[self injectJavaScript: source];
|
|
@@ -1386,8 +1394,10 @@ RCTAutoInsetsProtocol>
|
|
|
1386
1394
|
}
|
|
1387
1395
|
|
|
1388
1396
|
if (_onShouldStartLoadWithRequest) {
|
|
1389
|
-
|
|
1397
|
+
NSInteger lockIdentifier = [[RNCWebViewDecisionManager getInstance] setDecisionHandler: ^(BOOL shouldStart){
|
|
1390
1398
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1399
|
+
[self->_pendingLockIdentifiers removeObject:@(lockIdentifier)];
|
|
1400
|
+
|
|
1391
1401
|
if (!shouldStart) {
|
|
1392
1402
|
decisionHandler(WKNavigationActionPolicyCancel);
|
|
1393
1403
|
return;
|
|
@@ -1409,6 +1419,9 @@ RCTAutoInsetsProtocol>
|
|
|
1409
1419
|
});
|
|
1410
1420
|
|
|
1411
1421
|
}];
|
|
1422
|
+
|
|
1423
|
+
[_pendingLockIdentifiers addObject:@(lockIdentifier)];
|
|
1424
|
+
|
|
1412
1425
|
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
|
|
1413
1426
|
if (request.mainDocumentURL) {
|
|
1414
1427
|
[event addEntriesFromDictionary: @{
|
|
@@ -18,7 +18,7 @@ RCT_EXPORT_METHOD(isFileUploadSupported:(RCTPromiseResolveBlock)resolve reject:(
|
|
|
18
18
|
|
|
19
19
|
RCT_EXPORT_METHOD(shouldStartLoadWithLockIdentifier:(BOOL)shouldStart lockIdentifier:(double)lockIdentifier)
|
|
20
20
|
{
|
|
21
|
-
[[RNCWebViewDecisionManager getInstance] setResult:shouldStart forLockIdentifier:(
|
|
21
|
+
[[RNCWebViewDecisionManager getInstance] setResult:shouldStart forLockIdentifier:(NSInteger)lockIdentifier];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
#ifdef RCT_NEW_ARCH_ENABLED
|
package/lib/WebView.android.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _BatchedBridge=_interopRequireDefault(require("react-native/Libraries/BatchedBridge/BatchedBridge"));var _EventEmitter=_interopRequireDefault(require("react-native/Libraries/vendor/emitter/EventEmitter"));var _invariant=_interopRequireDefault(require("invariant"));var _RNCWebViewNativeComponent=_interopRequireWildcard(require("./RNCWebViewNativeComponent"));var _NativeRNCWebViewModule=_interopRequireDefault(require("./NativeRNCWebViewModule"));var _WebViewShared=require("./WebViewShared");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["overScrollMode","javaScriptEnabled","thirdPartyCookiesEnabled","scalesPageToFit","allowsFullscreenVideo","allowFileAccess","saveFormDataDisabled","cacheEnabled","androidLayerType","originWhitelist","deeplinkWhitelist","setSupportMultipleWindows","setBuiltInZoomControls","setDisplayZoomControls","nestedScrollEnabled","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadSubResourceError","onLoadProgress","onHttpError","onRenderProcessGone","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","nativeConfig","onShouldStartLoadWithRequest","injectedJavaScriptObject","validateMeta","validateData"],_excluded2=["messagingModuleName"],_excluded3=["messagingModuleName"];var _require$registerCall,_this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebView.android.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var resolveAssetSource=_reactNative.Image.resolveAssetSource;var directEventEmitter=new _EventEmitter.default();var registerCallableModule=(_require$registerCall=require('react-native').registerCallableModule)!=null?_require$registerCall:_BatchedBridge.default.registerCallableModule.bind(_BatchedBridge.default);registerCallableModule('RNCWebViewMessagingModule',{onShouldStartLoadWithRequest:function onShouldStartLoadWithRequest(event){directEventEmitter.emit('onShouldStartLoadWithRequest',event);},onMessage:function onMessage(event){directEventEmitter.emit('onMessage',event);}});var uniqueRef=0;var WebViewComponent=(0,_react.forwardRef)(function(_ref,ref){var _ref$overScrollMode=_ref.overScrollMode,overScrollMode=_ref$overScrollMode===void 0?'always':_ref$overScrollMode,_ref$javaScriptEnable=_ref.javaScriptEnabled,javaScriptEnabled=_ref$javaScriptEnable===void 0?true:_ref$javaScriptEnable,_ref$thirdPartyCookie=_ref.thirdPartyCookiesEnabled,thirdPartyCookiesEnabled=_ref$thirdPartyCookie===void 0?true:_ref$thirdPartyCookie,_ref$scalesPageToFit=_ref.scalesPageToFit,scalesPageToFit=_ref$scalesPageToFit===void 0?true:_ref$scalesPageToFit,_ref$allowsFullscreen=_ref.allowsFullscreenVideo,allowsFullscreenVideo=_ref$allowsFullscreen===void 0?false:_ref$allowsFullscreen,_ref$allowFileAccess=_ref.allowFileAccess,allowFileAccess=_ref$allowFileAccess===void 0?false:_ref$allowFileAccess,_ref$saveFormDataDisa=_ref.saveFormDataDisabled,saveFormDataDisabled=_ref$saveFormDataDisa===void 0?false:_ref$saveFormDataDisa,_ref$cacheEnabled=_ref.cacheEnabled,cacheEnabled=_ref$cacheEnabled===void 0?true:_ref$cacheEnabled,_ref$androidLayerType=_ref.androidLayerType,androidLayerType=_ref$androidLayerType===void 0?'none':_ref$androidLayerType,_ref$originWhitelist=_ref.originWhitelist,originWhitelist=_ref$originWhitelist===void 0?_WebViewShared.defaultOriginWhitelist:_ref$originWhitelist,_ref$deeplinkWhitelis=_ref.deeplinkWhitelist,deeplinkWhitelist=_ref$deeplinkWhitelis===void 0?_WebViewShared.defaultDeeplinkWhitelist:_ref$deeplinkWhitelis,_ref$setSupportMultip=_ref.setSupportMultipleWindows,setSupportMultipleWindows=_ref$setSupportMultip===void 0?true:_ref$setSupportMultip,_ref$setBuiltInZoomCo=_ref.setBuiltInZoomControls,setBuiltInZoomControls=_ref$setBuiltInZoomCo===void 0?true:_ref$setBuiltInZoomCo,_ref$setDisplayZoomCo=_ref.setDisplayZoomControls,setDisplayZoomControls=_ref$setDisplayZoomCo===void 0?false:_ref$setDisplayZoomCo,_ref$nestedScrollEnab=_ref.nestedScrollEnabled,nestedScrollEnabled=_ref$nestedScrollEnab===void 0?false:_ref$nestedScrollEnab,startInLoadingState=_ref.startInLoadingState,onNavigationStateChange=_ref.onNavigationStateChange,onLoadStart=_ref.onLoadStart,onError=_ref.onError,onLoad=_ref.onLoad,onLoadEnd=_ref.onLoadEnd,onLoadSubResourceError=_ref.onLoadSubResourceError,onLoadProgress=_ref.onLoadProgress,onHttpErrorProp=_ref.onHttpError,onRenderProcessGoneProp=_ref.onRenderProcessGone,onMessageProp=_ref.onMessage,onOpenWindowProp=_ref.onOpenWindow,renderLoading=_ref.renderLoading,renderError=_ref.renderError,style=_ref.style,containerStyle=_ref.containerStyle,source=_ref.source,nativeConfig=_ref.nativeConfig,onShouldStartLoadWithRequestProp=_ref.onShouldStartLoadWithRequest,injectedJavaScriptObject=_ref.injectedJavaScriptObject,validateMeta=_ref.validateMeta,validateData=_ref.validateData,otherProps=(0,_objectWithoutProperties2.default)(_ref,_excluded);var messagingModuleName=(0,_react.useRef)(`WebViewMessageHandler${uniqueRef+=1}`).current;var webViewRef=(0,_react.useRef)(null);var onShouldStartLoadWithRequestCallback=(0,_react.useCallback)(function(shouldStart,url,lockIdentifier){if(lockIdentifier){_NativeRNCWebViewModule.default.shouldStartLoadWithLockIdentifier(shouldStart,lockIdentifier);}else if(shouldStart&&webViewRef.current){_RNCWebViewNativeComponent.Commands.loadUrl(webViewRef.current,url);}},[]);var _useWebViewLogic=(0,_WebViewShared.useWebViewLogic)({onNavigationStateChange:onNavigationStateChange,onLoad:onLoad,onError:onError,onHttpErrorProp:onHttpErrorProp,onLoadSubResourceError:onLoadSubResourceError,onLoadEnd:onLoadEnd,onLoadProgress:onLoadProgress,onLoadStart:onLoadStart,onRenderProcessGoneProp:onRenderProcessGoneProp,onMessageProp:onMessageProp,onOpenWindowProp:onOpenWindowProp,startInLoadingState:startInLoadingState,originWhitelist:originWhitelist,deeplinkWhitelist:deeplinkWhitelist,onShouldStartLoadWithRequestProp:onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback:onShouldStartLoadWithRequestCallback,validateMeta:validateMeta,validateData:validateData}),onLoadingStart=_useWebViewLogic.onLoadingStart,onShouldStartLoadWithRequest=_useWebViewLogic.onShouldStartLoadWithRequest,onMessage=_useWebViewLogic.onMessage,viewState=_useWebViewLogic.viewState,setViewState=_useWebViewLogic.setViewState,lastErrorEvent=_useWebViewLogic.lastErrorEvent,onHttpError=_useWebViewLogic.onHttpError,onLoadingError=_useWebViewLogic.onLoadingError,onLoadingSubResourceError=_useWebViewLogic.onLoadingSubResourceError,onLoadingFinish=_useWebViewLogic.onLoadingFinish,onLoadingProgress=_useWebViewLogic.onLoadingProgress,onOpenWindow=_useWebViewLogic.onOpenWindow,onRenderProcessGone=_useWebViewLogic.onRenderProcessGone;(0,_react.useImperativeHandle)(ref,function(){return{goForward:function goForward(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goForward(webViewRef.current);},goBack:function goBack(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goBack(webViewRef.current);},reload:function reload(){setViewState('LOADING');if(webViewRef.current){_RNCWebViewNativeComponent.Commands.reload(webViewRef.current);}},stopLoading:function stopLoading(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.stopLoading(webViewRef.current);},postMessage:function postMessage(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.postMessage(webViewRef.current,data);},injectJavaScript:function injectJavaScript(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.injectJavaScript(webViewRef.current,data);},requestFocus:function requestFocus(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.requestFocus(webViewRef.current);},clearFormData:function clearFormData(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearFormData(webViewRef.current);},clearCache:function clearCache(includeDiskFiles){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearCache(webViewRef.current,includeDiskFiles);},clearHistory:function clearHistory(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearHistory(webViewRef.current);}};},[setViewState,webViewRef]);(0,_react.useEffect)(function(){var onShouldStartLoadWithRequestSubscription=directEventEmitter.addListener('onShouldStartLoadWithRequest',function(event){if(event.messagingModuleName===messagingModuleName){var _=event.messagingModuleName,rest=(0,_objectWithoutProperties2.default)(event,_excluded2);onShouldStartLoadWithRequest(rest);}});var onMessageSubscription=directEventEmitter.addListener('onMessage',function(event){if(event.messagingModuleName===messagingModuleName){var _=event.messagingModuleName,rest=(0,_objectWithoutProperties2.default)(event,_excluded3);onMessage(rest);}});return function(){onShouldStartLoadWithRequestSubscription.remove();onMessageSubscription.remove();};},[messagingModuleName,onMessage,onShouldStartLoadWithRequest]);var otherView;if(viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(viewState==='ERROR'){(0,_invariant.default)(lastErrorEvent!=null,'lastErrorEvent expected to be non-null');if(lastErrorEvent){otherView=(renderError||_WebViewShared.defaultRenderError)(lastErrorEvent.domain,lastErrorEvent.code,lastErrorEvent.description);}}else if(viewState!=='IDLE'){console.error(`RNCWebView invalid state encountered: ${viewState}`);}var webViewStyles=[_WebView.default.container,_WebView.default.webView,style];var webViewContainerStyle=[_WebView.default.container,containerStyle];if(typeof source!=='number'&&source&&'method'in source){if(source.method==='POST'&&source.headers){console.warn('WebView: `source.headers` is not supported when using POST.');}else if(source.method==='GET'&&source.body){console.warn('WebView: `source.body` is not supported when using GET.');}}var NativeWebView=(nativeConfig==null?void 0:nativeConfig.component)||_RNCWebViewNativeComponent.default;var sourceResolved=resolveAssetSource(source);var newSource=typeof sourceResolved==='object'?Object.entries(sourceResolved).reduce(function(prev,_ref2){var _ref3=(0,_slicedToArray2.default)(_ref2,2),currKey=_ref3[0],currValue=_ref3[1];return Object.assign({},prev,(0,_defineProperty2.default)({},currKey,currKey==='headers'&&currValue&&typeof currValue==='object'?Object.entries(currValue).map(function(_ref4){var _ref5=(0,_slicedToArray2.default)(_ref4,2),key=_ref5[0],value=_ref5[1];return{name:key,value:value};}):currValue));},{}):sourceResolved;var webView=(0,_jsxRuntime.jsx)(NativeWebView,Object.assign({},otherProps,{messagingEnabled:typeof onMessageProp==='function',messagingModuleName:messagingModuleName,hasOnScroll:!!otherProps.onScroll,onLoadingError:onLoadingError,onLoadingSubResourceError:onLoadingSubResourceError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onLoadingStart:onLoadingStart,onHttpError:onHttpError,onRenderProcessGone:onRenderProcessGone,onMessage:onMessage,onOpenWindow:onOpenWindow,hasOnOpenWindowEvent:onOpenWindowProp!==undefined,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,ref:webViewRef,source:sourceResolved,newSource:newSource,style:webViewStyles,overScrollMode:overScrollMode,javaScriptEnabled:javaScriptEnabled,thirdPartyCookiesEnabled:thirdPartyCookiesEnabled,scalesPageToFit:scalesPageToFit,allowsFullscreenVideo:allowsFullscreenVideo,allowFileAccess:allowFileAccess,saveFormDataDisabled:saveFormDataDisabled,cacheEnabled:cacheEnabled,androidLayerType:androidLayerType,setSupportMultipleWindows:setSupportMultipleWindows,setBuiltInZoomControls:setBuiltInZoomControls,setDisplayZoomControls:setDisplayZoomControls,nestedScrollEnabled:nestedScrollEnabled,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject)},nativeConfig==null?void 0:nativeConfig.props),"webViewKey");return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:webViewContainerStyle,children:[webView,otherView]});});var isFileUploadSupported=_NativeRNCWebViewModule.default.isFileUploadSupported;var WebView=Object.assign(WebViewComponent,{isFileUploadSupported:isFileUploadSupported});var _default=exports.default=WebView;
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _BatchedBridge=_interopRequireDefault(require("react-native/Libraries/BatchedBridge/BatchedBridge"));var _EventEmitter=_interopRequireDefault(require("react-native/Libraries/vendor/emitter/EventEmitter"));var _invariant=_interopRequireDefault(require("invariant"));var _RNCWebViewNativeComponent=_interopRequireWildcard(require("./RNCWebViewNativeComponent"));var _NativeRNCWebViewModule=_interopRequireDefault(require("./NativeRNCWebViewModule"));var _WebViewShared=require("./WebViewShared");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["overScrollMode","javaScriptEnabled","thirdPartyCookiesEnabled","scalesPageToFit","allowsFullscreenVideo","allowFileAccess","saveFormDataDisabled","cacheEnabled","androidLayerType","originWhitelist","deeplinkWhitelist","setBuiltInZoomControls","setDisplayZoomControls","nestedScrollEnabled","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadSubResourceError","onLoadProgress","onHttpError","onRenderProcessGone","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","nativeConfig","onShouldStartLoadWithRequest","injectedJavaScriptObject","validateMeta","validateData","minimumChromeVersion","unsupportedVersionComponent"],_excluded2=["messagingModuleName"],_excluded3=["messagingModuleName"];var _require$registerCall,_this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebView.android.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var resolveAssetSource=_reactNative.Image.resolveAssetSource;var directEventEmitter=new _EventEmitter.default();var registerCallableModule=(_require$registerCall=require('react-native').registerCallableModule)!=null?_require$registerCall:_BatchedBridge.default.registerCallableModule.bind(_BatchedBridge.default);registerCallableModule('RNCWebViewMessagingModule',{onShouldStartLoadWithRequest:function onShouldStartLoadWithRequest(event){directEventEmitter.emit('onShouldStartLoadWithRequest',event);},onMessage:function onMessage(event){directEventEmitter.emit('onMessage',event);}});var _ref=_reactNative.NativeModules.RNCWebViewUtils||{},getWebViewDefaultUserAgent=_ref.getWebViewDefaultUserAgent;var userAgentPromise;function getUserAgent(){return _getUserAgent.apply(this,arguments);}function _getUserAgent(){_getUserAgent=(0,_asyncToGenerator2.default)(function*(){if(!getWebViewDefaultUserAgent)return'unknown';if(!userAgentPromise)userAgentPromise=getWebViewDefaultUserAgent();var userAgent=yield userAgentPromise;return userAgent||'unknown';});return _getUserAgent.apply(this,arguments);}var hardMinimumChromeVersion='100.0';var mediaPlaybackRequiresUserAction=true;var securitySupportMultipleWindows=true;var securityMixedContentMode='never';var uniqueRef=0;var WebViewComponent=(0,_react.forwardRef)(function(_ref2,ref){var _userAgent$match;var _ref2$overScrollMode=_ref2.overScrollMode,overScrollMode=_ref2$overScrollMode===void 0?'always':_ref2$overScrollMode,_ref2$javaScriptEnabl=_ref2.javaScriptEnabled,javaScriptEnabled=_ref2$javaScriptEnabl===void 0?true:_ref2$javaScriptEnabl,_ref2$thirdPartyCooki=_ref2.thirdPartyCookiesEnabled,thirdPartyCookiesEnabled=_ref2$thirdPartyCooki===void 0?true:_ref2$thirdPartyCooki,_ref2$scalesPageToFit=_ref2.scalesPageToFit,scalesPageToFit=_ref2$scalesPageToFit===void 0?true:_ref2$scalesPageToFit,_ref2$allowsFullscree=_ref2.allowsFullscreenVideo,allowsFullscreenVideo=_ref2$allowsFullscree===void 0?false:_ref2$allowsFullscree,_ref2$allowFileAccess=_ref2.allowFileAccess,allowFileAccess=_ref2$allowFileAccess===void 0?false:_ref2$allowFileAccess,_ref2$saveFormDataDis=_ref2.saveFormDataDisabled,saveFormDataDisabled=_ref2$saveFormDataDis===void 0?false:_ref2$saveFormDataDis,_ref2$cacheEnabled=_ref2.cacheEnabled,cacheEnabled=_ref2$cacheEnabled===void 0?true:_ref2$cacheEnabled,_ref2$androidLayerTyp=_ref2.androidLayerType,androidLayerType=_ref2$androidLayerTyp===void 0?'none':_ref2$androidLayerTyp,_ref2$originWhitelist=_ref2.originWhitelist,originWhitelist=_ref2$originWhitelist===void 0?_WebViewShared.defaultOriginWhitelist:_ref2$originWhitelist,_ref2$deeplinkWhiteli=_ref2.deeplinkWhitelist,deeplinkWhitelist=_ref2$deeplinkWhiteli===void 0?_WebViewShared.defaultDeeplinkWhitelist:_ref2$deeplinkWhiteli,_ref2$setBuiltInZoomC=_ref2.setBuiltInZoomControls,setBuiltInZoomControls=_ref2$setBuiltInZoomC===void 0?true:_ref2$setBuiltInZoomC,_ref2$setDisplayZoomC=_ref2.setDisplayZoomControls,setDisplayZoomControls=_ref2$setDisplayZoomC===void 0?false:_ref2$setDisplayZoomC,_ref2$nestedScrollEna=_ref2.nestedScrollEnabled,nestedScrollEnabled=_ref2$nestedScrollEna===void 0?false:_ref2$nestedScrollEna,startInLoadingState=_ref2.startInLoadingState,onNavigationStateChange=_ref2.onNavigationStateChange,onLoadStart=_ref2.onLoadStart,onError=_ref2.onError,onLoad=_ref2.onLoad,onLoadEnd=_ref2.onLoadEnd,onLoadSubResourceError=_ref2.onLoadSubResourceError,onLoadProgress=_ref2.onLoadProgress,onHttpErrorProp=_ref2.onHttpError,onRenderProcessGoneProp=_ref2.onRenderProcessGone,onMessageProp=_ref2.onMessage,onOpenWindowProp=_ref2.onOpenWindow,renderLoading=_ref2.renderLoading,renderError=_ref2.renderError,style=_ref2.style,containerStyle=_ref2.containerStyle,source=_ref2.source,nativeConfig=_ref2.nativeConfig,onShouldStartLoadWithRequestProp=_ref2.onShouldStartLoadWithRequest,injectedJavaScriptObject=_ref2.injectedJavaScriptObject,validateMeta=_ref2.validateMeta,validateData=_ref2.validateData,minimumChromeVersion=_ref2.minimumChromeVersion,UnsupportedVersionComponent=_ref2.unsupportedVersionComponent,otherProps=(0,_objectWithoutProperties2.default)(_ref2,_excluded);var messagingModuleName=(0,_react.useRef)(`WebViewMessageHandler${uniqueRef+=1}`).current;var webViewRef=(0,_react.useRef)(null);var _useState=(0,_react.useState)(),_useState2=(0,_slicedToArray2.default)(_useState,2),userAgent=_useState2[0],setUserAgent=_useState2[1];(0,_react.useEffect)(function(){getUserAgent().then(setUserAgent);},[]);var onShouldStartLoadWithRequestCallback=(0,_react.useCallback)(function(shouldStart,url,lockIdentifier){if(lockIdentifier){_NativeRNCWebViewModule.default.shouldStartLoadWithLockIdentifier(shouldStart,lockIdentifier);}else if(shouldStart&&webViewRef.current){_RNCWebViewNativeComponent.Commands.loadUrl(webViewRef.current,url);}},[]);var _useWebViewLogic=(0,_WebViewShared.useWebViewLogic)({onNavigationStateChange:onNavigationStateChange,onLoad:onLoad,onError:onError,onHttpErrorProp:onHttpErrorProp,onLoadSubResourceError:onLoadSubResourceError,onLoadEnd:onLoadEnd,onLoadProgress:onLoadProgress,onLoadStart:onLoadStart,onRenderProcessGoneProp:onRenderProcessGoneProp,onMessageProp:onMessageProp,onOpenWindowProp:onOpenWindowProp,startInLoadingState:startInLoadingState,originWhitelist:originWhitelist,deeplinkWhitelist:deeplinkWhitelist,onShouldStartLoadWithRequestProp:onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback:onShouldStartLoadWithRequestCallback,validateMeta:validateMeta,validateData:validateData}),onLoadingStart=_useWebViewLogic.onLoadingStart,onShouldStartLoadWithRequest=_useWebViewLogic.onShouldStartLoadWithRequest,onMessage=_useWebViewLogic.onMessage,viewState=_useWebViewLogic.viewState,setViewState=_useWebViewLogic.setViewState,lastErrorEvent=_useWebViewLogic.lastErrorEvent,onHttpError=_useWebViewLogic.onHttpError,onLoadingError=_useWebViewLogic.onLoadingError,onLoadingSubResourceError=_useWebViewLogic.onLoadingSubResourceError,onLoadingFinish=_useWebViewLogic.onLoadingFinish,onLoadingProgress=_useWebViewLogic.onLoadingProgress,onOpenWindow=_useWebViewLogic.onOpenWindow,onRenderProcessGone=_useWebViewLogic.onRenderProcessGone;(0,_react.useImperativeHandle)(ref,function(){return{goForward:function goForward(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goForward(webViewRef.current);},goBack:function goBack(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goBack(webViewRef.current);},reload:function reload(){setViewState('LOADING');if(webViewRef.current){_RNCWebViewNativeComponent.Commands.reload(webViewRef.current);}},stopLoading:function stopLoading(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.stopLoading(webViewRef.current);},postMessage:function postMessage(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.postMessage(webViewRef.current,data);},injectJavaScript:function injectJavaScript(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.injectJavaScript(webViewRef.current,data);},requestFocus:function requestFocus(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.requestFocus(webViewRef.current);},clearFormData:function clearFormData(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearFormData(webViewRef.current);},clearCache:function clearCache(includeDiskFiles){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearCache(webViewRef.current,includeDiskFiles);},clearHistory:function clearHistory(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearHistory(webViewRef.current);}};},[setViewState,webViewRef]);(0,_react.useEffect)(function(){var onShouldStartLoadWithRequestSubscription=directEventEmitter.addListener('onShouldStartLoadWithRequest',function(event){if(event.messagingModuleName===messagingModuleName){var _=event.messagingModuleName,rest=(0,_objectWithoutProperties2.default)(event,_excluded2);onShouldStartLoadWithRequest(rest);}});var onMessageSubscription=directEventEmitter.addListener('onMessage',function(event){if(event.messagingModuleName===messagingModuleName){var _=event.messagingModuleName,rest=(0,_objectWithoutProperties2.default)(event,_excluded3);onMessage(rest);}});return function(){onShouldStartLoadWithRequestSubscription.remove();onMessageSubscription.remove();};},[messagingModuleName,onMessage,onShouldStartLoadWithRequest]);if(!userAgent)return null;var chromeVersion=(_userAgent$match=userAgent.match(/chrome\/((?:[0-9]+\.)+[0-9]+)/i))==null?void 0:_userAgent$match[1];if(!((0,_WebViewShared.versionPasses)(chromeVersion,minimumChromeVersion)&&(0,_WebViewShared.versionPasses)(chromeVersion,hardMinimumChromeVersion))){if(UnsupportedVersionComponent){return(0,_jsxRuntime.jsx)(UnsupportedVersionComponent,{});}return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{alignSelf:'flex-start'},children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:'red'},children:"Chrome version is outdated and insecure. Update it to continue."})});}var otherView;if(viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(viewState==='ERROR'){(0,_invariant.default)(lastErrorEvent!=null,'lastErrorEvent expected to be non-null');if(lastErrorEvent){otherView=(renderError||_WebViewShared.defaultRenderError)(lastErrorEvent.domain,lastErrorEvent.code,lastErrorEvent.description);}}else if(viewState!=='IDLE'){console.error(`RNCWebView invalid state encountered: ${viewState}`);}var webViewStyles=[_WebView.default.container,_WebView.default.webView,style];var webViewContainerStyle=[_WebView.default.container,containerStyle];if(typeof source!=='number'&&source&&'method'in source){if(source.method==='POST'&&source.headers){console.warn('WebView: `source.headers` is not supported when using POST.');}else if(source.method==='GET'&&source.body){console.warn('WebView: `source.body` is not supported when using GET.');}}var NativeWebView=(nativeConfig==null?void 0:nativeConfig.component)||_RNCWebViewNativeComponent.default;var sourceResolved=resolveAssetSource(source);var newSource=typeof sourceResolved==='object'?Object.entries(sourceResolved).reduce(function(prev,_ref3){var _ref4=(0,_slicedToArray2.default)(_ref3,2),currKey=_ref4[0],currValue=_ref4[1];return Object.assign({},prev,(0,_defineProperty2.default)({},currKey,currKey==='headers'&&currValue&&typeof currValue==='object'?Object.entries(currValue).map(function(_ref5){var _ref6=(0,_slicedToArray2.default)(_ref5,2),key=_ref6[0],value=_ref6[1];return{name:key,value:value};}):currValue));},{}):sourceResolved;var webView=(0,_jsxRuntime.jsx)(NativeWebView,Object.assign({},otherProps,{messagingEnabled:typeof onMessageProp==='function',messagingModuleName:messagingModuleName,hasOnScroll:!!otherProps.onScroll,onLoadingError:onLoadingError,onLoadingSubResourceError:onLoadingSubResourceError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onLoadingStart:onLoadingStart,onHttpError:onHttpError,onRenderProcessGone:onRenderProcessGone,onMessage:onMessage,onOpenWindow:onOpenWindow,hasOnOpenWindowEvent:onOpenWindowProp!==undefined,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,ref:webViewRef,source:sourceResolved,newSource:newSource,style:webViewStyles,overScrollMode:overScrollMode,javaScriptEnabled:javaScriptEnabled,thirdPartyCookiesEnabled:thirdPartyCookiesEnabled,scalesPageToFit:scalesPageToFit,allowsFullscreenVideo:allowsFullscreenVideo,allowFileAccess:allowFileAccess,saveFormDataDisabled:saveFormDataDisabled,cacheEnabled:cacheEnabled,androidLayerType:androidLayerType,setSupportMultipleWindows:securitySupportMultipleWindows,setBuiltInZoomControls:setBuiltInZoomControls,setDisplayZoomControls:setDisplayZoomControls,nestedScrollEnabled:nestedScrollEnabled,mixedContentMode:securityMixedContentMode,mediaPlaybackRequiresUserAction:mediaPlaybackRequiresUserAction,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject)},nativeConfig==null?void 0:nativeConfig.props),"webViewKey");return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:webViewContainerStyle,children:[webView,otherView]});});var isFileUploadSupported=_NativeRNCWebViewModule.default.isFileUploadSupported;var WebView=Object.assign(WebViewComponent,{isFileUploadSupported:isFileUploadSupported});var _default=exports.default=WebView;
|
package/lib/WebView.ios.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _invariant=_interopRequireDefault(require("invariant"));var _RNCWebViewNativeComponent=_interopRequireWildcard(require("./RNCWebViewNativeComponent"));var _NativeRNCWebViewModule=_interopRequireDefault(require("./NativeRNCWebViewModule"));var _WebViewShared=require("./WebViewShared");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["fraudulentWebsiteWarningEnabled","javaScriptEnabled","cacheEnabled","originWhitelist","deeplinkWhitelist","useSharedProcessPool","textInteractionEnabled","injectedJavaScript","injectedJavaScriptBeforeContentLoaded","injectedJavaScriptForMainFrameOnly","injectedJavaScriptBeforeContentLoadedForMainFrameOnly","injectedJavaScriptObject","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadProgress","onContentProcessDidTerminate","onFileDownload","onHttpError","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","nativeConfig","allowsInlineMediaPlayback","allowsPictureInPictureMediaPlayback","allowsAirPlayForMediaPlayback","mediaPlaybackRequiresUserAction","dataDetectorTypes","incognito","decelerationRate","onShouldStartLoadWithRequest","validateMeta","validateData","minimumIOSVersion","unsupportedVersionComponent"];var _this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebView.ios.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var resolveAssetSource=_reactNative.Image.resolveAssetSource;var processDecelerationRate=function processDecelerationRate(decelerationRate){var newDecelerationRate=decelerationRate;if(newDecelerationRate==='normal'){newDecelerationRate=0.998;}else if(newDecelerationRate==='fast'){newDecelerationRate=0.99;}return newDecelerationRate;};var hardMinimumIOSVersion='12.5.6 <13, 13.6.1 <14, 14.8.1 <15, 15.7.1';var useWarnIfChanges=function useWarnIfChanges(value,name){var ref=(0,_react.useRef)(value);if(ref.current!==value){console.warn(`Changes to property ${name} do nothing after the initial render.`);ref.current=value;}};var WebViewComponent=(0,_react.forwardRef)(function(_ref,ref){var _ref$fraudulentWebsit=_ref.fraudulentWebsiteWarningEnabled,fraudulentWebsiteWarningEnabled=_ref$fraudulentWebsit===void 0?true:_ref$fraudulentWebsit,_ref$javaScriptEnable=_ref.javaScriptEnabled,javaScriptEnabled=_ref$javaScriptEnable===void 0?true:_ref$javaScriptEnable,_ref$cacheEnabled=_ref.cacheEnabled,cacheEnabled=_ref$cacheEnabled===void 0?true:_ref$cacheEnabled,_ref$originWhitelist=_ref.originWhitelist,originWhitelist=_ref$originWhitelist===void 0?_WebViewShared.defaultOriginWhitelist:_ref$originWhitelist,_ref$deeplinkWhitelis=_ref.deeplinkWhitelist,deeplinkWhitelist=_ref$deeplinkWhitelis===void 0?_WebViewShared.defaultDeeplinkWhitelist:_ref$deeplinkWhitelis,_ref$useSharedProcess=_ref.useSharedProcessPool,useSharedProcessPool=_ref$useSharedProcess===void 0?true:_ref$useSharedProcess,_ref$textInteractionE=_ref.textInteractionEnabled,textInteractionEnabled=_ref$textInteractionE===void 0?true:_ref$textInteractionE,injectedJavaScript=_ref.injectedJavaScript,injectedJavaScriptBeforeContentLoaded=_ref.injectedJavaScriptBeforeContentLoaded,_ref$injectedJavaScri=_ref.injectedJavaScriptForMainFrameOnly,injectedJavaScriptForMainFrameOnly=_ref$injectedJavaScri===void 0?true:_ref$injectedJavaScri,_ref$injectedJavaScri2=_ref.injectedJavaScriptBeforeContentLoadedForMainFrameOnly,injectedJavaScriptBeforeContentLoadedForMainFrameOnly=_ref$injectedJavaScri2===void 0?true:_ref$injectedJavaScri2,injectedJavaScriptObject=_ref.injectedJavaScriptObject,startInLoadingState=_ref.startInLoadingState,onNavigationStateChange=_ref.onNavigationStateChange,onLoadStart=_ref.onLoadStart,onError=_ref.onError,onLoad=_ref.onLoad,onLoadEnd=_ref.onLoadEnd,onLoadProgress=_ref.onLoadProgress,onContentProcessDidTerminateProp=_ref.onContentProcessDidTerminate,onFileDownload=_ref.onFileDownload,onHttpErrorProp=_ref.onHttpError,onMessageProp=_ref.onMessage,onOpenWindowProp=_ref.onOpenWindow,renderLoading=_ref.renderLoading,renderError=_ref.renderError,style=_ref.style,containerStyle=_ref.containerStyle,source=_ref.source,nativeConfig=_ref.nativeConfig,allowsInlineMediaPlayback=_ref.allowsInlineMediaPlayback,_ref$allowsPictureInP=_ref.allowsPictureInPictureMediaPlayback,allowsPictureInPictureMediaPlayback=_ref$allowsPictureInP===void 0?true:_ref$allowsPictureInP,allowsAirPlayForMediaPlayback=_ref.allowsAirPlayForMediaPlayback,mediaPlaybackRequiresUserAction=_ref.mediaPlaybackRequiresUserAction,dataDetectorTypes=_ref.dataDetectorTypes,incognito=_ref.incognito,decelerationRateProp=_ref.decelerationRate,onShouldStartLoadWithRequestProp=_ref.onShouldStartLoadWithRequest,validateMeta=_ref.validateMeta,validateData=_ref.validateData,minimumIOSVersion=_ref.minimumIOSVersion,UnsupportedVersionComponent=_ref.unsupportedVersionComponent,otherProps=(0,_objectWithoutProperties2.default)(_ref,_excluded);var webViewRef=(0,_react.useRef)(null);var onShouldStartLoadWithRequestCallback=(0,_react.useCallback)(function(shouldStart,_url){var lockIdentifier=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;_NativeRNCWebViewModule.default.shouldStartLoadWithLockIdentifier(shouldStart,lockIdentifier);},[]);var _useWebViewLogic=(0,_WebViewShared.useWebViewLogic)({onNavigationStateChange:onNavigationStateChange,onLoad:onLoad,onError:onError,onHttpErrorProp:onHttpErrorProp,onLoadEnd:onLoadEnd,onLoadProgress:onLoadProgress,onLoadStart:onLoadStart,onMessageProp:onMessageProp,onOpenWindowProp:onOpenWindowProp,startInLoadingState:startInLoadingState,originWhitelist:originWhitelist,deeplinkWhitelist:deeplinkWhitelist,onShouldStartLoadWithRequestProp:onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback:onShouldStartLoadWithRequestCallback,onContentProcessDidTerminateProp:onContentProcessDidTerminateProp,validateMeta:validateMeta,validateData:validateData}),onLoadingStart=_useWebViewLogic.onLoadingStart,onShouldStartLoadWithRequest=_useWebViewLogic.onShouldStartLoadWithRequest,onMessage=_useWebViewLogic.onMessage,viewState=_useWebViewLogic.viewState,setViewState=_useWebViewLogic.setViewState,lastErrorEvent=_useWebViewLogic.lastErrorEvent,onHttpError=_useWebViewLogic.onHttpError,onLoadingError=_useWebViewLogic.onLoadingError,onLoadingFinish=_useWebViewLogic.onLoadingFinish,onLoadingProgress=_useWebViewLogic.onLoadingProgress,onOpenWindow=_useWebViewLogic.onOpenWindow,onContentProcessDidTerminate=_useWebViewLogic.onContentProcessDidTerminate;(0,_react.useImperativeHandle)(ref,function(){return{goForward:function goForward(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goForward(webViewRef.current);},goBack:function goBack(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goBack(webViewRef.current);},reload:function reload(){setViewState('LOADING');if(webViewRef.current){_RNCWebViewNativeComponent.Commands.reload(webViewRef.current);}},stopLoading:function stopLoading(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.stopLoading(webViewRef.current);},postMessage:function postMessage(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.postMessage(webViewRef.current,data);},injectJavaScript:function injectJavaScript(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.injectJavaScript(webViewRef.current,data);},requestFocus:function requestFocus(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.requestFocus(webViewRef.current);},clearCache:function clearCache(includeDiskFiles){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearCache(webViewRef.current,includeDiskFiles);}};},[setViewState,webViewRef]);useWarnIfChanges(allowsInlineMediaPlayback,'allowsInlineMediaPlayback');useWarnIfChanges(allowsPictureInPictureMediaPlayback,'allowsPictureInPictureMediaPlayback');useWarnIfChanges(allowsAirPlayForMediaPlayback,'allowsAirPlayForMediaPlayback');useWarnIfChanges(incognito,'incognito');useWarnIfChanges(mediaPlaybackRequiresUserAction,'mediaPlaybackRequiresUserAction');useWarnIfChanges(dataDetectorTypes,'dataDetectorTypes');var iosVersion=String(_reactNative.Platform.Version);var passesMinimum=minimumIOSVersion?(0,_WebViewShared.versionPasses)(iosVersion,minimumIOSVersion):true;var passesHardMinimum=(0,_WebViewShared.versionPasses)(iosVersion,hardMinimumIOSVersion);if(!passesMinimum||!passesHardMinimum){if(UnsupportedVersionComponent){return(0,_jsxRuntime.jsx)(UnsupportedVersionComponent,{});}return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{alignSelf:'flex-start'},children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:'red'},children:"iOS version is outdated and insecure. Update it to continue."})});}var otherView=null;if(viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(viewState==='ERROR'){var _lastErrorEvent$code,_lastErrorEvent$descr;(0,_invariant.default)(lastErrorEvent!=null,'lastErrorEvent expected to be non-null');otherView=(renderError||_WebViewShared.defaultRenderError)(lastErrorEvent==null?void 0:lastErrorEvent.domain,(_lastErrorEvent$code=lastErrorEvent==null?void 0:lastErrorEvent.code)!=null?_lastErrorEvent$code:0,(_lastErrorEvent$descr=lastErrorEvent==null?void 0:lastErrorEvent.description)!=null?_lastErrorEvent$descr:'');}else if(viewState!=='IDLE'){console.error(`RNCWebView invalid state encountered: ${viewState}`);}var webViewStyles=[_WebView.default.container,_WebView.default.webView,style];var webViewContainerStyle=[_WebView.default.container,containerStyle];var decelerationRate=processDecelerationRate(decelerationRateProp);var NativeWebView=(nativeConfig==null?void 0:nativeConfig.component)||_RNCWebViewNativeComponent.default;var sourceResolved=resolveAssetSource(source);var newSource=typeof sourceResolved==='object'?Object.entries(sourceResolved).reduce(function(prev,_ref2){var _ref3=(0,_slicedToArray2.default)(_ref2,2),currKey=_ref3[0],currValue=_ref3[1];return Object.assign({},prev,(0,_defineProperty2.default)({},currKey,currKey==='headers'&&currValue&&typeof currValue==='object'?Object.entries(currValue).map(function(_ref4){var _ref5=(0,_slicedToArray2.default)(_ref4,2),key=_ref5[0],value=_ref5[1];return{name:key,value:value};}):currValue));},{}):sourceResolved;var webView=(0,_jsxRuntime.jsx)(NativeWebView,Object.assign({},otherProps,{fraudulentWebsiteWarningEnabled:fraudulentWebsiteWarningEnabled,javaScriptEnabled:javaScriptEnabled,cacheEnabled:cacheEnabled,useSharedProcessPool:useSharedProcessPool,textInteractionEnabled:textInteractionEnabled,decelerationRate:decelerationRate,messagingEnabled:typeof onMessageProp==='function',messagingModuleName:"",onLoadingError:onLoadingError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onFileDownload:onFileDownload,onLoadingStart:onLoadingStart,onHttpError:onHttpError,onMessage:onMessage,onOpenWindow:onOpenWindowProp&&onOpenWindow,hasOnOpenWindowEvent:onOpenWindowProp!==undefined,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onContentProcessDidTerminate:onContentProcessDidTerminate,injectedJavaScript:injectedJavaScript,injectedJavaScriptBeforeContentLoaded:injectedJavaScriptBeforeContentLoaded,injectedJavaScriptForMainFrameOnly:injectedJavaScriptForMainFrameOnly,injectedJavaScriptBeforeContentLoadedForMainFrameOnly:injectedJavaScriptBeforeContentLoadedForMainFrameOnly,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject),dataDetectorTypes:!dataDetectorTypes||Array.isArray(dataDetectorTypes)?dataDetectorTypes:[dataDetectorTypes],allowsAirPlayForMediaPlayback:allowsAirPlayForMediaPlayback,allowsInlineMediaPlayback:allowsInlineMediaPlayback,allowsPictureInPictureMediaPlayback:allowsPictureInPictureMediaPlayback,incognito:incognito,mediaPlaybackRequiresUserAction:mediaPlaybackRequiresUserAction,newSource:newSource,style:webViewStyles,hasOnFileDownload:!!onFileDownload,ref:webViewRef,source:sourceResolved},nativeConfig==null?void 0:nativeConfig.props),"webViewKey");return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:webViewContainerStyle,children:[webView,otherView]});});var isFileUploadSupported=function(){var _ref6=(0,_asyncToGenerator2.default)(function*(){return true;});return function isFileUploadSupported(){return _ref6.apply(this,arguments);};}();var WebView=Object.assign(WebViewComponent,{isFileUploadSupported:isFileUploadSupported});var _default=exports.default=WebView;
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _invariant=_interopRequireDefault(require("invariant"));var _RNCWebViewNativeComponent=_interopRequireWildcard(require("./RNCWebViewNativeComponent"));var _NativeRNCWebViewModule=_interopRequireDefault(require("./NativeRNCWebViewModule"));var _WebViewShared=require("./WebViewShared");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["fraudulentWebsiteWarningEnabled","javaScriptEnabled","cacheEnabled","originWhitelist","deeplinkWhitelist","textInteractionEnabled","injectedJavaScript","injectedJavaScriptBeforeContentLoaded","injectedJavaScriptForMainFrameOnly","injectedJavaScriptBeforeContentLoadedForMainFrameOnly","injectedJavaScriptObject","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadProgress","onContentProcessDidTerminate","onFileDownload","onHttpError","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","nativeConfig","allowsPictureInPictureMediaPlayback","allowsAirPlayForMediaPlayback","incognito","decelerationRate","onShouldStartLoadWithRequest","validateMeta","validateData","minimumIOSVersion","unsupportedVersionComponent"];var _this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebView.ios.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var resolveAssetSource=_reactNative.Image.resolveAssetSource;var processDecelerationRate=function processDecelerationRate(decelerationRate){var newDecelerationRate=decelerationRate;if(newDecelerationRate==='normal'){newDecelerationRate=0.998;}else if(newDecelerationRate==='fast'){newDecelerationRate=0.99;}return newDecelerationRate;};var hardMinimumIOSVersion='12.5.6 <13, 13.6.1 <14, 14.8.1 <15, 15.7.1';var securityMediaPlaybackRequiresUserAction=true;var securityAllowsInlineMediaPlayback=true;var securityUseSharedProcessPool=false;var securitySharedCookiesEnabled=false;var securityEnableApplePay=false;var securityDataDetectorTypes=['none'];var useWarnIfChanges=function useWarnIfChanges(value,name){var ref=(0,_react.useRef)(value);if(ref.current!==value){console.warn(`Changes to property ${name} do nothing after the initial render.`);ref.current=value;}};var WebViewComponent=(0,_react.forwardRef)(function(_ref,ref){var _ref$fraudulentWebsit=_ref.fraudulentWebsiteWarningEnabled,fraudulentWebsiteWarningEnabled=_ref$fraudulentWebsit===void 0?true:_ref$fraudulentWebsit,_ref$javaScriptEnable=_ref.javaScriptEnabled,javaScriptEnabled=_ref$javaScriptEnable===void 0?true:_ref$javaScriptEnable,_ref$cacheEnabled=_ref.cacheEnabled,cacheEnabled=_ref$cacheEnabled===void 0?true:_ref$cacheEnabled,_ref$originWhitelist=_ref.originWhitelist,originWhitelist=_ref$originWhitelist===void 0?_WebViewShared.defaultOriginWhitelist:_ref$originWhitelist,_ref$deeplinkWhitelis=_ref.deeplinkWhitelist,deeplinkWhitelist=_ref$deeplinkWhitelis===void 0?_WebViewShared.defaultDeeplinkWhitelist:_ref$deeplinkWhitelis,_ref$textInteractionE=_ref.textInteractionEnabled,textInteractionEnabled=_ref$textInteractionE===void 0?true:_ref$textInteractionE,injectedJavaScript=_ref.injectedJavaScript,injectedJavaScriptBeforeContentLoaded=_ref.injectedJavaScriptBeforeContentLoaded,_ref$injectedJavaScri=_ref.injectedJavaScriptForMainFrameOnly,injectedJavaScriptForMainFrameOnly=_ref$injectedJavaScri===void 0?true:_ref$injectedJavaScri,_ref$injectedJavaScri2=_ref.injectedJavaScriptBeforeContentLoadedForMainFrameOnly,injectedJavaScriptBeforeContentLoadedForMainFrameOnly=_ref$injectedJavaScri2===void 0?true:_ref$injectedJavaScri2,injectedJavaScriptObject=_ref.injectedJavaScriptObject,startInLoadingState=_ref.startInLoadingState,onNavigationStateChange=_ref.onNavigationStateChange,onLoadStart=_ref.onLoadStart,onError=_ref.onError,onLoad=_ref.onLoad,onLoadEnd=_ref.onLoadEnd,onLoadProgress=_ref.onLoadProgress,onContentProcessDidTerminateProp=_ref.onContentProcessDidTerminate,onFileDownload=_ref.onFileDownload,onHttpErrorProp=_ref.onHttpError,onMessageProp=_ref.onMessage,onOpenWindowProp=_ref.onOpenWindow,renderLoading=_ref.renderLoading,renderError=_ref.renderError,style=_ref.style,containerStyle=_ref.containerStyle,source=_ref.source,nativeConfig=_ref.nativeConfig,_ref$allowsPictureInP=_ref.allowsPictureInPictureMediaPlayback,allowsPictureInPictureMediaPlayback=_ref$allowsPictureInP===void 0?true:_ref$allowsPictureInP,allowsAirPlayForMediaPlayback=_ref.allowsAirPlayForMediaPlayback,incognito=_ref.incognito,decelerationRateProp=_ref.decelerationRate,onShouldStartLoadWithRequestProp=_ref.onShouldStartLoadWithRequest,validateMeta=_ref.validateMeta,validateData=_ref.validateData,minimumIOSVersion=_ref.minimumIOSVersion,UnsupportedVersionComponent=_ref.unsupportedVersionComponent,otherProps=(0,_objectWithoutProperties2.default)(_ref,_excluded);var webViewRef=(0,_react.useRef)(null);var onShouldStartLoadWithRequestCallback=(0,_react.useCallback)(function(shouldStart,_url){var lockIdentifier=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;_NativeRNCWebViewModule.default.shouldStartLoadWithLockIdentifier(shouldStart,lockIdentifier);},[]);var _useWebViewLogic=(0,_WebViewShared.useWebViewLogic)({onNavigationStateChange:onNavigationStateChange,onLoad:onLoad,onError:onError,onHttpErrorProp:onHttpErrorProp,onLoadEnd:onLoadEnd,onLoadProgress:onLoadProgress,onLoadStart:onLoadStart,onMessageProp:onMessageProp,onOpenWindowProp:onOpenWindowProp,startInLoadingState:startInLoadingState,originWhitelist:originWhitelist,deeplinkWhitelist:deeplinkWhitelist,onShouldStartLoadWithRequestProp:onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback:onShouldStartLoadWithRequestCallback,onContentProcessDidTerminateProp:onContentProcessDidTerminateProp,validateMeta:validateMeta,validateData:validateData}),onLoadingStart=_useWebViewLogic.onLoadingStart,onShouldStartLoadWithRequest=_useWebViewLogic.onShouldStartLoadWithRequest,onMessage=_useWebViewLogic.onMessage,viewState=_useWebViewLogic.viewState,setViewState=_useWebViewLogic.setViewState,lastErrorEvent=_useWebViewLogic.lastErrorEvent,onHttpError=_useWebViewLogic.onHttpError,onLoadingError=_useWebViewLogic.onLoadingError,onLoadingFinish=_useWebViewLogic.onLoadingFinish,onLoadingProgress=_useWebViewLogic.onLoadingProgress,onOpenWindow=_useWebViewLogic.onOpenWindow,onContentProcessDidTerminate=_useWebViewLogic.onContentProcessDidTerminate;(0,_react.useImperativeHandle)(ref,function(){return{goForward:function goForward(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goForward(webViewRef.current);},goBack:function goBack(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.goBack(webViewRef.current);},reload:function reload(){setViewState('LOADING');if(webViewRef.current){_RNCWebViewNativeComponent.Commands.reload(webViewRef.current);}},stopLoading:function stopLoading(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.stopLoading(webViewRef.current);},postMessage:function postMessage(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.postMessage(webViewRef.current,data);},injectJavaScript:function injectJavaScript(data){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.injectJavaScript(webViewRef.current,data);},requestFocus:function requestFocus(){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.requestFocus(webViewRef.current);},clearCache:function clearCache(includeDiskFiles){return webViewRef.current&&_RNCWebViewNativeComponent.Commands.clearCache(webViewRef.current,includeDiskFiles);}};},[setViewState,webViewRef]);useWarnIfChanges(securityAllowsInlineMediaPlayback,'allowsInlineMediaPlayback');useWarnIfChanges(allowsPictureInPictureMediaPlayback,'allowsPictureInPictureMediaPlayback');useWarnIfChanges(allowsAirPlayForMediaPlayback,'allowsAirPlayForMediaPlayback');useWarnIfChanges(incognito,'incognito');useWarnIfChanges(securityMediaPlaybackRequiresUserAction,'mediaPlaybackRequiresUserAction');useWarnIfChanges(securityDataDetectorTypes,'dataDetectorTypes');var iosVersion=String(_reactNative.Platform.Version);var passesMinimum=minimumIOSVersion?(0,_WebViewShared.versionPasses)(iosVersion,minimumIOSVersion):true;var passesHardMinimum=(0,_WebViewShared.versionPasses)(iosVersion,hardMinimumIOSVersion);if(!passesMinimum||!passesHardMinimum){if(UnsupportedVersionComponent){return(0,_jsxRuntime.jsx)(UnsupportedVersionComponent,{});}return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{alignSelf:'flex-start'},children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{color:'red'},children:"iOS version is outdated and insecure. Update it to continue."})});}var otherView=null;if(viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(viewState==='ERROR'){var _lastErrorEvent$code,_lastErrorEvent$descr;(0,_invariant.default)(lastErrorEvent!=null,'lastErrorEvent expected to be non-null');otherView=(renderError||_WebViewShared.defaultRenderError)(lastErrorEvent==null?void 0:lastErrorEvent.domain,(_lastErrorEvent$code=lastErrorEvent==null?void 0:lastErrorEvent.code)!=null?_lastErrorEvent$code:0,(_lastErrorEvent$descr=lastErrorEvent==null?void 0:lastErrorEvent.description)!=null?_lastErrorEvent$descr:'');}else if(viewState!=='IDLE'){console.error(`RNCWebView invalid state encountered: ${viewState}`);}var webViewStyles=[_WebView.default.container,_WebView.default.webView,style];var webViewContainerStyle=[_WebView.default.container,containerStyle];var decelerationRate=processDecelerationRate(decelerationRateProp);var NativeWebView=(nativeConfig==null?void 0:nativeConfig.component)||_RNCWebViewNativeComponent.default;var sourceResolved=resolveAssetSource(source);var newSource=typeof sourceResolved==='object'?Object.entries(sourceResolved).reduce(function(prev,_ref2){var _ref3=(0,_slicedToArray2.default)(_ref2,2),currKey=_ref3[0],currValue=_ref3[1];return Object.assign({},prev,(0,_defineProperty2.default)({},currKey,currKey==='headers'&&currValue&&typeof currValue==='object'?Object.entries(currValue).map(function(_ref4){var _ref5=(0,_slicedToArray2.default)(_ref4,2),key=_ref5[0],value=_ref5[1];return{name:key,value:value};}):currValue));},{}):sourceResolved;var webView=(0,_jsxRuntime.jsx)(NativeWebView,Object.assign({},otherProps,{fraudulentWebsiteWarningEnabled:fraudulentWebsiteWarningEnabled,javaScriptEnabled:javaScriptEnabled,cacheEnabled:cacheEnabled,useSharedProcessPool:securityUseSharedProcessPool,sharedCookiesEnabled:securitySharedCookiesEnabled,enableApplePay:securityEnableApplePay,textInteractionEnabled:textInteractionEnabled,decelerationRate:decelerationRate,messagingEnabled:typeof onMessageProp==='function',messagingModuleName:"",onLoadingError:onLoadingError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onFileDownload:onFileDownload,onLoadingStart:onLoadingStart,onHttpError:onHttpError,onMessage:onMessage,onOpenWindow:onOpenWindowProp&&onOpenWindow,hasOnOpenWindowEvent:onOpenWindowProp!==undefined,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onContentProcessDidTerminate:onContentProcessDidTerminate,injectedJavaScript:injectedJavaScript,injectedJavaScriptBeforeContentLoaded:injectedJavaScriptBeforeContentLoaded,injectedJavaScriptForMainFrameOnly:injectedJavaScriptForMainFrameOnly,injectedJavaScriptBeforeContentLoadedForMainFrameOnly:injectedJavaScriptBeforeContentLoadedForMainFrameOnly,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject),dataDetectorTypes:securityDataDetectorTypes,allowsAirPlayForMediaPlayback:allowsAirPlayForMediaPlayback,allowsInlineMediaPlayback:securityAllowsInlineMediaPlayback,allowsPictureInPictureMediaPlayback:allowsPictureInPictureMediaPlayback,incognito:incognito,mediaPlaybackRequiresUserAction:securityMediaPlaybackRequiresUserAction,newSource:newSource,style:webViewStyles,hasOnFileDownload:!!onFileDownload,ref:webViewRef,source:sourceResolved},nativeConfig==null?void 0:nativeConfig.props),"webViewKey");return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:webViewContainerStyle,children:[webView,otherView]});});var isFileUploadSupported=function(){var _ref6=(0,_asyncToGenerator2.default)(function*(){return true;});return function isFileUploadSupported(){return _ref6.apply(this,arguments);};}();var WebView=Object.assign(WebViewComponent,{isFileUploadSupported:isFileUploadSupported});var _default=exports.default=WebView;
|
package/lib/WebViewShared.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { OnShouldStartLoadWithRequest, ShouldStartLoadRequestEvent, WebViewError, WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessage, WebViewMessageEvent, WebViewNavigation, WebViewNativeEvent, WebViewNavigationEvent, WebViewOpenWindowEvent, WebViewProgressEvent, WebViewRenderProcessGoneEvent, WebViewTerminatedEvent } from './WebViewTypes';
|
|
3
|
-
declare const defaultOriginWhitelist: readonly ["
|
|
3
|
+
declare const defaultOriginWhitelist: readonly ["https://*"];
|
|
4
4
|
declare const defaultDeeplinkWhitelist: readonly ["https:"];
|
|
5
5
|
declare const createOnShouldStartLoadWithRequest: (loadRequest: (shouldStart: boolean, url: string, lockIdentifier: number) => void, originWhitelist: readonly string[], deeplinkWhitelist: readonly string[], onShouldStartLoadWithRequest?: OnShouldStartLoadWithRequest) => ({ nativeEvent }: ShouldStartLoadRequestEvent) => void;
|
|
6
6
|
declare const defaultRenderLoading: () => React.JSX.Element;
|
package/lib/WebViewShared.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.versionPasses=exports.useWebViewLogic=exports.defaultRenderLoading=exports.defaultRenderError=exports.defaultOriginWhitelist=exports.defaultDeeplinkWhitelist=exports.createOnShouldStartLoadWithRequest=void 0;var _toArray2=_interopRequireDefault(require("@babel/runtime/helpers/toArray"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _escapeStringRegexp=_interopRequireDefault(require("escape-string-regexp"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebViewShared.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var defaultOriginWhitelist=exports.defaultOriginWhitelist=['http://*','https://*'];var defaultDeeplinkWhitelist=exports.defaultDeeplinkWhitelist=['https:'];var defaultDeeplinkBlocklist=['http:','file:','javascript:'];var urlToProtocolScheme=function urlToProtocolScheme(url){try{return new URL(url).protocol;}catch(_unused){return null;}};var matchWithStringList=function matchWithStringList(prefixes,value){if(typeof value!=='string'){throw new Error('value was not a string');}return Array.prototype.includes.call(prefixes,value);};var stringWhitelistToRegex=function stringWhitelistToRegex(originWhitelist){return new RegExp(`^${(0,_escapeStringRegexp.default)(originWhitelist).replace(/\\\*/g,'.*')}$`);};var matchWithRegexList=function matchWithRegexList(compiledRegexList,value){return compiledRegexList.some(function(x){return x.test(value);});};var compileWhitelist=function compileWhitelist(originWhitelist){return['about:blank'].concat((0,_toConsumableArray2.default)(originWhitelist||[])).map(stringWhitelistToRegex);};var passesWhitelist=function passesWhitelist(compiledWhitelist,url){try{var _URL=new URL(url),href=_URL.href,origin=_URL.origin;if(origin&&origin!=='null'){return matchWithRegexList(compiledWhitelist,origin);}return matchWithRegexList(compiledWhitelist,href);}catch(_unused2){return false;}};var createOnShouldStartLoadWithRequest=exports.createOnShouldStartLoadWithRequest=function createOnShouldStartLoadWithRequest(loadRequest,originWhitelist,deeplinkWhitelist,onShouldStartLoadWithRequest){var compiledWhitelist=compileWhitelist(originWhitelist);return function(_ref){var nativeEvent=_ref.nativeEvent;var shouldStart=true;var url=nativeEvent.url,lockIdentifier=nativeEvent.lockIdentifier,isTopFrame=nativeEvent.isTopFrame;if(!passesWhitelist(compiledWhitelist,url)){var protocol=urlToProtocolScheme(url);if(protocol!==null){var foundMatchInBlocklist=matchWithStringList(defaultDeeplinkBlocklist,protocol);if(!foundMatchInBlocklist){var foundMatchInAllowlist=matchWithStringList(deeplinkWhitelist,protocol);if(foundMatchInAllowlist){_reactNative.Linking.canOpenURL(url).then(function(supported){if(supported&&isTopFrame||protocol.startsWith('mailto:')){return _reactNative.Linking.openURL(url);}console.warn(`Can't open url: ${url}`);return undefined;}).catch(function(e){console.warn('Error opening URL: ',e);});}else{console.warn(`Failed to pass whitelist for deep link url: ${url}`);}}else{console.warn(`Failed to pass default block list for deep link url: ${url}`);}}shouldStart=false;}else if(onShouldStartLoadWithRequest){shouldStart=onShouldStartLoadWithRequest(nativeEvent);}loadRequest(shouldStart,url,lockIdentifier);};};var defaultRenderLoading=exports.defaultRenderLoading=function defaultRenderLoading(){return(0,_jsxRuntime.jsx)(_reactNative.View,{style:_WebView.default.loadingOrErrorView,children:(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{})});};var defaultRenderError=exports.defaultRenderError=function defaultRenderError(errorDomain,errorCode,errorDesc){return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_WebView.default.loadingOrErrorView,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorTextTitle,children:"Error loading page"}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorText,children:`Domain: ${errorDomain}`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorText,children:`Error Code: ${errorCode}`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorText,children:`Description: ${errorDesc}`})]});};var useWebViewLogic=exports.useWebViewLogic=function useWebViewLogic(_ref2){var startInLoadingState=_ref2.startInLoadingState,onNavigationStateChange=_ref2.onNavigationStateChange,onLoadStart=_ref2.onLoadStart,onLoad=_ref2.onLoad,onLoadProgress=_ref2.onLoadProgress,onLoadEnd=_ref2.onLoadEnd,onError=_ref2.onError,onLoadSubResourceError=_ref2.onLoadSubResourceError,onHttpErrorProp=_ref2.onHttpErrorProp,onMessageProp=_ref2.onMessageProp,onOpenWindowProp=_ref2.onOpenWindowProp,onRenderProcessGoneProp=_ref2.onRenderProcessGoneProp,onContentProcessDidTerminateProp=_ref2.onContentProcessDidTerminateProp,originWhitelist=_ref2.originWhitelist,deeplinkWhitelist=_ref2.deeplinkWhitelist,onShouldStartLoadWithRequestProp=_ref2.onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback=_ref2.onShouldStartLoadWithRequestCallback,validateMeta=_ref2.validateMeta,validateData=_ref2.validateData;var _useState=(0,_react.useState)(startInLoadingState?'LOADING':'IDLE'),_useState2=(0,_slicedToArray2.default)(_useState,2),viewState=_useState2[0],setViewState=_useState2[1];var _useState3=(0,_react.useState)(null),_useState4=(0,_slicedToArray2.default)(_useState3,2),lastErrorEvent=_useState4[0],setLastErrorEvent=_useState4[1];var startUrl=(0,_react.useRef)(null);var passesWhitelistCallback=(0,_react.useCallback)(function(url){if(!url||typeof url!=='string')return false;return passesWhitelist(compileWhitelist(originWhitelist),url);},[originWhitelist]);var extractMeta=function extractMeta(nativeEvent){return{url:String(nativeEvent.url),loading:Boolean(nativeEvent.loading),title:String(nativeEvent.title).slice(0,512),canGoBack:Boolean(nativeEvent.canGoBack),canGoForward:Boolean(nativeEvent.canGoForward),lockIdentifier:Number(nativeEvent.lockIdentifier)};};var updateNavigationState=(0,_react.useCallback)(function(event){onNavigationStateChange==null?void 0:onNavigationStateChange(event.nativeEvent);},[onNavigationStateChange]);var onLoadingStart=(0,_react.useCallback)(function(event){startUrl.current=event.nativeEvent.url;onLoadStart==null?void 0:onLoadStart(event);updateNavigationState(event);},[onLoadStart,updateNavigationState]);var onLoadingError=(0,_react.useCallback)(function(event){event.persist();if(onError){onError(event);}else{console.warn('Encountered an error loading page',event.nativeEvent);}onLoadEnd==null?void 0:onLoadEnd(event);if(event.isDefaultPrevented()){return;}setViewState('ERROR');setLastErrorEvent(event.nativeEvent);},[onError,onLoadEnd]);var onLoadingSubResourceError=(0,_react.useCallback)(function(event){onLoadSubResourceError==null?void 0:onLoadSubResourceError(event);},[onLoadSubResourceError]);var onHttpError=(0,_react.useCallback)(function(event){onHttpErrorProp==null?void 0:onHttpErrorProp(event);},[onHttpErrorProp]);var onRenderProcessGone=(0,_react.useCallback)(function(event){onRenderProcessGoneProp==null?void 0:onRenderProcessGoneProp(event);},[onRenderProcessGoneProp]);var onContentProcessDidTerminate=(0,_react.useCallback)(function(event){onContentProcessDidTerminateProp==null?void 0:onContentProcessDidTerminateProp(event);},[onContentProcessDidTerminateProp]);var onLoadingFinish=(0,_react.useCallback)(function(event){onLoad==null?void 0:onLoad(event);onLoadEnd==null?void 0:onLoadEnd(event);var url=event.nativeEvent.url;if(_reactNative.Platform.OS!=='android'||url===startUrl.current){setViewState('IDLE');}updateNavigationState(event);},[onLoad,onLoadEnd,updateNavigationState]);var onMessage=(0,_react.useCallback)(function(event){var nativeEvent=event.nativeEvent;if(!passesWhitelistCallback(nativeEvent.url))return;try{var parsedData=JSON.parse(nativeEvent.data);var _data=JSON.stringify(validateData(parsedData));var meta=validateMeta(extractMeta(nativeEvent));onMessageProp==null?void 0:onMessageProp(Object.assign({},meta,{data:_data}));}catch(err){console.error('Error parsing WebView message',err);}},[onMessageProp,passesWhitelistCallback,validateData,validateMeta]);var onLoadingProgress=(0,_react.useCallback)(function(event){var progress=event.nativeEvent.progress;if(_reactNative.Platform.OS==='android'&&progress===1){setViewState(function(prevViewState){return prevViewState==='LOADING'?'IDLE':prevViewState;});}onLoadProgress==null?void 0:onLoadProgress(event);},[onLoadProgress]);var onShouldStartLoadWithRequest=(0,_react.useMemo)(function(){return createOnShouldStartLoadWithRequest(onShouldStartLoadWithRequestCallback,originWhitelist,deeplinkWhitelist,onShouldStartLoadWithRequestProp);},[originWhitelist,deeplinkWhitelist,onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback]);var onOpenWindow=(0,_react.useCallback)(function(event){onOpenWindowProp==null?void 0:onOpenWindowProp(event);},[onOpenWindowProp]);return{onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onLoadingStart:onLoadingStart,onLoadingProgress:onLoadingProgress,onLoadingError:onLoadingError,onLoadingSubResourceError:onLoadingSubResourceError,onLoadingFinish:onLoadingFinish,onHttpError:onHttpError,onRenderProcessGone:onRenderProcessGone,onContentProcessDidTerminate:onContentProcessDidTerminate,onMessage:onMessage,onOpenWindow:onOpenWindow,viewState:viewState,setViewState:setViewState,lastErrorEvent:lastErrorEvent};};var versionPasses=exports.versionPasses=function versionPasses(version,minimum){if(!version||!minimum)return false;if(typeof version!=='string'||typeof minimum!=='string')return false;if(minimum.includes(', ')){var variants=minimum.split(', ');if(!variants.slice(0,-1).every(function(x){return x.includes(' <');}))return false;return variants.some(function(x){return versionPasses(version,x);});}if(minimum.includes(' <')){var _minimum$split=minimum.split(' <'),_minimum$split2=(0,_toArray2.default)(_minimum$split),min=_minimum$split2[0],max=_minimum$split2[1],rest=_minimum$split2.slice(2);if(rest.length>0)return false;return versionPasses(version,min)&&!versionPasses(version,max)&&versionPasses(max,version);}var versionRegex=/^[0-9]+(\.[0-9]+)*$/;if(!versionRegex.test(version)||!versionRegex.test(minimum))return false;var versionParts=version.split('.').map(Number);var minimumParts=minimum.split('.').map(Number);var len=Math.max(versionParts.length,minimumParts.length);for(var i=0;i<len;i+=1){var ver=versionParts[i]||0;var _min=minimumParts[i]||0;if(ver>_min)return true;if(ver<_min)return false;}return true;};
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.versionPasses=exports.useWebViewLogic=exports.defaultRenderLoading=exports.defaultRenderError=exports.defaultOriginWhitelist=exports.defaultDeeplinkWhitelist=exports.createOnShouldStartLoadWithRequest=void 0;var _toArray2=_interopRequireDefault(require("@babel/runtime/helpers/toArray"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _escapeStringRegexp=_interopRequireDefault(require("escape-string-regexp"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebViewShared.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var defaultOriginWhitelist=exports.defaultOriginWhitelist=['https://*'];var defaultDeeplinkWhitelist=exports.defaultDeeplinkWhitelist=['https:'];var defaultDeeplinkBlocklist=['http:','file:','javascript:'];var urlToProtocolScheme=function urlToProtocolScheme(url){try{return new URL(url).protocol;}catch(_unused){return null;}};var matchWithStringList=function matchWithStringList(prefixes,value){if(typeof value!=='string'){throw new Error('value was not a string');}return Array.prototype.includes.call(prefixes,value);};var stringWhitelistToRegex=function stringWhitelistToRegex(originWhitelist){return new RegExp(`^${(0,_escapeStringRegexp.default)(originWhitelist).replace(/\\\*/g,'.*')}$`);};var matchWithRegexList=function matchWithRegexList(compiledRegexList,value){return compiledRegexList.some(function(x){return x.test(value);});};var compileWhitelist=function compileWhitelist(originWhitelist){return['about:blank'].concat((0,_toConsumableArray2.default)(originWhitelist||[])).map(stringWhitelistToRegex);};var passesWhitelist=function passesWhitelist(compiledWhitelist,url){try{var _URL=new URL(url),href=_URL.href,origin=_URL.origin;if(origin&&origin!=='null'){return matchWithRegexList(compiledWhitelist,origin);}return matchWithRegexList(compiledWhitelist,href);}catch(_unused2){return false;}};var createOnShouldStartLoadWithRequest=exports.createOnShouldStartLoadWithRequest=function createOnShouldStartLoadWithRequest(loadRequest,originWhitelist,deeplinkWhitelist,onShouldStartLoadWithRequest){var compiledWhitelist=compileWhitelist(originWhitelist);return function(_ref){var nativeEvent=_ref.nativeEvent;var shouldStart=true;var url=nativeEvent.url,lockIdentifier=nativeEvent.lockIdentifier,isTopFrame=nativeEvent.isTopFrame;if(!passesWhitelist(compiledWhitelist,url)){var protocol=urlToProtocolScheme(url);if(protocol!==null){var foundMatchInBlocklist=matchWithStringList(defaultDeeplinkBlocklist,protocol);if(!foundMatchInBlocklist){var foundMatchInAllowlist=matchWithStringList(deeplinkWhitelist,protocol);if(foundMatchInAllowlist){_reactNative.Linking.canOpenURL(url).then(function(supported){if(supported&&isTopFrame||protocol.startsWith('mailto:')){return _reactNative.Linking.openURL(url);}console.warn(`Can't open url: ${url}`);return undefined;}).catch(function(e){console.warn('Error opening URL: ',e);});}else{console.warn(`Failed to pass whitelist for deep link url: ${url}`);}}else{console.warn(`Failed to pass default block list for deep link url: ${url}`);}}shouldStart=false;}else if(onShouldStartLoadWithRequest){shouldStart=onShouldStartLoadWithRequest(nativeEvent);}loadRequest(shouldStart,url,lockIdentifier);};};var defaultRenderLoading=exports.defaultRenderLoading=function defaultRenderLoading(){return(0,_jsxRuntime.jsx)(_reactNative.View,{style:_WebView.default.loadingOrErrorView,children:(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{})});};var defaultRenderError=exports.defaultRenderError=function defaultRenderError(errorDomain,errorCode,errorDesc){return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:_WebView.default.loadingOrErrorView,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorTextTitle,children:"Error loading page"}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorText,children:`Domain: ${errorDomain}`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorText,children:`Error Code: ${errorCode}`}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.errorText,children:`Description: ${errorDesc}`})]});};var useWebViewLogic=exports.useWebViewLogic=function useWebViewLogic(_ref2){var startInLoadingState=_ref2.startInLoadingState,onNavigationStateChange=_ref2.onNavigationStateChange,onLoadStart=_ref2.onLoadStart,onLoad=_ref2.onLoad,onLoadProgress=_ref2.onLoadProgress,onLoadEnd=_ref2.onLoadEnd,onError=_ref2.onError,onLoadSubResourceError=_ref2.onLoadSubResourceError,onHttpErrorProp=_ref2.onHttpErrorProp,onMessageProp=_ref2.onMessageProp,onOpenWindowProp=_ref2.onOpenWindowProp,onRenderProcessGoneProp=_ref2.onRenderProcessGoneProp,onContentProcessDidTerminateProp=_ref2.onContentProcessDidTerminateProp,originWhitelist=_ref2.originWhitelist,deeplinkWhitelist=_ref2.deeplinkWhitelist,onShouldStartLoadWithRequestProp=_ref2.onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback=_ref2.onShouldStartLoadWithRequestCallback,validateMeta=_ref2.validateMeta,validateData=_ref2.validateData;var _useState=(0,_react.useState)(startInLoadingState?'LOADING':'IDLE'),_useState2=(0,_slicedToArray2.default)(_useState,2),viewState=_useState2[0],setViewState=_useState2[1];var _useState3=(0,_react.useState)(null),_useState4=(0,_slicedToArray2.default)(_useState3,2),lastErrorEvent=_useState4[0],setLastErrorEvent=_useState4[1];var startUrl=(0,_react.useRef)(null);var passesWhitelistCallback=(0,_react.useCallback)(function(url){if(!url||typeof url!=='string')return false;return passesWhitelist(compileWhitelist(originWhitelist),url);},[originWhitelist]);var extractMeta=function extractMeta(nativeEvent){return{url:String(nativeEvent.url),loading:Boolean(nativeEvent.loading),title:String(nativeEvent.title).slice(0,512),canGoBack:Boolean(nativeEvent.canGoBack),canGoForward:Boolean(nativeEvent.canGoForward),lockIdentifier:Number(nativeEvent.lockIdentifier)};};var updateNavigationState=(0,_react.useCallback)(function(event){onNavigationStateChange==null?void 0:onNavigationStateChange(event.nativeEvent);},[onNavigationStateChange]);var onLoadingStart=(0,_react.useCallback)(function(event){startUrl.current=event.nativeEvent.url;onLoadStart==null?void 0:onLoadStart(event);updateNavigationState(event);},[onLoadStart,updateNavigationState]);var onLoadingError=(0,_react.useCallback)(function(event){event.persist();if(onError){onError(event);}else{console.warn('Encountered an error loading page',event.nativeEvent);}onLoadEnd==null?void 0:onLoadEnd(event);if(event.isDefaultPrevented()){return;}setViewState('ERROR');setLastErrorEvent(event.nativeEvent);},[onError,onLoadEnd]);var onLoadingSubResourceError=(0,_react.useCallback)(function(event){onLoadSubResourceError==null?void 0:onLoadSubResourceError(event);},[onLoadSubResourceError]);var onHttpError=(0,_react.useCallback)(function(event){onHttpErrorProp==null?void 0:onHttpErrorProp(event);},[onHttpErrorProp]);var onRenderProcessGone=(0,_react.useCallback)(function(event){onRenderProcessGoneProp==null?void 0:onRenderProcessGoneProp(event);},[onRenderProcessGoneProp]);var onContentProcessDidTerminate=(0,_react.useCallback)(function(event){onContentProcessDidTerminateProp==null?void 0:onContentProcessDidTerminateProp(event);},[onContentProcessDidTerminateProp]);var onLoadingFinish=(0,_react.useCallback)(function(event){onLoad==null?void 0:onLoad(event);onLoadEnd==null?void 0:onLoadEnd(event);var url=event.nativeEvent.url;if(_reactNative.Platform.OS!=='android'||url===startUrl.current){setViewState('IDLE');}updateNavigationState(event);},[onLoad,onLoadEnd,updateNavigationState]);var onMessage=(0,_react.useCallback)(function(event){var nativeEvent=event.nativeEvent;if(!passesWhitelistCallback(nativeEvent.url))return;try{var parsedData=JSON.parse(nativeEvent.data);var _data=JSON.stringify(validateData(parsedData));var meta=validateMeta(extractMeta(nativeEvent));onMessageProp==null?void 0:onMessageProp(Object.assign({},meta,{data:_data}));}catch(err){console.error('Error parsing WebView message',err);}},[onMessageProp,passesWhitelistCallback,validateData,validateMeta]);var onLoadingProgress=(0,_react.useCallback)(function(event){var progress=event.nativeEvent.progress;if(_reactNative.Platform.OS==='android'&&progress===1){setViewState(function(prevViewState){return prevViewState==='LOADING'?'IDLE':prevViewState;});}onLoadProgress==null?void 0:onLoadProgress(event);},[onLoadProgress]);var onShouldStartLoadWithRequest=(0,_react.useMemo)(function(){return createOnShouldStartLoadWithRequest(onShouldStartLoadWithRequestCallback,originWhitelist,deeplinkWhitelist,onShouldStartLoadWithRequestProp);},[originWhitelist,deeplinkWhitelist,onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback]);var onOpenWindow=(0,_react.useCallback)(function(event){onOpenWindowProp==null?void 0:onOpenWindowProp(event);},[onOpenWindowProp]);return{onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onLoadingStart:onLoadingStart,onLoadingProgress:onLoadingProgress,onLoadingError:onLoadingError,onLoadingSubResourceError:onLoadingSubResourceError,onLoadingFinish:onLoadingFinish,onHttpError:onHttpError,onRenderProcessGone:onRenderProcessGone,onContentProcessDidTerminate:onContentProcessDidTerminate,onMessage:onMessage,onOpenWindow:onOpenWindow,viewState:viewState,setViewState:setViewState,lastErrorEvent:lastErrorEvent};};var versionPasses=exports.versionPasses=function versionPasses(version,minimum){if(!version||!minimum)return false;if(typeof version!=='string'||typeof minimum!=='string')return false;if(minimum.includes(', ')){var variants=minimum.split(', ');if(!variants.slice(0,-1).every(function(x){return x.includes(' <');}))return false;return variants.some(function(x){return versionPasses(version,x);});}if(minimum.includes(' <')){var _minimum$split=minimum.split(' <'),_minimum$split2=(0,_toArray2.default)(_minimum$split),min=_minimum$split2[0],max=_minimum$split2[1],rest=_minimum$split2.slice(2);if(rest.length>0)return false;return versionPasses(version,min)&&!versionPasses(version,max)&&versionPasses(max,version);}var versionRegex=/^[0-9]+(\.[0-9]+)*$/;if(!versionRegex.test(version)||!versionRegex.test(minimum))return false;var versionParts=version.split('.').map(Number);var minimumParts=minimum.split('.').map(Number);var len=Math.max(versionParts.length,minimumParts.length);for(var i=0;i<len;i+=1){var ver=versionParts[i]||0;var _min=minimumParts[i]||0;if(ver>_min)return true;if(ver<_min)return false;}return true;};
|
package/lib/WebViewTypes.d.ts
CHANGED
|
@@ -978,6 +978,18 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
|
|
|
978
978
|
* @platform android
|
|
979
979
|
*/
|
|
980
980
|
onLoadSubResourceError?: (event: WebViewErrorEvent) => void;
|
|
981
|
+
/**
|
|
982
|
+
* Exodus: Minimum Chrome version required to use the WebView on Android.
|
|
983
|
+
* If the device Chrome version is below this, the WebView will not render.
|
|
984
|
+
* @platform android
|
|
985
|
+
*/
|
|
986
|
+
minimumChromeVersion?: string;
|
|
987
|
+
/**
|
|
988
|
+
* Exodus: Component to render if the Chrome version is not supported.
|
|
989
|
+
* If not provided, a default error message will be shown.
|
|
990
|
+
* @platform android
|
|
991
|
+
*/
|
|
992
|
+
unsupportedVersionComponent?: ElementType;
|
|
981
993
|
}
|
|
982
994
|
export interface WebViewSharedProps extends ViewProps {
|
|
983
995
|
/**
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"Thibault Malbranche <malbranche.thibault@gmail.com>"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"version": "13.16.0-exodus.
|
|
13
|
+
"version": "13.16.0-exodus.2",
|
|
14
14
|
"homepage": "https://github.com/ExodusMovement/react-native-webview#readme",
|
|
15
15
|
"scripts": {
|
|
16
16
|
"android": "react-native run-android",
|
package/src/WebView.android.tsx
CHANGED
|
@@ -5,9 +5,17 @@ import React, {
|
|
|
5
5
|
useEffect,
|
|
6
6
|
useImperativeHandle,
|
|
7
7
|
useRef,
|
|
8
|
+
useState,
|
|
8
9
|
} from 'react';
|
|
9
10
|
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
Image,
|
|
13
|
+
View,
|
|
14
|
+
Text,
|
|
15
|
+
NativeModules,
|
|
16
|
+
ImageSourcePropType,
|
|
17
|
+
HostComponent,
|
|
18
|
+
} from 'react-native';
|
|
11
19
|
|
|
12
20
|
import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge';
|
|
13
21
|
import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';
|
|
@@ -22,6 +30,7 @@ import {
|
|
|
22
30
|
defaultRenderError,
|
|
23
31
|
defaultRenderLoading,
|
|
24
32
|
useWebViewLogic,
|
|
33
|
+
versionPasses,
|
|
25
34
|
} from './WebViewShared';
|
|
26
35
|
import {
|
|
27
36
|
AndroidWebViewProps,
|
|
@@ -56,6 +65,28 @@ registerCallableModule('RNCWebViewMessagingModule', {
|
|
|
56
65
|
},
|
|
57
66
|
});
|
|
58
67
|
|
|
68
|
+
const { getWebViewDefaultUserAgent } = NativeModules.RNCWebViewUtils || {};
|
|
69
|
+
|
|
70
|
+
let userAgentPromise: Promise<string> | undefined;
|
|
71
|
+
|
|
72
|
+
async function getUserAgent(): Promise<string> {
|
|
73
|
+
if (!getWebViewDefaultUserAgent) return 'unknown';
|
|
74
|
+
if (!userAgentPromise) userAgentPromise = getWebViewDefaultUserAgent();
|
|
75
|
+
const userAgent = await userAgentPromise;
|
|
76
|
+
return userAgent || 'unknown';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Exodus: Minimum Chrome version enforced by the library for security
|
|
80
|
+
const hardMinimumChromeVersion = '100.0';
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Exodus: Hardcoded security defaults that cannot be overridden by props.
|
|
84
|
+
* These values are always enforced regardless of what the consumer passes.
|
|
85
|
+
*/
|
|
86
|
+
const mediaPlaybackRequiresUserAction = true;
|
|
87
|
+
const securitySupportMultipleWindows = true;
|
|
88
|
+
const securityMixedContentMode = 'never' as const;
|
|
89
|
+
|
|
59
90
|
/**
|
|
60
91
|
* A simple counter to uniquely identify WebView instances. Do not use this for anything else.
|
|
61
92
|
*/
|
|
@@ -75,7 +106,6 @@ const WebViewComponent = forwardRef<{}, AndroidWebViewProps>(
|
|
|
75
106
|
androidLayerType = 'none',
|
|
76
107
|
originWhitelist = defaultOriginWhitelist,
|
|
77
108
|
deeplinkWhitelist = defaultDeeplinkWhitelist,
|
|
78
|
-
setSupportMultipleWindows = true,
|
|
79
109
|
setBuiltInZoomControls = true,
|
|
80
110
|
setDisplayZoomControls = false,
|
|
81
111
|
nestedScrollEnabled = false,
|
|
@@ -101,6 +131,8 @@ const WebViewComponent = forwardRef<{}, AndroidWebViewProps>(
|
|
|
101
131
|
injectedJavaScriptObject,
|
|
102
132
|
validateMeta,
|
|
103
133
|
validateData,
|
|
134
|
+
minimumChromeVersion,
|
|
135
|
+
unsupportedVersionComponent: UnsupportedVersionComponent,
|
|
104
136
|
...otherProps
|
|
105
137
|
},
|
|
106
138
|
ref
|
|
@@ -112,6 +144,12 @@ const WebViewComponent = forwardRef<{}, AndroidWebViewProps>(
|
|
|
112
144
|
HostComponent<NativeProps>
|
|
113
145
|
> | null>(null);
|
|
114
146
|
|
|
147
|
+
const [userAgent, setUserAgent] = useState<string>();
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
getUserAgent().then(setUserAgent);
|
|
151
|
+
}, []);
|
|
152
|
+
|
|
115
153
|
const onShouldStartLoadWithRequestCallback = useCallback(
|
|
116
154
|
(shouldStart: boolean, url: string, lockIdentifier?: number) => {
|
|
117
155
|
if (lockIdentifier) {
|
|
@@ -227,6 +265,31 @@ const WebViewComponent = forwardRef<{}, AndroidWebViewProps>(
|
|
|
227
265
|
};
|
|
228
266
|
}, [messagingModuleName, onMessage, onShouldStartLoadWithRequest]);
|
|
229
267
|
|
|
268
|
+
// Stop the rendering until userAgent is known
|
|
269
|
+
if (!userAgent) return null;
|
|
270
|
+
|
|
271
|
+
const chromeVersion = userAgent.match(
|
|
272
|
+
/chrome\/((?:[0-9]+\.)+[0-9]+)/i
|
|
273
|
+
)?.[1];
|
|
274
|
+
|
|
275
|
+
if (
|
|
276
|
+
!(
|
|
277
|
+
versionPasses(chromeVersion, minimumChromeVersion) &&
|
|
278
|
+
versionPasses(chromeVersion, hardMinimumChromeVersion)
|
|
279
|
+
)
|
|
280
|
+
) {
|
|
281
|
+
if (UnsupportedVersionComponent) {
|
|
282
|
+
return <UnsupportedVersionComponent />;
|
|
283
|
+
}
|
|
284
|
+
return (
|
|
285
|
+
<View style={{ alignSelf: 'flex-start' }}>
|
|
286
|
+
<Text style={{ color: 'red' }}>
|
|
287
|
+
Chrome version is outdated and insecure. Update it to continue.
|
|
288
|
+
</Text>
|
|
289
|
+
</View>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
230
293
|
let otherView: ReactElement | undefined;
|
|
231
294
|
if (viewState === 'LOADING') {
|
|
232
295
|
otherView = (renderLoading || defaultRenderLoading)();
|
|
@@ -319,10 +382,12 @@ const WebViewComponent = forwardRef<{}, AndroidWebViewProps>(
|
|
|
319
382
|
saveFormDataDisabled={saveFormDataDisabled}
|
|
320
383
|
cacheEnabled={cacheEnabled}
|
|
321
384
|
androidLayerType={androidLayerType}
|
|
322
|
-
setSupportMultipleWindows={
|
|
385
|
+
setSupportMultipleWindows={securitySupportMultipleWindows}
|
|
323
386
|
setBuiltInZoomControls={setBuiltInZoomControls}
|
|
324
387
|
setDisplayZoomControls={setDisplayZoomControls}
|
|
325
388
|
nestedScrollEnabled={nestedScrollEnabled}
|
|
389
|
+
mixedContentMode={securityMixedContentMode}
|
|
390
|
+
mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}
|
|
326
391
|
injectedJavaScriptObject={JSON.stringify(injectedJavaScriptObject)}
|
|
327
392
|
{...nativeConfig?.props}
|
|
328
393
|
/>
|
package/src/WebView.ios.tsx
CHANGED
|
@@ -51,6 +51,17 @@ const processDecelerationRate = (
|
|
|
51
51
|
// Last entry has no upper bound
|
|
52
52
|
const hardMinimumIOSVersion = '12.5.6 <13, 13.6.1 <14, 14.8.1 <15, 15.7.1';
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Exodus: Hardcoded security defaults that cannot be overridden by props.
|
|
56
|
+
* These values are always enforced regardless of what the consumer passes.
|
|
57
|
+
*/
|
|
58
|
+
const securityMediaPlaybackRequiresUserAction = true;
|
|
59
|
+
const securityAllowsInlineMediaPlayback = true;
|
|
60
|
+
const securityUseSharedProcessPool = false;
|
|
61
|
+
const securitySharedCookiesEnabled = false;
|
|
62
|
+
const securityEnableApplePay = false;
|
|
63
|
+
const securityDataDetectorTypes = ['none'] as const;
|
|
64
|
+
|
|
54
65
|
const useWarnIfChanges = <T extends unknown>(value: T, name: string) => {
|
|
55
66
|
const ref = useRef(value);
|
|
56
67
|
if (ref.current !== value) {
|
|
@@ -69,7 +80,6 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>(
|
|
|
69
80
|
cacheEnabled = true,
|
|
70
81
|
originWhitelist = defaultOriginWhitelist,
|
|
71
82
|
deeplinkWhitelist = defaultDeeplinkWhitelist,
|
|
72
|
-
useSharedProcessPool = true,
|
|
73
83
|
textInteractionEnabled = true,
|
|
74
84
|
injectedJavaScript,
|
|
75
85
|
injectedJavaScriptBeforeContentLoaded,
|
|
@@ -94,11 +104,8 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>(
|
|
|
94
104
|
containerStyle,
|
|
95
105
|
source,
|
|
96
106
|
nativeConfig,
|
|
97
|
-
allowsInlineMediaPlayback,
|
|
98
107
|
allowsPictureInPictureMediaPlayback = true,
|
|
99
108
|
allowsAirPlayForMediaPlayback,
|
|
100
|
-
mediaPlaybackRequiresUserAction,
|
|
101
|
-
dataDetectorTypes,
|
|
102
109
|
incognito,
|
|
103
110
|
decelerationRate: decelerationRateProp,
|
|
104
111
|
onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp,
|
|
@@ -185,7 +192,10 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>(
|
|
|
185
192
|
[setViewState, webViewRef]
|
|
186
193
|
);
|
|
187
194
|
|
|
188
|
-
useWarnIfChanges(
|
|
195
|
+
useWarnIfChanges(
|
|
196
|
+
securityAllowsInlineMediaPlayback,
|
|
197
|
+
'allowsInlineMediaPlayback'
|
|
198
|
+
);
|
|
189
199
|
useWarnIfChanges(
|
|
190
200
|
allowsPictureInPictureMediaPlayback,
|
|
191
201
|
'allowsPictureInPictureMediaPlayback'
|
|
@@ -196,10 +206,10 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>(
|
|
|
196
206
|
);
|
|
197
207
|
useWarnIfChanges(incognito, 'incognito');
|
|
198
208
|
useWarnIfChanges(
|
|
199
|
-
|
|
209
|
+
securityMediaPlaybackRequiresUserAction,
|
|
200
210
|
'mediaPlaybackRequiresUserAction'
|
|
201
211
|
);
|
|
202
|
-
useWarnIfChanges(
|
|
212
|
+
useWarnIfChanges(securityDataDetectorTypes, 'dataDetectorTypes');
|
|
203
213
|
|
|
204
214
|
// Exodus: Check iOS version against minimum requirements
|
|
205
215
|
const iosVersion = String(Platform.Version);
|
|
@@ -277,7 +287,9 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>(
|
|
|
277
287
|
fraudulentWebsiteWarningEnabled={fraudulentWebsiteWarningEnabled}
|
|
278
288
|
javaScriptEnabled={javaScriptEnabled}
|
|
279
289
|
cacheEnabled={cacheEnabled}
|
|
280
|
-
useSharedProcessPool={
|
|
290
|
+
useSharedProcessPool={securityUseSharedProcessPool}
|
|
291
|
+
sharedCookiesEnabled={securitySharedCookiesEnabled}
|
|
292
|
+
enableApplePay={securityEnableApplePay}
|
|
281
293
|
textInteractionEnabled={textInteractionEnabled}
|
|
282
294
|
decelerationRate={decelerationRate}
|
|
283
295
|
messagingEnabled={typeof onMessageProp === 'function'}
|
|
@@ -302,23 +314,21 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>(
|
|
|
302
314
|
injectedJavaScriptBeforeContentLoadedForMainFrameOnly
|
|
303
315
|
}
|
|
304
316
|
injectedJavaScriptObject={JSON.stringify(injectedJavaScriptObject)}
|
|
305
|
-
dataDetectorTypes={
|
|
306
|
-
!dataDetectorTypes || Array.isArray(dataDetectorTypes)
|
|
307
|
-
? dataDetectorTypes
|
|
308
|
-
: [dataDetectorTypes]
|
|
309
|
-
}
|
|
317
|
+
dataDetectorTypes={securityDataDetectorTypes}
|
|
310
318
|
allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback}
|
|
311
|
-
allowsInlineMediaPlayback={
|
|
319
|
+
allowsInlineMediaPlayback={securityAllowsInlineMediaPlayback}
|
|
312
320
|
allowsPictureInPictureMediaPlayback={
|
|
313
321
|
allowsPictureInPictureMediaPlayback
|
|
314
322
|
}
|
|
315
323
|
incognito={incognito}
|
|
316
|
-
mediaPlaybackRequiresUserAction={
|
|
324
|
+
mediaPlaybackRequiresUserAction={
|
|
325
|
+
securityMediaPlaybackRequiresUserAction
|
|
326
|
+
}
|
|
317
327
|
newSource={newSource}
|
|
318
328
|
style={webViewStyles}
|
|
319
329
|
hasOnFileDownload={!!onFileDownload}
|
|
320
330
|
ref={webViewRef}
|
|
321
|
-
// @ts-expect-error old arch
|
|
331
|
+
// @ts-expect-error source prop for old arch compatibility
|
|
322
332
|
source={sourceResolved}
|
|
323
333
|
{...nativeConfig?.props}
|
|
324
334
|
/>
|
package/src/WebViewShared.tsx
CHANGED
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
} from './WebViewTypes';
|
|
20
20
|
import styles from './WebView.styles';
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// Exodus: Only allow HTTPS by default for security
|
|
23
|
+
const defaultOriginWhitelist = ['https://*'] as const;
|
|
23
24
|
|
|
24
25
|
// Exodus: Default protocol schemes for deep linking
|
|
25
26
|
const defaultDeeplinkWhitelist = ['https:'] as const;
|
package/src/WebViewTypes.ts
CHANGED
|
@@ -1188,6 +1188,20 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
|
|
|
1188
1188
|
* @platform android
|
|
1189
1189
|
*/
|
|
1190
1190
|
onLoadSubResourceError?: (event: WebViewErrorEvent) => void;
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Exodus: Minimum Chrome version required to use the WebView on Android.
|
|
1194
|
+
* If the device Chrome version is below this, the WebView will not render.
|
|
1195
|
+
* @platform android
|
|
1196
|
+
*/
|
|
1197
|
+
minimumChromeVersion?: string;
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Exodus: Component to render if the Chrome version is not supported.
|
|
1201
|
+
* If not provided, a default error message will be shown.
|
|
1202
|
+
* @platform android
|
|
1203
|
+
*/
|
|
1204
|
+
unsupportedVersionComponent?: ElementType;
|
|
1191
1205
|
}
|
|
1192
1206
|
|
|
1193
1207
|
export interface WebViewSharedProps extends ViewProps {
|