@exodus/react-native-webview 13.16.0-exodus.4 → 13.16.0-exodus.6
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/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java +17 -40
- package/apple/RNCWebView.mm +0 -31
- package/apple/RNCWebViewManager.mm +0 -3
- package/lib/WebView.android.js +1 -1
- package/lib/WebView.ios.js +1 -1
- package/lib/WebView.js +1 -1
- package/lib/WebViewShared.js +1 -1
- package/package.json +3 -2
- package/lib/WebView.macos.d.ts +0 -6
- package/lib/WebView.macos.js +0 -1
- package/src/__tests__/WebViewShared-test.js +0 -301
- package/src/__tests__/__snapshots__/WebViewShared-test.js.snap +0 -7
- package/src/__tests__/validation-test.js +0 -38
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
package com.reactnativecommunity.webview;
|
|
2
2
|
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
3
|
import android.graphics.Rect;
|
|
5
4
|
import android.net.Uri;
|
|
6
5
|
import android.text.TextUtils;
|
|
@@ -9,7 +8,6 @@ import android.view.Menu;
|
|
|
9
8
|
import android.view.MenuItem;
|
|
10
9
|
import android.view.MotionEvent;
|
|
11
10
|
import android.view.View;
|
|
12
|
-
import android.webkit.JavascriptInterface;
|
|
13
11
|
import android.webkit.ValueCallback;
|
|
14
12
|
import android.webkit.WebChromeClient;
|
|
15
13
|
import android.webkit.WebView;
|
|
@@ -55,17 +53,8 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
55
53
|
String injectedJSBeforeContentLoaded;
|
|
56
54
|
protected static final String JAVASCRIPT_INTERFACE = "ReactNativeWebView";
|
|
57
55
|
protected @Nullable
|
|
58
|
-
RNCWebViewBridge fallbackBridge;
|
|
59
|
-
protected @Nullable
|
|
60
56
|
WebViewCompat.WebMessageListener bridgeListener = null;
|
|
61
57
|
|
|
62
|
-
/**
|
|
63
|
-
* android.webkit.WebChromeClient fundamentally does not support JS injection into frames other
|
|
64
|
-
* than the main frame, so these two properties are mostly here just for parity with iOS & macOS.
|
|
65
|
-
*/
|
|
66
|
-
protected boolean injectedJavaScriptForMainFrameOnly = true;
|
|
67
|
-
protected boolean injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
|
|
68
|
-
|
|
69
58
|
protected boolean messagingEnabled = false;
|
|
70
59
|
protected @Nullable
|
|
71
60
|
String messagingModuleName;
|
|
@@ -253,6 +242,15 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
253
242
|
this.bridgeListener = new WebViewCompat.WebMessageListener() {
|
|
254
243
|
@Override
|
|
255
244
|
public void onPostMessage(@NonNull WebView view, @NonNull WebMessageCompat message, @NonNull Uri sourceOrigin, boolean isMainFrame, @NonNull JavaScriptReplyProxy replyProxy) {
|
|
245
|
+
// Exodus: only accept messages from the top frame. The injected
|
|
246
|
+
// ReactNativeWebView object is available in every frame (subframes
|
|
247
|
+
// included), so without this guard any embedded iframe — even a
|
|
248
|
+
// cross-origin one that happens to pass the origin whitelist — could
|
|
249
|
+
// reach the native onMessage handler. This mirrors the iOS bridge,
|
|
250
|
+
// which is injected with forMainFrameOnly:YES.
|
|
251
|
+
if (!isMainFrame) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
256
254
|
RNCWebView.this.onMessage(message.getData(), sourceOrigin.toString());
|
|
257
255
|
}
|
|
258
256
|
};
|
|
@@ -264,10 +262,14 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
264
262
|
);
|
|
265
263
|
}
|
|
266
264
|
} else {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
265
|
+
// Exodus: the legacy addJavascriptInterface bridge injects ReactNativeWebView
|
|
266
|
+
// into every frame and gives the native side no way to tell which frame a
|
|
267
|
+
// message came from, so it cannot enforce the top-frame restriction above.
|
|
268
|
+
// WEB_MESSAGE_LISTENER is supported on every WebView new enough to clear
|
|
269
|
+
// hardMinimumChromeVersion (100, see src/WebView.android.tsx), so this branch
|
|
270
|
+
// is unreachable in practice. Fail closed rather than install an unhardenable
|
|
271
|
+
// bridge.
|
|
272
|
+
FLog.w("RNCWebView", "WEB_MESSAGE_LISTENER is unsupported on this WebView; ReactNativeWebView messaging bridge not installed.");
|
|
271
273
|
}
|
|
272
274
|
injectJavascriptObject();
|
|
273
275
|
}
|
|
@@ -282,7 +284,6 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
282
284
|
}
|
|
283
285
|
}
|
|
284
286
|
|
|
285
|
-
@SuppressLint("AddJavascriptInterface")
|
|
286
287
|
public void setMessagingEnabled(boolean enabled) {
|
|
287
288
|
if (messagingEnabled == enabled) {
|
|
288
289
|
return;
|
|
@@ -430,30 +431,6 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
430
431
|
return this.getThemedReactContext().getReactApplicationContext();
|
|
431
432
|
}
|
|
432
433
|
|
|
433
|
-
protected class RNCWebViewBridge {
|
|
434
|
-
private String TAG = "RNCWebViewBridge";
|
|
435
|
-
RNCWebView mWebView;
|
|
436
|
-
|
|
437
|
-
RNCWebViewBridge(RNCWebView c) {
|
|
438
|
-
mWebView = c;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* This method is called whenever JavaScript running within the web view calls:
|
|
443
|
-
* - window[JAVASCRIPT_INTERFACE].postMessage
|
|
444
|
-
*/
|
|
445
|
-
@JavascriptInterface
|
|
446
|
-
public void postMessage(String message) {
|
|
447
|
-
if (mWebView.getMessagingEnabled()) {
|
|
448
|
-
// Post to main thread because `mWebView.getUrl()` requires to be executed on main.
|
|
449
|
-
mWebView.post(() -> mWebView.onMessage(message, mWebView.getUrl()));
|
|
450
|
-
} else {
|
|
451
|
-
FLog.w(TAG, "ReactNativeWebView.postMessage method was called but messaging is disabled. Pass an onMessage handler to the WebView.");
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
|
|
457
434
|
protected static class ProgressChangedFilter {
|
|
458
435
|
private boolean waitingForCommandLoadUrl = false;
|
|
459
436
|
|
package/apple/RNCWebView.mm
CHANGED
|
@@ -228,22 +228,6 @@ auto stringToOnLoadingFinishNavigationTypeEnum(std::string value) {
|
|
|
228
228
|
webViewEventEmitter->onScroll(data);
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
|
-
_view.onHttpError = [self](NSDictionary* dictionary) {
|
|
232
|
-
if (_eventEmitter) {
|
|
233
|
-
auto webViewEventEmitter = std::static_pointer_cast<RNCWebViewEventEmitter const>(_eventEmitter);
|
|
234
|
-
facebook::react::RNCWebViewEventEmitter::OnHttpError data = {
|
|
235
|
-
.url = std::string([[dictionary valueForKey:@"url"] UTF8String]),
|
|
236
|
-
.lockIdentifier = [[dictionary valueForKey:@"lockIdentifier"] doubleValue],
|
|
237
|
-
.title = std::string([[dictionary valueForKey:@"title"] UTF8String]),
|
|
238
|
-
.statusCode = [[dictionary valueForKey:@"statusCode"] intValue],
|
|
239
|
-
.description = std::string([[dictionary valueForKey:@"description"] UTF8String] ?: ""),
|
|
240
|
-
.canGoBack = static_cast<bool>([[dictionary valueForKey:@"canGoBack"] boolValue]),
|
|
241
|
-
.canGoForward = static_cast<bool>([[dictionary valueForKey:@"canGoForward"] boolValue]),
|
|
242
|
-
.loading = static_cast<bool>([[dictionary valueForKey:@"loading"] boolValue])
|
|
243
|
-
};
|
|
244
|
-
webViewEventEmitter->onHttpError(data);
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
231
|
self.contentView = _view;
|
|
248
232
|
}
|
|
249
233
|
return self;
|
|
@@ -393,21 +377,6 @@ auto stringToOnLoadingFinishNavigationTypeEnum(std::string value) {
|
|
|
393
377
|
|
|
394
378
|
[_view setSuppressMenuItems:suppressMenuItems];
|
|
395
379
|
}
|
|
396
|
-
if (oldViewProps.hasOnFileDownload != newViewProps.hasOnFileDownload) {
|
|
397
|
-
if (newViewProps.hasOnFileDownload) {
|
|
398
|
-
_view.onFileDownload = [self](NSDictionary* dictionary) {
|
|
399
|
-
if (_eventEmitter) {
|
|
400
|
-
auto webViewEventEmitter = std::static_pointer_cast<RNCWebViewEventEmitter const>(_eventEmitter);
|
|
401
|
-
facebook::react::RNCWebViewEventEmitter::OnFileDownload data = {
|
|
402
|
-
.downloadUrl = std::string([[dictionary valueForKey:@"downloadUrl"] UTF8String])
|
|
403
|
-
};
|
|
404
|
-
webViewEventEmitter->onFileDownload(data);
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
} else {
|
|
408
|
-
_view.onFileDownload = nil;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
380
|
if (oldViewProps.hasOnOpenWindowEvent != newViewProps.hasOnOpenWindowEvent) {
|
|
412
381
|
if (newViewProps.hasOnOpenWindowEvent) {
|
|
413
382
|
_view.onOpenWindow = [self](NSDictionary* dictionary) {
|
|
@@ -43,12 +43,10 @@ RCT_EXPORT_MODULE(RNCWebView)
|
|
|
43
43
|
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
|
|
44
44
|
// New arch only
|
|
45
45
|
RCT_CUSTOM_VIEW_PROPERTY(newSource, NSDictionary, RNCWebViewImpl) {}
|
|
46
|
-
RCT_EXPORT_VIEW_PROPERTY(onFileDownload, RCTDirectEventBlock)
|
|
47
46
|
RCT_EXPORT_VIEW_PROPERTY(onLoadingStart, RCTDirectEventBlock)
|
|
48
47
|
RCT_EXPORT_VIEW_PROPERTY(onLoadingFinish, RCTDirectEventBlock)
|
|
49
48
|
RCT_EXPORT_VIEW_PROPERTY(onLoadingError, RCTDirectEventBlock)
|
|
50
49
|
RCT_EXPORT_VIEW_PROPERTY(onLoadingProgress, RCTDirectEventBlock)
|
|
51
|
-
RCT_EXPORT_VIEW_PROPERTY(onHttpError, RCTDirectEventBlock)
|
|
52
50
|
RCT_EXPORT_VIEW_PROPERTY(onShouldStartLoadWithRequest, RCTDirectEventBlock)
|
|
53
51
|
RCT_EXPORT_VIEW_PROPERTY(onContentProcessDidTerminate, RCTDirectEventBlock)
|
|
54
52
|
RCT_EXPORT_VIEW_PROPERTY(onOpenWindow, RCTDirectEventBlock)
|
|
@@ -112,7 +110,6 @@ RCT_EXPORT_VIEW_PROPERTY(menuItems, NSArray);
|
|
|
112
110
|
RCT_EXPORT_VIEW_PROPERTY(suppressMenuItems, NSArray);
|
|
113
111
|
|
|
114
112
|
// New arch only
|
|
115
|
-
RCT_CUSTOM_VIEW_PROPERTY(hasOnFileDownload, BOOL, RNCWebViewImpl) {}
|
|
116
113
|
RCT_CUSTOM_VIEW_PROPERTY(hasOnOpenWindowEvent, BOOL, RNCWebViewImpl) {}
|
|
117
114
|
|
|
118
115
|
RCT_EXPORT_VIEW_PROPERTY(onCustomMenuSelection, RCTDirectEventBlock)
|
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 _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 _validation=_interopRequireDefault(require("./validation"));var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["overScrollMode","javaScriptEnabled","thirdPartyCookiesEnabled","scalesPageToFit","allowsFullscreenVideo","saveFormDataDisabled","cacheEnabled","androidLayerType","originWhitelist","deeplinkWhitelist","setBuiltInZoomControls","setDisplayZoomControls","nestedScrollEnabled","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadSubResourceError","onLoadProgress","onRenderProcessGone","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","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(props,ref){var _userAgent$match;(0,_validation.default)(props);var _props$overScrollMode=props.overScrollMode,overScrollMode=_props$overScrollMode===void 0?'always':_props$overScrollMode,_props$javaScriptEnab=props.javaScriptEnabled,javaScriptEnabled=_props$javaScriptEnab===void 0?true:_props$javaScriptEnab,_props$thirdPartyCook=props.thirdPartyCookiesEnabled,thirdPartyCookiesEnabled=_props$thirdPartyCook===void 0?true:_props$thirdPartyCook,_props$scalesPageToFi=props.scalesPageToFit,scalesPageToFit=_props$scalesPageToFi===void 0?true:_props$scalesPageToFi,_props$allowsFullscre=props.allowsFullscreenVideo,allowsFullscreenVideo=_props$allowsFullscre===void 0?false:_props$allowsFullscre,_props$saveFormDataDi=props.saveFormDataDisabled,saveFormDataDisabled=_props$saveFormDataDi===void 0?false:_props$saveFormDataDi,_props$cacheEnabled=props.cacheEnabled,cacheEnabled=_props$cacheEnabled===void 0?true:_props$cacheEnabled,_props$androidLayerTy=props.androidLayerType,androidLayerType=_props$androidLayerTy===void 0?'none':_props$androidLayerTy,_props$originWhitelis=props.originWhitelist,originWhitelist=_props$originWhitelis===void 0?_WebViewShared.defaultOriginWhitelist:_props$originWhitelis,_props$deeplinkWhitel=props.deeplinkWhitelist,deeplinkWhitelist=_props$deeplinkWhitel===void 0?_WebViewShared.defaultDeeplinkWhitelist:_props$deeplinkWhitel,_props$setBuiltInZoom=props.setBuiltInZoomControls,setBuiltInZoomControls=_props$setBuiltInZoom===void 0?true:_props$setBuiltInZoom,_props$setDisplayZoom=props.setDisplayZoomControls,setDisplayZoomControls=_props$setDisplayZoom===void 0?false:_props$setDisplayZoom,_props$nestedScrollEn=props.nestedScrollEnabled,nestedScrollEnabled=_props$nestedScrollEn===void 0?false:_props$nestedScrollEn,startInLoadingState=props.startInLoadingState,onNavigationStateChange=props.onNavigationStateChange,onLoadStart=props.onLoadStart,onError=props.onError,onLoad=props.onLoad,onLoadEnd=props.onLoadEnd,onLoadSubResourceError=props.onLoadSubResourceError,onLoadProgress=props.onLoadProgress,onRenderProcessGoneProp=props.onRenderProcessGone,onMessageProp=props.onMessage,onOpenWindowProp=props.onOpenWindow,renderLoading=props.renderLoading,renderError=props.renderError,style=props.style,containerStyle=props.containerStyle,source=props.source,onShouldStartLoadWithRequestProp=props.onShouldStartLoadWithRequest,injectedJavaScriptObject=props.injectedJavaScriptObject,validateMeta=props.validateMeta,validateData=props.validateData,minimumChromeVersion=props.minimumChromeVersion,UnsupportedVersionComponent=props.unsupportedVersionComponent,otherProps=(0,_objectWithoutProperties2.default)(props,_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,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,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);},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 compiledWhitelist=(0,_react.useMemo)(function(){return(0,_WebViewShared.compileWhitelist)(originWhitelist);},[originWhitelist]);var safeSource=(0,_react.useMemo)(function(){if(source&&typeof source==='object'&&'uri'in source&&typeof source.uri==='string'){if(!(0,_WebViewShared.passesWhitelist)(compiledWhitelist,source.uri)){console.warn(`WebView: source.uri "${source.uri}" does not pass the origin whitelist. Loading about:blank instead.`);return{uri:'about:blank'};}}return source;},[source,compiledWhitelist]);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 safeSource!=='number'&&safeSource&&'method'in safeSource){if(safeSource.method==='POST'&&safeSource.headers){console.warn('WebView: `source.headers` is not supported when using POST.');}else if(safeSource.method==='GET'&&safeSource.body){console.warn('WebView: `source.body` is not supported when using GET.');}}var sourceResolved=resolveAssetSource(safeSource);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)(_RNCWebViewNativeComponent.default,Object.assign({},otherProps,{messagingEnabled:typeof onMessageProp==='function',messagingModuleName:messagingModuleName,hasOnScroll:!!otherProps.onScroll,onLoadingError:onLoadingError,onLoadingSubResourceError:onLoadingSubResourceError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onLoadingStart:onLoadingStart,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,saveFormDataDisabled:saveFormDataDisabled,cacheEnabled:cacheEnabled,androidLayerType:androidLayerType,setSupportMultipleWindows:securitySupportMultipleWindows,setBuiltInZoomControls:setBuiltInZoomControls,setDisplayZoomControls:setDisplayZoomControls,nestedScrollEnabled:nestedScrollEnabled,mixedContentMode:securityMixedContentMode,mediaPlaybackRequiresUserAction:mediaPlaybackRequiresUserAction,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject)}),"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 _validation=_interopRequireDefault(require("./validation"));var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["overScrollMode","javaScriptEnabled","thirdPartyCookiesEnabled","scalesPageToFit","allowsFullscreenVideo","saveFormDataDisabled","cacheEnabled","androidLayerType","originWhitelist","deeplinkWhitelist","setBuiltInZoomControls","setDisplayZoomControls","nestedScrollEnabled","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadSubResourceError","onLoadProgress","onRenderProcessGone","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","onShouldStartLoadWithRequest","injectedJavaScriptObject","validateMeta","validateData","minimumChromeVersion","unsupportedVersionComponent"],_excluded2=["messagingModuleName"],_excluded3=["messagingModuleName"];var _require$registerCall;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(props,ref){var _userAgent$match;(0,_validation.default)(props);var _props$overScrollMode=props.overScrollMode,overScrollMode=_props$overScrollMode===void 0?'always':_props$overScrollMode,_props$javaScriptEnab=props.javaScriptEnabled,javaScriptEnabled=_props$javaScriptEnab===void 0?true:_props$javaScriptEnab,_props$thirdPartyCook=props.thirdPartyCookiesEnabled,thirdPartyCookiesEnabled=_props$thirdPartyCook===void 0?true:_props$thirdPartyCook,_props$scalesPageToFi=props.scalesPageToFit,scalesPageToFit=_props$scalesPageToFi===void 0?true:_props$scalesPageToFi,_props$allowsFullscre=props.allowsFullscreenVideo,allowsFullscreenVideo=_props$allowsFullscre===void 0?false:_props$allowsFullscre,_props$saveFormDataDi=props.saveFormDataDisabled,saveFormDataDisabled=_props$saveFormDataDi===void 0?false:_props$saveFormDataDi,_props$cacheEnabled=props.cacheEnabled,cacheEnabled=_props$cacheEnabled===void 0?true:_props$cacheEnabled,_props$androidLayerTy=props.androidLayerType,androidLayerType=_props$androidLayerTy===void 0?'none':_props$androidLayerTy,_props$originWhitelis=props.originWhitelist,originWhitelist=_props$originWhitelis===void 0?_WebViewShared.defaultOriginWhitelist:_props$originWhitelis,_props$deeplinkWhitel=props.deeplinkWhitelist,deeplinkWhitelist=_props$deeplinkWhitel===void 0?_WebViewShared.defaultDeeplinkWhitelist:_props$deeplinkWhitel,_props$setBuiltInZoom=props.setBuiltInZoomControls,setBuiltInZoomControls=_props$setBuiltInZoom===void 0?true:_props$setBuiltInZoom,_props$setDisplayZoom=props.setDisplayZoomControls,setDisplayZoomControls=_props$setDisplayZoom===void 0?false:_props$setDisplayZoom,_props$nestedScrollEn=props.nestedScrollEnabled,nestedScrollEnabled=_props$nestedScrollEn===void 0?false:_props$nestedScrollEn,startInLoadingState=props.startInLoadingState,onNavigationStateChange=props.onNavigationStateChange,onLoadStart=props.onLoadStart,onError=props.onError,onLoad=props.onLoad,onLoadEnd=props.onLoadEnd,onLoadSubResourceError=props.onLoadSubResourceError,onLoadProgress=props.onLoadProgress,onRenderProcessGoneProp=props.onRenderProcessGone,onMessageProp=props.onMessage,onOpenWindowProp=props.onOpenWindow,renderLoading=props.renderLoading,renderError=props.renderError,style=props.style,containerStyle=props.containerStyle,source=props.source,onShouldStartLoadWithRequestProp=props.onShouldStartLoadWithRequest,injectedJavaScriptObject=props.injectedJavaScriptObject,validateMeta=props.validateMeta,validateData=props.validateData,minimumChromeVersion=props.minimumChromeVersion,UnsupportedVersionComponent=props.unsupportedVersionComponent,otherProps=(0,_objectWithoutProperties2.default)(props,_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,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,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);},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 compiledWhitelist=(0,_react.useMemo)(function(){return(0,_WebViewShared.compileWhitelist)(originWhitelist);},[originWhitelist]);var safeSource=(0,_react.useMemo)(function(){if(source&&typeof source==='object'&&'uri'in source&&typeof source.uri==='string'){if(!(0,_WebViewShared.passesWhitelist)(compiledWhitelist,source.uri)){console.warn(`WebView: source.uri "${source.uri}" does not pass the origin whitelist. Loading about:blank instead.`);return{uri:'about:blank'};}}return source;},[source,compiledWhitelist]);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 safeSource!=='number'&&safeSource&&'method'in safeSource){if(safeSource.method==='POST'&&safeSource.headers){console.warn('WebView: `source.headers` is not supported when using POST.');}else if(safeSource.method==='GET'&&safeSource.body){console.warn('WebView: `source.body` is not supported when using GET.');}}var sourceResolved=resolveAssetSource(safeSource);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)(_RNCWebViewNativeComponent.default,Object.assign({},otherProps,{messagingEnabled:typeof onMessageProp==='function',messagingModuleName:messagingModuleName,hasOnScroll:!!otherProps.onScroll,onLoadingError:onLoadingError,onLoadingSubResourceError:onLoadingSubResourceError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onLoadingStart:onLoadingStart,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,saveFormDataDisabled:saveFormDataDisabled,cacheEnabled:cacheEnabled,androidLayerType:androidLayerType,setSupportMultipleWindows:securitySupportMultipleWindows,setBuiltInZoomControls:setBuiltInZoomControls,setDisplayZoomControls:setDisplayZoomControls,nestedScrollEnabled:nestedScrollEnabled,mixedContentMode:securityMixedContentMode,mediaPlaybackRequiresUserAction:mediaPlaybackRequiresUserAction,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject)}),"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 _validation=_interopRequireDefault(require("./validation"));var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["fraudulentWebsiteWarningEnabled","javaScriptEnabled","cacheEnabled","originWhitelist","deeplinkWhitelist","textInteractionEnabled","injectedJavaScript","injectedJavaScriptBeforeContentLoaded","injectedJavaScriptObject","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadProgress","onContentProcessDidTerminate","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","allowsPictureInPictureMediaPlayback","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(props,ref){(0,_validation.default)(props);var _props$fraudulentWebs=props.fraudulentWebsiteWarningEnabled,fraudulentWebsiteWarningEnabled=_props$fraudulentWebs===void 0?true:_props$fraudulentWebs,_props$javaScriptEnab=props.javaScriptEnabled,javaScriptEnabled=_props$javaScriptEnab===void 0?true:_props$javaScriptEnab,_props$cacheEnabled=props.cacheEnabled,cacheEnabled=_props$cacheEnabled===void 0?true:_props$cacheEnabled,_props$originWhitelis=props.originWhitelist,originWhitelist=_props$originWhitelis===void 0?_WebViewShared.defaultOriginWhitelist:_props$originWhitelis,_props$deeplinkWhitel=props.deeplinkWhitelist,deeplinkWhitelist=_props$deeplinkWhitel===void 0?_WebViewShared.defaultDeeplinkWhitelist:_props$deeplinkWhitel,_props$textInteractio=props.textInteractionEnabled,textInteractionEnabled=_props$textInteractio===void 0?true:_props$textInteractio,injectedJavaScript=props.injectedJavaScript,injectedJavaScriptBeforeContentLoaded=props.injectedJavaScriptBeforeContentLoaded,injectedJavaScriptObject=props.injectedJavaScriptObject,startInLoadingState=props.startInLoadingState,onNavigationStateChange=props.onNavigationStateChange,onLoadStart=props.onLoadStart,onError=props.onError,onLoad=props.onLoad,onLoadEnd=props.onLoadEnd,onLoadProgress=props.onLoadProgress,onContentProcessDidTerminateProp=props.onContentProcessDidTerminate,onMessageProp=props.onMessage,onOpenWindowProp=props.onOpenWindow,renderLoading=props.renderLoading,renderError=props.renderError,style=props.style,containerStyle=props.containerStyle,source=props.source,_props$allowsPictureI=props.allowsPictureInPictureMediaPlayback,allowsPictureInPictureMediaPlayback=_props$allowsPictureI===void 0?true:_props$allowsPictureI,incognito=props.incognito,decelerationRateProp=props.decelerationRate,onShouldStartLoadWithRequestProp=props.onShouldStartLoadWithRequest,validateMeta=props.validateMeta,validateData=props.validateData,minimumIOSVersion=props.minimumIOSVersion,UnsupportedVersionComponent=props.unsupportedVersionComponent,otherProps=(0,_objectWithoutProperties2.default)(props,_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,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,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);},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(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 sourceResolved=resolveAssetSource(source);var newSource=typeof sourceResolved==='object'?Object.entries(sourceResolved).reduce(function(prev,_ref){var _ref2=(0,_slicedToArray2.default)(_ref,2),currKey=_ref2[0],currValue=_ref2[1];return Object.assign({},prev,(0,_defineProperty2.default)({},currKey,currKey==='headers'&&currValue&&typeof currValue==='object'?Object.entries(currValue).map(function(_ref3){var _ref4=(0,_slicedToArray2.default)(_ref3,2),key=_ref4[0],value=_ref4[1];return{name:key,value:value};}):currValue));},{}):sourceResolved;var webView=(0,_jsxRuntime.jsx)(_RNCWebViewNativeComponent.default,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,onLoadingStart:onLoadingStart,onMessage:onMessage,onOpenWindow:onOpenWindowProp&&onOpenWindow,hasOnOpenWindowEvent:onOpenWindowProp!==undefined,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onContentProcessDidTerminate:onContentProcessDidTerminate,injectedJavaScript:injectedJavaScript,injectedJavaScriptBeforeContentLoaded:injectedJavaScriptBeforeContentLoaded,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject),dataDetectorTypes:securityDataDetectorTypes,allowsInlineMediaPlayback:securityAllowsInlineMediaPlayback,allowsPictureInPictureMediaPlayback:allowsPictureInPictureMediaPlayback,incognito:incognito,mediaPlaybackRequiresUserAction:securityMediaPlaybackRequiresUserAction,newSource:newSource,style:webViewStyles,ref:webViewRef,source:sourceResolved}),"webViewKey");return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:webViewContainerStyle,children:[webView,otherView]});});var isFileUploadSupported=function(){var _ref5=(0,_asyncToGenerator2.default)(function*(){return true;});return function isFileUploadSupported(){return _ref5.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 _validation=_interopRequireDefault(require("./validation"));var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["fraudulentWebsiteWarningEnabled","javaScriptEnabled","cacheEnabled","originWhitelist","deeplinkWhitelist","textInteractionEnabled","injectedJavaScript","injectedJavaScriptBeforeContentLoaded","injectedJavaScriptObject","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadProgress","onContentProcessDidTerminate","onMessage","onOpenWindow","renderLoading","renderError","style","containerStyle","source","allowsPictureInPictureMediaPlayback","incognito","decelerationRate","onShouldStartLoadWithRequest","validateMeta","validateData","minimumIOSVersion","unsupportedVersionComponent"];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(props,ref){(0,_validation.default)(props);var _props$fraudulentWebs=props.fraudulentWebsiteWarningEnabled,fraudulentWebsiteWarningEnabled=_props$fraudulentWebs===void 0?true:_props$fraudulentWebs,_props$javaScriptEnab=props.javaScriptEnabled,javaScriptEnabled=_props$javaScriptEnab===void 0?true:_props$javaScriptEnab,_props$cacheEnabled=props.cacheEnabled,cacheEnabled=_props$cacheEnabled===void 0?true:_props$cacheEnabled,_props$originWhitelis=props.originWhitelist,originWhitelist=_props$originWhitelis===void 0?_WebViewShared.defaultOriginWhitelist:_props$originWhitelis,_props$deeplinkWhitel=props.deeplinkWhitelist,deeplinkWhitelist=_props$deeplinkWhitel===void 0?_WebViewShared.defaultDeeplinkWhitelist:_props$deeplinkWhitel,_props$textInteractio=props.textInteractionEnabled,textInteractionEnabled=_props$textInteractio===void 0?true:_props$textInteractio,injectedJavaScript=props.injectedJavaScript,injectedJavaScriptBeforeContentLoaded=props.injectedJavaScriptBeforeContentLoaded,injectedJavaScriptObject=props.injectedJavaScriptObject,startInLoadingState=props.startInLoadingState,onNavigationStateChange=props.onNavigationStateChange,onLoadStart=props.onLoadStart,onError=props.onError,onLoad=props.onLoad,onLoadEnd=props.onLoadEnd,onLoadProgress=props.onLoadProgress,onContentProcessDidTerminateProp=props.onContentProcessDidTerminate,onMessageProp=props.onMessage,onOpenWindowProp=props.onOpenWindow,renderLoading=props.renderLoading,renderError=props.renderError,style=props.style,containerStyle=props.containerStyle,source=props.source,_props$allowsPictureI=props.allowsPictureInPictureMediaPlayback,allowsPictureInPictureMediaPlayback=_props$allowsPictureI===void 0?true:_props$allowsPictureI,incognito=props.incognito,decelerationRateProp=props.decelerationRate,onShouldStartLoadWithRequestProp=props.onShouldStartLoadWithRequest,validateMeta=props.validateMeta,validateData=props.validateData,minimumIOSVersion=props.minimumIOSVersion,UnsupportedVersionComponent=props.unsupportedVersionComponent,otherProps=(0,_objectWithoutProperties2.default)(props,_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,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,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);},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(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 sourceResolved=resolveAssetSource(source);var newSource=typeof sourceResolved==='object'?Object.entries(sourceResolved).reduce(function(prev,_ref){var _ref2=(0,_slicedToArray2.default)(_ref,2),currKey=_ref2[0],currValue=_ref2[1];return Object.assign({},prev,(0,_defineProperty2.default)({},currKey,currKey==='headers'&&currValue&&typeof currValue==='object'?Object.entries(currValue).map(function(_ref3){var _ref4=(0,_slicedToArray2.default)(_ref3,2),key=_ref4[0],value=_ref4[1];return{name:key,value:value};}):currValue));},{}):sourceResolved;var webView=(0,_jsxRuntime.jsx)(_RNCWebViewNativeComponent.default,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,onLoadingStart:onLoadingStart,onMessage:onMessage,onOpenWindow:onOpenWindowProp&&onOpenWindow,hasOnOpenWindowEvent:onOpenWindowProp!==undefined,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onContentProcessDidTerminate:onContentProcessDidTerminate,injectedJavaScript:injectedJavaScript,injectedJavaScriptBeforeContentLoaded:injectedJavaScriptBeforeContentLoaded,injectedJavaScriptObject:JSON.stringify(injectedJavaScriptObject),dataDetectorTypes:securityDataDetectorTypes,allowsInlineMediaPlayback:securityAllowsInlineMediaPlayback,allowsPictureInPictureMediaPlayback:allowsPictureInPictureMediaPlayback,incognito:incognito,mediaPlaybackRequiresUserAction:securityMediaPlaybackRequiresUserAction,newSource:newSource,style:webViewStyles,ref:webViewRef,source:sourceResolved}),"webViewKey");return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:webViewContainerStyle,children:[webView,otherView]});});var isFileUploadSupported=function(){var _ref5=(0,_asyncToGenerator2.default)(function*(){return true;});return function isFileUploadSupported(){return _ref5.apply(this,arguments);};}();var WebView=Object.assign(WebViewComponent,{isFileUploadSupported:isFileUploadSupported});var _default=exports.default=WebView;
|
package/lib/WebView.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.WebView=void 0;var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.WebView=void 0;var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var WebView=exports.WebView=function WebView(){return(0,_jsxRuntime.jsx)(_reactNative.View,{style:_WebView.default.flexStart,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:_WebView.default.colorRed,children:"React Native WebView does not support this platform."})});};var _default=exports.default=WebView;
|
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.passesWhitelist=exports.defaultRenderLoading=exports.defaultRenderError=exports.defaultOriginWhitelist=exports.defaultDeeplinkWhitelist=exports.createOnShouldStartLoadWithRequest=exports.compileWhitelist=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=exports.compileWhitelist=function compileWhitelist(originWhitelist){return['about:blank'].concat((0,_toConsumableArray2.default)(originWhitelist||[])).map(stringWhitelistToRegex);};var passesWhitelist=exports.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,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 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,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.passesWhitelist=exports.defaultRenderLoading=exports.defaultRenderError=exports.defaultOriginWhitelist=exports.defaultDeeplinkWhitelist=exports.createOnShouldStartLoadWithRequest=exports.compileWhitelist=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");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=exports.compileWhitelist=function compileWhitelist(originWhitelist){return['about:blank'].concat((0,_toConsumableArray2.default)(originWhitelist||[])).map(stringWhitelistToRegex);};var passesWhitelist=exports.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,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 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,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/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.6",
|
|
14
14
|
"homepage": "https://github.com/ExodusMovement/react-native-webview#readme",
|
|
15
15
|
"scripts": {
|
|
16
16
|
"android": "react-native run-android",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"ci": "CI=true && yarn lint",
|
|
20
20
|
"ci:publish": "yarn semantic-release",
|
|
21
21
|
"lint": "yarn tsc --noEmit && yarn eslint ./src --ext .ts,.tsx,.js,.jsx",
|
|
22
|
-
"build": "babel --extensions \".ts,.tsx\" --out-dir lib src",
|
|
22
|
+
"build": "NODE_ENV=production babel --extensions \".ts,.tsx\" --out-dir lib src",
|
|
23
23
|
"prepare:types": "tsc --noEmit false --emitDeclarationOnly --declaration --rootDir src --outDir lib",
|
|
24
24
|
"prepare": "yarn prepare:types && yarn build",
|
|
25
25
|
"appium": "appium"
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"ios",
|
|
76
76
|
"lib",
|
|
77
77
|
"src",
|
|
78
|
+
"!src/__tests__",
|
|
78
79
|
"index.js",
|
|
79
80
|
"index.d.ts",
|
|
80
81
|
"react-native-webview.podspec",
|
package/lib/WebView.macos.d.ts
DELETED
package/lib/WebView.macos.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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=["javaScriptEnabled","cacheEnabled","originWhitelist","deeplinkWhitelist","useSharedProcessPool","injectedJavaScript","injectedJavaScriptBeforeContentLoaded","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadProgress","onHttpError","onMessage","renderLoading","renderError","style","containerStyle","source","nativeConfig","allowsInlineMediaPlayback","allowsPictureInPictureMediaPlayback","allowsAirPlayForMediaPlayback","mediaPlaybackRequiresUserAction","incognito","onShouldStartLoadWithRequest","validateMeta","validateData"];var _this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebView.macos.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 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$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,injectedJavaScript=_ref.injectedJavaScript,injectedJavaScriptBeforeContentLoaded=_ref.injectedJavaScriptBeforeContentLoaded,startInLoadingState=_ref.startInLoadingState,onNavigationStateChange=_ref.onNavigationStateChange,onLoadStart=_ref.onLoadStart,onError=_ref.onError,onLoad=_ref.onLoad,onLoadEnd=_ref.onLoadEnd,onLoadProgress=_ref.onLoadProgress,onHttpErrorProp=_ref.onHttpError,onMessageProp=_ref.onMessage,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,incognito=_ref.incognito,onShouldStartLoadWithRequestProp=_ref.onShouldStartLoadWithRequest,validateMeta=_ref.validateMeta,validateData=_ref.validateData,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,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,onLoadingFinish=_useWebViewLogic.onLoadingFinish,onLoadingProgress=_useWebViewLogic.onLoadingProgress,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);}};},[setViewState,webViewRef]);useWarnIfChanges(allowsInlineMediaPlayback,'allowsInlineMediaPlayback');useWarnIfChanges(allowsPictureInPictureMediaPlayback,'allowsPictureInPictureMediaPlayback');useWarnIfChanges(allowsAirPlayForMediaPlayback,'allowsAirPlayForMediaPlayback');useWarnIfChanges(incognito,'incognito');useWarnIfChanges(mediaPlaybackRequiresUserAction,'mediaPlaybackRequiresUserAction');var otherView=null;if(viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(viewState==='ERROR'){var _lastErrorEvent$descr;(0,_invariant.default)(lastErrorEvent!=null,'lastErrorEvent expected to be non-null');otherView=(renderError||_WebViewShared.defaultRenderError)(lastErrorEvent==null?void 0:lastErrorEvent.domain,(lastErrorEvent==null?void 0: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 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,{javaScriptEnabled:javaScriptEnabled,cacheEnabled:cacheEnabled,useSharedProcessPool:useSharedProcessPool,messagingEnabled:typeof onMessageProp==='function',newSource:newSource,onLoadingError:onLoadingError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onLoadingStart:onLoadingStart,onHttpError:onHttpError,onMessage:onMessage,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onContentProcessDidTerminate:onContentProcessDidTerminate,injectedJavaScript:injectedJavaScript,injectedJavaScriptBeforeContentLoaded:injectedJavaScriptBeforeContentLoaded,allowsAirPlayForMediaPlayback:allowsAirPlayForMediaPlayback,allowsInlineMediaPlayback:allowsInlineMediaPlayback,allowsPictureInPictureMediaPlayback:allowsPictureInPictureMediaPlayback,incognito:incognito,mediaPlaybackRequiresUserAction:mediaPlaybackRequiresUserAction,ref:webViewRef,source:sourceResolved,style:webViewStyles},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,301 +0,0 @@
|
|
|
1
|
-
import { Linking } from 'react-native';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
defaultOriginWhitelist,
|
|
5
|
-
defaultDeeplinkWhitelist,
|
|
6
|
-
createOnShouldStartLoadWithRequest,
|
|
7
|
-
} from '../WebViewShared';
|
|
8
|
-
|
|
9
|
-
Linking.openURL.mockResolvedValue(undefined);
|
|
10
|
-
Linking.canOpenURL.mockResolvedValue(true);
|
|
11
|
-
|
|
12
|
-
// The tests that call createOnShouldStartLoadWithRequest will cause a promise
|
|
13
|
-
// to get kicked off (by calling the mocked `Linking.canOpenURL`) that the tests
|
|
14
|
-
// _need_ to get run to completion _before_ doing any `expect`ing. The reason
|
|
15
|
-
// is: once that promise is resolved another function should get run which will
|
|
16
|
-
// call `Linking.openURL`, and we want to test that.
|
|
17
|
-
//
|
|
18
|
-
// Normally we would probably do something like `await
|
|
19
|
-
// createShouldStartLoadWithRequest(...)` in the tests, but that doesn't work
|
|
20
|
-
// here because the promise that gets kicked off is not returned (because
|
|
21
|
-
// non-test code doesn't need to know about it).
|
|
22
|
-
//
|
|
23
|
-
// The tests thus need a way to "flush any pending promises" (to make sure
|
|
24
|
-
// pending promises run to completion) before doing any `expect`ing. `jest`
|
|
25
|
-
// doesn't provide a way to do this out of the box, but we can use this function
|
|
26
|
-
// to do it.
|
|
27
|
-
//
|
|
28
|
-
// See this issue for more discussion: https://github.com/facebook/jest/issues/2157
|
|
29
|
-
function flushPromises() {
|
|
30
|
-
return new Promise((resolve) => setImmediate(resolve));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe('WebViewShared', () => {
|
|
34
|
-
test('exports defaultOriginWhitelist', () => {
|
|
35
|
-
expect(defaultOriginWhitelist).toMatchSnapshot();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('createOnShouldStartLoadWithRequest', () => {
|
|
39
|
-
const alwaysTrueOnShouldStartLoadWithRequest = (nativeEvent) => {
|
|
40
|
-
return true;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const alwaysFalseOnShouldStartLoadWithRequest = (nativeEvent) => {
|
|
44
|
-
return false;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const loadRequest = jest.fn();
|
|
48
|
-
|
|
49
|
-
test('loadRequest is called without onShouldStartLoadWithRequest override', async () => {
|
|
50
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
51
|
-
loadRequest,
|
|
52
|
-
defaultOriginWhitelist,
|
|
53
|
-
defaultDeeplinkWhitelist
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
onShouldStartLoadWithRequest({
|
|
57
|
-
nativeEvent: { url: 'https://www.example.com/', lockIdentifier: 1 },
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
await flushPromises();
|
|
61
|
-
|
|
62
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
63
|
-
expect(loadRequest).toHaveBeenCalledWith(
|
|
64
|
-
true,
|
|
65
|
-
'https://www.example.com/',
|
|
66
|
-
1
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('non-whitelisted protocol is blocked without calling Linking.openURL', async () => {
|
|
71
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
72
|
-
loadRequest,
|
|
73
|
-
defaultOriginWhitelist,
|
|
74
|
-
defaultDeeplinkWhitelist
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
onShouldStartLoadWithRequest({
|
|
78
|
-
nativeEvent: { url: 'invalid://example.com/', lockIdentifier: 2 },
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
await flushPromises();
|
|
82
|
-
|
|
83
|
-
// Exodus: non-whitelisted protocols are blocked, not opened
|
|
84
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
85
|
-
expect(loadRequest).toHaveBeenCalledWith(
|
|
86
|
-
false,
|
|
87
|
-
'invalid://example.com/',
|
|
88
|
-
2
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('loadRequest with true onShouldStartLoadWithRequest override is called', async () => {
|
|
93
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
94
|
-
loadRequest,
|
|
95
|
-
defaultOriginWhitelist,
|
|
96
|
-
defaultDeeplinkWhitelist,
|
|
97
|
-
alwaysTrueOnShouldStartLoadWithRequest
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
onShouldStartLoadWithRequest({
|
|
101
|
-
nativeEvent: { url: 'https://www.example.com/', lockIdentifier: 1 },
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
await flushPromises();
|
|
105
|
-
|
|
106
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
107
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
108
|
-
true,
|
|
109
|
-
'https://www.example.com/',
|
|
110
|
-
1
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('non-whitelisted protocol is blocked even with true onShouldStartLoadWithRequest override', async () => {
|
|
115
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
116
|
-
loadRequest,
|
|
117
|
-
defaultOriginWhitelist,
|
|
118
|
-
defaultDeeplinkWhitelist,
|
|
119
|
-
alwaysTrueOnShouldStartLoadWithRequest
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
onShouldStartLoadWithRequest({
|
|
123
|
-
nativeEvent: { url: 'invalid://example.com/', lockIdentifier: 1 },
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
await flushPromises();
|
|
127
|
-
|
|
128
|
-
// Exodus: non-whitelisted protocols are blocked, not opened
|
|
129
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
130
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
131
|
-
false,
|
|
132
|
-
'invalid://example.com/',
|
|
133
|
-
1
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('loadRequest with false onShouldStartLoadWithRequest override is called', async () => {
|
|
138
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
139
|
-
loadRequest,
|
|
140
|
-
defaultOriginWhitelist,
|
|
141
|
-
defaultDeeplinkWhitelist,
|
|
142
|
-
alwaysFalseOnShouldStartLoadWithRequest
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
onShouldStartLoadWithRequest({
|
|
146
|
-
nativeEvent: { url: 'https://www.example.com/', lockIdentifier: 1 },
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
await flushPromises();
|
|
150
|
-
|
|
151
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
152
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
153
|
-
false,
|
|
154
|
-
'https://www.example.com/',
|
|
155
|
-
1
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test('loadRequest with limited whitelist', async () => {
|
|
160
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
161
|
-
loadRequest,
|
|
162
|
-
['https://*'],
|
|
163
|
-
defaultDeeplinkWhitelist
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
onShouldStartLoadWithRequest({
|
|
167
|
-
nativeEvent: { url: 'https://www.example.com/', lockIdentifier: 1 },
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
await flushPromises();
|
|
171
|
-
|
|
172
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
173
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
174
|
-
true,
|
|
175
|
-
'https://www.example.com/',
|
|
176
|
-
1
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
// Exodus: http:// is in the default blocklist, so it's blocked without Linking.openURL
|
|
180
|
-
onShouldStartLoadWithRequest({
|
|
181
|
-
nativeEvent: { url: 'http://insecure.com/', lockIdentifier: 2 },
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
await flushPromises();
|
|
185
|
-
|
|
186
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
187
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
188
|
-
false,
|
|
189
|
-
'http://insecure.com/',
|
|
190
|
-
2
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
// Exodus: git+https:// is not in the deeplink whitelist, so it's blocked
|
|
194
|
-
onShouldStartLoadWithRequest({
|
|
195
|
-
nativeEvent: { url: 'git+https://insecure.com/', lockIdentifier: 3 },
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
await flushPromises();
|
|
199
|
-
|
|
200
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
201
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
202
|
-
false,
|
|
203
|
-
'git+https://insecure.com/',
|
|
204
|
-
3
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
// Exodus: fakehttps:// is not in the deeplink whitelist, so it's blocked
|
|
208
|
-
onShouldStartLoadWithRequest({
|
|
209
|
-
nativeEvent: { url: 'fakehttps://insecure.com/', lockIdentifier: 4 },
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
await flushPromises();
|
|
213
|
-
|
|
214
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
215
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
216
|
-
false,
|
|
217
|
-
'fakehttps://insecure.com/',
|
|
218
|
-
4
|
|
219
|
-
);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test('loadRequest allows for valid URIs matching origin whitelist', async () => {
|
|
223
|
-
// Exodus: Use lowercase schemes since URL API normalizes scheme to lowercase
|
|
224
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
225
|
-
loadRequest,
|
|
226
|
-
[
|
|
227
|
-
'plus+https://*',
|
|
228
|
-
'dot.https://*',
|
|
229
|
-
'dash-https://*',
|
|
230
|
-
],
|
|
231
|
-
defaultDeeplinkWhitelist
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
onShouldStartLoadWithRequest({
|
|
235
|
-
nativeEvent: {
|
|
236
|
-
url: 'plus+https://www.example.com/',
|
|
237
|
-
lockIdentifier: 1,
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
await flushPromises();
|
|
242
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
243
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
244
|
-
true,
|
|
245
|
-
'plus+https://www.example.com/',
|
|
246
|
-
1
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
onShouldStartLoadWithRequest({
|
|
250
|
-
nativeEvent: { url: 'dot.https://www.example.com/', lockIdentifier: 2 },
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
await flushPromises();
|
|
254
|
-
|
|
255
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
256
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
257
|
-
true,
|
|
258
|
-
'dot.https://www.example.com/',
|
|
259
|
-
2
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
onShouldStartLoadWithRequest({
|
|
263
|
-
nativeEvent: {
|
|
264
|
-
url: 'dash-https://www.example.com/',
|
|
265
|
-
lockIdentifier: 3,
|
|
266
|
-
},
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
await flushPromises();
|
|
270
|
-
|
|
271
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
272
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
273
|
-
true,
|
|
274
|
-
'dash-https://www.example.com/',
|
|
275
|
-
3
|
|
276
|
-
);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
test('non-whitelisted protocols are blocked without Linking.openURL', async () => {
|
|
280
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
281
|
-
loadRequest,
|
|
282
|
-
['https://*'],
|
|
283
|
-
defaultDeeplinkWhitelist
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
// Exodus: non-whitelisted protocols are blocked, not opened via Linking
|
|
287
|
-
onShouldStartLoadWithRequest({
|
|
288
|
-
nativeEvent: { url: '0invalid://www.example.com/', lockIdentifier: 1 },
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
await flushPromises();
|
|
292
|
-
|
|
293
|
-
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
294
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
295
|
-
false,
|
|
296
|
-
'0invalid://www.example.com/',
|
|
297
|
-
1
|
|
298
|
-
);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import validateProps from '../validation';
|
|
2
|
-
|
|
3
|
-
describe('validateProps', () => {
|
|
4
|
-
test('throws when providing static html without origin whitelist', () => {
|
|
5
|
-
expect(() => {
|
|
6
|
-
validateProps({
|
|
7
|
-
source: { html: '<h1>Wayne Foundation</h1>' },
|
|
8
|
-
});
|
|
9
|
-
}).toThrow('originWhitelist');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('throws when providing static html with wildcard whitelist', () => {
|
|
13
|
-
expect(() => {
|
|
14
|
-
validateProps({
|
|
15
|
-
originWhitelist: ['*', 'http://localhost'],
|
|
16
|
-
source: { html: '<h1>Wayne Foundation</h1>' },
|
|
17
|
-
});
|
|
18
|
-
}).toThrow('originWhitelist');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('throws when providing static html with empty whitelist', () => {
|
|
22
|
-
expect(() => {
|
|
23
|
-
validateProps({
|
|
24
|
-
originWhitelist: [],
|
|
25
|
-
source: { html: '<h1>Wayne Foundation</h1>' },
|
|
26
|
-
});
|
|
27
|
-
}).toThrow('originWhitelist');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('returns props when origin whitelist present', () => {
|
|
31
|
-
const props = {
|
|
32
|
-
originWhitelist: ['http://localhost'],
|
|
33
|
-
source: { html: '<h1>Wayne Foundation</h1>' },
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
expect(validateProps(props)).toBe(props);
|
|
37
|
-
});
|
|
38
|
-
});
|