From 7159069879af1fd8073b0bb6465bd368d15a098c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=84=B6=E8=B1=AA=28LiRanHao=29-=E9=A1=BA?= =?UTF-8?q?=E4=B8=B0=E7=A7=91=E6=8A=80?= Date: Tue, 26 Jan 2021 19:46:33 +0800 Subject: [PATCH 1/2] Add support allowUniversalAccessFromFileURLs iOS --- ios/Classes/InAppWebView.swift | 2 ++ ios/Classes/InAppWebViewOptions.swift | 2 ++ lib/src/webview_options.dart | 12 ++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ios/Classes/InAppWebView.swift b/ios/Classes/InAppWebView.swift index 264c6fd4e..0e31c4fc6 100755 --- a/ios/Classes/InAppWebView.swift +++ b/ios/Classes/InAppWebView.swift @@ -1371,6 +1371,8 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi configuration.dataDetectorTypes = dataDetectorTypes configuration.mediaTypesRequiringUserActionForPlayback = options.mediaPlaybackRequiresUserGesture ? .all : [] + + configuration.setValue(options.allowUniversalAccessFromFileURLs, forKey: "allowUniversalAccessFromFileURLs") } else { // Fallback on earlier versions configuration.mediaPlaybackRequiresUserAction = options.mediaPlaybackRequiresUserGesture diff --git a/ios/Classes/InAppWebViewOptions.swift b/ios/Classes/InAppWebViewOptions.swift index 7668370a7..b8e739249 100755 --- a/ios/Classes/InAppWebViewOptions.swift +++ b/ios/Classes/InAppWebViewOptions.swift @@ -61,6 +61,8 @@ public class InAppWebViewOptions: Options { var minimumZoomScale = 1.0 var contentInsetAdjustmentBehavior = 2 // UIScrollView.ContentInsetAdjustmentBehavior.never + var allowUniversalAccessFromFileURLs = false; + override init(){ super.init() } diff --git a/lib/src/webview_options.dart b/lib/src/webview_options.dart index 9391de7be..2fbac7667 100755 --- a/lib/src/webview_options.dart +++ b/lib/src/webview_options.dart @@ -832,6 +832,9 @@ class IOSInAppWebViewOptions ///The default value is [IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER]. IOSUIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior; + ///Set to true to support cross-domain. The default value is `false`. + bool allowUniversalAccessFromFileURLs; + IOSInAppWebViewOptions( {this.disallowOverScroll = false, this.enableViewportScale = false, @@ -856,7 +859,8 @@ class IOSInAppWebViewOptions this.maximumZoomScale = 1.0, this.minimumZoomScale = 1.0, this.contentInsetAdjustmentBehavior = - IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER}); + IOSUIScrollViewContentInsetAdjustmentBehavior.NEVER, + this.allowUniversalAccessFromFileURLs = false}); @override Map toMap() { @@ -891,7 +895,9 @@ class IOSInAppWebViewOptions "isPagingEnabled": isPagingEnabled, "maximumZoomScale": maximumZoomScale, "minimumZoomScale": minimumZoomScale, - "contentInsetAdjustmentBehavior": contentInsetAdjustmentBehavior.toValue() + "contentInsetAdjustmentBehavior": + contentInsetAdjustmentBehavior.toValue(), + "allowUniversalAccessFromFileURLs": allowUniversalAccessFromFileURLs }; } @@ -938,6 +944,8 @@ class IOSInAppWebViewOptions options.contentInsetAdjustmentBehavior = IOSUIScrollViewContentInsetAdjustmentBehavior.fromValue( map["contentInsetAdjustmentBehavior"]); + options.allowUniversalAccessFromFileURLs = + map["optioallowUniversalAccessFromFileURLsns"]; return options; } From 500d5e452601675196ded14cea070bb87f6e4df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=84=B6=E8=B1=AA=28LiRanHao=29-=E9=A1=BA?= =?UTF-8?q?=E4=B8=B0=E7=A7=91=E6=8A=80?= Date: Thu, 28 Jan 2021 15:24:55 +0800 Subject: [PATCH 2/2] fix --- lib/src/webview_options.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/webview_options.dart b/lib/src/webview_options.dart index 2fbac7667..f5c75b2f7 100755 --- a/lib/src/webview_options.dart +++ b/lib/src/webview_options.dart @@ -945,7 +945,7 @@ class IOSInAppWebViewOptions IOSUIScrollViewContentInsetAdjustmentBehavior.fromValue( map["contentInsetAdjustmentBehavior"]); options.allowUniversalAccessFromFileURLs = - map["optioallowUniversalAccessFromFileURLsns"]; + map["allowUniversalAccessFromFileURLs"]; return options; }