Skip to content

Commit 8d098ef

Browse files
feat(iOS & MacOS): allowUniversalAccessFromFileURLs property(react-native-webview#1730)
* Added allowUniversalAccessFromFileURLs property to iOS and macOS Updated the types to include allowUniversalAccessFromFileURLs and allowFileAccessFromFileURLs for iOS and macOS Updated the Reference.md to include in the allowUniversalAccessFromFileURLs section iOS and macOS * Updated platform in the type definition
1 parent b2f9ed2 commit 8d098ef

5 files changed

Lines changed: 44 additions & 3 deletions

File tree

apple/RNCWebView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
@property (nonatomic, assign) BOOL javaScriptEnabled;
5858
@property (nonatomic, assign) BOOL javaScriptCanOpenWindowsAutomatically;
5959
@property (nonatomic, assign) BOOL allowFileAccessFromFileURLs;
60+
@property (nonatomic, assign) BOOL allowUniversalAccessFromFileURLs;
6061
@property (nonatomic, assign) BOOL allowsLinkPreview;
6162
@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
6263
@property (nonatomic, assign) BOOL showsVerticalScrollIndicator;

apple/RNCWebView.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
213213
prefs.javaScriptEnabled = NO;
214214
_prefsUsed = YES;
215215
}
216+
if (_allowUniversalAccessFromFileURLs) {
217+
[wkWebViewConfig setValue:@TRUE forKey:@"allowUniversalAccessFromFileURLs"];
218+
}
216219
if (_allowFileAccessFromFileURLs) {
217220
[prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
218221
_prefsUsed = YES;

apple/RNCWebViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ - (RCTUIView *)view
5959
RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
6060
RCT_EXPORT_VIEW_PROPERTY(javaScriptCanOpenWindowsAutomatically, BOOL)
6161
RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
62+
RCT_EXPORT_VIEW_PROPERTY(allowUniversalAccessFromFileURLs, BOOL)
6263
RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
6364
RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
6465
#if WEBKIT_IOS_10_APIS_AVAILABLE

docs/Reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,9 @@ Boolean that sets whether JavaScript running in the context of a file scheme URL
10921092

10931093
Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin. Including accessing content from other file scheme URLs. The default value is `false`.
10941094

1095-
| Type | Required | Platform |
1096-
| ---- | -------- | -------- |
1097-
| bool | No | Android |
1095+
| Type | Required | Platform |
1096+
| ---- | -------- | -------------------- |
1097+
| bool | No | iOS, Android, macOS |
10981098

10991099
---
11001100

src/WebViewTypes.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
313313
allowsBackForwardNavigationGestures?: boolean;
314314
allowsInlineMediaPlayback?: boolean;
315315
allowsLinkPreview?: boolean;
316+
allowFileAccessFromFileURLs?: boolean;
317+
allowUniversalAccessFromFileURLs?: boolean;
316318
automaticallyAdjustContentInsets?: boolean;
317319
autoManageStatusBarEnabled?: boolean;
318320
bounces?: boolean;
@@ -334,6 +336,8 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
334336

335337
export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
336338
allowingReadAccessToURL?: string;
339+
allowFileAccessFromFileURLs?: boolean;
340+
allowUniversalAccessFromFileURLs?: boolean;
337341
allowsBackForwardNavigationGestures?: boolean;
338342
allowsInlineMediaPlayback?: boolean;
339343
allowsLinkPreview?: boolean;
@@ -548,6 +552,22 @@ export interface IOSWebViewProps extends WebViewSharedProps {
548552
*/
549553
allowingReadAccessToURL?: string;
550554

555+
/**
556+
* Boolean that sets whether JavaScript running in the context of a file
557+
* scheme URL should be allowed to access content from other file scheme URLs.
558+
* Including accessing content from other file scheme URLs
559+
* @platform ios
560+
*/
561+
allowFileAccessFromFileURLs?: boolean;
562+
563+
/**
564+
* Boolean that sets whether JavaScript running in the context of a file
565+
* scheme URL should be allowed to access content from any origin.
566+
* Including accessing content from other file scheme URLs
567+
* @platform ios
568+
*/
569+
allowUniversalAccessFromFileURLs?: boolean;
570+
551571
/**
552572
* Function that is invoked when the WebKit WebView content process gets terminated.
553573
* @platform ios
@@ -726,6 +746,22 @@ export interface MacOSWebViewProps extends WebViewSharedProps {
726746
*/
727747
allowingReadAccessToURL?: string;
728748

749+
/**
750+
* Boolean that sets whether JavaScript running in the context of a file
751+
* scheme URL should be allowed to access content from other file scheme URLs.
752+
* Including accessing content from other file scheme URLs
753+
* @platform macos
754+
*/
755+
allowFileAccessFromFileURLs?: boolean;
756+
757+
/**
758+
* Boolean that sets whether JavaScript running in the context of a file
759+
* scheme URL should be allowed to access content from any origin.
760+
* Including accessing content from other file scheme URLs
761+
* @platform macos
762+
*/
763+
allowUniversalAccessFromFileURLs?: boolean;
764+
729765
/**
730766
* Function that is invoked when the WebKit WebView content process gets terminated.
731767
* @platform macos

0 commit comments

Comments
 (0)