added URLRequestAttribution, added URLRequest attribution and assumesHTTP3Capable properties for iOS
This commit is contained in:
parent
01d16eed91
commit
26ddf0cef9
|
@ -53,6 +53,8 @@ public class URLRequest {
|
||||||
urlRequestMap.put("networkServiceType", null);
|
urlRequestMap.put("networkServiceType", null);
|
||||||
urlRequestMap.put("timeoutInterval", null);
|
urlRequestMap.put("timeoutInterval", null);
|
||||||
urlRequestMap.put("mainDocumentURL", null);
|
urlRequestMap.put("mainDocumentURL", null);
|
||||||
|
urlRequestMap.put("assumesHTTP3Capable", null);
|
||||||
|
urlRequestMap.put("attribution", null);
|
||||||
return urlRequestMap;
|
return urlRequestMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,41 +26,56 @@ extension URLRequest {
|
||||||
setValue(value, forHTTPHeaderField: key)
|
setValue(value, forHTTPHeaderField: key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let iosAllowsCellularAccess = fromPluginMap["allowsCellularAccess"] as? Bool {
|
if let _allowsCellularAccess = fromPluginMap["allowsCellularAccess"] as? Bool {
|
||||||
allowsCellularAccess = iosAllowsCellularAccess
|
allowsCellularAccess = _allowsCellularAccess
|
||||||
}
|
}
|
||||||
if #available(iOS 13.0, *), let iosAllowsConstrainedNetworkAccess = fromPluginMap["allowsConstrainedNetworkAccess"] as? Bool {
|
if #available(iOS 13.0, *), let _allowsConstrainedNetworkAccess = fromPluginMap["allowsConstrainedNetworkAccess"] as? Bool {
|
||||||
allowsConstrainedNetworkAccess = iosAllowsConstrainedNetworkAccess
|
allowsConstrainedNetworkAccess = _allowsConstrainedNetworkAccess
|
||||||
}
|
}
|
||||||
if #available(iOS 13.0, *), let iosAllowsExpensiveNetworkAccess = fromPluginMap["allowsExpensiveNetworkAccess"] as? Bool {
|
if #available(iOS 13.0, *), let _allowsExpensiveNetworkAccess = fromPluginMap["allowsExpensiveNetworkAccess"] as? Bool {
|
||||||
allowsExpensiveNetworkAccess = iosAllowsExpensiveNetworkAccess
|
allowsExpensiveNetworkAccess = _allowsExpensiveNetworkAccess
|
||||||
}
|
}
|
||||||
if let iosCachePolicy = fromPluginMap["cachePolicy"] as? Int {
|
if let _cachePolicy = fromPluginMap["cachePolicy"] as? Int {
|
||||||
cachePolicy = CachePolicy.init(rawValue: UInt(iosCachePolicy)) ?? .useProtocolCachePolicy
|
cachePolicy = CachePolicy.init(rawValue: UInt(_cachePolicy)) ?? .useProtocolCachePolicy
|
||||||
}
|
}
|
||||||
if let iosHttpShouldHandleCookies = fromPluginMap["httpShouldHandleCookies"] as? Bool {
|
if let _httpShouldHandleCookies = fromPluginMap["httpShouldHandleCookies"] as? Bool {
|
||||||
httpShouldHandleCookies = iosHttpShouldHandleCookies
|
httpShouldHandleCookies = _httpShouldHandleCookies
|
||||||
}
|
}
|
||||||
if let iosHttpShouldUsePipelining = fromPluginMap["httpShouldUsePipelining"] as? Bool {
|
if let _httpShouldUsePipelining = fromPluginMap["httpShouldUsePipelining"] as? Bool {
|
||||||
httpShouldUsePipelining = iosHttpShouldUsePipelining
|
httpShouldUsePipelining = _httpShouldUsePipelining
|
||||||
}
|
}
|
||||||
if let iosNetworkServiceType = fromPluginMap["networkServiceType"] as? Int {
|
if let _networkServiceType = fromPluginMap["networkServiceType"] as? Int {
|
||||||
networkServiceType = NetworkServiceType.init(rawValue: UInt(iosNetworkServiceType)) ?? .default
|
networkServiceType = NetworkServiceType.init(rawValue: UInt(_networkServiceType)) ?? .default
|
||||||
}
|
}
|
||||||
if let iosTimeoutInterval = fromPluginMap["timeoutInterval"] as? Double {
|
if let _timeoutInterval = fromPluginMap["timeoutInterval"] as? Double {
|
||||||
timeoutInterval = iosTimeoutInterval
|
timeoutInterval = _timeoutInterval
|
||||||
}
|
}
|
||||||
if let iosMainDocumentURL = fromPluginMap["mainDocumentURL"] as? String {
|
if let _mainDocumentURL = fromPluginMap["mainDocumentURL"] as? String {
|
||||||
mainDocumentURL = URL(string: iosMainDocumentURL)!
|
mainDocumentURL = URL(string: _mainDocumentURL)!
|
||||||
|
}
|
||||||
|
if #available(iOS 14.5, *), let _assumesHTTP3Capable = fromPluginMap["assumesHTTP3Capable"] as? Bool {
|
||||||
|
assumesHTTP3Capable = _assumesHTTP3Capable
|
||||||
|
}
|
||||||
|
if #available(iOS 15.0, *), let attributionRawValue = fromPluginMap["attribution"] as? UInt,
|
||||||
|
let _attribution = URLRequest.Attribution(rawValue: attributionRawValue) {
|
||||||
|
attribution = _attribution
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func toMap () -> [String:Any?] {
|
public func toMap () -> [String:Any?] {
|
||||||
var iosAllowsConstrainedNetworkAccess: Bool? = nil
|
var _allowsConstrainedNetworkAccess: Bool? = nil
|
||||||
var iosAllowsExpensiveNetworkAccess: Bool? = nil
|
var _allowsExpensiveNetworkAccess: Bool? = nil
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
iosAllowsConstrainedNetworkAccess = allowsConstrainedNetworkAccess
|
_allowsConstrainedNetworkAccess = allowsConstrainedNetworkAccess
|
||||||
iosAllowsExpensiveNetworkAccess = allowsExpensiveNetworkAccess
|
_allowsExpensiveNetworkAccess = allowsExpensiveNetworkAccess
|
||||||
|
}
|
||||||
|
var _assumesHTTP3Capable: Bool? = nil
|
||||||
|
if #available(iOS 14.5, *) {
|
||||||
|
_assumesHTTP3Capable = assumesHTTP3Capable
|
||||||
|
}
|
||||||
|
var _attribution: UInt? = nil
|
||||||
|
if #available(iOS 15.0, *) {
|
||||||
|
_attribution = attribution.rawValue
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
"url": url?.absoluteString,
|
"url": url?.absoluteString,
|
||||||
|
@ -68,14 +83,16 @@ extension URLRequest {
|
||||||
"headers": allHTTPHeaderFields,
|
"headers": allHTTPHeaderFields,
|
||||||
"body": httpBody.map(FlutterStandardTypedData.init(bytes:)),
|
"body": httpBody.map(FlutterStandardTypedData.init(bytes:)),
|
||||||
"allowsCellularAccess": allowsCellularAccess,
|
"allowsCellularAccess": allowsCellularAccess,
|
||||||
"allowsConstrainedNetworkAccess": iosAllowsConstrainedNetworkAccess,
|
"allowsConstrainedNetworkAccess": _allowsConstrainedNetworkAccess,
|
||||||
"allowsExpensiveNetworkAccess": iosAllowsExpensiveNetworkAccess,
|
"allowsExpensiveNetworkAccess": _allowsExpensiveNetworkAccess,
|
||||||
"cachePolicy": cachePolicy.rawValue,
|
"cachePolicy": cachePolicy.rawValue,
|
||||||
"httpShouldHandleCookies": httpShouldHandleCookies,
|
"httpShouldHandleCookies": httpShouldHandleCookies,
|
||||||
"httpShouldUsePipelining": httpShouldUsePipelining,
|
"httpShouldUsePipelining": httpShouldUsePipelining,
|
||||||
"networkServiceType": networkServiceType.rawValue,
|
"networkServiceType": networkServiceType.rawValue,
|
||||||
"timeoutInterval": timeoutInterval,
|
"timeoutInterval": timeoutInterval,
|
||||||
"mainDocumentURL": mainDocumentURL?.absoluteString
|
"mainDocumentURL": mainDocumentURL?.absoluteString,
|
||||||
|
"assumesHTTP3Capable": _assumesHTTP3Capable,
|
||||||
|
"attribution": _attribution
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,4 +147,5 @@ export 'web_resource_error_type.dart';
|
||||||
export 'media_capture_state.dart';
|
export 'media_capture_state.dart';
|
||||||
export 'proxy_rule.dart';
|
export 'proxy_rule.dart';
|
||||||
export 'proxy_scheme_filter.dart';
|
export 'proxy_scheme_filter.dart';
|
||||||
export 'force_dark_strategy.dart';
|
export 'force_dark_strategy.dart';
|
||||||
|
export 'url_request_attribution.dart';
|
|
@ -1,4 +1,6 @@
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
import 'package:flutter_inappwebview/src/types/url_request_attribution.dart';
|
||||||
|
|
||||||
import 'url_request_cache_policy.dart';
|
import 'url_request_cache_policy.dart';
|
||||||
import 'url_request_network_service_type.dart';
|
import 'url_request_network_service_type.dart';
|
||||||
|
|
||||||
|
@ -100,6 +102,20 @@ class URLRequest {
|
||||||
///**NOTE**: available only on iOS.
|
///**NOTE**: available only on iOS.
|
||||||
Uri? mainDocumentURL;
|
Uri? mainDocumentURL;
|
||||||
|
|
||||||
|
///`true` if server endpoint is known to support HTTP/3. Enables QUIC racing
|
||||||
|
///without HTTP/3 service discovery. Defaults to `false`.
|
||||||
|
///The default may be `true` in a future OS update.
|
||||||
|
///
|
||||||
|
///**NOTE**: available only on iOS 14.5+.
|
||||||
|
bool? assumesHTTP3Capable;
|
||||||
|
|
||||||
|
///The entities that can make a network request.
|
||||||
|
///
|
||||||
|
///If you don’t set a value, the system assumes [URLRequestAttribution.DEVELOPER].
|
||||||
|
///
|
||||||
|
///**NOTE**: available only on iOS 15.0+.
|
||||||
|
URLRequestAttribution? attribution;
|
||||||
|
|
||||||
URLRequest({
|
URLRequest({
|
||||||
required this.url,
|
required this.url,
|
||||||
this.method,
|
this.method,
|
||||||
|
@ -128,6 +144,8 @@ class URLRequest {
|
||||||
this.timeoutInterval,
|
this.timeoutInterval,
|
||||||
@Deprecated("Use mainDocumentURL instead") this.iosMainDocumentURL,
|
@Deprecated("Use mainDocumentURL instead") this.iosMainDocumentURL,
|
||||||
this.mainDocumentURL,
|
this.mainDocumentURL,
|
||||||
|
this.assumesHTTP3Capable,
|
||||||
|
this.attribution
|
||||||
}) {
|
}) {
|
||||||
this.allowsCellularAccess =
|
this.allowsCellularAccess =
|
||||||
// ignore: deprecated_member_use_from_same_package
|
// ignore: deprecated_member_use_from_same_package
|
||||||
|
@ -201,6 +219,8 @@ class URLRequest {
|
||||||
mainDocumentURL: map["mainDocumentURL"] != null
|
mainDocumentURL: map["mainDocumentURL"] != null
|
||||||
? Uri.parse(map["mainDocumentURL"])
|
? Uri.parse(map["mainDocumentURL"])
|
||||||
: null,
|
: null,
|
||||||
|
assumesHTTP3Capable: map["assumesHTTP3Capable"],
|
||||||
|
attribution: URLRequestAttribution.fromValue(map["attribution"])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +278,8 @@ class URLRequest {
|
||||||
"iosMainDocumentURL": (mainDocumentURL ?? iosMainDocumentURL)?.toString(),
|
"iosMainDocumentURL": (mainDocumentURL ?? iosMainDocumentURL)?.toString(),
|
||||||
// ignore: deprecated_member_use_from_same_package
|
// ignore: deprecated_member_use_from_same_package
|
||||||
"mainDocumentURL": (mainDocumentURL ?? iosMainDocumentURL)?.toString(),
|
"mainDocumentURL": (mainDocumentURL ?? iosMainDocumentURL)?.toString(),
|
||||||
|
"assumesHTTP3Capable": assumesHTTP3Capable,
|
||||||
|
"attribution": attribution?.toValue(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
import 'url_request.dart';
|
||||||
|
|
||||||
|
///Class that represents the constants used to indicate the entities that can make a network request.
|
||||||
|
class URLRequestAttribution {
|
||||||
|
final int _value;
|
||||||
|
|
||||||
|
const URLRequestAttribution._internal(this._value);
|
||||||
|
|
||||||
|
///Set of all values of [URLRequestAttribution].
|
||||||
|
static final Set<URLRequestAttribution> values = [
|
||||||
|
URLRequestAttribution.DEVELOPER,
|
||||||
|
URLRequestAttribution.USER,
|
||||||
|
].toSet();
|
||||||
|
|
||||||
|
///Gets a possible [URLRequestAttribution] instance from an [int] value.
|
||||||
|
static URLRequestAttribution? fromValue(int? value) {
|
||||||
|
if (value != null) {
|
||||||
|
try {
|
||||||
|
return URLRequestAttribution.values
|
||||||
|
.firstWhere((element) => element.toValue() == value);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
///Gets [int] value.
|
||||||
|
int toValue() => _value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
switch (_value) {
|
||||||
|
case 1:
|
||||||
|
return "USER";
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
return "DEVELOPER";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///A developer-initiated network request.
|
||||||
|
///
|
||||||
|
///Use this value for the attribution parameter of a [URLRequest] that your app makes for any purpose other than when the user explicitly accesses a link.
|
||||||
|
///This includes requests that your app makes to get user data. This is the default value.
|
||||||
|
///
|
||||||
|
///For cases where the user enters a URL, like in the navigation bar of a web browser, or taps or clicks a URL to load the content it represents, use the [URLRequestAttribution.USER] value instead.
|
||||||
|
static const DEVELOPER =
|
||||||
|
const URLRequestAttribution._internal(0);
|
||||||
|
|
||||||
|
///Use this value for the attribution parameter of a [URLRequest] that satisfies a user request to access an explicit, unmodified URL.
|
||||||
|
///In all other cases, use the [URLRequestAttribution.DEVELOPER] value instead.
|
||||||
|
static const USER =
|
||||||
|
const URLRequestAttribution._internal(1);
|
||||||
|
|
||||||
|
bool operator ==(value) => value == _value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => _value.hashCode;
|
||||||
|
}
|
Loading…
Reference in New Issue