mirror of
https://github.com/undeaDD/FakeWebKit.git
synced 2026-03-11 10:50:21 +01:00
safely wrap for tvOS only
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import UIKit
|
||||
#if os(tvOS)
|
||||
import UIKit
|
||||
|
||||
// MARK: - ✅ - Cookie + DataStore
|
||||
// MARK: - ✅ - Cookie + DataStore
|
||||
|
||||
public struct WKCookie {
|
||||
public struct WKCookie {
|
||||
public let name: String
|
||||
public let value: String
|
||||
}
|
||||
}
|
||||
|
||||
public class WKCookieStore {
|
||||
public class WKCookieStore {
|
||||
fileprivate let cookieStorage = HTTPCookieStorage.shared
|
||||
|
||||
public func getAllCookies(_ callback: ([WKCookie]) -> Void) {
|
||||
@@ -26,32 +27,32 @@ public class WKCookieStore {
|
||||
cookieStorage.setCookie(httpCookie)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct WKDataStore {
|
||||
public struct WKDataStore {
|
||||
public let httpCookieStore = WKCookieStore()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ✅ - Script Message Handler
|
||||
// MARK: - ✅ - Script Message Handler
|
||||
|
||||
public struct WKScriptMessage {
|
||||
public struct WKScriptMessage {
|
||||
public let name: String
|
||||
public let body: AnyObject
|
||||
}
|
||||
}
|
||||
|
||||
public protocol WKScriptMessageHandler : NSObjectProtocol {
|
||||
public protocol WKScriptMessageHandler : NSObjectProtocol {
|
||||
func userContentController(_ userContentController: WKUserContentController,
|
||||
didReceive message: WKScriptMessage)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ✅ - User Scripts + Messaging
|
||||
// MARK: - ✅ - User Scripts + Messaging
|
||||
|
||||
public enum WKUserScriptInjectionTime {
|
||||
public enum WKUserScriptInjectionTime {
|
||||
case atDocumentStart
|
||||
case atDocumentEnd
|
||||
}
|
||||
}
|
||||
|
||||
public struct WKUserScript {
|
||||
public struct WKUserScript {
|
||||
public let source: String
|
||||
public let injectionTime: WKUserScriptInjectionTime
|
||||
public let forMainFrameOnly: Bool
|
||||
@@ -61,9 +62,9 @@ public struct WKUserScript {
|
||||
self.injectionTime = injectionTime
|
||||
self.forMainFrameOnly = forMainFrameOnly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class WKUserContentController {
|
||||
public class WKUserContentController {
|
||||
fileprivate weak var owner: WKWebView?
|
||||
fileprivate var scripts: [WKUserScript] = []
|
||||
fileprivate var scriptMessageHandlers: [String : WKScriptMessageHandler] = [:]
|
||||
@@ -81,11 +82,11 @@ public class WKUserContentController {
|
||||
scriptMessageHandlers[name] = scriptMessageHandler
|
||||
owner?._updateJSBridgeBindings()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ✅ - Configuration
|
||||
// MARK: - ✅ - Configuration
|
||||
|
||||
public class WKWebViewConfiguration {
|
||||
public class WKWebViewConfiguration {
|
||||
public init() {}
|
||||
|
||||
public var websiteDataStore = WKDataStore()
|
||||
@@ -125,46 +126,46 @@ public class WKWebViewConfiguration {
|
||||
"mediaTypesRequiringUserActionForPlayback must be empty")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ✅ - Navigation + Delegates
|
||||
// MARK: - ✅ - Navigation + Delegates
|
||||
|
||||
public struct WKNavigation {
|
||||
public struct WKNavigation {
|
||||
@available(*, unavailable, message: "The effectiveContentMode property is not supported.")
|
||||
public var effectiveContentMode: Any {
|
||||
fatalError("This property is unavailable.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct WKNavigationAction: Sendable {
|
||||
public struct WKNavigationAction: Sendable {
|
||||
public let request: URLRequest
|
||||
|
||||
@available(*, unavailable, message: "The navigationType property is not supported.")
|
||||
public var navigationType: Any {
|
||||
fatalError("This property is unavailable.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum WKNavigationActionPolicy: Sendable {
|
||||
public enum WKNavigationActionPolicy: Sendable {
|
||||
case allow
|
||||
case cancel
|
||||
|
||||
@available(*, unavailable, message: "The .download policy is not supported.")
|
||||
case download
|
||||
}
|
||||
}
|
||||
|
||||
public protocol WKNavigationDelegate : NSObjectProtocol {
|
||||
public protocol WKNavigationDelegate : NSObjectProtocol {
|
||||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation)
|
||||
func webView(_ webView: WKWebView, didFail navigation: WKNavigation, withError error: Error)
|
||||
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction,
|
||||
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)
|
||||
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ✅ - WKWebView ( without WebKit )
|
||||
// MARK: - ✅ - WKWebView ( without WebKit )
|
||||
|
||||
public class WKWebView: UIView {
|
||||
public class WKWebView: UIView {
|
||||
fileprivate var _webView: AnyObject?
|
||||
fileprivate var _delegateProxy: _DelegateProxy?
|
||||
public static var logger: DebugLogger?
|
||||
@@ -271,19 +272,19 @@ public class WKWebView: UIView {
|
||||
completionHandler?(result?.takeUnretainedValue(), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Internal Helper Functions
|
||||
// MARK: Internal Helper Functions
|
||||
|
||||
public protocol DebugLogger {
|
||||
public protocol DebugLogger {
|
||||
func log(_ message: String)
|
||||
func logError(_ message: String)
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
func sel(_ name: String) -> Selector { Selector(name) }
|
||||
@inlinable
|
||||
func sel(_ name: String) -> Selector { Selector(name) }
|
||||
|
||||
fileprivate extension WKWebView {
|
||||
fileprivate extension WKWebView {
|
||||
|
||||
@inline(never)
|
||||
func getInternalClassName() -> [String] {
|
||||
@@ -392,10 +393,10 @@ fileprivate extension WKWebView {
|
||||
WKWebView.logger?.log("JSBridge message received for '\(handlerName)'")
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
fileprivate class _DelegateProxy: NSObject {
|
||||
@objc
|
||||
fileprivate class _DelegateProxy: NSObject {
|
||||
fileprivate weak var owner: WKWebView?
|
||||
|
||||
init(owner: WKWebView) {
|
||||
@@ -509,4 +510,5 @@ fileprivate class _DelegateProxy: NSObject {
|
||||
WKWebView.logger?.log("Decision: \(decision == .allow ? "ALLOW" : "CANCEL")")
|
||||
return decision == .allow
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user