@capacitor/ios 9.0.0-rc.0 → 9.0.0

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.
@@ -354,12 +354,6 @@ extension CAPBridgeViewController {
354
354
  if descriptor.warnings.contains(.invalidFile) {
355
355
  CAPLog.print("Unable to parse capacitor.config.json. Make sure it's valid JSON.")
356
356
  }
357
- if descriptor.warnings.contains(.missingCordovaFile) {
358
- CAPLog.print("Unable to find config.xml, make sure it exists and run npx cap copy.")
359
- }
360
- if descriptor.warnings.contains(.invalidCordovaFile) {
361
- CAPLog.print("Unable to parse config.xml. Make sure it's valid XML.")
362
- }
363
357
  }
364
358
  }
365
359
 
@@ -29,7 +29,7 @@ internal extension InstanceDescriptor {
29
29
  // swiftlint:disable cyclomatic_complexity
30
30
  // swiftlint:disable function_body_length
31
31
  // swiftlint:disable:next identifier_name
32
- @objc func _parseConfiguration(at capacitorURL: URL?, cordovaConfiguration cordovaURL: URL?) {
32
+ @objc func _parseConfiguration(at capacitorURL: URL?) {
33
33
  // sanity check that the app directory is valid
34
34
  var isDirectory: ObjCBool = ObjCBool(false)
35
35
  if warnings.contains(.missingAppDir) == false,
@@ -137,6 +137,7 @@ internal extension InstanceDescriptor {
137
137
  }
138
138
 
139
139
  extension InstanceDescriptor {
140
+ @available(*, deprecated, message: "Always false. The Cordova configuration is not read.")
140
141
  @objc public var cordovaDeployDisabled: Bool {
141
142
  return false
142
143
  }
@@ -36,11 +36,31 @@ import WebKit
36
36
  return bridge?.config.getPluginConfig(pluginName) ?? PluginConfig(config: JSObject())
37
37
  }
38
38
 
39
- func notifyListeners(_ eventName: String, data: [String: Any]?) {
39
+ /**
40
+ * Configure popover sourceRect, sourceView and permittedArrowDirections to show it centered
41
+ */
42
+ func setCenteredPopover(_ viewController: UIViewController) {
43
+ guard let hostView = bridge?.viewController?.view else { return }
44
+ viewController.popoverPresentationController?.sourceRect = CGRect(x: hostView.center.x, y: hostView.center.y, width: 0, height: 0)
45
+ viewController.popoverPresentationController?.sourceView = hostView
46
+ viewController.popoverPresentationController?.permittedArrowDirections = []
47
+ }
48
+
49
+ func setCenteredPopover(_ viewController: UIViewController, size: CGSize) {
50
+ guard let hostView = bridge?.viewController?.view else { return }
51
+ viewController.popoverPresentationController?.sourceRect = CGRect(x: hostView.center.x, y: hostView.center.y, width: 0, height: 0)
52
+ viewController.preferredContentSize = size
53
+ viewController.popoverPresentationController?.sourceView = hostView
54
+ viewController.popoverPresentationController?.permittedArrowDirections = []
55
+ }
56
+ }
57
+
58
+ @objc extension CAPPlugin {
59
+ open func notifyListeners(_ eventName: String, data: [String: Any]?) {
40
60
  notifyListeners(eventName, data: data, retainUntilConsumed: false)
41
61
  }
42
62
 
43
- func notifyListeners(_ eventName: String, data: [String: Any]?, retainUntilConsumed retain: Bool) {
63
+ open func notifyListeners(_ eventName: String, data: [String: Any]?, retainUntilConsumed retain: Bool) {
44
64
  guard let listenersForEvent = eventListeners?.object(forKey: eventName) as? NSArray,
45
65
  listenersForEvent.count > 0 else {
46
66
  if retain, let data = data {
@@ -61,7 +81,7 @@ import WebKit
61
81
  }
62
82
  }
63
83
 
64
- func removeListener(_ call: CAPPluginCall) {
84
+ open func removeListener(_ call: CAPPluginCall) {
65
85
  guard let eventName = call.options["eventName"] as? String,
66
86
  let callbackId = call.options["callbackId"] as? String else { return }
67
87
  if let storedCall = bridge?.savedCall(withID: callbackId) {
@@ -70,31 +90,11 @@ import WebKit
70
90
  bridge?.releaseCall(withID: callbackId)
71
91
  }
72
92
 
73
- func removeAllListeners(_ call: CAPPluginCall) {
93
+ open func removeAllListeners(_ call: CAPPluginCall) {
74
94
  eventListeners?.removeAllObjects()
75
95
  call.resolve()
76
96
  }
77
97
 
78
- /**
79
- * Configure popover sourceRect, sourceView and permittedArrowDirections to show it centered
80
- */
81
- func setCenteredPopover(_ viewController: UIViewController) {
82
- guard let hostView = bridge?.viewController?.view else { return }
83
- viewController.popoverPresentationController?.sourceRect = CGRect(x: hostView.center.x, y: hostView.center.y, width: 0, height: 0)
84
- viewController.popoverPresentationController?.sourceView = hostView
85
- viewController.popoverPresentationController?.permittedArrowDirections = []
86
- }
87
-
88
- func setCenteredPopover(_ viewController: UIViewController, size: CGSize) {
89
- guard let hostView = bridge?.viewController?.view else { return }
90
- viewController.popoverPresentationController?.sourceRect = CGRect(x: hostView.center.x, y: hostView.center.y, width: 0, height: 0)
91
- viewController.preferredContentSize = size
92
- viewController.popoverPresentationController?.sourceView = hostView
93
- viewController.popoverPresentationController?.permittedArrowDirections = []
94
- }
95
- }
96
-
97
- @objc extension CAPPlugin {
98
98
  /**
99
99
  * Default implementation of the capacitor 3.0 permission pattern
100
100
  */
@@ -92,6 +92,12 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
92
92
  public static let fileStartIdentifier = "/_capacitor_file_"
93
93
  public static let httpInterceptorStartIdentifier = "/_capacitor_http_interceptor_"
94
94
  public static let httpInterceptorUrlParam = "u"
95
+
96
+ /// Whether `path` addresses one of the bridge's internal proxy routes (local files or the HTTP proxy).
97
+ /// These are served at the app's own origin, so they must never be loaded as a document.
98
+ public static func isInternalProxyPath(_ path: String) -> Bool {
99
+ return path.starts(with: fileStartIdentifier) || path.starts(with: httpInterceptorStartIdentifier)
100
+ }
95
101
  public static let defaultScheme = "capacitor"
96
102
 
97
103
  public private(set) var webViewAssetHandler: WebViewAssetHandler
@@ -30,7 +30,6 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
30
30
  }
31
31
 
32
32
  open func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
33
- let startPath: String
34
33
  let url = urlSchemeTask.request.url!
35
34
  let stringToLoad = url.path
36
35
  let localUrl = URL.init(string: url.absoluteString)!
@@ -46,10 +45,9 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
46
45
  return
47
46
  }
48
47
 
49
- if stringToLoad.starts(with: CapacitorBridge.fileStartIdentifier) {
50
- startPath = stringToLoad.replacingOccurrences(of: CapacitorBridge.fileStartIdentifier, with: "")
51
- } else {
52
- startPath = router.route(for: stringToLoad)
48
+ guard let startPath = startPath(for: stringToLoad) else {
49
+ urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
50
+ return
53
51
  }
54
52
 
55
53
  let fileUrl = URL.init(fileURLWithPath: startPath)
@@ -62,6 +60,8 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
62
60
  "Cache-Control": "no-cache"
63
61
  ]
64
62
 
63
+ headers.merge(securityHeaders(forPath: stringToLoad)) { _, new in new }
64
+
65
65
  // if using live reload, then set CORS headers
66
66
  if isUsingLiveReload(localUrl) {
67
67
  headers["Access-Control-Allow-Origin"] = self.serverUrl?.absoluteString
@@ -111,6 +111,27 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
111
111
  urlSchemeTask.didFinish()
112
112
  }
113
113
 
114
+ /// The file to serve for a request path, or nil if the path must not be served.
115
+ /// `URL.path` decodes `%2F`, so an encoded slash can carry `..` segments the web view did not
116
+ /// resolve. Joined to the base path they would leave it and serve any file the app can read.
117
+ private func startPath(for path: String) -> String? {
118
+ if path.starts(with: CapacitorBridge.fileStartIdentifier) {
119
+ return path.replacingOccurrences(of: CapacitorBridge.fileStartIdentifier, with: "")
120
+ }
121
+ if path.split(separator: "/").contains("..") {
122
+ return nil
123
+ }
124
+ return router.route(for: path)
125
+ }
126
+
127
+ /// A proxied file that is ever rendered as a document must stay inert and unframeable.
128
+ private func securityHeaders(forPath path: String) -> [String: String] {
129
+ guard path.starts(with: CapacitorBridge.fileStartIdentifier) else {
130
+ return [:]
131
+ }
132
+ return ["Content-Security-Policy": "sandbox; frame-ancestors 'none'"]
133
+ }
134
+
114
135
  open func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
115
136
  urlSchemeTask.stopped = true
116
137
  }
@@ -160,7 +181,10 @@ open class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
160
181
  }
161
182
 
162
183
  if let response = response as? HTTPURLResponse {
163
- let existingHeaders = response.allHeaderFields
184
+ // The target's CORS grant is not forwarded, so another origin cannot read the proxied response.
185
+ let existingHeaders = response.allHeaderFields.filter {
186
+ ($0.key as? String)?.caseInsensitiveCompare("Access-Control-Allow-Origin") != .orderedSame
187
+ }
164
188
  var newHeaders: [AnyHashable: Any] = [:]
165
189
 
166
190
  // Nothing should render this. If anything does, sandbox keeps it inert.
@@ -74,8 +74,8 @@ open class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDelegat
74
74
  return
75
75
  }
76
76
 
77
- // The proxy returns a remote body at the app origin, so block it before plugins can allow it.
78
- if navURL.path.starts(with: CapacitorBridge.httpInterceptorStartIdentifier) {
77
+ // The proxy routes return remote or local content at the app origin, so block them before plugins can allow it.
78
+ if CapacitorBridge.isInternalProxyPath(navURL.path) {
79
79
  decisionHandler(.cancel)
80
80
  return
81
81
  }
@@ -882,11 +882,24 @@ var nativeBridge = (function (exports) {
882
882
  try {
883
883
  if (typeof postToNative === 'function') {
884
884
  let callbackId = '-1';
885
- if (storedCallback &&
885
+ // native never answers removeListener nor sends `save: false` for a removed listener,
886
+ // so release those callbacks here, otherwise everything they capture is never freed
887
+ if (methodName === 'removeListener') {
888
+ callbacks.delete(options === null || options === void 0 ? void 0 : options.callbackId);
889
+ }
890
+ else if (methodName === 'removeAllListeners') {
891
+ callbacks.forEach((stored, id) => {
892
+ if (stored.pluginName === pluginName && stored.methodName === 'addListener') {
893
+ callbacks.delete(id);
894
+ }
895
+ });
896
+ }
897
+ if (methodName !== 'removeListener' &&
898
+ storedCallback &&
886
899
  (typeof storedCallback.callback === 'function' || typeof storedCallback.resolve === 'function')) {
887
900
  // store the call for later lookup
888
901
  callbackId = String(++callbackIdCount);
889
- callbacks.set(callbackId, storedCallback);
902
+ callbacks.set(callbackId, Object.assign(Object.assign({}, storedCallback), { pluginName, methodName }));
890
903
  }
891
904
  const callData = {
892
905
  callbackId: callbackId,
@@ -5,7 +5,6 @@
5
5
  // circular dependency. Declared locally rather than in the header so Swift doesn't see a
6
6
  // redeclaration.
7
7
  @interface CAPInstanceDescriptor (SwiftVended)
8
- @property (nonatomic, readonly) BOOL cordovaDeployDisabled;
9
8
  - (void)normalize;
10
9
  @end
11
10
 
@@ -58,8 +57,6 @@
58
57
  _serverURL = _localURL;
59
58
  }
60
59
  _errorPath = descriptor.errorPath;
61
- // extract the one value we care about from the cordova configuration
62
- _cordovaDeployDisabled = [descriptor cordovaDeployDisabled];
63
60
  }
64
61
  return self;
65
62
  }
@@ -81,7 +78,6 @@
81
78
  _handleApplicationNotifications = configuration.handleApplicationNotifications;
82
79
  _isWebDebuggable = configuration.isWebDebuggable;
83
80
  _hasInitialFocus = configuration.hasInitialFocus;
84
- _cordovaDeployDisabled = configuration.cordovaDeployDisabled;
85
81
  _contentInsetAdjustmentBehavior = configuration.contentInsetAdjustmentBehavior;
86
82
  // we don't care about internal usage of deprecated APIs and the framework should build cleanly
87
83
  #pragma clang diagnostic push
@@ -3,7 +3,7 @@
3
3
  // Swift extensions marked as @objc and internal are available to the Obj-C runtime but are not available at compile time.
4
4
  // so we need this declaration to avoid compiler complaints
5
5
  @interface CAPInstanceDescriptor (InternalSwiftExtension)
6
- - (void)_parseConfigurationAt:(NSURL *)configURL cordovaConfiguration:(NSURL *)cordovaURL;
6
+ - (void)_parseConfigurationAt:(NSURL *)configURL;
7
7
  @end
8
8
 
9
9
  NSString* const CAPInstanceDescriptorDefaultScheme = @"capacitor";
@@ -14,7 +14,16 @@ NSString* const CAPInstanceDescriptorDefaultHostname = @"localhost";
14
14
  if (self = [super init]) {
15
15
  _instanceType = CAPInstanceTypeFixed;
16
16
  [self _setDefaultsWithAppLocation:[[NSBundle mainBundle] URLForResource:@"public" withExtension:nil]];
17
- [self _parseConfigurationAt:[[NSBundle mainBundle] URLForResource:@"capacitor.config" withExtension:@"json"] cordovaConfiguration:[[NSBundle mainBundle] URLForResource:@"config" withExtension:@"xml"]];
17
+ [self _parseConfigurationAt:[[NSBundle mainBundle] URLForResource:@"capacitor.config" withExtension:@"json"]];
18
+ }
19
+ return self;
20
+ }
21
+
22
+ - (instancetype)initAtLocation:(NSURL*)appURL configuration:(NSURL*)configURL {
23
+ if (self = [super init]) {
24
+ _instanceType = CAPInstanceTypeVariable;
25
+ [self _setDefaultsWithAppLocation:appURL];
26
+ [self _parseConfigurationAt:configURL];
18
27
  }
19
28
  return self;
20
29
  }
@@ -23,7 +32,7 @@ NSString* const CAPInstanceDescriptorDefaultHostname = @"localhost";
23
32
  if (self = [super init]) {
24
33
  _instanceType = CAPInstanceTypeVariable;
25
34
  [self _setDefaultsWithAppLocation:appURL];
26
- [self _parseConfigurationAt:configURL cordovaConfiguration:cordovaURL];
35
+ [self _parseConfigurationAt:configURL];
27
36
  }
28
37
  return self;
29
38
  }
@@ -22,7 +22,7 @@ NS_SWIFT_NAME(InstanceConfiguration)
22
22
  @property (nonatomic, readonly) BOOL handleApplicationNotifications;
23
23
  @property (nonatomic, readonly) BOOL isWebDebuggable;
24
24
  @property (nonatomic, readonly) BOOL hasInitialFocus;
25
- @property (nonatomic, readonly) BOOL cordovaDeployDisabled;
25
+ @property (nonatomic, readonly) BOOL cordovaDeployDisabled DEPRECATED_MSG_ATTRIBUTE("Always false. The Cordova configuration is not read.");
26
26
  @property (nonatomic, readonly) UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior;
27
27
  @property (nonatomic, readonly, nonnull) NSURL *appLocation;
28
28
  @property (nonatomic, readonly, nullable) NSString *appStartPath;
@@ -13,8 +13,8 @@ typedef NS_OPTIONS(NSUInteger, CAPInstanceWarning) {
13
13
  CAPInstanceWarningMissingAppDir NS_SWIFT_NAME(missingAppDir) = 1 << 0,
14
14
  CAPInstanceWarningMissingFile NS_SWIFT_NAME(missingFile) = 1 << 1,
15
15
  CAPInstanceWarningInvalidFile NS_SWIFT_NAME(invalidFile) = 1 << 2,
16
- CAPInstanceWarningMissingCordovaFile NS_SWIFT_NAME(missingCordovaFile) = 1 << 3,
17
- CAPInstanceWarningInvalidCordovaFile NS_SWIFT_NAME(invalidCordovaFile) = 1 << 4
16
+ CAPInstanceWarningMissingCordovaFile NS_SWIFT_NAME(missingCordovaFile) DEPRECATED_MSG_ATTRIBUTE("Never raised. The Cordova configuration is not read.") = 1 << 3,
17
+ CAPInstanceWarningInvalidCordovaFile NS_SWIFT_NAME(invalidCordovaFile) DEPRECATED_MSG_ATTRIBUTE("Never raised. The Cordova configuration is not read.") = 1 << 4
18
18
  } NS_SWIFT_NAME(InstanceWarning);
19
19
 
20
20
  typedef NS_OPTIONS(NSUInteger, CAPInstanceLoggingBehavior) {
@@ -137,7 +137,7 @@ NS_SWIFT_NAME(InstanceDescriptor)
137
137
  /**
138
138
  @brief The parser used to load the cofiguration for Cordova plugins.
139
139
  */
140
- @property (nonatomic, copy, nonnull) NSObject *cordovaConfiguration;
140
+ @property (nonatomic, copy, nonnull) NSObject *cordovaConfiguration DEPRECATED_MSG_ATTRIBUTE("Never set. The Cordova configuration is not read.");
141
141
  /**
142
142
  @brief Warnings generated during initialization.
143
143
  */
@@ -159,9 +159,9 @@ NS_SWIFT_NAME(InstanceDescriptor)
159
159
  @brief Initialize the descriptor for use in other contexts. The app location is the one required parameter.
160
160
  @param appURL The location of the folder containing the web app.
161
161
  @param configURL The location of the Capacitor configuration file.
162
- @param cordovaURL The location of the Cordova configuration file.
163
162
  */
164
- - (instancetype _Nonnull)initAtLocation:(NSURL* _Nonnull)appURL configuration:(NSURL* _Nullable)configURL cordovaConfiguration:(NSURL* _Nullable)cordovaURL NS_SWIFT_NAME(init(at:configuration:cordovaConfiguration:));
163
+ - (instancetype _Nonnull)initAtLocation:(NSURL* _Nonnull)appURL configuration:(NSURL* _Nullable)configURL NS_SWIFT_NAME(init(at:configuration:));
164
+ - (instancetype _Nonnull)initAtLocation:(NSURL* _Nonnull)appURL configuration:(NSURL* _Nullable)configURL cordovaConfiguration:(NSURL* _Nullable)cordovaURL NS_SWIFT_NAME(init(at:configuration:cordovaConfiguration:)) DEPRECATED_MSG_ATTRIBUTE("The Cordova configuration is not read. Use init(at:configuration:) instead.");
165
165
  @end
166
166
 
167
167
  #endif /* CAPInstanceDescriptor_h */
@@ -1,7 +1,6 @@
1
1
  framework module Capacitor {
2
2
  umbrella header "Capacitor.h"
3
3
  exclude header "CAPBridgedJSTypes.h"
4
- exclude header "CAPBridgeViewController+CDVScreenOrientationDelegate.h"
5
4
 
6
5
  export *
7
6
  module * { export * }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/ios",
3
- "version": "9.0.0-rc.0",
3
+ "version": "9.0.0",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
@@ -25,7 +25,7 @@
25
25
  "xc:test": "cd .. && xcodebuild test -scheme Capacitor-Package -destination 'platform=iOS Simulator,name=iPhone 17,OS=27.0' -collect-test-diagnostics never"
26
26
  },
27
27
  "peerDependencies": {
28
- "@capacitor/core": "^9.0.0-rc.0"
28
+ "@capacitor/core": "^9.0.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"