@capgo/capacitor-inappbrowser 8.10.3-beta.pr621.476.1 → 8.10.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.
|
@@ -2,7 +2,6 @@ import Foundation
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
import WebKit
|
|
4
4
|
import AuthenticationServices
|
|
5
|
-
import SafariServices
|
|
6
5
|
|
|
7
6
|
enum ActiveWebViewSupport {
|
|
8
7
|
static func shouldActivateNewWebView(isHidden: Bool, hasActiveWebView: Bool) -> Bool {
|
|
@@ -256,8 +255,6 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
256
255
|
private var closeModalDescription: String?
|
|
257
256
|
private var closeModalOk: String?
|
|
258
257
|
private var closeModalCancel: String?
|
|
259
|
-
private var safariViewController: SFSafariViewController?
|
|
260
|
-
private var safariOpenedUrl: String?
|
|
261
258
|
private var openSecureWindowCall: CAPPluginCall?
|
|
262
259
|
|
|
263
260
|
private func setup() {
|
|
@@ -2186,6 +2183,12 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2186
2183
|
self.setup()
|
|
2187
2184
|
}
|
|
2188
2185
|
|
|
2186
|
+
let isInspectable = call.getBool("isInspectable", false)
|
|
2187
|
+
let preventDeeplink = call.getBool("preventDeeplink", false)
|
|
2188
|
+
self.isPresentAfterPageLoad = call.getBool("isPresentAfterPageLoad", false)
|
|
2189
|
+
|
|
2190
|
+
self.currentPluginCall = call
|
|
2191
|
+
|
|
2189
2192
|
guard let urlString = call.getString("url") else {
|
|
2190
2193
|
call.reject("Must provide a URL to open")
|
|
2191
2194
|
return
|
|
@@ -2196,42 +2199,70 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2196
2199
|
return
|
|
2197
2200
|
}
|
|
2198
2201
|
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
["http", "https"].contains(scheme) else {
|
|
2202
|
-
call.reject("Must provide a valid http(s) URL to open")
|
|
2203
|
-
return
|
|
2204
|
-
}
|
|
2202
|
+
let headers = call.getObject("headers", [:]).mapValues { String(describing: $0 as Any) }
|
|
2203
|
+
let credentials = self.readCredentials(call)
|
|
2205
2204
|
|
|
2206
2205
|
DispatchQueue.main.async {
|
|
2207
|
-
|
|
2208
|
-
call.reject("
|
|
2206
|
+
guard let webSource = self.webSource(for: urlString) else {
|
|
2207
|
+
call.reject("Invalid URL format")
|
|
2209
2208
|
return
|
|
2210
2209
|
}
|
|
2211
2210
|
|
|
2212
|
-
let
|
|
2213
|
-
safariVC.delegate = self
|
|
2214
|
-
safariVC.modalPresentationStyle = .fullScreen
|
|
2211
|
+
let initialUrl = webSource.remoteURL ?? URL(string: "about:blank")!
|
|
2215
2212
|
|
|
2216
|
-
self.
|
|
2217
|
-
self.safariOpenedUrl = url.absoluteString
|
|
2213
|
+
self.webViewController = WKWebViewController.init(url: initialUrl, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink, blankNavigationTab: true, enabledSafeBottomMargin: false, enabledSafeTopMargin: true)
|
|
2218
2214
|
|
|
2219
|
-
guard let
|
|
2220
|
-
|
|
2221
|
-
self.safariOpenedUrl = nil
|
|
2222
|
-
call.reject("Unable to present Safari View Controller")
|
|
2215
|
+
guard let webViewController = self.webViewController else {
|
|
2216
|
+
call.reject("Failed to initialize WebViewController")
|
|
2223
2217
|
return
|
|
2224
2218
|
}
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2219
|
+
|
|
2220
|
+
if self.bridge?.statusBarVisible == true {
|
|
2221
|
+
let subviews = self.bridge?.webView?.superview?.subviews
|
|
2222
|
+
if let emptyStatusBarIndex = subviews?.firstIndex(where: { $0.subviews.isEmpty }) {
|
|
2223
|
+
if let emptyStatusBar = subviews?[emptyStatusBarIndex] {
|
|
2224
|
+
webViewController.capacitorStatusBar = emptyStatusBar
|
|
2225
|
+
emptyStatusBar.removeFromSuperview()
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2231
2228
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2229
|
+
|
|
2230
|
+
webViewController.source = webSource
|
|
2231
|
+
webViewController.leftNavigationBarItemTypes = [.back, .forward, .reload]
|
|
2232
|
+
webViewController.capBrowserPlugin = self
|
|
2233
|
+
webViewController.hasDynamicTitle = true
|
|
2234
|
+
|
|
2235
|
+
self.navigationWebViewController = UINavigationController.init(rootViewController: webViewController)
|
|
2236
|
+
self.navigationWebViewController?.navigationBar.isTranslucent = false
|
|
2237
|
+
|
|
2238
|
+
// Ensure no lines or borders appear by default
|
|
2239
|
+
self.navigationWebViewController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
|
|
2240
|
+
self.navigationWebViewController?.navigationBar.shadowImage = UIImage()
|
|
2241
|
+
self.navigationWebViewController?.navigationBar.setValue(true, forKey: "hidesShadow")
|
|
2242
|
+
|
|
2243
|
+
// Use system appearance
|
|
2244
|
+
let isDarkMode = UITraitCollection.current.userInterfaceStyle == .dark
|
|
2245
|
+
let backgroundColor = isDarkMode ? UIColor.black : UIColor.white
|
|
2246
|
+
let textColor = isDarkMode ? UIColor.white : UIColor.black
|
|
2247
|
+
|
|
2248
|
+
// Apply colors
|
|
2249
|
+
webViewController.setupStatusBarBackground(color: backgroundColor)
|
|
2250
|
+
webViewController.tintColor = textColor
|
|
2251
|
+
self.navigationWebViewController?.navigationBar.tintColor = textColor
|
|
2252
|
+
self.navigationWebViewController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: textColor]
|
|
2253
|
+
webViewController.statusBarStyle = isDarkMode ? .lightContent : .darkContent
|
|
2254
|
+
webViewController.updateStatusBarStyle()
|
|
2255
|
+
|
|
2256
|
+
// Always hide toolbar to ensure no bottom bar
|
|
2257
|
+
self.navigationWebViewController?.setToolbarHidden(true, animated: false)
|
|
2258
|
+
|
|
2259
|
+
self.navigationWebViewController?.modalPresentationStyle = .overCurrentContext
|
|
2260
|
+
self.navigationWebViewController?.modalTransitionStyle = .crossDissolve
|
|
2261
|
+
|
|
2262
|
+
if !self.isPresentAfterPageLoad {
|
|
2263
|
+
self.presentView()
|
|
2234
2264
|
}
|
|
2265
|
+
call.resolve()
|
|
2235
2266
|
}
|
|
2236
2267
|
}
|
|
2237
2268
|
|
|
@@ -2328,17 +2359,6 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2328
2359
|
let isAnimated = call.getBool("isAnimated", true)
|
|
2329
2360
|
|
|
2330
2361
|
DispatchQueue.main.async {
|
|
2331
|
-
if call.getString("id") == nil, let safariViewController = self.safariViewController {
|
|
2332
|
-
let url = self.safariOpenedUrl ?? ""
|
|
2333
|
-
self.safariViewController = nil
|
|
2334
|
-
self.safariOpenedUrl = nil
|
|
2335
|
-
safariViewController.dismiss(animated: isAnimated) {
|
|
2336
|
-
self.notifyListeners("closeEvent", data: ["url": url])
|
|
2337
|
-
call.resolve()
|
|
2338
|
-
}
|
|
2339
|
-
return
|
|
2340
|
-
}
|
|
2341
|
-
|
|
2342
2362
|
let targetId = call.getString("id") ?? self.activeWebViewId
|
|
2343
2363
|
if let targetId,
|
|
2344
2364
|
let webViewController = self.webViewControllers[targetId],
|
|
@@ -2382,7 +2402,6 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2382
2402
|
}
|
|
2383
2403
|
}
|
|
2384
2404
|
|
|
2385
|
-
|
|
2386
2405
|
private func showPrivacyScreen() {
|
|
2387
2406
|
if privacyScreen == nil {
|
|
2388
2407
|
let newPrivacyScreen = UIImageView()
|
|
@@ -2564,23 +2583,3 @@ extension CapgoInAppBrowserPlugin: ASWebAuthenticationPresentationContextProvidi
|
|
|
2564
2583
|
return self.bridge?.viewController?.view.window ?? ASPresentationAnchor()
|
|
2565
2584
|
}
|
|
2566
2585
|
}
|
|
2567
|
-
|
|
2568
|
-
extension CapgoInAppBrowserPlugin: SFSafariViewControllerDelegate {
|
|
2569
|
-
public func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
|
|
2570
|
-
guard safariViewController != nil else {
|
|
2571
|
-
return
|
|
2572
|
-
}
|
|
2573
|
-
let url = safariOpenedUrl ?? ""
|
|
2574
|
-
safariViewController = nil
|
|
2575
|
-
safariOpenedUrl = nil
|
|
2576
|
-
notifyListeners("closeEvent", data: ["url": url])
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
public func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
|
|
2580
|
-
if didLoadSuccessfully {
|
|
2581
|
-
notifyListeners("browserPageLoaded", data: [:])
|
|
2582
|
-
} else {
|
|
2583
|
-
notifyListeners("pageLoadError", data: [:])
|
|
2584
|
-
}
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
@@ -47,35 +47,6 @@ private enum BlobDownloadSupport {
|
|
|
47
47
|
static let chunkBytes = 64 * 1024
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/// Script message handlers registered on every in-app browser WKWebView.
|
|
51
|
-
/// Popup configs from `createWebViewWith` copy parent handlers, so we must
|
|
52
|
-
/// remove these names before re-adding or WKWebView raises NSInvalidArgumentException.
|
|
53
|
-
enum ScriptMessageHandlerSupport {
|
|
54
|
-
static let allNames = [
|
|
55
|
-
"messageHandler",
|
|
56
|
-
"preShowScriptError",
|
|
57
|
-
"preShowScriptSuccess",
|
|
58
|
-
"close",
|
|
59
|
-
"hide",
|
|
60
|
-
"show",
|
|
61
|
-
"blobDownload",
|
|
62
|
-
"blobDownloadStart",
|
|
63
|
-
"blobDownloadChunk",
|
|
64
|
-
"blobDownloadFinish",
|
|
65
|
-
"blobDownloadAbort",
|
|
66
|
-
"takeScreenshot",
|
|
67
|
-
"consoleMessageHandler",
|
|
68
|
-
"magicPrint",
|
|
69
|
-
"capgoProxyBridge"
|
|
70
|
-
]
|
|
71
|
-
|
|
72
|
-
static func removeAll(from userContentController: WKUserContentController) {
|
|
73
|
-
for name in allNames {
|
|
74
|
-
userContentController.removeScriptMessageHandler(forName: name)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
50
|
private struct BlobDownloadSession {
|
|
80
51
|
let destinationURL: URL
|
|
81
52
|
let sourceURL: String?
|
|
@@ -2037,7 +2008,16 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
2037
2008
|
}
|
|
2038
2009
|
let userContentController = webConfiguration.userContentController
|
|
2039
2010
|
userContentController.removeAllUserScripts()
|
|
2040
|
-
|
|
2011
|
+
userContentController.removeScriptMessageHandler(forName: "messageHandler")
|
|
2012
|
+
userContentController.removeScriptMessageHandler(forName: "preShowScriptError")
|
|
2013
|
+
userContentController.removeScriptMessageHandler(forName: "preShowScriptSuccess")
|
|
2014
|
+
userContentController.removeScriptMessageHandler(forName: "close")
|
|
2015
|
+
userContentController.removeScriptMessageHandler(forName: "hide")
|
|
2016
|
+
userContentController.removeScriptMessageHandler(forName: "show")
|
|
2017
|
+
userContentController.removeScriptMessageHandler(forName: "takeScreenshot")
|
|
2018
|
+
userContentController.removeScriptMessageHandler(forName: "consoleMessageHandler")
|
|
2019
|
+
userContentController.removeScriptMessageHandler(forName: "magicPrint")
|
|
2020
|
+
userContentController.removeScriptMessageHandler(forName: "capgoProxyBridge")
|
|
2041
2021
|
|
|
2042
2022
|
if proxyRequests || proxySchemeHandler != nil, let handler = proxySchemeHandler {
|
|
2043
2023
|
WKWebView.enableCustomSchemeHandling(for: ["https", "http"])
|
|
@@ -2284,9 +2264,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
2284
2264
|
self.enabledSafeTopMargin = parent.enabledSafeTopMargin
|
|
2285
2265
|
self.blockedHosts = parent.blockedHosts
|
|
2286
2266
|
self.authorizedAppLinks = parent.authorizedAppLinks
|
|
2287
|
-
|
|
2288
|
-
// initWebview can register blobDownload/etc without NSInvalidArgumentException.
|
|
2289
|
-
configuration.userContentController = WKUserContentController()
|
|
2267
|
+
self.activeNativeNavigationForWebview = parent.activeNativeNavigationForWebview
|
|
2290
2268
|
self.initialWebConfiguration = configuration
|
|
2291
2269
|
self.persistWebViewData = parent.persistWebViewData
|
|
2292
2270
|
self.disableOverscroll = parent.disableOverscroll
|
|
@@ -2570,7 +2548,20 @@ public extension WKWebViewController {
|
|
|
2570
2548
|
webView.loadHTMLString("", baseURL: nil)
|
|
2571
2549
|
|
|
2572
2550
|
webView.configuration.userContentController.removeAllUserScripts()
|
|
2573
|
-
|
|
2551
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "messageHandler")
|
|
2552
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "close")
|
|
2553
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "hide")
|
|
2554
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "show")
|
|
2555
|
+
if allowScreenshotsFromWebPage {
|
|
2556
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "takeScreenshot")
|
|
2557
|
+
}
|
|
2558
|
+
if captureConsoleLogs {
|
|
2559
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "consoleMessageHandler")
|
|
2560
|
+
}
|
|
2561
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "preShowScriptSuccess")
|
|
2562
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "preShowScriptError")
|
|
2563
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "magicPrint")
|
|
2564
|
+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "capgoProxyBridge")
|
|
2574
2565
|
|
|
2575
2566
|
webView.removeFromSuperview()
|
|
2576
2567
|
// Also clean progress bar view if present
|