@capacitor/ios 6.2.1 → 6.2.3
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/Capacitor/Capacitor/CapacitorBridge.swift +3 -2
- package/Capacitor/Capacitor/Codable/JSValueDecoder.swift +4 -4
- package/Capacitor/Capacitor/Codable/JSValueEncoder.swift +0 -1
- package/Capacitor/Capacitor/WebViewAssetHandler.swift +18 -6
- package/Capacitor/Capacitor/WebViewDelegationHandler.swift +6 -0
- package/package.json +1 -1
|
@@ -210,6 +210,7 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
|
|
|
210
210
|
super.init()
|
|
211
211
|
|
|
212
212
|
self.webViewDelegationHandler.bridge = self
|
|
213
|
+
self.webViewAssetHandler.setConfiguration(configuration)
|
|
213
214
|
|
|
214
215
|
exportCoreJS(localUrl: configuration.localURL.absoluteString)
|
|
215
216
|
registerPlugins()
|
|
@@ -492,13 +493,13 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
|
|
|
492
493
|
let pluginCall = CAPPluginCall(callbackId: call.callbackId, methodName: call.method,
|
|
493
494
|
options: JSTypes.coerceDictionaryToJSObject(call.options,
|
|
494
495
|
formattingDatesAsStrings: plugin.shouldStringifyDatesInCalls) ?? [:],
|
|
495
|
-
success: {(result: CAPPluginCallResult?, pluginCall: CAPPluginCall?)
|
|
496
|
+
success: {(result: CAPPluginCallResult?, pluginCall: CAPPluginCall?) in
|
|
496
497
|
if let result = result {
|
|
497
498
|
self?.toJs(result: JSResult(call: call, callResult: result), save: pluginCall?.keepAlive ?? false)
|
|
498
499
|
} else {
|
|
499
500
|
self?.toJs(result: JSResult(call: call, result: .dictionary([:])), save: pluginCall?.keepAlive ?? false)
|
|
500
501
|
}
|
|
501
|
-
}, error: {(error: CAPPluginCallError?)
|
|
502
|
+
}, error: {(error: CAPPluginCallError?) in
|
|
502
503
|
if let error = error {
|
|
503
504
|
self?.toJsError(error: JSResultError(call: call, callError: error))
|
|
504
505
|
} else {
|
|
@@ -146,8 +146,8 @@ extension _JSValueDecoder: Decoder {
|
|
|
146
146
|
return date as! T
|
|
147
147
|
case .formatted(let formatter):
|
|
148
148
|
guard let value = data as? String else { throw DecodingError.dataCorrupted(data, target: String.self, codingPath: codingPath) }
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
guard let date = formatter.date(from: value) else { throw DecodingError.dataCorrupted(value, target: Date.self, codingPath: codingPath) }
|
|
150
|
+
return date as! T
|
|
151
151
|
case .custom(let decode):
|
|
152
152
|
return try decode(self) as! T
|
|
153
153
|
@unknown default:
|
|
@@ -155,7 +155,7 @@ extension _JSValueDecoder: Decoder {
|
|
|
155
155
|
}
|
|
156
156
|
case is URL.Type:
|
|
157
157
|
guard let str = data as? String,
|
|
158
|
-
|
|
158
|
+
let url = URL(string: str)
|
|
159
159
|
else { throw DecodingError.dataCorrupted(data, target: URL.self, codingPath: codingPath) }
|
|
160
160
|
|
|
161
161
|
return url as! T
|
|
@@ -354,7 +354,7 @@ extension SingleValueContainer: SingleValueDecodingContainer {
|
|
|
354
354
|
|
|
355
355
|
private func castFloat<N>(to type: N.Type) throws -> N where N: FloatingPoint {
|
|
356
356
|
if let data = data as? String,
|
|
357
|
-
|
|
357
|
+
case let .convertFromString(positiveInfinity: pos, negativeInfinity: neg, nan: nan) = options.nonConformingStrategy {
|
|
358
358
|
switch data {
|
|
359
359
|
case pos:
|
|
360
360
|
return N.infinity
|
|
@@ -82,7 +82,6 @@ public final class JSValueEncoder: TopLevelEncoder {
|
|
|
82
82
|
self.options = .init(optionalStrategy: optionalEncodingStrategy, dateStrategy: dateEncodingStrategy, dataStrategy: dataEncodingStrategy, nonConformingFloatStrategy: nonConformingFloatEncodingStategy)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
86
85
|
/// Encodes an `Encodable` value to a ``JSValue``
|
|
87
86
|
/// - Parameter value: The value to encode to ``JSValue``
|
|
88
87
|
/// - Returns: The encoded ``JSValue``
|
|
@@ -6,6 +6,7 @@ import MobileCoreServices
|
|
|
6
6
|
open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
7
7
|
private var router: Router
|
|
8
8
|
private var serverUrl: URL?
|
|
9
|
+
private var configuration: InstanceConfiguration?
|
|
9
10
|
|
|
10
11
|
public init(router: Router) {
|
|
11
12
|
self.router = router
|
|
@@ -20,6 +21,10 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
20
21
|
self.serverUrl = serverUrl
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
open func setConfiguration(_ configuration: InstanceConfiguration?) {
|
|
25
|
+
self.configuration = configuration
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
private func isUsingLiveReload(_ localUrl: URL) -> Bool {
|
|
24
29
|
return self.serverUrl != nil && self.serverUrl?.scheme != localUrl.scheme
|
|
25
30
|
}
|
|
@@ -31,7 +36,13 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
31
36
|
let localUrl = URL.init(string: url.absoluteString)!
|
|
32
37
|
|
|
33
38
|
if url.path.starts(with: CapacitorBridge.httpInterceptorStartIdentifier) {
|
|
34
|
-
|
|
39
|
+
// Only serve the proxy when CapacitorHttp is on. A scheme task can't tell a document from
|
|
40
|
+
// a subresource, so keeping documents out relies on the check in decidePolicyFor.
|
|
41
|
+
if configuration?.getPluginConfig("CapacitorHttp").getBoolean("enabled", false) == true {
|
|
42
|
+
handleCapacitorHttpRequest(urlSchemeTask, localUrl, false)
|
|
43
|
+
} else {
|
|
44
|
+
urlSchemeTask.didFailWithError(URLError(.unsupportedURL))
|
|
45
|
+
}
|
|
35
46
|
return
|
|
36
47
|
}
|
|
37
48
|
|
|
@@ -132,7 +143,7 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
132
143
|
func handleCapacitorHttpRequest(_ urlSchemeTask: WKURLSchemeTask, _ localUrl: URL, _ isHttpsRequest: Bool) {
|
|
133
144
|
var urlRequest = urlSchemeTask.request
|
|
134
145
|
guard let url = urlRequest.url else { return }
|
|
135
|
-
|
|
146
|
+
|
|
136
147
|
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
|
|
137
148
|
if let targetUrl = urlComponents?.queryItems?.first(where: { $0.name == CapacitorBridge.httpInterceptorUrlParam })?.value,
|
|
138
149
|
!targetUrl.isEmpty {
|
|
@@ -152,12 +163,13 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
152
163
|
let existingHeaders = response.allHeaderFields
|
|
153
164
|
var newHeaders: [AnyHashable: Any] = [:]
|
|
154
165
|
|
|
166
|
+
// Nothing should render this. If anything does, sandbox keeps it inert.
|
|
167
|
+
newHeaders["Content-Security-Policy"] = "sandbox; frame-ancestors 'none'"
|
|
168
|
+
|
|
155
169
|
// if using live reload, then set CORS headers
|
|
156
170
|
if self.isUsingLiveReload(url) {
|
|
157
|
-
newHeaders =
|
|
158
|
-
|
|
159
|
-
"Access-Control-Allow-Methods": "GET, HEAD, OPTIONS, TRACE"
|
|
160
|
-
]
|
|
171
|
+
newHeaders["Access-Control-Allow-Origin"] = self.serverUrl?.absoluteString ?? ""
|
|
172
|
+
newHeaders["Access-Control-Allow-Methods"] = "GET, HEAD, OPTIONS, TRACE"
|
|
161
173
|
}
|
|
162
174
|
|
|
163
175
|
if let mergedHeaders = existingHeaders.merging(newHeaders, uniquingKeysWith: { (_, newHeaders) in newHeaders }) as? [String: String] {
|
|
@@ -76,6 +76,12 @@ open class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDelegat
|
|
|
76
76
|
return
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// The proxy returns a remote body at the app origin, so block it before plugins can allow it.
|
|
80
|
+
if navURL.path.starts(with: CapacitorBridge.httpInterceptorStartIdentifier) {
|
|
81
|
+
decisionHandler(.cancel)
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
// first, give plugins the chance to handle the decision
|
|
80
86
|
for pluginObject in bridge.plugins {
|
|
81
87
|
let plugin = pluginObject.value
|
package/package.json
CHANGED