@capgo/inappbrowser 8.1.18 → 8.1.20

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.
@@ -1,6 +1,7 @@
1
1
  import Foundation
2
2
  import Capacitor
3
3
  import WebKit
4
+ import AuthenticationServices
4
5
 
5
6
  extension UIColor {
6
7
 
@@ -28,7 +29,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
28
29
  case aware = "AWARE"
29
30
  case fakeVisible = "FAKE_VISIBLE"
30
31
  }
31
- private let pluginVersion: String = "8.1.18"
32
+ private let pluginVersion: String = "8.1.20"
32
33
  public let identifier = "InAppBrowserPlugin"
33
34
  public let jsName = "InAppBrowser"
34
35
  public let pluginMethods: [CAPPluginMethod] = [
@@ -47,7 +48,8 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
47
48
  CAPPluginMethod(name: "executeScript", returnType: CAPPluginReturnPromise),
48
49
  CAPPluginMethod(name: "postMessage", returnType: CAPPluginReturnPromise),
49
50
  CAPPluginMethod(name: "updateDimensions", returnType: CAPPluginReturnPromise),
50
- CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
51
+ CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise),
52
+ CAPPluginMethod(name: "openSecureWindow", returnType: CAPPluginReturnPromise),
51
53
  ]
52
54
  var navigationWebViewController: UINavigationController?
53
55
  private var navigationControllers: [String: UINavigationController] = [:]
@@ -68,6 +70,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
68
70
  private var closeModalDescription: String?
69
71
  private var closeModalOk: String?
70
72
  private var closeModalCancel: String?
73
+ private var openSecureWindowCall: CAPPluginCall?
71
74
 
72
75
  private func setup() {
73
76
  self.isSetupDone = true
@@ -195,8 +198,12 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
195
198
  ? webViewController.view.safeAreaLayoutGuide.bottomAnchor
196
199
  : webViewController.view.bottomAnchor
197
200
 
201
+ let topAnchor = webViewController.enabledSafeTopMargin
202
+ ? webViewController.view.safeAreaLayoutGuide.topAnchor
203
+ : webViewController.view.topAnchor
204
+
198
205
  NSLayoutConstraint.activate([
199
- webView.topAnchor.constraint(equalTo: webViewController.view.safeAreaLayoutGuide.topAnchor),
206
+ webView.topAnchor.constraint(equalTo: topAnchor),
200
207
  webView.leadingAnchor.constraint(equalTo: webViewController.view.leadingAnchor),
201
208
  webView.trailingAnchor.constraint(equalTo: webViewController.view.trailingAnchor),
202
209
  webView.bottomAnchor.constraint(equalTo: bottomAnchor)
@@ -494,6 +501,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
494
501
  let preventDeeplink = call.getBool("preventDeeplink", false)
495
502
  let isAnimated = call.getBool("isAnimated", true)
496
503
  let enabledSafeBottomMargin = call.getBool("enabledSafeBottomMargin", false)
504
+ let enabledSafeTopMargin = call.getBool("enabledSafeTopMargin", true)
497
505
  let hidden = call.getBool("hidden", false)
498
506
  self.isHidden = hidden
499
507
  let allowWebViewJsVisibilityControl = self.getConfig().getBoolean("allowWebViewJsVisibilityControl", false)
@@ -572,6 +580,10 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
572
580
 
573
581
  let credentials = self.readCredentials(call)
574
582
 
583
+ // Read HTTP method and body for custom requests
584
+ let httpMethod = call.getString("method")
585
+ let httpBody = call.getString("body")
586
+
575
587
  // Read dimension options
576
588
  let width = call.getFloat("width")
577
589
  let height = call.getFloat("height")
@@ -601,6 +613,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
601
613
  preventDeeplink: preventDeeplink,
602
614
  blankNavigationTab: toolbarType == "blank",
603
615
  enabledSafeBottomMargin: enabledSafeBottomMargin,
616
+ enabledSafeTopMargin: enabledSafeTopMargin,
604
617
  blockedHosts: blockedHosts,
605
618
  authorizedAppLinks: authorizedAppLinks,
606
619
  )
@@ -614,6 +627,14 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
614
627
  webViewController.instanceId = webViewId
615
628
  webViewController.allowWebViewJsVisibilityControl = allowWebViewJsVisibilityControl
616
629
 
630
+ // Set HTTP method and body if provided
631
+ if let method = httpMethod {
632
+ webViewController.httpMethod = method
633
+ }
634
+ if let body = httpBody {
635
+ webViewController.httpBody = body
636
+ }
637
+
617
638
  // Set dimensions if provided
618
639
  if let width = width {
619
640
  webViewController.customWidth = CGFloat(width)
@@ -1154,7 +1175,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
1154
1175
  return
1155
1176
  }
1156
1177
 
1157
- self.webViewController = WKWebViewController.init(url: url, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink, blankNavigationTab: true, enabledSafeBottomMargin: false)
1178
+ self.webViewController = WKWebViewController.init(url: url, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink, blankNavigationTab: true, enabledSafeBottomMargin: false, enabledSafeTopMargin: true)
1158
1179
 
1159
1180
  guard let webViewController = self.webViewController else {
1160
1181
  call.reject("Failed to initialize WebViewController")
@@ -1336,4 +1357,62 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
1336
1357
  }
1337
1358
  }
1338
1359
 
1360
+ @objc func openSecureWindow(_ call: CAPPluginCall) {
1361
+ guard let urlString = call.getString("authEndpoint") else {
1362
+ call.reject("authEndpoint is required")
1363
+ return
1364
+ }
1365
+
1366
+ guard let url = URL(string: urlString) else {
1367
+ call.reject("Invalid URL")
1368
+ return
1369
+ }
1370
+
1371
+ guard let redirectUri = call.getString("redirectUri") else {
1372
+ call.reject("Redirect URI is required")
1373
+ return
1374
+ }
1375
+
1376
+ // Store the call for later resolution
1377
+ self.openSecureWindowCall = call
1378
+
1379
+ // Open the URL in a secure browser window
1380
+ DispatchQueue.main.async {
1381
+ let session = ASWebAuthenticationSession(url: url, callbackURLScheme: url.scheme) {
1382
+ callbackURL, error in
1383
+
1384
+ // Clean up the stored call
1385
+ self.openSecureWindowCall = nil
1386
+
1387
+ if let error = error {
1388
+ // Handle error (e.g., user cancelled)
1389
+ call.reject(error.localizedDescription)
1390
+ return
1391
+ }
1392
+
1393
+ guard let callbackURL = callbackURL else {
1394
+ call.reject("No callback URL received")
1395
+ return
1396
+ }
1397
+
1398
+ if !callbackURL.absoluteString.hasPrefix(redirectUri) {
1399
+ call.reject("Redirect URI does not match, expected " + redirectUri + " but got " + callbackURL.absoluteString)
1400
+ return
1401
+ }
1402
+
1403
+ // Resolve the call with the callback URL
1404
+ call.resolve(["redirectedUri": callbackURL.absoluteString])
1405
+ }
1406
+
1407
+ // Present the session
1408
+ session.presentationContextProvider = self
1409
+ session.start()
1410
+ }
1411
+ }
1412
+ }
1413
+
1414
+ extension InAppBrowserPlugin: ASWebAuthenticationPresentationContextProviding {
1415
+ public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
1416
+ return self.bridge?.viewController?.view.window ?? ASPresentationAnchor()
1417
+ }
1339
1418
  }
@@ -76,10 +76,11 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
76
76
  self.initWebview(isInspectable: isInspectable)
77
77
  }
78
78
 
79
- public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool, enabledSafeBottomMargin: Bool) {
79
+ public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool, enabledSafeBottomMargin: Bool, enabledSafeTopMargin: Bool = true) {
80
80
  super.init(nibName: nil, bundle: nil)
81
81
  self.blankNavigationTab = blankNavigationTab
82
82
  self.enabledSafeBottomMargin = enabledSafeBottomMargin
83
+ self.enabledSafeTopMargin = enabledSafeTopMargin
83
84
  self.source = .remote(url)
84
85
  self.credentials = credentials
85
86
  self.setHeaders(headers: headers)
@@ -87,10 +88,11 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
87
88
  self.initWebview(isInspectable: isInspectable)
88
89
  }
89
90
 
90
- public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool, enabledSafeBottomMargin: Bool, blockedHosts: [String]) {
91
+ public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool, enabledSafeBottomMargin: Bool, enabledSafeTopMargin: Bool = true, blockedHosts: [String]) {
91
92
  super.init(nibName: nil, bundle: nil)
92
93
  self.blankNavigationTab = blankNavigationTab
93
94
  self.enabledSafeBottomMargin = enabledSafeBottomMargin
95
+ self.enabledSafeTopMargin = enabledSafeTopMargin
94
96
  self.source = .remote(url)
95
97
  self.credentials = credentials
96
98
  self.setHeaders(headers: headers)
@@ -99,10 +101,11 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
99
101
  self.initWebview(isInspectable: isInspectable)
100
102
  }
101
103
 
102
- public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool, enabledSafeBottomMargin: Bool, blockedHosts: [String], authorizedAppLinks: [String]) {
104
+ public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool, enabledSafeBottomMargin: Bool, enabledSafeTopMargin: Bool = true, blockedHosts: [String], authorizedAppLinks: [String]) {
103
105
  super.init(nibName: nil, bundle: nil)
104
106
  self.blankNavigationTab = blankNavigationTab
105
107
  self.enabledSafeBottomMargin = enabledSafeBottomMargin
108
+ self.enabledSafeTopMargin = enabledSafeTopMargin
106
109
  self.source = .remote(url)
107
110
  self.credentials = credentials
108
111
  self.setHeaders(headers: headers)
@@ -123,6 +126,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
123
126
  open var bypassedSSLHosts: [String]?
124
127
  open var cookies: [HTTPCookie]?
125
128
  open var headers: [String: String]?
129
+ open var httpMethod: String?
130
+ open var httpBody: String?
126
131
  open var capBrowserPlugin: InAppBrowserPlugin?
127
132
  var instanceId: String = ""
128
133
  var shareDisclaimer: [String: Any]?
@@ -143,6 +148,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
143
148
  var blankNavigationTab: Bool = false
144
149
  var capacitorStatusBar: UIView?
145
150
  var enabledSafeBottomMargin: Bool = false
151
+ var enabledSafeTopMargin: Bool = true
146
152
  var blockedHosts: [String] = []
147
153
  var authorizedAppLinks: [String] = []
148
154
  var activeNativeNavigationForWebview: Bool = true
@@ -731,17 +737,22 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
731
737
 
732
738
  // Then set up constraints
733
739
  webView.translatesAutoresizingMaskIntoConstraints = false
734
- var bottomPadding = self.view.bottomAnchor
740
+ var bottomAnchor = self.view.bottomAnchor
741
+ var topAnchor = self.view.safeAreaLayoutGuide.topAnchor
735
742
 
736
743
  if self.enabledSafeBottomMargin {
737
- bottomPadding = self.view.safeAreaLayoutGuide.bottomAnchor
744
+ bottomAnchor = self.view.safeAreaLayoutGuide.bottomAnchor
745
+ }
746
+
747
+ if !self.enabledSafeTopMargin {
748
+ topAnchor = self.view.topAnchor
738
749
  }
739
750
 
740
751
  NSLayoutConstraint.activate([
741
- webView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
752
+ webView.topAnchor.constraint(equalTo: topAnchor),
742
753
  webView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
743
754
  webView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
744
- webView.bottomAnchor.constraint(equalTo: bottomPadding)
755
+ webView.bottomAnchor.constraint(equalTo: bottomAnchor)
745
756
  ])
746
757
 
747
758
  webView.uiDelegate = self
@@ -1079,6 +1090,16 @@ fileprivate extension WKWebViewController {
1079
1090
  func createRequest(url: URL) -> URLRequest {
1080
1091
  var request = URLRequest(url: url)
1081
1092
 
1093
+ // Set up HTTP method if specified
1094
+ if let method = httpMethod {
1095
+ request.httpMethod = method.uppercased()
1096
+ }
1097
+
1098
+ // Set up HTTP body if specified
1099
+ if let body = httpBody, let data = body.data(using: .utf8) {
1100
+ request.httpBody = data
1101
+ }
1102
+
1082
1103
  // Set up headers
1083
1104
  if let headers = headers {
1084
1105
  for (field, value) in headers {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "8.1.18",
3
+ "version": "8.1.20",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",